/* Loop Bloom. System fonts only (no web fonts, no third-party requests). The board and kolams are always dark,
 * like a swept floor at dawn; the menus follow the light or dark system theme. */
:root {
  --bg: #F6F1E7; --surface: #FFFFFF; --surface-2: #EFE7D8; --text: #1D1B2F; --muted: #4F4A63;
  --primary: #8A3B12; --primary-ink: #FFFFFF; --accent: #B5653A; --border: #D6CBB5; --focus: #1F5FBF;
  --danger: #A11C1C; --floor: #1D1B2F; --chalk: #F3EEE3;
  --radius: 16px; --shadow: 0 2px 0 rgba(29, 27, 47, .1), 0 6px 18px rgba(29, 27, 47, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14121F; --surface: #1F1C30; --surface-2: #2A2640; --text: #F3EEE3; --muted: #C9C2DA;
    --primary: #F5A623; --primary-ink: #1D1B2F; --accent: #FFB547; --border: #3A3554; --focus: #FDE68A; --danger: #FCA5A5;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #14121F; --surface: #1F1C30; --surface-2: #2A2640; --text: #F3EEE3; --muted: #C9C2DA;
  --primary: #F5A623; --primary-ink: #1D1B2F; --accent: #FFB547; --border: #3A3554; --focus: #FDE68A; --danger: #FCA5A5;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text); min-height: 100vh;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Tamil", sans-serif;
  font-size: 17px; line-height: 1.5;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--primary); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; border-radius: 8px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: 8px; top: -60px; background: var(--primary); color: var(--primary-ink); padding: 8px 14px; border-radius: 10px; z-index: 10; }
.skip-link:focus { top: 8px; }
.noscript { padding: 16px; }
main { max-width: 560px; margin: 0 auto; padding: 12px 16px 32px; outline: none; position: relative; }
.fine { font-size: .9rem; color: var(--muted); }
.center { text-align: center; }
.icon { width: 1.1em; height: 1.1em; vertical-align: -0.18em; }

/* Buttons */
.btn { min-height: 48px; padding: 10px 20px; border-radius: 999px; border: 2px solid var(--primary); background: var(--primary); color: var(--primary-ink); font-weight: 700; }
.btn.secondary { background: transparent; color: var(--text); border-color: var(--border); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn.big { width: 100%; min-height: 56px; font-size: 1.15rem; position: relative; }
.icon-btn { min-width: 44px; min-height: 44px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); font-size: 1.2rem; line-height: 1; }
.row-buttons { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin: 16px 0; }
.stack { display: grid; gap: 10px; margin: 12px 0; }
.bar { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.bar-title { margin: 0; font-size: 1.3rem; }

/* Home */
.screen-home { min-height: 100vh; display: grid; place-items: center; }
.home-kolam { position: fixed; inset: 0; margin: auto; opacity: .35; pointer-events: none; border-radius: 24px; max-width: 100vw; }
.home { position: relative; width: 100%; max-width: 380px; text-align: center; padding: 24px 0; }
.gear { position: absolute; right: 0; top: 0; }
.logo { font-size: 2.6rem; margin: 40px 0 4px; letter-spacing: .02em; }
.logo span { color: var(--accent); }
.tagline { margin: 0 0 28px; color: var(--muted); }
.home-buttons { display: grid; gap: 12px; }
.new-dot { position: absolute; top: 10px; right: 18px; width: 12px; height: 12px; border-radius: 50%; background: #EC5FA0; }
.btn[aria-disabled="true"] { opacity: .6; }
.credit { font-size: .85rem; color: var(--muted); margin-top: 28px; }
.legal-links { font-size: .9rem; }

/* Level map */
.map { position: relative; margin: 8px auto 0; max-width: 360px; }
.map-path { position: absolute; inset: 0; width: 100%; height: 100%; }
.map-path polyline { stroke: var(--border); stroke-width: 4; stroke-dasharray: 2 10; stroke-linecap: round; }
.node { position: absolute; transform: translate(-50%, -50%); width: 64px; height: 64px; border-radius: 50%; border: 3px solid var(--accent);
  background: var(--surface); display: grid; place-items: center; align-content: center; gap: 0; padding: 0; box-shadow: var(--shadow); }
.node .num { font-weight: 800; font-size: 1.15rem; line-height: 1; }
.node .stars .icon { width: 13px; height: 13px; }
.node.locked { opacity: .45; border-color: var(--border); }
.node.current { animation: soft-pulse 2.4s ease-in-out infinite; }
.stars { display: inline-flex; gap: 2px; }
.stars .icon path { stroke: #FFB547; stroke-width: .12; }
@keyframes soft-pulse { 50% { box-shadow: 0 0 0 8px rgba(245, 166, 35, .25); } }

/* Play */
.screen-play { padding-top: 8px; }
.play-top { display: grid; grid-template-columns: auto auto 1fr auto; gap: 8px; align-items: center; margin-bottom: 10px; }
.moves, .score { display: grid; text-align: center; line-height: 1.1; min-width: 52px; }
.moves .label, .score .label { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.moves-num { font-size: 1.5rem; font-weight: 800; }
.moves-num.low { color: #C77700; }
.moves-num.pulse { animation: once-pulse .8s ease-in-out 1; }
@keyframes once-pulse { 50% { transform: scale(1.18); } }
.score-num { font-weight: 700; }
.goals { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; background: var(--surface-2); font-size: .85rem; font-weight: 600; }
.chip.done { outline: 2px solid #4DB86A; }
.chip-prog { font-variant-numeric: tabular-nums; color: var(--muted); }
.tut-hint { text-align: center; font-weight: 700; font-size: 1.1rem; margin: 0 0 8px; }
.board-wrap { position: relative; width: fit-content; margin: 0 auto; }
.board { display: block; border-radius: 18px; background: var(--floor); user-select: none; -webkit-user-select: none; }
.cells { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(6, 1fr); grid-template-rows: repeat(6, 1fr); touch-action: none; user-select: none; -webkit-user-select: none; }
.cell { background: transparent; border: 0; padding: 0; margin: 0; border-radius: 10px; -webkit-tap-highlight-color: transparent; }
/* The ring is drawn inside the dark floor, so it has strong contrast in both themes (WCAG 2.4.7). */
.cell:focus-visible { outline: 3px solid #FDE68A; outline-offset: -4px; box-shadow: inset 0 0 0 6px rgba(29, 27, 47, .9); }
.tap-controls { display: flex; justify-content: center; gap: 10px; margin: 10px 0 0; }
.tap-controls[hidden] { display: none; }
.kbd-help { font-size: .85rem; color: var(--muted); text-align: center; max-width: 480px; margin: 10px auto 0; }
.kbd-help .key-help { display: none; }
.screen-play:focus-within .board-wrap:focus-within ~ .kbd-help .key-help { display: inline; }
.controls { padding-left: 20px; margin: 4px 0; }
.hand { position: absolute; left: 0; top: 0; width: 34px; height: 34px; margin: -6px 0 0 -6px; border-radius: 50%;
  background: rgba(243, 238, 227, .55); border: 3px solid #fff; pointer-events: none; box-shadow: 0 0 16px rgba(255, 255, 255, .5); }

/* Toast */
.toast { position: fixed; left: 50%; top: 18%; transform: translate(-50%, -8px); background: rgba(29, 27, 47, .92); color: #F3EEE3;
  padding: 10px 20px; border-radius: 999px; font-weight: 700; opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; z-index: 20; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Result, daily, gallery */
.result { text-align: center; }
.result h1 { margin: 12px 0 4px; }
.result .stars .icon { width: 36px; height: 36px; }
.sub { color: var(--muted); margin: 4px 0; }
.kolam-big { display: block; margin: 8px auto; border-radius: 16px; }
.kolam-label { display: flex; justify-content: center; align-items: center; gap: 8px; margin: 4px 0; font-weight: 600; }
.info-btn { width: 32px; height: 32px; min-width: 32px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface); font-weight: 800; font-style: italic; }
.badge { display: inline-block; padding: 4px 12px; border-radius: 999px; background: #FFB547; color: #1D1B2F; font-weight: 700; font-size: .85rem; margin: 4px 0; }
.fact { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; margin: 14px auto 0; max-width: 420px; text-align: left; }
.fact-title { margin: 0; font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.fact p { margin: 4px 0; }
.gallery { list-style: none; padding: 0; margin: 8px 0; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.thumb-btn { width: 100%; padding: 6px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); display: grid; gap: 4px; justify-items: center; font-size: .85rem; }
.thumb { width: 100%; height: auto; aspect-ratio: 1; border-radius: 12px; }
.empty { text-align: center; color: var(--muted); margin-top: 40px; }

/* Settings */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; margin: 12px 0; }
.panel h2 { font-size: 1.05rem; margin: 0 0 6px; }
.toggle label { display: flex; justify-content: space-between; align-items: center; min-height: 44px; gap: 12px; }
.toggle input { width: 26px; height: 26px; accent-color: var(--primary); }
.toggle .fine { margin: -4px 0 8px; }
.radio { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.radio input { width: 22px; height: 22px; accent-color: var(--primary); }
.radio.locked { color: var(--muted); }
.swatch { width: 28px; height: 28px; border-radius: 8px; border: 3px solid; display: inline-block; }
.shop ul { padding-left: 20px; margin: 6px 0 12px; }
.price { margin: 0; }
.thanks { font-weight: 700; }
.code { word-break: break-all; background: var(--surface-2); padding: 2px 6px; border-radius: 6px; }
.restore { display: grid; gap: 8px; margin-top: 14px; }
.restore input, #gate-answer { min-height: 44px; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); }
.kid-summary { font-weight: 600; }

/* Dialog */
dialog { border: none; border-radius: 20px; padding: 0; max-width: min(460px, calc(100vw - 32px)); width: 100%; background: var(--surface); color: var(--text); box-shadow: 0 10px 40px rgba(0, 0, 0, .35); }
dialog::backdrop { background: rgba(10, 8, 20, .6); }
.dialog-body { padding: 20px; max-height: 85vh; overflow-y: auto; }
.dialog-body h2 { margin-top: 0; }
.dialog-body form { display: grid; gap: 10px; }
.facts { padding-left: 22px; }
.facts li { margin-bottom: 8px; }
.fake-ad { position: fixed; inset: 0; background: #777; color: #fff; display: grid; place-items: center; font-size: 3rem; z-index: 50; }

/* Legal pages */
.legal { max-width: 720px; margin: 0 auto; padding: 20px 16px 48px; }
.legal h1 { font-size: 1.8rem; }
.legal h2 { font-size: 1.2rem; margin-top: 1.6em; }

@media (max-width: 360px) {
  body { font-size: 16px; }
  .play-top { grid-template-columns: auto auto 1fr; }
  .play-top .score { grid-column: 2; grid-row: 2; }
  .goals { grid-column: 1 / -1; }
  .node { width: 56px; height: 56px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
.reduce-motion *, .reduce-motion *::before, .reduce-motion *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
.home .btn.secondary { background: var(--surface); }
