/* Meowdle — minimalist cat-coat theme (light only, per CONTEXT.md) */
:root {
  --bg: #faf4e8;          /* cream tabby */
  --ink: #2e2823;         /* charcoal */
  --muted: #8d8272;
  --tile-border: #d9cebf;
  --tile-filled-border: #b9ae9e;
  --correct: #c25a10;     /* deep ginger — right letter, right spot */
  --present: #f2dda4;     /* pale sand — right letter, wrong spot */
  --absent: #a29889;      /* ash gray — not in name */
  --key-bg: #ede3d2;
  --card: #fffaf0;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
}
header {
  width: 100%;
  max-width: 30rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.9rem;
  border-bottom: 1px solid var(--tile-border);
}
h1 { font-size: 1.35rem; letter-spacing: 0.03em; }
.paw { font-size: 1rem; }
.mode-btn {
  font: inherit;
  font-size: 0.85rem;
  color: var(--ink);
  background: var(--key-bg);
  border: 1px solid var(--tile-filled-border);
  border-radius: 999px;
  padding: 0.35rem 0.8rem;
  cursor: pointer;
}
.mode-btn:active { transform: scale(0.96); }
.header-btns { display: flex; gap: 0.4rem; }
#helpBtn { min-width: 2.1rem; font-weight: 700; }

#helpOverlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: rgba(46, 40, 35, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
#helpOverlay[hidden] { display: none; }
.help-card {
  background: var(--card);
  border: 1px solid var(--tile-border);
  border-radius: 0.9rem;
  padding: 1.1rem;
  max-width: 20rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}
.help-card h2 { font-size: 1.1rem; }
.help-card p { font-size: 0.85rem; line-height: 1.35; }
.help-note { color: var(--muted); }
.legend-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.85rem;
}
.legend-row .cell { flex: none; }
#helpClose { align-self: center; padding: 0.45rem 1.2rem; }

main {
  width: 100%;
  max-width: 30rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 0.75rem 0.2rem;
}
.photo-card {
  width: fit-content;
  max-width: 100%;
  min-height: 5rem;
  margin: 0 auto;
  background: var(--card);
  border: 1px solid var(--tile-border);
  border-radius: 0.9rem;
  overflow: hidden;
}
/* frame hugs the photo's own aspect ratio; height capped per device */
.photo-card img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: min(30vh, 18rem);
  margin: 0 auto;
  background: var(--key-bg);
  cursor: zoom-in;
}
@media (min-width: 640px) {
  .photo-card img { max-height: min(38vh, 22rem); }
}

#photoOverlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: rgba(46, 40, 35, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
  opacity: 0;
  transition: opacity 0.25s ease;
}
#photoOverlay.open { opacity: 1; }
#photoOverlay[hidden] { display: none; }
#photoOverlay img {
  max-width: 100vw;
  max-height: 100dvh;
  object-fit: contain;
  will-change: transform;
  transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}
@media (prefers-reduced-motion: reduce) {
  #photoOverlay, #photoOverlay img { transition: none; }
}
.photo-card figcaption {
  font-size: 0.75rem;
  color: var(--muted);
  text-align: center;
  padding: 0.3rem;
}

#board { display: flex; flex-direction: column; gap: 0.3rem; }
.row { display: flex; gap: 0.3rem; justify-content: center; }
.cell {
  width: 2rem;
  height: 2.35rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  font-weight: 700;
  text-transform: uppercase;
  border: 2px solid var(--tile-border);
  border-radius: 0.35rem;
  background: transparent;
  transition: background 0.25s, border-color 0.25s, transform 0.12s;
}
/* shrink tiles for long names so 10 letters + separators fit 320px screens */
.size-8 .cell { width: 1.75rem; height: 2.1rem; font-size: 1rem; }
.size-10 .cell { width: 1.5rem; height: 1.75rem; font-size: 0.9rem; }
.size-10 .row { gap: 0.25rem; }
#board.size-10 { gap: 0.25rem; }
.cell.filled { border-color: var(--tile-filled-border); transform: scale(1.05); }
/* punctuation hugs the letter on its left instead of floating between tiles */
.cell.sep {
  border: none;
  width: auto;
  min-width: 0.28rem;
  margin-left: -0.2rem;
  color: var(--muted);
  font-weight: 400;
}
.size-10 .cell.sep { margin-left: -0.17rem; }
.cell.correct { background: var(--correct); border-color: var(--correct); color: #fff; }
.cell.present { background: var(--present); border-color: var(--present); color: var(--ink); }
.cell.absent  { background: var(--absent);  border-color: var(--absent);  color: #fff; }

#toast {
  min-height: 1.3rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--ink);
}

#reveal {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--tile-border);
  border-radius: 0.9rem;
  padding: 0.9rem;
  text-align: center;
}
#reveal h2 { font-size: 1.2rem; margin-bottom: 0.4rem; }
#revealFacts {
  list-style: none;
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 0.6rem;
}
#revealFacts li { padding: 0.1rem 0; }
#revealLink {
  display: inline-block;
  color: #fff;
  background: var(--correct);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
  border-radius: 999px;
  padding: 0.45rem 1rem;
  margin-bottom: 0.6rem;
}
.reveal-actions { display: flex; gap: 0.5rem; justify-content: center; flex-wrap: wrap; }

#keyboard {
  width: 100%;
  max-width: 30rem;
  padding: 0.4rem 0.3rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  user-select: none;
  -webkit-user-select: none;
}
.krow { display: flex; gap: 0.28rem; justify-content: center; }
.key {
  flex: 1;
  max-width: 2.4rem;
  height: 2.7rem;
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--ink);
  background: var(--key-bg);
  border: none;
  border-radius: 0.35rem;
  cursor: pointer;
  transition: background 0.2s;
  touch-action: manipulation;
}
.key.wide { max-width: 3.9rem; flex: 1.6; font-size: 0.75rem; }
.key:active { filter: brightness(0.92); }
.key.correct { background: var(--correct); color: #fff; }
.key.present { background: var(--present); color: var(--ink); }
.key.absent  { background: var(--absent);  color: #fff; }

footer {
  font-size: 0.7rem;
  color: var(--muted);
  text-align: center;
  padding: 0.2rem 1rem 0.4rem;
}
footer a { color: var(--muted); }

@keyframes shake { 20%,60% { transform: translateX(-4px); } 40%,80% { transform: translateX(4px); } }
.row.shake { animation: shake 0.35s; }
@keyframes pop { 40% { transform: scale(1.12); } }
.cell.win { animation: pop 0.45s; }

/* ---------- V2 additions ---------- */
h1 a { color: inherit; text-decoration: none; }
.header-btns a.mode-btn { text-decoration: none; display: inline-flex; align-items: center; }

#hints { display: flex; gap: 0.4rem; flex-wrap: wrap; justify-content: center; min-height: 0; }
.hint-chip {
  font-size: 0.8rem;
  background: var(--card);
  border: 1px dashed var(--tile-filled-border);
  border-radius: 999px;
  padding: 0.25rem 0.7rem;
  animation: pop 0.4s;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#reveal .count { font-size: 0.85rem; color: var(--correct); font-weight: 600; margin-bottom: 0.3rem; }
#reveal .source { font-size: 0.8rem; color: var(--muted); margin-bottom: 0.6rem; line-height: 1.4; }
#reveal .source a { color: var(--muted); }
.gallery { display: flex; gap: 0.4rem; justify-content: center; flex-wrap: wrap; margin-bottom: 0.6rem; }
.gallery img { width: 5.2rem; height: 5.2rem; object-fit: cover; border-radius: 0.5rem; cursor: zoom-in; }

/* archive page */
.day-list { list-style: none; width: 100%; display: flex; flex-direction: column; gap: 0.4rem; }
.day-list a {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--card); border: 1px solid var(--tile-border); border-radius: 0.6rem;
  padding: 0.6rem 0.9rem; text-decoration: none; color: var(--ink); font-weight: 600;
}
.day-list .state { font-size: 0.8rem; color: var(--muted); font-weight: 400; }
.day-list .state.won { color: var(--correct); }
.page-note { font-size: 0.85rem; color: var(--muted); text-align: center; line-height: 1.5; margin: 0.4rem 0; }
.about h2 { font-size: 1rem; margin: 0.8rem 0 0.3rem; }
.about p { font-size: 0.88rem; line-height: 1.5; margin-bottom: 0.4rem; }

/* Prefill mechanic: long names show pre-revealed letters; grid wraps by word */
.row { flex-wrap: wrap; row-gap: 0.3rem; }
.word { display: flex; gap: inherit; }
.row .word + .word { margin-left: 0.55rem; }
.cell.given {
  background: var(--key-bg);
  border-color: var(--key-bg);
  color: var(--muted);
}
#gallery:empty { display: none; }


/* Long (wrapping) names: tighten the surrounding chrome */
body.long-name main { gap: 0.4rem; }
body.long-name #toast { min-height: 1rem; }
body.long-name #keyboard { padding-top: 0.2rem; padding-bottom: 0.35rem; }
body.long-name footer { padding-top: 0.1rem; }

/* Wrapped (multi-line) names: tighter tiles, and a sticky keyboard so typing
   stays reachable even when the board is taller than the screen. */
body.long-name #board.size-10 .cell { width: 1.35rem; height: 1.55rem; font-size: 0.8rem; }
body.long-name #board .row { row-gap: 0.2rem; }
body.long-name #board { gap: 0.28rem; }
/* keyboard always reachable, even when the board scrolls */
#keyboard {
  position: sticky;
  bottom: 0;
  background: var(--bg);
  box-shadow: 0 -0.5rem 0.6rem var(--bg);
}

/* attempts stack above, the input card sits at the bottom, counter under it */
.attempts {
  align-self: center;
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
  border: 1px solid var(--tile-border);
  border-radius: 999px;
  padding: 0.15rem 0.6rem;
  margin-top: 0.15rem;
}
.row.input-row { margin-top: 0.15rem; }
/* new attempts rise into place from below */
@keyframes fadeIn { from { opacity: 0; transform: translateY(0.5rem); } to { opacity: 1; transform: none; } }
.row.fade-in { animation: fadeIn 0.4s ease; }
/* every attempt is its own card; past attempts dim out */
#board .row {
  background: var(--card);
  border: 1px solid var(--tile-border);
  border-radius: 0.7rem;
  padding: 0.28rem 0.45rem;
}
#board .row.past { opacity: 0.45; }
#board .row.input-row { border-color: var(--tile-filled-border); }
/* pre-filled letters are out of play: flat, dashed, muted — and their keys are dead */
.cell.given {
  background: transparent;
  border: 2px dashed var(--tile-border);
  color: var(--muted);
}
.key.disabled {
  background: transparent;
  color: var(--tile-border);
  box-shadow: inset 0 0 0 1px var(--tile-border);
  pointer-events: none;
}
@keyframes dimOut { from { opacity: 1; } to { opacity: 0.45; } }
#board .row.just-done { animation: dimOut 0.5s ease; }
/* Enter turns the tiles over one at a time. The tile is edge-on at the
   half-way point, which is exactly when app.js paints the mark on, so a colour
   is never visible before its own flip. Duration and stagger are set inline —
   app.js owns the timing (FLIP_MS / STAGGER_MS / FLIP_TOTAL_CAP).

   Easing is per half: accelerate into the edge, decelerate out of it. A single
   ease-in-out would ease both halves and stall the tile at its blank midpoint.
   The transition is switched off for the duration, because .cell fades its
   background over 250ms — longer than the 170ms the tile spends coming back —
   so the colour would still be washing in after the flip had finished, which
   reads as the tile never quite turning over. */
@keyframes flipTile {
  0%   { transform: rotateX(0deg);  animation-timing-function: ease-in; }
  50%  { transform: rotateX(90deg); animation-timing-function: ease-out; }
  100% { transform: rotateX(0deg); }
}
.word { perspective: 600px; }   /* else rotateX reads as a flat vertical squash */
.cell.to-flip { animation: flipTile 340ms both; transition: none; }
@media (prefers-reduced-motion: reduce) { .cell.to-flip { animation: none; } }
/* keep the input card + counter clear of the sticky keyboard when auto-scrolling */
.row.input-row, .attempts { scroll-margin-bottom: 11rem; }
/* keep punctuation narrow even where size classes set a fixed cell width */
#board .cell.sep,
body.long-name #board.size-10 .cell.sep,
body.long-name #board.size-8 .cell.sep {
  width: auto;
  min-width: 0.28rem;
  height: auto;
  margin-left: -0.2rem;
}
/* Digits ("Agent 99") are shown from the start and never guessed, so they read
   as a pre-filled letter rather than as punctuation. Each selector mirrors the
   .cell.sep rule above with one extra class, so it wins on specificity. */
#board .cell.sep.digit,
body.long-name #board.size-10 .cell.sep.digit,
body.long-name #board.size-8 .cell.sep.digit {
  width: 2rem;
  height: 2.35rem;
  min-width: 0;
  margin-left: 0;
  border: 2px dashed var(--tile-border);
  font-weight: 700;
}
#board.size-8 .cell.sep.digit,
body.long-name #board.size-8 .cell.sep.digit { width: 1.75rem; height: 2.1rem; font-size: 1rem; }
#board.size-10 .cell.sep.digit,
body.long-name #board.size-10 .cell.sep.digit { width: 1.5rem; height: 1.75rem; font-size: 0.9rem; }

/* cap the board width so long names wrap the same on desktop as on a phone */
#board .row { max-width: 21.5rem; }

/* ---------- submission form ---------- */
.submit form { display: flex; flex-direction: column; gap: 0.8rem; }
.field { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.88rem; }
.field > span { font-weight: 600; }
.field small { font-weight: 400; color: var(--muted); }
/* the intro is multi-line body copy, and every label, input and hint below it
   sits on one left axis — centring it is the only thing that breaks the axis */
.submit > .page-note { text-align: left; }
.field input[type="text"], .field select {
  font: inherit;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--tile-border);
  border-radius: 0.5rem;
  background: var(--card);
  color: var(--ink);
}
.field input[type="file"] { font-size: 0.82rem; padding: 0.3rem 0; }
.hint { color: var(--muted); min-height: 1rem; }
.check { display: flex; gap: 0.55rem; align-items: flex-start; font-size: 0.85rem; line-height: 1.4; }
.check input { margin-top: 0.2rem; flex: none; width: 1.1rem; height: 1.1rem; }
.previews { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.previews:empty { display: none; }
.preview { width: 5.5rem; }
.preview img {
  width: 5.5rem; height: 5.5rem; object-fit: cover;
  border-radius: 0.5rem; background: var(--key-bg);
}
.preview figcaption { font-size: 0.68rem; color: var(--muted); text-align: center; padding-top: 0.15rem; }
.mode-btn.primary {
  align-self: center;
  background: var(--correct);
  border-color: var(--correct);
  color: #fff;
  font-weight: 600;
  padding: 0.55rem 1.4rem;
}
.mode-btn.primary:disabled { opacity: 0.6; }

/* a letter handed to the player: clearly theirs for free, not something typed */
.cell.freebie {
  background: transparent;
  border: 2px dashed var(--correct);
  color: var(--correct);
}
.header-btns { flex-wrap: wrap; justify-content: flex-end; }
@media (max-width: 380px) { .mode-btn { padding: 0.35rem 0.6rem; font-size: 0.8rem; } }

/* the submitter's one line about their cat, revealed with the answer */
.cat-fact {
  max-width: 21.5rem;
  text-align: center;
  font-size: 0.92rem;
  line-height: 1.4;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--tile-border);
  border-radius: 0.7rem;
  padding: 0.5rem 0.8rem;
}
.cat-fact[hidden] { display: none; }
.field textarea {
  font: inherit;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--tile-border);
  border-radius: 0.5rem;
  background: var(--card);
  color: var(--ink);
  resize: vertical;
}
