/* Fredoka, self-hosted as one Latin file (weights 500-700): no request leaves the site for a font. */
@font-face {
  font-family: "Fredoka";
  font-style: normal;
  font-weight: 500 700;
  font-display: swap;
  src: url("../fonts/fredoka-latin.woff2") format("woff2");
}

/* ---------- Themes ---------- */

:root,
[data-theme="classic"] {
  --bg: #f5f5f4;
  --surface: #ffffff;
  --text: #1c1917;
  --muted: #78716c;
  --line: #d6d3d1;
  --x: #2563eb;
  --o: #dc2626;
  --win: #fde68a;
  --accent: #7c3aed;
  --on-accent: #ffffff;
  --glow: none;
}

@media (prefers-color-scheme: dark) {
  :root,
  [data-theme="classic"] {
    --bg: #1c1917;
    --surface: #292524;
    --text: #f5f5f4;
    --muted: #a8a29e;
    --line: #44403c;
    --x: #60a5fa;
    --o: #f87171;
    --win: #713f12;
    --accent: #a78bfa;
    --on-accent: #1c1917;
  }
}

[data-theme="midnight"] {
  --bg: #0f172a;
  --surface: #1e293b;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --line: #334155;
  --x: #a78bfa;
  --o: #fbbf24;
  --win: #3730a3;
  --accent: #a78bfa;
  --on-accent: #0f172a;
  --glow: none;
}

[data-theme="ocean"] {
  --bg: #e0f2fe;
  --surface: #f0f9ff;
  --text: #0c4a6e;
  --muted: #0369a1;
  --line: #7dd3fc;
  --x: #0284c7;
  --o: #ea580c;
  --win: #fed7aa;
  --accent: #0369a1;
  --on-accent: #ffffff;
  --glow: none;
}

[data-theme="candy"] {
  --bg: #fdf2f8;
  --surface: #ffffff;
  --text: #831843;
  --muted: #be185d;
  --line: #f9a8d4;
  --x: #db2777;
  --o: #7c3aed;
  --win: #fbcfe8;
  --accent: #db2777;
  --on-accent: #ffffff;
  --glow: none;
}

[data-theme="neon"] {
  --bg: #09090b;
  --surface: #18181b;
  --text: #fafafa;
  --muted: #a1a1aa;
  --line: #3f3f46;
  --x: #22d3ee;
  --o: #e879f9;
  --win: #27272a;
  --accent: #22d3ee;
  --on-accent: #09090b;
  --glow: 0 0 12px currentColor;
}

[data-theme="forest"] {
  --bg: #ecfdf5;
  --surface: #ffffff;
  --text: #14532d;
  --muted: #15803d;
  --line: #bbf7d0;
  --x: #15803d;
  --o: #b45309;
  --win: #fef08a;
  --accent: #16a34a;
  --on-accent: #ffffff;
  --glow: none;
}

[data-theme="sunset"] {
  --bg: #2a1033;
  --surface: #3b1745;
  --text: #fff1e6;
  --muted: #f9a8d4;
  --line: #5b2463;
  --x: #fb923c;
  --o: #f472b6;
  --win: #7c2d12;
  --accent: #fb7185;
  --on-accent: #2a1033;
  --glow: 0 0 10px currentColor;
}

[data-theme="gold"] {
  --bg: #1c1408;
  --surface: #2b1f0c;
  --text: #fef3c7;
  --muted: #d6b25e;
  --line: #4a3815;
  --x: #fbbf24;
  --o: #f8fafc;
  --win: #78350f;
  --accent: #f59e0b;
  --on-accent: #1c1408;
  --glow: 0 0 12px currentColor;
}

:root {
  --rainbow: conic-gradient(#f43f5e, #f59e0b, #facc15, #22c55e, #06b6d4, #6366f1, #d946ef, #f43f5e);
}

/* ---------- Layout ---------- */

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: start center;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  transition: background 0.2s, color 0.2s;
}

main {
  width: min(380px, 100% - 32px);
  padding: 24px 0;
  margin-top: 4vh;
}

[hidden] { display: none !important; }

.screen { display: flex; flex-direction: column; gap: 16px; text-align: center; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 32px;
}

h2 { margin: 0; font-family: "Fredoka", system-ui, sans-serif; font-size: 1.75rem; font-weight: 700; }

.hint { margin: 0; color: var(--muted); font-size: 0.875rem; line-height: 1.5; }

/* ---------- Buttons ---------- */

button { font: inherit; cursor: pointer; }
button:disabled { cursor: default; }

/* Chunky 3D buttons: a solid "ledge" underneath that the button sinks into when pressed. */
.primary,
.secondary {
  --ledge: color-mix(in srgb, var(--accent), #000 35%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: 12px;
  border: 0;
  font-family: "Fredoka", system-ui, sans-serif;
  font-weight: 600;
  box-shadow: 0 4px 0 var(--ledge);
  transform: translateY(0);
  transition: transform 0.08s ease-out, box-shadow 0.08s ease-out, filter 0.15s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.primary:hover:not(:disabled),
.secondary:hover:not(:disabled) {
  filter: brightness(1.08);
  transform: translateY(-2px);
  box-shadow: 0 6px 0 var(--ledge);
}

.primary:active:not(:disabled),
.secondary:active:not(:disabled) {
  transform: translateY(4px);
  box-shadow: 0 0 0 var(--ledge);
  transition-duration: 0.03s;
}

.primary { background: var(--accent); color: var(--on-accent); }
.primary:disabled { opacity: 0.4; }
.secondary {
  --ledge: color-mix(in srgb, var(--line), #000 20%);
  background: var(--surface);
  color: var(--text);
  outline: 1px solid var(--line);
  outline-offset: -1px;
}
.secondary:disabled { box-shadow: none; transform: translateY(4px); opacity: 0.7; }

.big { padding: 15px; font-size: 1.125rem; }

.link {
  background: none;
  border: 0;
  padding: 4px 0;
  color: var(--muted);
}
.link:hover { color: var(--text); }
.link.inline { padding: 0; color: var(--text); text-decoration: underline; font-size: inherit; }

/* ---------- Menu ---------- */

.menu { gap: 14px; }

/* Title: three tilted, bobbing word tiles in the theme's X / O / accent colours. */
.title {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 0 0 4px;
  font-family: "Fredoka", system-ui, sans-serif;
  font-size: clamp(2.25rem, 12vw, 3.25rem);
  font-weight: 700;
  line-height: 1;
}

.word {
  --tile: var(--x);
  padding: 8px 12px 10px;
  border-radius: 14px;
  background: var(--tile);
  color: var(--surface);
  box-shadow: 0 6px 0 color-mix(in srgb, var(--tile), #000 35%);
  animation: bob 3s ease-in-out infinite;
}
.w1 { --tile: var(--x); --tilt: -5deg; }
.w2 { --tile: var(--o); --tilt: 4deg; animation-delay: -1s; }
.w3 { --tile: var(--accent); --tilt: -2deg; color: var(--on-accent); animation-delay: -2s; }

@keyframes bob {
  0%, 100% { transform: rotate(var(--tilt)) translateY(0); }
  50% { transform: rotate(var(--tilt)) translateY(-5px); }
}
.word { transform: rotate(var(--tilt)); }

.menu-meta { display: flex; justify-content: space-between; align-items: center; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 0;
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  outline: 1px solid var(--line);
  outline-offset: -1px;
  font-size: 0.875rem;
  font-weight: 600;
}
button.pill { transition: transform 0.08s; }
button.pill:active { transform: scale(0.93); }

.panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px 14px 20px;
  border-radius: 18px;
  background: color-mix(in srgb, var(--surface), var(--bg) 40%);
  outline: 1px solid var(--line);
  outline-offset: -1px;
}

.field { display: flex; flex-direction: column; gap: 8px; }
.label {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  text-align: left;
}
.label-note { font-weight: 500; letter-spacing: 0; text-transform: none; }

/* Choice chips: raised when off, pressed in and coloured when chosen. */
.seg {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 8px;
  padding-bottom: 5px;
}

.seg button {
  --chip: var(--accent);
  --on-chip: var(--on-accent);
  --chip-text: var(--text);
  --ledge: color-mix(in srgb, var(--line), #000 25%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 4px;
  border: 0;
  border-radius: 12px;
  background: var(--surface);
  color: var(--chip-text);
  outline: 2px solid var(--line);
  outline-offset: -2px;
  font-family: "Fredoka", system-ui, sans-serif;
  font-size: 1rem;
  font-weight: 600;
  box-shadow: 0 5px 0 var(--ledge);
  transition: transform 0.08s ease-out, box-shadow 0.08s ease-out, background 0.15s, color 0.15s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.seg button:hover { transform: translateY(-2px); box-shadow: 0 7px 0 var(--ledge); }
.seg button:active { transform: translateY(5px); box-shadow: 0 0 0 var(--ledge); transition-duration: 0.03s; }

.seg button[aria-pressed="true"] {
  --ledge: color-mix(in srgb, var(--chip), #000 35%);
  background: var(--chip);
  color: var(--on-chip);
  outline-color: transparent;
  transform: translateY(3px);
  box-shadow: 0 2px 0 var(--ledge);
}

.chip-icon { font-size: 1.1em; }

.seg-marks button { font-size: 2rem; padding: 4px; line-height: 1.2; }
.seg-marks [data-value="X"] { --chip: var(--x); --chip-text: var(--x); --on-chip: var(--surface); }
.seg-marks [data-value="O"] { --chip: var(--o); --chip-text: var(--o); --on-chip: var(--surface); }

.seg-difficulty button { --on-chip: #fff; --chip-text: var(--chip); font-size: 0.875rem; }
.seg-difficulty [data-value="easy"] { --chip: #16a34a; }
.seg-difficulty [data-value="medium"] { --chip: #d97706; }
.seg-difficulty [data-value="hard"] { --chip: #ea580c; }
.seg-difficulty [data-value="impossible"] { --chip: #dc2626; }

.seg-small { gap: 6px; }
.seg-small button { padding: 6px 2px; font-size: 0.8125rem; }

/* Big Play button in the X→O gradient. */
.play-btn {
  --ledge: color-mix(in srgb, var(--x), #000 40%);
  padding: 16px;
  border: 0;
  border-radius: 16px;
  background: linear-gradient(100deg, var(--x), var(--o));
  color: #fff;
  font-family: "Fredoka", system-ui, sans-serif;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-shadow: 0 2px 0 rgb(0 0 0 / 0.25);
  box-shadow: 0 7px 0 var(--ledge);
  transition: transform 0.08s ease-out, box-shadow 0.08s ease-out, filter 0.15s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.play-btn:hover { filter: brightness(1.08); transform: translateY(-2px); box-shadow: 0 9px 0 var(--ledge); }
.play-btn:active { transform: translateY(7px); box-shadow: 0 0 0 var(--ledge); transition-duration: 0.03s; }

.coins {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.coins.bump { animation: bump 0.45s ease-out; }

@keyframes bump {
  30% { transform: scale(1.35); }
  60% { transform: scale(0.95); }
}

/* The Tac: a gold token with a raised rim and a stamped X. */
.coin {
  display: inline-block;
  flex: none;
  width: 18px;
  height: 18px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cdefs%3E%3ClinearGradient id='g' x1='0' y1='0' x2='1' y2='1'%3E%3Cstop offset='0' stop-color='%23fef08a'/%3E%3Cstop offset='.45' stop-color='%23f59e0b'/%3E%3Cstop offset='1' stop-color='%23b45309'/%3E%3C/linearGradient%3E%3C/defs%3E%3Ccircle cx='12' cy='12' r='11' fill='url(%23g)' stroke='%2392400e' stroke-width='1.4'/%3E%3Ccircle cx='12' cy='12' r='7.6' fill='none' stroke='%23fffbeb' stroke-opacity='.65' stroke-width='1.1'/%3E%3Cpath d='M9.2 9.2l5.6 5.6M14.8 9.2l-5.6 5.6' stroke='%2378350f' stroke-width='2.3' stroke-linecap='round'/%3E%3Cpath d='M6.5 8.5a6.5 6.5 0 0 1 4-3.5' stroke='%23fff' stroke-opacity='.8' stroke-width='1.3' fill='none' stroke-linecap='round'/%3E%3C/svg%3E") center / contain no-repeat;
  filter: drop-shadow(0 1px 0 rgb(0 0 0 / 0.25));
}

.coins.bump .coin { animation: flip 0.45s ease-out; }

@keyframes flip {
  50% { transform: rotateY(180deg) scale(1.2); }
}

/* Shop: how Tacs are earned */
.earn { display: flex; flex-direction: column; gap: 8px; }
.earn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.earn-chip {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 10px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--chip), transparent 85%);
  color: var(--text);
  font-size: 0.8125rem;
  font-weight: 600;
  outline: 1.5px solid color-mix(in srgb, var(--chip), transparent 50%);
  outline-offset: -1.5px;
}
.earn-chip b { color: var(--chip); font-family: "Fredoka", system-ui, sans-serif; font-size: 1rem; }

.section-title {
  margin: 8px 0 0;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ---------- Game ---------- */

.status { min-height: 1.5em; font-weight: 600; margin: 0; }
.status.done { font-size: 1.125rem; }

.board {
  display: grid;
  grid-template-columns: repeat(var(--size, 3), 1fr);
  grid-template-rows: repeat(var(--size, 3), 1fr);
  gap: 6px;
  aspect-ratio: 1;
  background: var(--line);
  padding: 6px;
  border-radius: 14px;
}

.cell {
  border: 0;
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-family: "Fredoka", system-ui, sans-serif;
  font-size: clamp(2.5rem, 14vw, 4rem);
  font-weight: 700;
  min-height: 0;
  padding: 0;
  transition: background 0.15s, transform 0.08s;
  -webkit-tap-highlight-color: transparent;
}

.cell:hover:not(:disabled) { background: color-mix(in srgb, var(--surface), var(--line) 50%); }
.cell:active:not(:disabled) { transform: scale(0.92); }
.cell.x, .mark.x { color: var(--x); }
.cell.o, .mark.o { color: var(--o); }
.cell.x, .cell.o { text-shadow: var(--glow); animation: pop 0.25s cubic-bezier(0.34, 1.56, 0.64, 1); }
.cell.win { background: var(--win); animation: pulse 0.5s ease-in-out 2; }

@keyframes pop {
  from { transform: scale(0.4); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

@keyframes pulse {
  50% { transform: scale(1.06); }
}

.board { position: relative; }

.win-line {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
  opacity: 0;
}
.win-line.drawn { opacity: 1; }

.win-line line {
  fill: none;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.45s cubic-bezier(0.65, 0, 0.35, 1) 0.08s;
}
.win-line.instant line { transition: none; }
.win-line .under { stroke: var(--surface); stroke-width: var(--under-width, 18px); }
.win-line .over {
  stroke: var(--line-color);
  stroke-width: var(--over-width, 10px);
  filter: drop-shadow(0 0 6px var(--line-color));
}

.confetti {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 10;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

.mark { font-weight: 700; }

.scores {
  display: flex;
  justify-content: space-between;
  font-variant-numeric: tabular-nums;
}

/* ---------- Themes / shop lists ---------- */

.item-list { display: flex; flex-direction: column; gap: 8px; }

.item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
}

.item-name { flex: 1; text-align: left; font-weight: 600; }
.item button { min-width: 84px; padding: 8px 12px; margin-bottom: 4px; }

/* A swatch carries its own data-theme, so it shows that theme's colours. */
.swatch {
  flex: none;
  justify-content: center;
  width: 84px;
  display: inline-flex;
  gap: 4px;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--bg);
  border: 1px solid var(--line);
  font-size: 1.25rem;
}
.swatch .mark { text-shadow: var(--glow); }

/* ---------- High scores ---------- */

.score-table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}
.score-table th,
.score-table td { padding: 10px 6px; border-bottom: 1px solid var(--line); }
.score-table th { font-size: 0.8125rem; color: var(--muted); font-weight: 600; }
.score-table td:first-child,
.score-table th:first-child { text-align: left; }

/* ---------- Bigger boards ---------- */

.board[data-size="4"] { gap: 5px; padding: 5px; --over-width: 8px; --under-width: 14px; }
.board[data-size="4"] .cell { font-size: clamp(1.9rem, 10vw, 3rem); border-radius: 8px; }
.board[data-size="5"] { gap: 4px; padding: 4px; --over-width: 7px; --under-width: 12px; }
.board[data-size="5"] .cell { font-size: clamp(1.5rem, 8vw, 2.4rem); border-radius: 7px; }

.seg-small + .seg-small { margin-top: -8px; }
