/* Meowdoku — phone first. Everything is sized off the viewport so the board
   and the toolbar both fit without scrolling on a handset. */

:root {
  color-scheme: light dark;

  --bg: #f4efe9;
  --bg-2: #ffffff;
  --ink: #241f2b;
  --ink-soft: #6b6474;
  --line: #d8d0c6;
  --accent: #7c4dff;
  --accent-ink: #ffffff;
  --danger: #d64545;
  --grid-line: rgba(36, 31, 43, .16);
  --region-edge: #2c2634;
  --cell-ink: #241f2b;

  /* Region colours. Ordered so neighbours in the palette stay distinguishable
     even for the common red/green confusions; the thick region outlines carry
     the real information, colour is the fast lookup. */
  --r0: #f6b8ab;
  --r1: #a9cdf2;
  --r2: #bde3a8;
  --r3: #f8dd93;
  --r4: #cfbdf0;
  --r5: #f7b9dd;
  --r6: #a5e2d8;
  --r7: #e0cfae;
  --r8: #c4cbd6;
  --r9: #d9a8c8;
  --r10: #ccb69c;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #191521;
    --bg-2: #241f2e;
    --ink: #f3eef8;
    --ink-soft: #a79fb4;
    --line: #372f45;
    --accent: #a98bff;
    --accent-ink: #1a1521;
    --grid-line: rgba(0, 0, 0, .35);
    --region-edge: #100d16;
    --cell-ink: #1a1520;

    --r0: #c9776a;
    --r1: #6d92bd;
    --r2: #7ba76a;
    --r3: #c0a057;
    --r4: #9280bd;
    --r5: #bd7aa2;
    --r6: #63a89d;
    --r7: #a08e6f;
    --r8: #808a99;
    --r9: #a56d90;
    --r10: #8f7a63;
  }
}

* { box-sizing: border-box; }

/* Several elements here set display:grid/flex, which otherwise beats the
   [hidden] attribute and leaves an invisible layer eating taps. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-rounded, "SF Pro Rounded", "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

button { font: inherit; color: inherit; }

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

.topbar {
  width: 100%;
  max-width: 560px;
  padding: 10px 14px 4px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.brand { display: flex; align-items: center; gap: 8px; }
.brand-cat { width: 26px; height: 26px; color: var(--accent); flex: none; }

.topbar h1 {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: -.02em;
  font-weight: 800;
}

.topbar-actions { display: flex; gap: 6px; }

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--bg-2);
  font-size: .95rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
}

/* ---------- mode tabs ---------- */

.modes {
  width: 100%;
  max-width: 560px;
  padding: 4px 14px 8px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.mode {
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--ink-soft);
  border-radius: 999px;
  padding: 8px 4px;
  font-size: .85rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}

.mode.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

main {
  width: 100%;
  max-width: 560px;
  padding: 0 14px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  flex: 1;
}

/* ---------- status line ---------- */

.status {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .85rem;
}

.status-label { font-weight: 700; margin-right: auto; }

.status-chip {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 10px;
  color: var(--ink-soft);
  font-weight: 600;
}

.mono { font-variant-numeric: tabular-nums; }

/* ---------- board ---------- */

.board-wrap { position: relative; width: 100%; display: flex; justify-content: center; }

.board {
  width: min(100%, 62dvh, 460px);
  aspect-ratio: 1;
  display: grid;
  /* The 1px gap, showing the board's own dark background, is the thin grid. */
  gap: 1px;
  background: var(--region-edge);
  border: 3px solid var(--region-edge);
  border-radius: 12px;
  overflow: hidden;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.cell {
  position: relative;
  /* Region outlines are borders rather than box-shadows so that a cell on two
     boundaries at once draws both, instead of the second rule replacing the
     first. Both neighbours draw their own half, so a boundary reads as one
     solid line. */
  border: 0 solid var(--region-edge);
  padding: 0;
  margin: 0;
  background: var(--cellbg);
  color: var(--cell-ink);
  display: block;
  cursor: pointer;
  touch-action: manipulation;
  outline: none;
}

.cell.et { border-top-width: 2px; }
.cell.er { border-right-width: 2px; }
.cell.eb { border-bottom-width: 2px; }
.cell.el { border-left-width: 2px; }

/* Cell contents are positioned out of flow. If they took part in layout, the
   grid tracks would resize the instant a cat or paw appeared and the whole
   board would jump under the player's finger. */
.cell svg {
  position: absolute;
  display: block;
  left: 13%;
  top: 13%;
  width: 74%;
  height: 74%;
}

.cell .paw {
  left: 28%;
  top: 28%;
  width: 44%;
  height: 44%;
  opacity: .5;
}

.cell .paw.auto { opacity: .22; }

.cell.cat-cell svg { animation: pounce .28s cubic-bezier(.3, 1.5, .5, 1); }
@keyframes pounce {
  from { transform: scale(.2) rotate(-14deg); }
  to { transform: scale(1) rotate(0); }
}

.cell.conflict { background: var(--danger); }
.cell.conflict svg { color: #fff; animation: shake .3s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-9%); }
  75% { transform: translateX(9%); }
}

/* Hint highlighting: focus squares are the evidence, target squares are the
   move being suggested. */
.cell.focus::after {
  content: "";
  position: absolute;
  inset: 8%;
  border-radius: 6px;
  background: rgba(124, 77, 255, .3);
  animation: glow 1.2s ease-in-out infinite alternate;
}
.cell.target::after {
  content: "";
  position: absolute;
  inset: 6%;
  border-radius: 6px;
  border: 3px dashed var(--accent);
  animation: glow 1.2s ease-in-out infinite alternate;
}
@keyframes glow { from { opacity: .35; } to { opacity: 1; } }

.cell.revealed svg { opacity: .85; }

.loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  border-radius: 12px;
  font-weight: 700;
  color: var(--ink-soft);
}

/* ---------- hint bar ---------- */

.hintbar {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  animation: rise .18s ease-out;
}

@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.hint-text { font-size: .88rem; line-height: 1.35; }
.hint-text strong { display: block; margin-bottom: 2px; }
.hint-text span { color: var(--ink-soft); }
.hint-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* ---------- buttons ---------- */

.toolbar {
  width: 100%;
  display: flex;
  gap: 8px;
}

.toolbar-secondary { align-items: center; }

.btn {
  flex: 1;
  border: 1px solid var(--line);
  background: var(--bg-2);
  border-radius: 12px;
  padding: 12px 6px;
  font-size: .9rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  min-height: 46px;
}

.btn:disabled { opacity: .4; cursor: default; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-small { flex: 0 0 auto; padding: 8px 14px; min-height: 0; font-size: .85rem; }
.btn-wide { width: 100%; }
.btn-ghost { background: none; border: none; color: var(--ink-soft); font-weight: 600; }

.switch {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .82rem;
  color: var(--ink-soft);
  font-weight: 600;
  justify-content: flex-end;
}

.switch input { width: 20px; height: 20px; accent-color: var(--accent); }

/* ---------- overlays ---------- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(12, 9, 17, .55);
  backdrop-filter: blur(3px);
  display: grid;
  place-items: center;
  padding: 18px;
  z-index: 20;
}

.overlay[hidden] { display: none; }

.sheet {
  position: relative;
  width: 100%;
  max-width: 380px;
  background: var(--bg-2);
  border-radius: 20px;
  padding: 22px 20px;
  text-align: center;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .35);
  animation: rise .22s ease-out;
  overflow: hidden;
}

.sheet-scroll { text-align: left; max-height: 84dvh; overflow-y: auto; }
.sheet h2 { margin: 0 0 10px; font-size: 1.4rem; }
.sheet p { margin: 0 0 10px; line-height: 1.45; font-size: .92rem; color: var(--ink-soft); }
.sheet p strong { color: var(--ink); }

.help-list { margin: 0 0 12px; padding-left: 18px; font-size: .9rem; color: var(--ink-soft); line-height: 1.6; }
.help-tap { color: var(--ink); font-weight: 700; }
.help-note { font-size: .85rem; }

.win-sub { margin-bottom: 14px; }

.win-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 0 0 16px;
}

.stats-grid { grid-template-columns: repeat(2, 1fr); }

.win-stats div {
  background: var(--bg);
  border-radius: 12px;
  padding: 10px 4px;
}

.win-stats dt { font-size: .7rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-soft); }
.win-stats dd { margin: 3px 0 0; font-size: 1.05rem; font-weight: 800; font-variant-numeric: tabular-nums; }

.sheet-actions { display: flex; gap: 8px; margin-bottom: 6px; }

/* Falling paws on a win. Purely decorative, and kept behind the text. */
.paw-rain { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 0; }
.sheet > *:not(.paw-rain) { position: relative; z-index: 1; }
.paw-rain span {
  position: absolute;
  top: -30px;
  font-size: 1.1rem;
  opacity: .55;
  animation: fall linear forwards;
}
@keyframes fall {
  to { transform: translateY(420px) rotate(320deg); opacity: 0; }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: .85rem;
  font-weight: 700;
  z-index: 30;
  animation: rise .16s ease-out;
}

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

/* Landscape phones: keep the board on screen by shrinking it, not by scrolling. */
@media (max-height: 560px) and (orientation: landscape) {
  .board { width: min(100%, 56dvh, 380px); }
  .modes { padding-bottom: 4px; }
}
