/* Spectrum — mobile-first daily ordering puzzle */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --tile: #ffffff;
  --tile-border: #d9dee5;
  --ink: #131720;
  --ink-soft: #5c6673;
  --ink-faint: #97a1ae;
  --accent: #2f6df6;
  --correct: #2f9e5f;
  --correct-bg: #e6f5ec;
  --wrong-bg: #ffffff;
  --shadow: 0 1px 2px rgba(16, 22, 34, .08), 0 4px 14px rgba(16, 22, 34, .06);
  --shadow-lift: 0 10px 28px rgba(16, 22, 34, .22);
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --surface: #171c23;
    --tile: #1c222b;
    --tile-border: #2c3540;
    --ink: #eef2f7;
    --ink-soft: #9aa5b3;
    --ink-faint: #6b7684;
    --accent: #5c8dff;
    --correct: #43c17f;
    --correct-bg: #16342a;
    --wrong-bg: #1c222b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-lift: 0 10px 28px rgba(0, 0, 0, .55);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI",
               Roboto, "Helvetica Neue", sans-serif;
  -webkit-text-size-adjust: 100%;
  /* Android paints a tap highlight over whatever you touch, tinted from the
     system accent — green on a stock Samsung — which read as part of the
     button's shake. Inherited, so setting it here covers everything. */
  -webkit-tap-highlight-color: transparent;
}

button {
  touch-action: manipulation;   /* no 300ms double-tap-zoom wait */
  -webkit-user-select: none;
  user-select: none;
}

/* Keep a focus ring for keyboards, drop the one a tap leaves behind. */
button:focus { outline: none; }
button:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
}

body {
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ---------- top bar ---------- */
.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  max-width: 520px;
  margin: 0 auto;
  padding: 7px 14px;
  border-bottom: 1px solid var(--tile-border);
}

.topbar-side { display: flex; align-items: center; gap: 2px; }
.topbar-side.end { justify-self: end; }

.wordmark {
  margin: 0;
  text-align: center;
  font-size: 19px;
  font-weight: 800;
  letter-spacing: .22em;
  text-indent: .22em;
}
/* The game's own icon, sitting with the wordmark. letter-spacing is reset so
   the wordmark's tracking does not push the glyph away from the text. */
.mark {
  font-size: 17px;
  letter-spacing: 0;
  margin-right: 9px;
  vertical-align: -1px;
}

.icon-btn {
  width: 32px; height: 32px;
  border: 0; border-radius: 50%;
  background: transparent;
  color: var(--ink-soft);
  font-size: 17px;
  cursor: pointer;
}
.icon-btn:active { background: var(--tile-border); }

/* The back link wears the same chrome as the buttons beside it. */
a.icon-btn {
  display: grid;
  place-items: center;
  text-decoration: none;
}

/* ---------- game ---------- */
#game {
  max-width: 520px;
  margin: 0 auto;
  padding: 12px 16px 18px;
}

.puzzle-no {
  margin: 0;
  text-align: center;
  font-size: 12px;
  letter-spacing: .1em;
  color: var(--ink-faint);
  text-transform: uppercase;
}

.category {
  margin: 9px 0 3px;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .13em;
  text-transform: uppercase;
  color: var(--accent);
}

.prompt {
  margin: 0 0 12px;
  text-align: center;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.3;
  text-wrap: balance;
}

.scale-label {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .11em;
  text-transform: uppercase;
  color: var(--ink-soft);
  display: flex;
  align-items: center;
  gap: 10px;
}
.scale-label::before,
.scale-label::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--tile-border);
}
.scale-top { margin-bottom: 8px; }
.scale-bottom { margin-top: 8px; }

/* ---------- direction reveal ----------
   Play-testers ordered a puzzle backwards, so the scale is shown on its own
   first and the tiles arrive afterwards. Direction before options. */
.board {
  position: relative;
  width: fit-content;
  min-width: min(100%, 270px);
  max-width: 100%;
  margin-inline: auto;
}

/* The tile list collapses to nothing via grid rows, which animates cleanly and
   lets the bottom scale label ride down as the cards arrive. */
.tiles-wrap {
  display: grid;
  grid-template-rows: 1fr;
}
.board.intro .tiles-wrap { grid-template-rows: 0fr; }
.board.revealing .tiles-wrap {
  grid-template-rows: 1fr;
  transition: grid-template-rows .8s cubic-bezier(.2, .8, .3, 1);
}
/* Only clip while opening — a dragged tile must not be cut off mid-play. */
.board.intro .tiles,
.board.revealing .tiles { overflow: hidden; min-height: 0; }
.board.intro .tiles { opacity: 0; }

.dir-arrow {
  margin: 4px 0;
  text-align: center;
  font-size: 40px;
  line-height: 1;
  color: var(--accent);
  animation: arrowNudge 1.05s ease-in-out infinite;
}
.dir-arrow[hidden] { display: none; }

@keyframes arrowNudge {
  0%, 100% { transform: translateY(-4px); opacity: .75; }
  50%      { transform: translateY(6px);  opacity: 1; }
}

/* Tiles stagger in as the board opens. */
.board.revealing .tile { animation: tileIn .5s cubic-bezier(.2, .8, .3, 1) backwards; }
.board.revealing .tile:nth-child(1) { animation-delay: 0ms; }
.board.revealing .tile:nth-child(2) { animation-delay: 80ms; }
.board.revealing .tile:nth-child(3) { animation-delay: 160ms; }
.board.revealing .tile:nth-child(4) { animation-delay: 240ms; }
.board.revealing .tile:nth-child(5) { animation-delay: 320ms; }
.board.revealing .tile:nth-child(6) { animation-delay: 400ms; }

@keyframes tileIn { from { opacity: 0; transform: translateY(16px); } }
@keyframes fadeIn { from { opacity: 0; } }

/* ---------- tiles ---------- */
.tiles {
  list-style: none;
  margin: 0;
  padding: 0;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tile {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 54px;
  padding: 10px 13px;
  background: var(--tile);
  border: 1.5px solid var(--tile-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  transition: transform .18s cubic-bezier(.2, .8, .3, 1),
              border-color .15s, background .15s, box-shadow .15s;
}

.tile:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.tile .name {
  flex: 1;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.25;
}

.tile .grip {
  flex: none;
  width: 18px;
  color: var(--ink-faint);
  font-size: 15px;
  letter-spacing: 1px;
  text-align: right;
}

/* A pinned tile shows the figure it was ordered on, in place of the grip. */
.tile .val {
  flex: none;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  animation: valueIn .32s ease backwards;
  animation-delay: .1s;
}
.tile .val.ok { color: var(--correct); }

/* The padlock sits in the grip slot while the puzzle is still live. */
.tile.correct.locked .grip { font-size: 12px; opacity: .8; }

@keyframes valueIn { from { opacity: 0; transform: translateX(6px); } }

/* states */
.tile.dragging {
  cursor: grabbing;
  box-shadow: var(--shadow-lift);
  border-color: var(--accent);
  transition: none;
  z-index: 5;
}

.tile.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

.tile.correct {
  background: var(--correct-bg);
  border-color: var(--correct);
}

/* Locked tiles are settled, not just right: no grab cursor, no lift, and the
   grip is replaced by a padlock so the tile reads as out of play. */
.tile.locked {
  cursor: default;
  box-shadow: none;
  touch-action: auto;
}

/* ---------- feedback + actions ---------- */
.feedback {
  min-height: 19px;
  margin: 10px 0 0;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
}

.actions {
  margin-top: 9px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.pips { display: flex; gap: 8px; }

.pip {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--tile-border);
}
.pip.used { background: var(--ink-faint); }

/* The spent check is the main sign a wrong guess landed, so make it land. */
.pip.flash { animation: pipFlash .55s cubic-bezier(.2, .8, .3, 1); }
@keyframes pipFlash {
  0%   { transform: scale(1); }
  35%  { transform: scale(2.1); }
  100% { transform: scale(1); }
}

.primary {
  display: block;
  width: fit-content;
  max-width: 100%;
  margin-inline: auto;
  padding: 13px 30px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  font-family: inherit;
  letter-spacing: .02em;
  cursor: pointer;
}
/* Press feedback: a definite push in, then a small rebound. `:active` alone is
   unreliable under a thumb, so a click also runs the rebound outright. */
.primary:active,
.secondary:active { transform: scale(.94); }

.primary.press,
.secondary.press { animation: press .26s cubic-bezier(.2, .8, .3, 1); }
@keyframes press {
  0%   { transform: scale(.94); }
  55%  { transform: scale(1.035); }
  100% { transform: scale(1); }
}

.icon-btn:active { transform: scale(.88); }

/* A check on an untouched board is refused; the button shakes to say so. */
.primary.nudge { animation: nudge .42s ease; }
@keyframes nudge {
  0%, 100% { transform: translateX(0); }
  14%      { transform: translateX(-6px); }
  30%      { transform: translateX(5px); }
  46%      { transform: translateX(-4px); }
  62%      { transform: translateX(3px); }
  80%      { transform: translateX(-2px); }
}
.primary:disabled { background: var(--tile-border); color: var(--ink-faint); cursor: default; }

/* ---------- sheets ---------- */
/* Must come first: a bare `display: flex` below would otherwise beat the
   user-agent `[hidden] { display: none }` rule and pin every sheet open. */
.sheet-wrap[hidden] { display: none; }

.sheet-wrap {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(8, 11, 16, .55);
  animation: fade .18s ease;
}
@keyframes fade { from { opacity: 0; } }

.sheet {
  position: relative;
  width: 100%;
  max-width: 520px;
  max-height: 90dvh;
  overflow-y: auto;
  padding: 26px 20px calc(26px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  animation: rise .26s cubic-bezier(.2, .8, .3, 1);
}
@keyframes rise { from { transform: translateY(24px); } }

@media (min-width: 560px) {
  .sheet-wrap { align-items: center; }
  .sheet { border-radius: 20px; }
}

.sheet h2 { margin: 0 0 6px; font-size: 22px; text-align: center; }

.close {
  position: absolute;
  top: 12px; right: 12px;
  width: 34px; height: 34px;
  border: 0; border-radius: 50%;
  background: transparent;
  color: var(--ink-soft);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

.result-sub {
  margin: 0 0 14px;
  text-align: center;
  color: var(--ink-soft);
  font-size: 15px;
}


/* A real grid rather than letter-spaced text, so cell size and the gap between
   check columns can be set independently. */
.share-grid {
  display: grid;
  justify-content: center;
  gap: 4px 10px;
  margin: 0 0 14px;
  font-size: 14px;
  line-height: 1;
}

.secondary {
  display: block;
  width: fit-content;
  max-width: 100%;
  margin: 10px auto 0;
  padding: 11px 26px;
  border: 1.5px solid var(--tile-border);
  border-radius: 999px;
  background: transparent;
  color: var(--ink-soft);
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}
.secondary[hidden] { display: none; }


.statrow {
  display: flex;
  justify-content: center;
  gap: 22px;
  margin: 20px 0 0;
}
.stat { text-align: center; }
.stat b { display: block; font-size: 26px; font-weight: 800; }
.stat span { font-size: 11px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .06em; }

.countdown {
  margin: 18px 0 0;
  text-align: center;
  font-size: 13px;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}

.dist-title {
  margin: 22px 0 10px;
  font-size: 13px;
  text-align: center;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: .09em;
}
.dist { display: flex; flex-direction: column; gap: 6px; }
.dist-row { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.dist-row .lab { width: 14px; font-weight: 700; color: var(--ink-soft); }
.dist-row .bar {
  background: var(--accent);
  color: #fff;
  padding: 3px 8px;
  border-radius: 5px;
  font-weight: 700;
  font-size: 12px;
  min-width: 26px;
  text-align: right;
}

.help-list { margin: 16px 0; padding-left: 20px; line-height: 1.65; font-size: 15px; }
.help-list li { margin-bottom: 8px; }
.help-foot {
  margin: 18px 0 0;
  padding-top: 16px;
  border-top: 1px solid var(--tile-border);
  text-align: center;
  font-size: 14px;
  color: var(--ink-soft);
  font-style: italic;
}

/* Short screens (Galaxy S23 is 360x780 CSS px, and browser chrome takes ~100 of
   that). Everything above the fold or nothing — the Check button has to be
   reachable without scrolling. */
@media (max-height: 740px) {
  .topbar { padding: 5px 12px; }
  .wordmark { font-size: 17px; }
  #game { padding: 8px 14px 12px; }
  .puzzle-no { font-size: 11px; }
  .category { margin: 6px 0 2px; font-size: 11px; }
  .prompt { font-size: 16px; margin-bottom: 8px; }
  .scale-label { font-size: 10px; }
  .scale-top { margin-bottom: 6px; }
  .scale-bottom { margin-top: 6px; }
  .tiles { gap: 5px; }
  .tile { min-height: 46px; padding: 7px 12px; }
  .tile .name { font-size: 14px; }
  .feedback { margin-top: 7px; min-height: 17px; font-size: 12px; }
  .actions { margin-top: 7px; gap: 8px; }
  .primary { padding: 11px 18px; font-size: 15px; }
}

/* Shorter still, or landscape on a phone. */
@media (max-height: 640px) {
  .prompt { font-size: 15px; margin-bottom: 6px; }
  .tiles { gap: 4px; }
  .tile { min-height: 40px; padding: 5px 11px; }
  .feedback { margin-top: 5px; }
  .actions { margin-top: 5px; gap: 6px; }
  .primary { padding: 9px 16px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
