:root {
  --grey: #6b7280;      /* page background around the board */
  --panel: #12161d;
  --border: #2a313c;
  --text: #e8ecf1;
  --muted: #9aa4b2;
  --accent: #e63946;
  --ok: #2a9d8f;
  --shadow: 0 -10px 40px rgba(0, 0, 0, 0.5);
  --pad: max(12px, env(safe-area-inset-bottom));
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--grey);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ── Stage / canvas ───────────────────────── */
.stage { position: fixed; inset: 0; }
#board {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  display: block;
  cursor: crosshair;
  touch-action: none;
}

/* ── Bottom bar (shown once a pixel is selected) ── */
.bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 25;
  background: var(--panel);
  border-top: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  box-shadow: var(--shadow);
  padding: 12px 12px var(--pad);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Row 1 — square colour swatches, horizontal scroll */
.swatches {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}
.swatches::-webkit-scrollbar { display: none; }
.swatches button {
  flex: 0 0 auto;
  width: 34px; height: 34px;
  border-radius: 4px;
  border: 2px solid rgba(255, 255, 255, 0.14);
  cursor: pointer; padding: 0;
}
.swatches button.active { border-color: #fff; transform: scale(1.05); }

/* First swatch = custom colour: just the gradient favicon, rounded, no border. */
.swatches button.custom {
  background: url(/favicon.png) center/cover;
  border: none;
  border-radius: 6px;
}
.swatches button.custom.active { transform: none; }

/* ── Colour-picker modal ──────────────────── */
.picker-card { width: min(340px, 100%); }
.picker-card h2 { margin: 0 0 12px; font-size: 17px; }
.sv-wrap { position: relative; touch-action: none; }
.sv-box { display: block; width: 100%; height: 160px; border-radius: 10px; cursor: crosshair; }
.sv-handle {
  position: absolute; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,0.5);
  transform: translate(-50%, -50%); pointer-events: none;
}
.hue-slider {
  position: relative; height: 16px; margin: 14px 0; border-radius: 999px; touch-action: none;
  cursor: pointer;
  background: linear-gradient(to right, #f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00);
}
.hue-handle {
  position: absolute; top: 50%; width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,0.5); background: transparent;
  transform: translate(-50%, -50%); pointer-events: none;
}
.picker-row { display: flex; gap: 8px; align-items: center; }
.picker-preview {
  flex: 0 0 auto; width: 44px; height: 44px; border-radius: 9px;
  border: 1px solid var(--border);
}
.picker-row .hex {
  flex: 1 1 0; min-width: 0;
  padding: 12px; font-size: 15px; font-family: ui-monospace, monospace;
  background: #0e1116; color: var(--text);
  border: 1px solid var(--border); border-radius: 9px;
}
.picker-row .hex:focus { outline: none; border-color: var(--accent); }
.picker-row .primary { flex: 0 0 auto; padding: 12px 18px; }

.bar-title {
  margin: 0 0 1px;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: var(--text);
  text-align: center;
}
.bar-hint {
  margin: 0 0 4px;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

/* Row 2 — Clear + Buy */
.actions { display: flex; gap: 8px; }
button.primary, button.ghost {
  border-radius: 11px; padding: 13px 12px; font-size: 15px; font-weight: 700;
  cursor: pointer; border: 1px solid transparent; white-space: nowrap;
}
button.ghost { background: transparent; color: var(--muted); border-color: var(--border); flex: 0 0 auto; padding-inline: 18px; }
button.primary { flex: 1 1 0; background: var(--accent); color: #fff; }
button.primary:active:not(:disabled) { transform: scale(0.99); }
button:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Desktop: dock the bar as a centered card ── */
@media (min-width: 768px) {
  .bar {
    left: 50%; right: auto; bottom: 18px;
    transform: translateX(-50%);
    width: min(460px, calc(100vw - 36px));
    border-radius: 16px;
    border: 1px solid var(--border);
    padding: 14px;
  }
}

/* ── Buy modal ────────────────────────────── */
.modal {
  position: fixed; left: 0; right: 0; top: 0; z-index: 60;
  height: 100dvh; /* JS narrows this to visualViewport when the keyboard opens */
  background: rgba(0, 0, 0, 0.55);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  overflow-y: auto;
}
.modal-card {
  width: min(400px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}
.modal-card h2 { margin: 0 0 4px; font-size: 19px; }
.modal-sub { margin: 0 0 16px; font-size: 13px; color: var(--muted); }
.field { display: block; margin-bottom: 12px; }
.field span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.field input {
  width: 100%; padding: 11px 12px; font-size: 15px;
  background: #0e1116; color: var(--text);
  border: 1px solid var(--border); border-radius: 9px;
}
.field input:focus { outline: none; border-color: var(--accent); }
.modal-err { margin: 0 0 10px; font-size: 12px; color: var(--accent); min-height: 14px; }
.modal-actions { display: flex; gap: 8px; }
.modal-actions .primary { flex: 1 1 0; }

/* ── Owned-pixel tooltip (anchored bottom-right of the pixel by JS) ── */
.tooltip {
  position: fixed; z-index: 40;
  min-width: 44px; max-width: 260px;
  background: #0e1116;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}
.tt-desc { margin: 0 0 6px; font-size: 13px; word-break: break-word; }
.tt-link { font-size: 12px; color: #7cc4ff; word-break: break-all; }

.spinner {
  width: 20px; height: 20px; margin: 2px auto;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toast ────────────────────────────────── */
.toast {
  position: fixed; left: 50%; bottom: 24px;
  transform: translateX(-50%) translateY(16px);
  z-index: 50;
  background: #22262e; color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 16px; font-size: 13px; box-shadow: 0 8px 30px rgba(0,0,0,0.45);
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; max-width: 84vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.ok { border-color: var(--ok); }
.toast.err { border-color: var(--accent); }
