/* Bird Sudoku — paper-and-ink field-guide palette from the design canvas. */

:root {
  --paper: #F4EFE3;
  --card: #FBF8F1;
  --tint: #EAE3D3;
  --peer: #EFE8D8;
  --match: #DCE6CC;
  --sel: #E3D48C;
  --bad: #F5D6CF;
  --bad-ink: #A33A2B;
  --bad-line: #D9A194;
  --line: #D8CFBC;
  --line-2: #B9AE96;
  --ink: #22301F;
  --ink-2: #4A5343;
  --ink-3: #5A6352;
  --green: #4E6B3A;
  --green-dk: #34492A;
  --green-line: #9DB585;
  --gold: #9A6A1F;
  --serif: Fraunces, Georgia, 'Times New Roman', serif;
  --sans: Karla, system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: #E6DFCF;
  color: var(--ink);
  font-family: var(--sans);
  -webkit-text-size-adjust: 100%;
}

body {
  display: flex;
  justify-content: center;
  min-height: 100dvh;
}

#app {
  width: 100%;
  max-width: 430px;
  background: var(--paper);
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  position: relative;
  overflow: hidden;
}

@media (min-width: 460px) {
  body { padding: 20px 0; }
  #app { min-height: min(880px, calc(100dvh - 40px)); border-radius: 22px; box-shadow: 0 10px 40px rgba(34, 48, 31, .18); }
}

button { font: inherit; color: inherit; cursor: pointer; border: none; background: none; }
button:disabled { cursor: default; }
a { color: var(--green); }

/* --- screens ------------------------------------------------------------ */

.screen { display: none; flex-direction: column; flex: 1; min-height: 0; padding: 14px 16px 18px; gap: 14px; }

/* The puzzle screen spreads its slack evenly rather than pooling it in one gap,
   so the controls stay under the thumb without a hole in the middle. */
#s-puzzle, #s-crossword { justify-content: space-between; }

/* Short screens (SE-class, or a browser with heavy chrome) have no slack at all —
   tighten every fixed height so the grid and controls still fit without scrolling. */
@media (max-height: 740px) {
  .screen { padding: 10px 12px 12px; gap: 8px; }
  .chip { height: 30px; font-size: 12px; }
  .info { min-height: 52px; padding: 8px 11px; }
  .info-tok { width: 34px; height: 34px; }
  .info-name { font-size: 15px; }
  .info-fact { font-size: 12px; }
  .tool { height: 46px; font-size: 10px; }
  .pal { padding: 3px 0 2px; }
  .bar { min-height: 38px; }
  .icon-btn { height: 38px; }
}
.screen.on { display: flex; }

/* --- top bar ------------------------------------------------------------ */

.bar { display: flex; align-items: center; justify-content: space-between; min-height: 44px; flex-shrink: 0; }
.bar-title { display: flex; flex-direction: column; align-items: center; gap: 2px; line-height: 1.15; }
.bar-title h1, .bar-title h2 { margin: 0; font-family: var(--serif); font-size: 20px; font-weight: 700; letter-spacing: -.2px; }
.bar-sub { font-size: 12px; color: var(--ink-3); }

.icon-btn {
  width: 44px; height: 44px; border-radius: 22px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--tint); }
.icon-btn.ghost { visibility: hidden; }

/* --- stat chips --------------------------------------------------------- */

.chips { display: flex; gap: 8px; flex-shrink: 0; }
.chip {
  flex: 1; height: 34px; border-radius: 17px; background: var(--tint);
  display: flex; align-items: center; justify-content: center; gap: 6px;
  font-size: 13px; font-weight: 500; white-space: nowrap;
}
.chip.warn { background: var(--bad); color: #7d2a1f; }

/* --- grid --------------------------------------------------------------- */

.grid-wrap { position: relative; flex-shrink: 0; }
.grid {
  width: 100%; aspect-ratio: 1;
  border: 2px solid var(--ink); border-radius: 10px; overflow: hidden;
  display: grid; grid-template-columns: repeat(9, 1fr); grid-template-rows: repeat(9, 1fr);
  background: var(--card);
  touch-action: manipulation;
}
.cell {
  position: relative; padding: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--card);
  border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.cell.r3 { border-bottom-width: 2px; border-bottom-color: var(--ink); }
.cell.c3 { border-right-width: 2px; border-right-color: var(--ink); }
.cell.r8 { border-bottom: none; }
.cell.c8 { border-right: none; }

/* Cross-hatching view — active while a bird is in hand.
   Shaded = swept out by a row, column or box that already has this bird.
   Pale with a ring = still open. The player finds the box with one ring left. */
.cell.ruled { background: #E4DCC9; }
.cell.open { background: #FFFDF7; }
.cell.lit { background: var(--match); }
.cell.muted .tok { opacity: .36; }
/* Named .perch-open, not .ghost: .ghost is the header spacer, and because this
   rule came later in the file it was overriding .icon-btn's width, making every
   header spacer 46% wide and pushing every title off-centre. */
.perch-open {
  width: 46%; aspect-ratio: 1; border-radius: 50%;
  border: 2px solid currentColor; opacity: .75;
}
.cell.lit .tok { box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--green-dk); }

.cell.peer { background: var(--peer); }
.cell.match { background: var(--match); }
.cell.bad { background: var(--bad); }
/* A ring, not a fill: the old amber selection sat at dE 11.6 from the yellow
   birds, which made the selected Goldfinch effectively invisible. */
.cell.sel { background: var(--card); box-shadow: inset 0 0 0 3px var(--green-dk); z-index: 1; }

.tok {
  width: 82%; aspect-ratio: 1; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: clamp(9px, 2.9vw, 13px); font-weight: 700; letter-spacing: .2px;
  line-height: 1;
  box-shadow:
    0 1.5px 2.5px rgba(34, 48, 31, .28),      /* sits on the paper */
    inset 0 1px 0 rgba(255, 255, 255, .22),   /* catches the light */
    inset 0 0 0 1px rgba(34, 48, 31, .18);    /* rim, so a pale bird still reads */
}
.tok.entry {
  box-shadow:
    0 0 0 1.5px var(--card), 0 0 0 3px var(--green),
    0 2px 3px rgba(34, 48, 31, .3),
    inset 0 1px 0 rgba(255, 255, 255, .22);
}
.tok.bad { box-shadow: 0 0 0 2px var(--bad-ink); }

.notes {
  position: absolute; inset: 8%;
  display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr);
  gap: 1px; pointer-events: none;
}
.note { border-radius: 50%; }

/* --- overlays on the grid ---------------------------------------------- */

/* The end-of-run card grew past the grid once it carried a standing line and
   award badges, so it is a modal over the whole app with its own scroll. */
.modal {
  position: absolute; inset: 0; z-index: 35; padding: 22px 20px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(34, 48, 31, .5);
}
.modal[hidden] { display: none; }
.overlay {
  width: 100%; max-height: 100%; overflow-y: auto;
  padding: 20px; border-radius: 16px; background: var(--ink); color: var(--card);
  display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center;
  box-shadow: 0 12px 32px rgba(34, 48, 31, .38);
}
.overlay h3 { margin: 0; font-family: var(--serif); font-size: 22px; font-weight: 700; }
.overlay p { margin: 0; font-size: 14px; color: #D8CFBC; line-height: 1.4; }
.overlay .row { display: flex; gap: 8px; margin-top: 6px; width: 100%; }
.overlay button {
  flex: 1; height: 44px; border-radius: 22px; font-size: 14px; font-weight: 700;
  background: var(--card); color: var(--ink);
}
.overlay button.alt { background: transparent; color: var(--card); box-shadow: inset 0 0 0 1.5px #6B7A62; }

/* --- info card ---------------------------------------------------------- */

.info {
  display: flex; gap: 12px; align-items: center; padding: 11px 13px;
  border-radius: 14px; background: var(--card); border: 1px solid var(--line);
  min-height: 62px; flex-shrink: 0;
}
.info-tok {
  width: 40px; height: 40px; flex-shrink: 0; border-radius: 20px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700;
}
.info-text { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.info-name { font-family: var(--serif); font-size: 16px; font-weight: 700; line-height: 1.2; }
.info-fact { font-size: 13px; line-height: 1.35; color: var(--ink-2); }

/* --- palette ------------------------------------------------------------ */

.palette { display: grid; grid-template-columns: repeat(9, 1fr); gap: 3px; flex-shrink: 0; }
.pal {
  padding: 5px 0 4px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card);
  display: flex; flex-direction: column; align-items: center; gap: 3px;
}
.pal:active { transform: scale(.94); }
.pal.out { background: var(--tint); border-style: dashed; border-color: var(--line-2); }
.pal.armed { background: var(--match); border-color: var(--green); box-shadow: inset 0 0 0 1px var(--green); }
.pal.armed .pal-left { color: var(--green-dk); font-weight: 700; }
.pal.done { opacity: .5; }
.pal-tok {
  width: clamp(24px, 7vw, 30px); aspect-ratio: 1; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: clamp(9px, 2.6vw, 12px); font-weight: 700;
}
.pal.out .pal-tok { opacity: .3; }
.pal-left { font-size: 10px; font-weight: 500; color: var(--ink-3); }

/* --- tools -------------------------------------------------------------- */

.tools { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; flex-shrink: 0; }
.tool {
  height: 54px; border-radius: 12px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 11px; font-weight: 500;
}
.tool span { white-space: nowrap; }
.tool:hover { background: var(--tint); }

@media (max-width: 384px) { .tool { font-size: 9.5px; } }
.tool.on { background: var(--match); }
.tool:disabled { opacity: .35; }

/* --- habitat list ------------------------------------------------------- */

.hero { display: flex; flex-direction: column; gap: 6px; flex-shrink: 0; }
.hero h1 { margin: 0; font-family: var(--serif); font-size: 30px; font-weight: 700; letter-spacing: -.4px; line-height: 1.08; }
.hero p { margin: 0; font-size: 15px; line-height: 1.45; color: var(--ink-2); }

.list { display: flex; flex-direction: column; gap: 10px; overflow-y: auto; flex: 1; min-height: 0; padding-bottom: 4px; }

.hab {
  width: 100%; text-align: left; padding: 14px; border-radius: 16px;
  background: var(--card); border: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 8px;
}
.hab:hover { border-color: var(--green-line); }
.hab-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.hab-name { font-family: var(--serif); font-size: 18px; font-weight: 700; }
.hab-diff { font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--green); }
.hab-blurb { font-size: 13px; line-height: 1.4; color: var(--ink-2); }
.hab-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--ink-3); }
.swatches { display: flex; gap: 3px; }
.sw { width: 15px; height: 15px; border-radius: 50%; }
.resume { font-size: 11px; font-weight: 700; color: var(--green); background: var(--match); padding: 3px 8px; border-radius: 9px; }

/* --- life list ---------------------------------------------------------- */

.ll-group { display: flex; flex-direction: column; gap: 8px; }
.ll-head { font-family: var(--serif); font-size: 15px; font-weight: 700; margin-top: 4px; }
.ll-row {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px;
  border-radius: 12px; background: var(--card); border: 1px solid var(--line);
}
.ll-row.unseen { background: transparent; border-style: dashed; border-color: var(--line-2); }
.ll-tok { width: 32px; height: 32px; flex-shrink: 0; border-radius: 16px; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; }
.ll-row.unseen .ll-tok { background: var(--tint) !important; color: var(--line-2) !important; }
.ll-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.ll-name { font-size: 14px; font-weight: 700; }
.ll-row.unseen .ll-name { color: var(--ink-3); font-weight: 500; }
.ll-row { width: 100%; text-align: left; }
.ll-meta { font-size: 11px; color: var(--ink-3); }

/* --- settings ----------------------------------------------------------- */

.set-row {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  border-radius: 12px; background: var(--card); border: 1px solid var(--line);
}
.set-text { flex: 1; }
.set-name { font-size: 14px; font-weight: 700; }
.set-note { font-size: 12px; color: var(--ink-3); line-height: 1.35; margin-top: 2px; }
.toggle {
  width: 46px; height: 28px; border-radius: 14px; flex-shrink: 0;
  background: var(--line); position: relative; transition: background .14s;
}
.toggle::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px;
  border-radius: 11px; background: var(--card); transition: transform .14s;
  box-shadow: 0 1px 3px rgba(34, 48, 31, .3);
}
.toggle[aria-pressed="true"] { background: var(--green); }
.toggle[aria-pressed="true"]::after { transform: translateX(18px); }

.danger { color: var(--bad-ink); font-size: 13px; font-weight: 700; padding: 12px; text-align: center; }

/* --- misc --------------------------------------------------------------- */

.cta {
  height: 52px; border-radius: 26px; background: var(--ink); color: var(--card);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 700; flex-shrink: 0; text-decoration: none;
}
.cta.muted { background: #E2DAC8; color: var(--ink-3); font-weight: 500; font-size: 15px; }
.spacer { flex: 1; min-height: 0; }
.toast {
  position: absolute; left: 50%; bottom: 84px; transform: translate(-50%, 12px);
  padding: 10px 16px; border-radius: 20px; background: var(--ink); color: var(--card);
  font-size: 13px; font-weight: 500; opacity: 0; pointer-events: none;
  transition: opacity .18s, transform .18s; max-width: 86%; text-align: center;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

.loading { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; flex: 1; color: var(--ink-3); font-size: 14px; }

.pips { display: flex; gap: 6px; align-items: center; }
.pip { width: 6px; height: 6px; border-radius: 3px; background: #C9BFA8; }
.pip.on { width: 22px; background: var(--green); }

.msg { padding: 13px 15px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); min-height: 52px; flex-shrink: 0; }
.msg.good { background: var(--match); border-color: var(--green-line); }
.msg.bad { background: var(--bad); border-color: var(--bad-line); }
.msg-title { font-family: var(--serif); font-size: 17px; font-weight: 700; }
.msg-body { font-size: 14px; line-height: 1.4; color: var(--ink-2); margin-top: 3px; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* --- rank bar ------------------------------------------------------------ */

.rankbar {
  display: flex; flex-direction: column; gap: 6px; flex-shrink: 0;
  padding: 11px 14px; border-radius: 14px;
  background: var(--card); border: 1px solid var(--line);
}
.rank-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.rank-name { font-family: var(--serif); font-size: 17px; font-weight: 700; }
.rank-next { font-size: 11px; color: var(--ink-3); }
.rank-track { height: 6px; border-radius: 3px; background: var(--tint); overflow: hidden; }
.rank-fill { height: 100%; border-radius: 3px; background: var(--green); }
.rank-streak { font-size: 11px; font-weight: 700; color: var(--gold); }

/* --- stats --------------------------------------------------------------- */

.stat-card {
  padding: 13px 14px; border-radius: 14px;
  background: var(--card); border: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 10px;
}
.stat-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.stat-name { font-family: var(--serif); font-size: 16px; font-weight: 700; }
.stat-played { font-size: 11px; color: var(--ink-3); }
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.stat-cell { display: flex; flex-direction: column; gap: 2px; align-items: flex-start; }
.stat-k { font-size: 10px; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-3); }
.stat-v { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-v.dim { color: var(--line-2); font-weight: 500; }
.stat-empty { font-size: 13px; color: var(--ink-3); }

/* --- awards -------------------------------------------------------------- */

.aw-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.aw {
  padding: 12px 8px; border-radius: 14px; text-align: center;
  background: var(--card); border: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.aw.locked { background: transparent; border-style: dashed; border-color: var(--line-2); }
.aw-icon {
  width: 38px; height: 38px; border-radius: 19px; flex-shrink: 0;
  background: var(--match); color: var(--green-dk);
  display: flex; align-items: center; justify-content: center;
}
.aw-icon svg { width: 20px; height: 20px; }
.aw.locked .aw-icon { background: var(--tint); color: var(--line-2); }
.aw-name { font-size: 12px; font-weight: 700; line-height: 1.2; }
.aw.locked .aw-name { color: var(--ink-3); font-weight: 500; }
.aw-hint { font-size: 10px; line-height: 1.25; color: var(--ink-3); }
.aw-date { font-size: 10px; color: var(--green); font-weight: 700; }

/* --- species sheet ------------------------------------------------------- */

/* `display: flex` here outranks the user-agent's [hidden] rule, so the attribute
   has to be honoured explicitly or the sheet is visible from page load. */
.sheet { position: absolute; inset: 0; z-index: 40; display: flex; align-items: flex-end; }
.sheet[hidden], .celebrate[hidden] { display: none; }
.sheet-scrim { position: absolute; inset: 0; background: rgba(34, 48, 31, .45); }
.sheet-card {
  position: relative; width: 100%; max-height: 86%; overflow-y: auto;
  background: var(--paper); border-radius: 22px 22px 0 0;
  animation: sheet-up .22s ease-out;
}
@keyframes sheet-up { from { transform: translateY(16px); opacity: 0; } }
.sheet-close {
  position: absolute; top: 10px; right: 12px; z-index: 2;
  width: 36px; height: 36px; border-radius: 18px; font-size: 22px; line-height: 1;
  background: rgba(251, 248, 241, .9); color: var(--ink);
}
.sp-plate {
  height: 150px; display: flex; align-items: center; justify-content: center;
  border-radius: 22px 22px 0 0; position: relative; overflow: hidden;
}
.sp-plate img { width: 100%; height: 100%; object-fit: cover; }
.sp-plate .sp-mono {
  width: 82px; height: 82px; border-radius: 41px;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; font-weight: 700; letter-spacing: .4px;
  box-shadow: 0 6px 18px rgba(34, 48, 31, .22);
}
.sp-plate .sp-nophoto {
  position: absolute; bottom: 8px; right: 12px;
  font-size: 10px; color: rgba(34, 48, 31, .45);
}
.sp-body { padding: 14px 16px 22px; display: flex; flex-direction: column; gap: 10px; }
.sp-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.sp-name { font-family: var(--serif); font-size: 21px; font-weight: 700; line-height: 1.15; }
.sp-sci { font-size: 13px; font-style: italic; color: var(--ink-3); margin-top: 2px; }
.sp-seen {
  flex-shrink: 0; font-size: 10px; font-weight: 700; padding: 4px 9px; border-radius: 10px;
  background: var(--match); color: var(--green-dk); white-space: nowrap;
}
.sp-seen.unseen { background: var(--tint); color: var(--ink-3); }
.sp-fact { margin: 0; font-size: 14px; line-height: 1.45; color: var(--ink-2); }
.sp-facts { margin: 0; display: flex; flex-direction: column; gap: 0; }
.sp-facts div {
  display: flex; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line);
  font-size: 13px; line-height: 1.35;
}
.sp-facts dt {
  flex-shrink: 0; width: 76px; color: var(--ink-3);
  font-size: 10px; letter-spacing: .04em; text-transform: uppercase; padding-top: 2px;
}
.sp-facts dd { margin: 0; flex: 1; }

/* --- celebration --------------------------------------------------------- */

.celebrate { position: absolute; inset: 0; z-index: 30; pointer-events: none; overflow: hidden; }
.feather {
  position: absolute; top: -24px; width: 11px; height: 11px; border-radius: 50% 50% 50% 2px;
  opacity: .9; animation: fall linear forwards;
}
@keyframes fall {
  to { transform: translateY(105vh) rotate(540deg); opacity: 0; }
}
.overlay.win { animation: pop .26s cubic-bezier(.2, 1.3, .4, 1); }
@keyframes pop { from { transform: scale(.92); opacity: 0; } }

.badges { display: flex; flex-direction: column; gap: 6px; width: 100%; margin-top: 4px; }
.badge-row {
  display: flex; align-items: center; gap: 9px; padding: 8px 10px;
  border-radius: 11px; background: rgba(251, 248, 241, .12);
  animation: slide-in .3s ease-out backwards;
}
@keyframes slide-in { from { transform: translateX(-10px); opacity: 0; } }
.badge-row .aw-icon { width: 28px; height: 28px; background: var(--match); }
.badge-row .aw-icon svg { width: 16px; height: 16px; }
.badge-text { text-align: left; }
.badge-name { font-size: 13px; font-weight: 700; color: var(--card); }
.badge-hint { font-size: 11px; color: #C2BAA6; }

.overlay .standing { font-size: 13px; color: #D8CFBC; line-height: 1.45; }
.overlay .standing b { color: var(--card); }

/* --- segmented control --------------------------------------------------- */

.seg { display: flex; gap: 4px; padding: 3px; border-radius: 11px; background: var(--tint); }
.seg-btn {
  flex: 1; height: 32px; border-radius: 9px; font-size: 13px; font-weight: 500;
  color: var(--ink-3);
}
.seg-btn.on { background: var(--card); color: var(--ink); font-weight: 700; box-shadow: 0 1px 3px rgba(34, 48, 31, .12); }

/* --- deduction ledger on the win card ------------------------------------ */

.ledger {
  width: 100%; margin: 4px 0 2px; padding: 11px 12px; border-radius: 12px;
  background: rgba(251, 248, 241, .1); display: flex; flex-direction: column; gap: 5px;
}
.led-row { display: flex; align-items: baseline; gap: 8px; text-align: left; }
.led-k { font-size: 12px; font-weight: 700; color: var(--card); width: 76px; flex-shrink: 0; }
.led-v { font-size: 16px; font-weight: 700; color: var(--card); width: 26px; flex-shrink: 0; font-variant-numeric: tabular-nums; }
.led-n { font-size: 11px; color: #BDB5A2; line-height: 1.3; }
.led-bar { height: 5px; border-radius: 3px; background: rgba(251, 248, 241, .15); overflow: hidden; margin-top: 3px; }
.led-fill { height: 100%; border-radius: 3px; background: var(--green-line); }
.led-foot { font-size: 11px; color: #BDB5A2; }

/* --- pause ---------------------------------------------------------------- */

/* Fully opaque on purpose: a translucent pause screen would let you stop the
   clock and go on reading the grid. */
.pause-cover {
  position: absolute; inset: 0; z-index: 45; background: var(--paper);
  display: flex; align-items: center; justify-content: center; padding: 28px 24px;
}
.pause-cover[hidden] { display: none; }
.pause-inner {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  text-align: center; width: 100%; max-width: 300px; color: var(--ink-3);
}
.pause-title { font-family: var(--serif); font-size: 26px; font-weight: 700; color: var(--ink); }
.pause-time { font-size: 34px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--ink); letter-spacing: -.5px; }
.pause-note { font-size: 13px; line-height: 1.4; margin-bottom: 8px; }
.pause-inner .cta { width: 100%; }
.pause-leave { font-size: 13px; font-weight: 500; color: var(--green); padding: 10px; }
.chip.tappable { cursor: pointer; }
.chip.tappable:hover { background: var(--line); }

/* --- game menu ------------------------------------------------------------ */

.game-card {
  width: 100%; text-align: left; padding: 16px; border-radius: 16px;
  background: var(--card); border: 1px solid var(--line);
  display: flex; align-items: center; gap: 14px;
}
.game-card:hover { border-color: var(--green-line); }
.game-card .mark {
  width: 56px; height: 56px; flex-shrink: 0; border-radius: 14px;
  display: grid; gap: 2px; padding: 6px; background: var(--paper);
}
.game-card .mark span { border-radius: 3px; }
.game-card .gc-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.game-card .gc-name { font-family: var(--serif); font-size: 19px; font-weight: 700; }
.game-card .gc-note { font-size: 13px; line-height: 1.35; color: var(--ink-2); }
.game-card .gc-stat { font-size: 11px; color: var(--ink-3); }
.game-card .gc-go { font-size: 20px; color: var(--line-2); flex-shrink: 0; }

/* --- crossword ------------------------------------------------------------ */

.xw-wrap { display: flex; justify-content: center; flex-shrink: 0; }
.xw-grid {
  width: 100%; max-width: 360px; aspect-ratio: 1;
  display: grid; grid-template-columns: repeat(7, 1fr); grid-template-rows: repeat(7, 1fr);
  border: 2px solid var(--ink); border-radius: 6px; overflow: hidden; background: var(--ink);
  gap: 1px;
}
.xw-cell {
  position: relative; background: var(--card); padding: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: clamp(16px, 5.2vw, 24px); font-weight: 700; line-height: 1; color: var(--ink);
}
.xw-cell.block { background: var(--ink); }
.xw-cell.in-entry { background: #E7EDDC; }
.xw-cell.active { background: var(--sel); }
.xw-cell.wrong { color: var(--bad-ink); }
.xw-cell.wrong::after {
  content: ''; position: absolute; inset: 14% 12%;
  border-top: 2px solid var(--bad-ink); transform: rotate(-32deg);
}
.xw-num {
  position: absolute; top: 1px; left: 3px;
  font-size: 9px; font-weight: 700; color: var(--ink-3); line-height: 1;
}

.xw-cluebar {
  display: flex; align-items: stretch; gap: 6px; flex-shrink: 0;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  min-height: 56px; overflow: hidden;
}
.xw-step { width: 38px; flex-shrink: 0; font-size: 22px; color: var(--green); background: var(--tint); }
.xw-step:hover { background: var(--line); }
.xw-clue {
  flex: 1; text-align: left; padding: 9px 4px; font-size: 14px; line-height: 1.3;
  display: flex; flex-direction: column; justify-content: center; gap: 3px; min-width: 0;
}
.xw-clue .xw-num-label {
  font-size: 10px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--green);
}

.xw-keys { display: flex; flex-direction: column; gap: 5px; flex-shrink: 0; }
.xw-keyrow { display: flex; gap: 4px; justify-content: center; }
.xw-key {
  flex: 1; max-width: 42px; height: 42px; border-radius: 7px;
  background: var(--card); border: 1px solid var(--line);
  font-size: 16px; font-weight: 700; color: var(--ink);
}
.xw-key:active { background: var(--tint); }
.xw-key.wide { max-width: 64px; flex: 1.4; font-size: 18px; }

@media (max-height: 740px) {
  .xw-key { height: 36px; }
  .xw-cluebar { min-height: 48px; }
  .xw-grid { max-width: 300px; }
}

/* --- crossword hints ------------------------------------------------------ */

.hint-list { display: flex; flex-direction: column; gap: 7px; margin-top: 4px; }
.hint-btn {
  display: flex; align-items: center; gap: 11px; width: 100%; text-align: left;
  padding: 12px 14px; border-radius: 12px;
  background: var(--card); border: 1px solid var(--line);
}
.hint-btn:hover { border-color: var(--green-line); }
.hint-btn:disabled { opacity: .45; }
.hint-btn .hb-text { flex: 1; min-width: 0; }
.hint-btn .hb-name { font-size: 14px; font-weight: 700; }
.hint-btn .hb-note { font-size: 12px; color: var(--ink-3); line-height: 1.35; margin-top: 2px; }
.hint-btn.strong { background: var(--tint); }
.xw-cell.revealed { color: var(--green); }

/* --- memory --------------------------------------------------------------- */

.mem-wrap { display: flex; justify-content: center; flex: 1; min-height: 0; align-items: center; }
.mem-grid { display: grid; gap: 8px; width: 100%; }
.mem-card {
  position: relative; aspect-ratio: 3 / 4; padding: 0; border-radius: 11px;
  background: transparent; perspective: 600px;
}
.mem-card .mem-back, .mem-card .mem-face {
  position: absolute; inset: 0; border-radius: 11px;
  display: flex; align-items: center; justify-content: center;
  backface-visibility: hidden; transition: transform .28s ease;
}
.mem-card .mem-back {
  background: var(--green-dk); border: 1px solid var(--green);
  background-image:
    radial-gradient(circle at 30% 30%, rgba(251,248,241,.14) 0 2px, transparent 3px),
    radial-gradient(circle at 70% 60%, rgba(251,248,241,.10) 0 2px, transparent 3px);
  background-size: 18px 18px;
}
.mem-card .mem-face {
  background: var(--card); border: 1px solid var(--line);
  transform: rotateY(180deg); overflow: hidden;
}
.mem-card .mem-face svg { width: 100%; height: 100%; }
.mem-card.up .mem-back { transform: rotateY(180deg); }
.mem-card.up .mem-face { transform: rotateY(0deg); }
.mem-card.matched .mem-face { border-color: var(--green-line); background: var(--match); }
.mem-card:not(.up):active { transform: scale(.96); }

.lv-card {
  width: 100%; text-align: left; padding: 14px; border-radius: 14px;
  background: var(--card); border: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px;
}
.lv-card:hover { border-color: var(--green-line); }
/* Stacked, not inline. Label-above-note spans have now run together on three
   separate card types because the wrapper was left as a block. */
.lv-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.lv-name { font-family: var(--serif); font-size: 17px; font-weight: 700; }
.lv-note { font-size: 13px; color: var(--ink-2); margin-top: 2px; }
.lv-best { font-size: 11px; color: var(--ink-3); flex-shrink: 0; }

@media (prefers-reduced-motion: reduce) {
  .mem-card .mem-back, .mem-card .mem-face { transition: none; }
}

/* --- what a token shows --------------------------------------------------- */

.tok, .pal-tok { position: relative; overflow: hidden; }
.tok-bird { position: absolute; inset: 6%; display: flex; align-items: center; justify-content: center; }
.tok-bird svg { width: 100%; height: 100%; }
.tok-code, .tok-num { position: relative; z-index: 1; line-height: 1; }
.tok-code.corner {
  position: absolute; left: 0; right: 0; bottom: 0;
  font-size: 7.5px; letter-spacing: 0; text-align: center;
  background: rgba(251, 248, 241, .82); padding: 1px 0;
}
.tok-num.corner {
  position: absolute; top: 1px; right: 2px;
  font-size: 8px; opacity: .85;
}
.pal-tok .tok-code.corner { font-size: 7px; }

/* --- celebration ---------------------------------------------------------- */

.celebrate-canvas {
  position: absolute; inset: 0; z-index: 60;
  pointer-events: none;   /* never interrupts play */
}

/* --- mahjong -------------------------------------------------------------- */

.mj-wrap { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; overflow: auto; }
.mj-board {
  position: relative;
  /* one tile is --tw wide; the board sizes itself from the layout's extent */
  /* fit BOTH ways: the board was sizing on width alone and using a third of
     the screen on a tall phone */
  /* Fit both ways, but never below a size a bird is readable at — the 144-tile
     turtle is 16 columns wide and would come out at 22px a tile on a phone.
     Below the floor the board simply scrolls, which is what it should do. */
  --tw: max(38px, min(
    calc((100vw - 34px) / var(--cols)),
    calc((100dvh - 250px) / (var(--rows) * 1.3))
  ));
  --th: calc(var(--tw) * 1.3);
  width: calc(var(--tw) * var(--cols));
  height: calc(var(--th) * var(--rows));
  flex-shrink: 0;
}
.mj-tile {
  position: absolute; width: var(--tw); height: var(--th); padding: 0;
  border-radius: calc(var(--tw) * 0.13);
  background: var(--card);
  border: 1px solid var(--line-2);
  box-shadow: 0 2px 0 var(--line-2), 0 3px 4px rgba(34, 48, 31, .2);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.mj-tile[hidden] { display: none; }
.mj-face { width: 88%; height: 88%; display: flex; align-items: center; justify-content: center; }
.mj-face svg { width: 100%; height: 100%; }

/* a buried tile is dimmed, not hidden - you still need to see what is under there */
.mj-tile:not(.free) { filter: brightness(.9) saturate(.55); }
.mj-tile:not(.free) .mj-face { opacity: .62; }
.mj-tile.free { border-color: var(--green-line); }
.mj-tile.picked { background: var(--match); border-color: var(--green-dk); border-width: 2px; transform: translateY(-2px); }
.mj-tile.hinted { animation: mj-hint 1.1s ease-out 2; }
.mj-tile.blocked { animation: mj-nope .3s ease-out; }
@keyframes mj-hint {
  0%, 100% { box-shadow: 0 2px 0 var(--line-2), 0 3px 4px rgba(34,48,31,.2); }
  50% { box-shadow: 0 0 0 3px var(--green), 0 3px 8px rgba(34,48,31,.3); }
}
@keyframes mj-nope {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}
@media (prefers-reduced-motion: reduce) {
  .mj-tile.hinted, .mj-tile.blocked { animation: none; }
  .mj-tile.hinted { box-shadow: 0 0 0 3px var(--green); }
}

/* --- account -------------------------------------------------------------- */

.ac-form { display: flex; flex-direction: column; gap: 10px; }
.ac-field { display: flex; flex-direction: column; gap: 4px; }
.ac-field label { font-size: 12px; font-weight: 700; color: var(--ink-3); letter-spacing: .03em; }
.ac-field input {
  height: 44px; padding: 0 13px; font: 500 15px var(--sans); color: var(--ink);
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
}
.ac-field input:focus-visible { outline: 2px solid var(--green); outline-offset: 1px; }
.ac-msg {
  font-size: 13.5px; line-height: 1.45; padding: 10px 13px; border-radius: 10px;
  background: var(--card); border: 1px solid var(--line);
}
.ac-msg.bad { background: var(--bad); border-color: var(--bad-line); color: #7d2a1f; }
.ac-msg.good { background: var(--match); border-color: var(--green-line); color: var(--green-dk); }
.ac-alt { font-size: 13.5px; color: var(--ink-3); text-align: center; padding: 4px; }
.ac-alt button { color: var(--green); font-weight: 700; font-size: 13.5px; }
.ac-who {
  display: flex; align-items: center; gap: 12px; padding: 14px;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
}
.ac-avatar {
  width: 44px; height: 44px; border-radius: 22px; flex-shrink: 0;
  background: var(--green); color: var(--paper);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--serif); font-size: 19px; font-weight: 700;
}
.ac-who-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.ac-name { font-family: var(--serif); font-size: 17px; font-weight: 700; }
.ac-email { font-size: 12.5px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; }
.ac-stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
