:root {
  color-scheme: light;
  --ink: #111827;
  --muted: #667085;
  --paper: #f4f7f6;
  --panel: #ffffff;
  --line: #d7dfdc;
  --gram: #138a72;
  --gram-dark: #0b5f50;
  --blue: #255a8f;
  --danger: #b42318;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

.page {
  display: grid;
  min-height: 100vh;
  align-content: start;
  justify-items: center;
  gap: clamp(18px, 4vw, 34px);
  padding: clamp(20px, 4vw, 48px);
}

h1 {
  margin: 0;
  text-align: center;
  font-size: clamp(2.8rem, 8vw, 7rem);
  line-height: 0.95;
  letter-spacing: 0;
}

.page-header {
  display: grid;
  justify-items: center;
  gap: 10px;
}

.tagline {
  margin: 0;
  color: var(--muted);
  font-size: clamp(1rem, 2vw, 1.25rem);
  font-weight: 850;
  line-height: 1.25;
  text-align: center;
}

.canvas-board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  width: min(100%, 1600px);
  overflow: hidden;
}

.canvas-frame {
  border: 1px solid #bfc9c5;
  background: #fff;
}

.contact-footer {
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 800;
}

.contact-footer-desktop {
  position: fixed;
  right: 18px;
  bottom: 14px;
  z-index: 5;
}

.contact-footer-mobile {
  display: none;
}

.contact-footer a {
  color: inherit;
  text-decoration-color: rgba(102, 112, 133, 0.5);
  text-underline-offset: 3px;
}

.contact-footer a:hover {
  color: var(--gram-dark);
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 400 / 625;
  background: #fff;
  image-rendering: pixelated;
  cursor: crosshair;
}

.selection-marker {
  position: absolute;
  inset: 0;
  display: none;
  pointer-events: none;
}

.selection-marker.is-visible {
  display: block;
}

.canvas-loader {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  color: var(--gram-dark);
  background: rgba(255, 255, 255, 0.86);
  font-weight: 900;
}

.canvas-loader.is-hidden {
  display: none;
}

.loader-cell {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  min-width: 0;
  text-align: center;
}

.loader-spinner {
  width: 42px;
  height: 42px;
  border: 4px solid rgba(19, 138, 114, 0.22);
  border-top-color: var(--gram);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.selection-fragment {
  position: absolute;
  width: 9px;
  height: 9px;
  border: 2px solid var(--danger);
  border-radius: 2px;
  box-shadow: 0 0 0 1px #fff;
  transform: translate(-4px, -4px);
}

.selection-marker.is-image .selection-fragment {
  border-color: var(--blue);
  background: rgba(37, 90, 143, 0.12);
  transform: none;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 20;
  max-width: min(520px, calc(100vw - 28px));
  margin: 0;
  border-radius: 6px;
  padding: 12px 14px;
  color: #fff;
  background: rgba(17, 24, 39, 0.92);
  font-weight: 800;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.buy-dialog {
  position: fixed;
  z-index: 30;
  width: min(430px, calc(100vw - 28px));
  max-height: calc(100vh - 28px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  color: var(--ink);
  background: var(--panel);
  box-shadow: 0 24px 70px rgba(17, 24, 39, 0.22);
}

.buy-dialog.is-dragging {
  user-select: none;
}

.buy-dialog::backdrop {
  background: rgba(17, 24, 39, 0.18);
}

.first-visit-dialog {
  width: min(430px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  color: var(--ink);
  background: var(--panel);
  box-shadow: 0 24px 70px rgba(17, 24, 39, 0.22);
}

.first-visit-dialog::backdrop {
  background: rgba(17, 24, 39, 0.24);
}

.first-visit-shell {
  display: grid;
  gap: 18px;
  padding: 20px;
}

.first-visit-copy h2 {
  margin: 0;
  font-size: 1.55rem;
  line-height: 1.1;
}

.first-visit-copy p:last-child {
  margin: 10px 0 0;
  color: var(--muted);
  font-weight: 800;
  line-height: 1.45;
}

.dialog-shell {
  display: grid;
}

.dialog-header,
.panel-section {
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.dialog-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  cursor: move;
  touch-action: none;
  user-select: none;
}

.dialog-header h2 {
  margin: 0;
  font-size: 1.5rem;
  line-height: 1.1;
}

.panel-section:last-child {
  border-bottom: 0;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--gram-dark);
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.icon-button {
  display: inline-grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: #fff;
  font-weight: 900;
  cursor: pointer;
}

.is-hidden {
  display: none;
}

.mode-control {
  display: grid;
  gap: 8px;
}

.mode-control label {
  display: flex;
  min-height: 42px;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
  background: #f8faf9;
  font-weight: 900;
  cursor: pointer;
}

.mode-control input {
  width: 16px;
  height: 16px;
  accent-color: var(--gram);
}

.field-label {
  display: grid;
  gap: 10px;
  color: var(--muted);
  font-weight: 900;
}

input[type="color"] {
  width: 100%;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px;
  background: #fff;
  cursor: pointer;
}

input[type="file"] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  background: #fff;
  color: var(--ink);
}

.coordinate-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.coordinate-control {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-weight: 900;
}

.coordinate-control input[type="number"] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  color: var(--ink);
  background: #fff;
  font-weight: 800;
}

.coordinate-control input[type="range"] {
  width: 100%;
  accent-color: var(--gram);
}

.image-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}

.image-summary span,
.price-row {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8faf9;
}

.image-summary span {
  display: grid;
  gap: 6px;
  padding: 12px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
}

.image-summary strong {
  color: var(--ink);
  font-size: 1rem;
}

.hint,
.status {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
}

.price-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  padding: 14px;
  color: var(--muted);
  font-weight: 900;
}

.price-row strong {
  color: var(--gram-dark);
  font-size: 1.35rem;
}

.ton-connect {
  display: flex;
  justify-content: center;
  margin-bottom: 12px;
}

.ton-connect-error {
  border: 1px solid rgba(180, 35, 24, 0.28);
  border-radius: 6px;
  padding: 10px 12px;
  color: var(--danger);
  background: #fff4f2;
  font-size: 0.9rem;
  font-weight: 800;
  line-height: 1.35;
  text-align: center;
}

.fake-payment-control {
  display: flex;
  min-height: 38px;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
  background: #fff8e6;
  color: #7a4d00;
  font-weight: 900;
}

.fake-payment-control.is-hidden {
  display: none;
}

.fake-payment-control input {
  width: 16px;
  height: 16px;
  accent-color: #b7791f;
}

.buy-button {
  display: inline-flex;
  width: 100%;
  min-height: 46px;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0 16px;
  color: #fff;
  background: var(--gram);
  font-weight: 900;
  cursor: pointer;
}

.buy-button:hover {
  background: var(--gram-dark);
}

.buy-button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.buy-button:focus-visible,
.icon-button:focus-visible,
.coordinate-control input:focus-visible,
canvas:focus-visible {
  outline: 3px solid rgba(37, 90, 143, 0.34);
  outline-offset: 2px;
}

@media (max-width: 520px) {
  .page {
    padding: 18px 12px;
  }

  .canvas-board {
    grid-template-columns: 1fr;
  }

  .contact-footer-desktop {
    display: none;
  }

  .contact-footer-mobile {
    display: block;
    width: 100%;
    margin-top: -8px;
    text-align: right;
  }

  .canvas-loader {
    grid-template-columns: 1fr;
  }

  .image-summary,
  .coordinate-controls {
    grid-template-columns: 1fr;
  }
}
