/* Price Grid — small-ads-on-newsprint look.
   Warm paper, ink text, one red marker accent, and cards that sit slightly
   crooked the way real ones do on a table.

   Dark mode is the same newspaper printed at night: the paper darkens, the
   ink lightens, and the marker warms up so it still reads against it. Every
   colour is a variable, so the dark theme is a palette swap, not a rewrite. */

:root {
  --paper:      #f2ece0;
  --paper-card: #fbf7ee;
  --paper-deep: #e8e0cf;
  --ink:        #23211d;
  --ink-soft:   #6f6858;
  --ink-faint:  #a79e8b;
  --rule:       #cdc2ab;
  --marker:     #c0392b;
  --marker-ink: #8e2a20;
  --stamp-good: #3f7048;
  --stamp-mid:  #9a6b1f;
  --stamp-bad:  #a8412f;

  --font-body: "Assistant", "Rubik", "Heebo", "Segoe UI", Arial, sans-serif;
  --font-display: "Frank Ruhl Libre", "Narkisim", "David", Georgia, "Times New Roman", serif;

  /* pulled out so the dark theme can deepen them rather than wash out */
  --shade:       rgba(35, 33, 29, .08);
  --shade-soft:  rgba(35, 33, 29, .07);
  --shade-lift:  rgba(35, 33, 29, .12);
  --shade-deep:  rgba(35, 33, 29, .10);
  --texture:     rgba(35, 33, 29, .022);
  --tint-warm:   rgba(192, 57, 43, .05);
  --tint-cool:   rgba(47, 95, 168, .05);

  --on-marker:   #fdf9f0;
  --marker-wash: rgba(192, 57, 43, .05);

  --shadow-card: 2px 3px 0 var(--shade), 0 6px 14px var(--shade-soft);
  --shadow-hard: 3px 3px 0 var(--ink);

  color-scheme: light;
}

/* The night edition. The inline script in index.html always stamps data-theme
   before first paint — resolving the saved choice or the OS preference — so
   this single block covers both cases and there is no duplicated palette. */
:root[data-theme="dark"] {
  --paper:      #211e18;
  --paper-card: #2c2921;
  --paper-deep: #3a352b;
  --ink:        #f3ede0;
  --ink-soft:   #bcb29c;
  --ink-faint:  #8d8472;
  --rule:       #4b4536;
  --marker:     #ef8168;
  --marker-ink: #c25c45;
  --stamp-good: #86c48e;
  --stamp-mid:  #ddb35f;
  --stamp-bad:  #f0917a;
  --on-marker:  #1c1811;   /* the accent lightens, so its text must darken */
  --marker-wash: rgba(239, 129, 104, .12);

  --shade:      rgba(0, 0, 0, .38);
  --shade-soft: rgba(0, 0, 0, .3);
  --shade-lift: rgba(0, 0, 0, .42);
  --shade-deep: rgba(0, 0, 0, .34);
  --texture:    rgba(243, 237, 224, .025);
  --tint-warm:  rgba(239, 129, 104, .07);
  --tint-cool:  rgba(110, 150, 215, .06);

  color-scheme: dark;      /* scrollbars and form controls follow */
}

* { box-sizing: border-box; }

/* Safari shows this behind the rubber-band overscroll, above and below the
   page. Without it you get a white flash against a dark page. */
html {
  background-color: var(--paper);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  /* Safari's URL bar collapses as you scroll, which changes what 100vh means
     and makes the layout jump. dvh follows the visible viewport; the vh line
     stays as a fallback for browsers without it. */
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  background-color: var(--paper);
  /* faint newsprint tint + ruled texture, no images needed */
  background-image:
    repeating-linear-gradient(0deg, var(--texture) 0 1px, transparent 1px 4px),
    radial-gradient(circle at 12% 8%, var(--tint-warm), transparent 42%),
    radial-gradient(circle at 88% 92%, var(--tint-cool), transparent 45%);
}

h1, h2 { margin: 0; font-family: var(--font-display); font-weight: 700; }

/* ---------------------------------------------------------- masthead */
.masthead {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  padding: 22px 26px 12px;
  border-bottom: 3px double var(--ink);
  margin-bottom: 30px;
}

.masthead-mid { text-align: center; flex: 1; }

.masthead h1 {
  font-size: clamp(30px, 6vw, 46px);
  letter-spacing: -.5px;
  line-height: 1.05;
}

.masthead-sub {
  margin: 4px 0 0;
  font-size: 13px;
  letter-spacing: .18em;
  color: var(--ink-soft);
}

.masthead-side {
  font-size: 11px;
  letter-spacing: .12em;
  color: var(--ink-faint);
  white-space: nowrap;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--rule);
  min-height: 20px;   /* hold the row's shape before the tally arrives */
}

.masthead-side-end {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.theme-toggle {
  font: inherit;
  font-size: 15px;
  line-height: 1;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  color: var(--ink-soft);
  background: var(--paper-card);
  border: 1px solid var(--rule);
  border-radius: 2px;
  cursor: pointer;
  transition: color .15s ease, border-color .15s ease, transform .07s ease;
}
.theme-toggle:hover { color: var(--marker); border-color: var(--marker); }
.theme-toggle:active { transform: translateY(1px); }
.theme-toggle:focus-visible { outline: 2px solid var(--marker); outline-offset: 2px; }

/* games-played counter, filled in from /api/stats after load */
.tally {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  letter-spacing: .06em;
  color: var(--ink-soft);
}
.tally b {
  font-family: var(--font-display);
  font-size: 17px;
  color: var(--marker);
  font-variant-numeric: tabular-nums;
  unicode-bidi: isolate;
}

main { padding: 0 26px 50px; }
.screen[hidden] { display: none; }

/* ---------------------------------------------------------- sheet (panel) */
.sheet {
  max-width: 620px;
  margin: 0 auto;
  padding: 30px 32px 34px;
  background: var(--paper-card);
  border: 1px solid var(--rule);
  border-radius: 3px;
  box-shadow: var(--shadow-card);
  position: relative;
}

/* the little folded corner */
.sheet::after {
  content: "";
  position: absolute;
  inset-inline-end: 0;
  bottom: 0;
  border-width: 0 0 22px 22px;
  border-style: solid;
  border-color: transparent transparent var(--paper-deep) transparent;
}

.sheet-wide { max-width: 940px; }

.sheet-title {
  font-size: 24px;
  margin-bottom: 22px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--rule);
}

.stub b { unicode-bidi: isolate; }

/* ---------------------------------------------------------- how to play */
.howto {
  margin: 0 0 24px;
  padding-inline-start: 22px;
  font-size: 15px;
  line-height: 1.65;
  color: var(--ink-soft);
}
.howto li { margin-bottom: 11px; padding-inline-start: 4px; }
.howto li::marker { color: var(--marker); font-weight: 700; }
.howto b { color: var(--ink); }

.notice {
  font-size: 13.5px;
  color: var(--ink-soft);
  margin: 0 0 4px;
  padding-top: 14px;
  border-top: 1px dashed var(--rule);
}
.notice.warn { color: var(--marker); font-weight: 600; }

.btn-quiet { margin-top: 10px; background: transparent; box-shadow: 2px 2px 0 var(--rule); }

.field-label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .16em;
  color: var(--ink-soft);
  margin-bottom: 9px;
}

/* ---------------------------------------------------------- score submission */
.score-submit {
  margin: 0 0 24px;
  padding: 18px 0;
  border-top: 1px dashed var(--rule);
  border-bottom: 1px dashed var(--rule);
  text-align: start;
}

.score-row { display: flex; gap: 10px; }

#score-name {
  flex: 1;
  min-width: 0;    /* without this a flex item won't shrink below its content */
  font: inherit;
  font-size: 15px;
  padding: 9px 12px;
  color: var(--ink);
  background: var(--paper-card);
  border: 1.5px solid var(--ink);
  border-radius: 2px;
}
#score-name:focus-visible { outline: 2px solid var(--marker); outline-offset: 1px; }
#score-name:disabled { opacity: .55; border-style: dashed; }

/* ---------------------------------------------------------- share */
.share-panel {
  margin: 0 0 24px;
  padding: 16px 0;
  border-top: 1px dashed var(--rule);
  border-bottom: 1px dashed var(--rule);
  text-align: start;
}

.share-preview {
  margin: 0 0 12px;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--ink-soft);
  overflow-wrap: anywhere;
}

.share-links { display: flex; flex-wrap: wrap; gap: 8px; }
.share-links .btn { text-decoration: none; }

/* ---------------------------------------------------------- contact */
.contact-intro {
  margin: 0 0 14px;
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink-soft);
}

.contact-hints {
  margin: 0 0 22px;
  padding-inline-start: 20px;
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--ink-soft);
}
.contact-hints li { margin-bottom: 5px; }
.contact-hints li::marker { color: var(--marker); }

#contact-link { display: block; text-align: center; text-decoration: none; }

#contact-address {
  text-align: center;
  direction: ltr;
  unicode-bidi: isolate;
  border-top: 0;
  padding-top: 10px;
}

/* ---------------------------------------------------------- leaderboard */
.board-list {
  list-style: none;
  margin: 0 0 22px;
  padding: 0;
  counter-reset: none;
}

.board-row {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 9px 4px;
  border-bottom: 1px dotted var(--rule);
}
.board-row:last-child { border-bottom: 0; }

.board-rank {
  min-width: 26px;
  font-family: var(--font-display);
  font-size: 15px;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}
.board-row-top .board-rank { color: var(--marker); font-weight: 700; }

.board-name { flex: 1; font-weight: 600; overflow-wrap: anywhere; }

.board-score {
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  unicode-bidi: isolate;
}

/* ---------------------------------------------------------- buttons */
.btn {
  font: inherit;
  font-weight: 700;
  /* Safari's grey flash on tap fights the hard-shadow press effect below */
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;   /* no 300ms double-tap-to-zoom delay */
  padding: 9px 18px;
  color: var(--ink);
  background: var(--paper-card);
  border: 1.5px solid var(--ink);
  border-radius: 2px;
  cursor: pointer;
  box-shadow: var(--shadow-hard);
  transition: transform .07s ease, box-shadow .07s ease;
}
.btn:hover { transform: translate(1px, 1px); box-shadow: 2px 2px 0 var(--ink); }
.btn:active { transform: translate(3px, 3px); box-shadow: none; }

.btn-primary { color: var(--on-marker); background: var(--marker); border-color: var(--marker-ink); }
.btn-lg { width: 100%; padding: 13px; font-size: 17px; margin-top: 8px; }
.btn-small { padding: 6px 13px; font-size: 13px; box-shadow: 2px 2px 0 var(--ink); }

/* ---------------------------------------------------------- scorebar */
/* Three stubs plus two buttons don't fit a phone on one line — wrap rather
   than pushing the whole page sideways. */
.scorebar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  max-width: 1180px;
  margin: 0 auto 26px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--rule);
}

.stub {
  display: flex;
  align-items: baseline;
  gap: 7px;
  padding: 5px 14px;
  background: var(--paper-card);
  border: 1px solid var(--rule);
  border-inline-start: 3px solid var(--ink);
  border-radius: 2px;
}
.stub b { font-family: var(--font-display); font-size: 20px; font-variant-numeric: tabular-nums; }
.stub span { font-size: 11px; letter-spacing: .1em; color: var(--ink-soft); }

/* the two buttons sit together at the far end of the bar */
.scorebar #btn-board-mid { margin-inline-start: auto; }

/* ---------------------------------------------------------- hand */
/* reserve the card's height so swapping cards never reflows the grid below */
.hand { text-align: center; margin-bottom: 34px; min-height: 268px; }

.hand-hint {
  font-size: 13.5px;
  color: var(--ink-soft);
  margin: 0 0 16px;
}
.hand-hint strong { color: var(--ink); border-bottom: 2px solid var(--marker); }

.feedback {
  min-height: 24px;
  margin: 16px auto 0;
  max-width: 520px;
  font-size: 15px;
  font-weight: 700;
}
.feedback.good { color: var(--stamp-good); }
.feedback.bad { color: var(--marker); }

/* ---------------------------------------------------------- cards */
.card {
  width: 216px;
  padding: 14px 15px 12px;
  text-align: start;
  background: var(--paper-card);
  border: 1px solid var(--rule);
  border-radius: 2px;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  gap: 8px;
  user-select: none;
  transition: transform .16s ease, box-shadow .16s ease;
}

/* perforated top edge, like a tear-off ad */
.card::before {
  content: "";
  display: block;
  height: 4px;
  margin: -6px -7px 2px;
  border-top: 2px dotted var(--rule);
}

.card-hand {
  margin: 0 auto;
  border-color: var(--ink);
  box-shadow: 4px 5px 0 var(--shade-lift), 0 10px 22px var(--shade-deep);
  transition: opacity .12s ease, transform .12s ease;
}

/* the outgoing card fades in place — it is never removed from the layout */
.card-hand.is-spent {
  opacity: 0;
  transform: scale(.97) rotate(.7deg);
  pointer-events: none;
}

/* hand-placed crookedness — straightens on hover */
.tilt-0 { transform: rotate(-1.1deg); }
.tilt-1 { transform: rotate(.7deg); }
.tilt-2 { transform: rotate(-.4deg); }
.tilt-3 { transform: rotate(1.2deg); }
.grid .card:hover {
  transform: rotate(0) translateY(-3px);
  box-shadow: 3px 5px 0 var(--shade-lift), 0 10px 20px var(--shade-deep);
}

/* the price sits alone on the top row now that the source badge is gone */
.card-top { display: flex; align-items: baseline; justify-content: flex-start; gap: 8px; }

.card-price {
  font-family: var(--font-display);
  font-size: 23px;                /* deliberately not scaled down for big sums */
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--marker);
  direction: ltr;
  unicode-bidi: isolate;
  min-width: 0;
  overflow-wrap: anywhere;        /* seven figures still fit; this is the backstop */
}
.card-price.hidden-price {
  color: var(--ink-faint);
  letter-spacing: .08em;
  font-size: 20px;
}

.card-title { font-size: 15.5px; font-weight: 700; line-height: 1.3; }
.card-desc { font-size: 12.5px; color: var(--ink-soft); line-height: 1.45; }

/* The stamp and the city share this row, but a long city on a narrow card
   used to push straight out through the card edge. Let the row wrap instead:
   the city drops onto its own line and the card grows, which is why .hand
   reserves enough height for a two-line footer. */
.card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px 8px;
  margin-top: auto;
  padding-top: 9px;
  border-top: 1px dashed var(--rule);
}

/* condition, as a rubber stamp */
.stamp {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .04em;
  padding: 3px 7px;
  border: 1.5px solid currentColor;
  border-radius: 3px;
  transform: rotate(-3.5deg);
  opacity: .85;
  white-space: nowrap;
}
.stamp-good { color: var(--stamp-good); }
.stamp-mid  { color: var(--stamp-mid); }
.stamp-bad  { color: var(--stamp-bad); }

.card-loc {
  font-size: 11.5px;
  color: var(--ink-soft);
  min-width: 0;                 /* a flex item won't shrink below content without this */
  overflow-wrap: anywhere;
}
.card-loc::before { content: "⌖ "; color: var(--marker); }

.card.correct { border-color: var(--stamp-good); animation: settle .32s ease; }
.card.wrong { border-color: var(--marker); animation: nope .36s ease; }

@keyframes settle {
  0% { transform: scale(.94) rotate(-3deg); }
  60% { transform: scale(1.03) rotate(1deg); }
  100% { transform: scale(1) rotate(0); }
}
@keyframes nope {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px) rotate(-1.5deg); }
  75% { transform: translateX(8px) rotate(1.5deg); }
}

/* ---------------------------------------------------------- grid */
.grid-wrap { max-width: 1180px; margin: 0 auto; }

.grid-axis {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
}
.axis-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .16em;
  color: var(--ink-soft);
  white-space: nowrap;
}
.axis-line {
  flex: 1;
  height: 0;
  border-top: 1px solid var(--rule);
  position: relative;
}
.axis-line::after {
  content: "";
  position: absolute;
  inset-inline-start: 0;
  top: -3px;
  border: 3px solid transparent;
  border-inline-end-color: var(--marker);
}

.grid {
  display: flex;
  align-items: stretch;
  gap: 8px;
  overflow-x: auto;
  padding: 8px 2px 20px;
  min-height: 250px;
}

.slot {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  flex: 0 0 auto;
  width: 50px;
  min-height: 190px;
  font: inherit;
  font-size: 20px;
  color: var(--ink-faint);
  background: transparent;
  border: 2px dashed var(--rule);
  border-radius: 3px;
  cursor: pointer;
  transition: all .15s ease;
}
.slot:hover {
  width: 74px;
  color: var(--marker);
  border-color: var(--marker);
  background: var(--marker-wash);
}
.slot:focus-visible { outline: 2px solid var(--marker); outline-offset: 2px; }

/* during the reveal the slots stay put and just go quiet — removing them
   reflowed the whole row and made the board jump */
.slot:disabled { cursor: default; opacity: .45; }
.slot:disabled:hover {
  width: 50px;
  color: var(--ink-faint);
  border-color: var(--rule);
  background: transparent;
}

/* ---------------------------------------------------------- over screen */
.over-body { color: var(--ink-soft); margin: 0 0 22px; font-size: 15px; }
/* four buttons don't fit a phone on one line — wrap instead of overflowing */
.over-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 26px; }
.grid-final { min-height: 0; padding-bottom: 6px; }

/* ---------------------------------------------------------- footer */
.foot {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 14px 26px 22px;
  border-top: 1px solid var(--rule);
  font-size: 12px;
  color: var(--ink-faint);
}
.foot-quip { font-style: italic; }

@media (max-width: 700px) {
  /* Only the decorative tagline goes. The games counter is real information
     and the theme toggle is a control — both stay. */
  .masthead-tagline { display: none; }

  /* With viewport-fit=cover the page runs under the notch and the home
     indicator, so pay that back on the sides and the bottom. */
  .masthead { padding-inline: max(16px, env(safe-area-inset-left)); }
  main { padding-inline: max(16px, env(safe-area-inset-left)); }
  .foot {
    padding-inline: max(16px, env(safe-area-inset-left));
    padding-bottom: max(22px, env(safe-area-inset-bottom));
  }

  /* iOS zooms the whole page when a focused input is under 16px. Nothing else
     about the field needs to change — it just must not be 15. */
  #score-name { font-size: 16px; }

  /* Three columns on a phone left the title crushed between a nowrap tally
     and the toggle. Give the title its own row and let the two small items
     share the one below it. */
  .masthead {
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 16px 16px 10px;
  }
  .masthead-mid { order: 1; flex: 1 0 100%; }
  .masthead-side { order: 2; flex: 0 0 auto; min-height: 0; }
  .masthead-side-end { order: 3; margin-inline-start: auto; }
  .masthead-side, .masthead-side-end { border-bottom: 0; padding-bottom: 0; }
  .field-row { flex-direction: column; gap: 0; }
  .card { width: 182px; }
  main { padding: 0 16px 40px; }
}
