/* Chai Tiles: one dark theme. Gold = active chain, links, rewards. Teal = exact sum, gauge, mastery. */
@font-face { font-family: 'Frank Ruhl Libre'; font-weight: 700; font-style: normal; font-display: swap; src: url(../fonts/frank-ruhl-libre-700.woff2) format('woff2'); }
@font-face { font-family: 'Frank Ruhl Libre'; font-weight: 800; font-style: normal; font-display: swap; src: url(../fonts/frank-ruhl-libre-800.woff2) format('woff2'); }

:root {
  --navy-0: #04101f; --navy-1: #0c3a63; --cream: #f7f3e8; --muted: #a9bdd2; --muted-hi: #cad8e6; --ink: #04101f; /* muted-hi: text on glass */
  --gold: #f4c842; --teal: #2dd4de; --coral: #ff9e86;
  --edge: rgba(150, 200, 250, .16);
  --glass: linear-gradient(165deg, #215a91 0%, #123d69 52%, #0b2d52 100%);
  --glass-shadow: inset 0 1px 0 rgba(255, 255, 255, .26), inset 0 -2px 0 rgba(0, 0, 0, .22), 0 6px 12px -5px rgba(0, 0, 0, .6);
  --heb: 'Frank Ruhl Libre', 'Times New Roman', serif;
  --ui: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --t: 64px; --drop-ms: 300ms;
  color-scheme: dark;
}
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { height: 100%; background: var(--navy-0); }
body {
  margin: 0; min-height: 100%; color: var(--cream); font: 16px/1.4 var(--ui);
  font-variant-numeric: tabular-nums; -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none; -webkit-text-size-adjust: 100%;
}
body::before {
  content: ''; position: fixed; inset: 0; z-index: -1;
  background: radial-gradient(120% 55% at 50% -8%, rgba(60, 150, 230, .22), transparent 62%),
              linear-gradient(180deg, #04101f 0%, #072448 52%, #0c3a63 100%);
}
button { font: inherit; color: inherit; }
h1, h2 { margin: 0; font-weight: 800; }
h1:focus, h2:focus { outline: none; }
:focus-visible { outline: 3px solid var(--cream); outline-offset: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

#app {
  max-width: 480px; height: 100vh; height: 100dvh; margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.screen { height: 100%; display: flex; flex-direction: column; }
.page { overflow-y: auto; padding-bottom: 24px; }

/* Buttons: 56 px targets, glass by default, cream for the main action */
.btn, .big-btn {
  min-height: 56px; min-width: 56px; padding: 0 18px; border-radius: 16px; border: 1px solid var(--edge);
  background: var(--glass); box-shadow: var(--glass-shadow); color: var(--cream);
  font-weight: 650; cursor: pointer; transition: transform 90ms ease-out;
}
.btn:active, .big-btn:active { transform: scale(.96); }
.btn.primary, .big-btn.primary { background: linear-gradient(180deg, #fffaf0, #e8e1cd); color: var(--ink); border-color: transparent; box-shadow: inset 0 1px 0 #fff, 0 8px 20px -8px rgba(0, 0, 0, .7); }
.btn:disabled { opacity: .45; cursor: default; transform: none; }
.btn.primary:disabled { opacity: 1; background: rgba(255, 255, 255, .05); color: var(--muted); border-color: var(--edge); box-shadow: none; } /* an empty slot that lights up cream when a chain is ready */
.btn[aria-pressed="true"] { background: #1d4f7f; box-shadow: inset 0 0 0 2px var(--cream); }
.row2 { display: flex; gap: 10px; }
.row2 > * { flex: 1; }

/* Home */
.home { justify-content: center; gap: 32px; text-align: center; }
.emblem { /* a lit chain tile: the first screen shows the core mechanic and its one warm colour */
  width: 112px; height: 112px; margin: 0 auto 20px; display: grid; place-items: center; border-radius: 30px;
  background: linear-gradient(165deg, #ffe596 0%, #f4c842 50%, #d9a423 100%); border: 1px solid rgba(255, 236, 170, .85);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .65), 0 18px 44px -10px rgba(244, 200, 66, .45);
  font: 800 64px/1 var(--heb); color: var(--ink);
}
.emblem span { margin-top: -6px; }
.emblem { animation: breathe 6s ease-in-out infinite; }           /* the one idle motion: a slow breath, nothing else moves at rest */
@keyframes breathe { 50% { transform: scale(1.03); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .65), 0 22px 54px -10px rgba(244, 200, 66, .6); } }
[data-motion="reduce"] .emblem { animation: none; }
.home h1 { font: 800 42px/1.05 var(--heb); letter-spacing: .01em; }
.tagline { margin: 8px 0 0; color: var(--muted); }
.home-actions { display: grid; gap: 12px; }
.big-btn { display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: 2px; min-height: 78px; padding: 12px 20px; text-align: left; }
.bb-title { font-size: 21px; font-weight: 750; }
.bb-sub { font-size: 14px; color: var(--muted-hi); }
.big-btn.primary .bb-sub { color: #33475c; }
.big-btn.done .bb-title::before { content: '\2713\00a0'; }
.countdown { margin: 0; min-height: 20px; color: var(--muted); font-size: 14px; }

/* Game HUD */
.hud { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; }
.stat { display: flex; flex-direction: column; font-size: 12px; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); }
.stat b { font-size: 24px; letter-spacing: 0; text-transform: none; color: var(--cream); font-weight: 750; line-height: 1.15; }
.stat.end { align-items: flex-end; text-align: right; }
.gauge { position: relative; width: 92px; height: 92px; }
.gauge svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.g-track, .g-fill { fill: none; stroke-width: 7; }
.g-track { stroke: rgba(255, 255, 255, .1); }
.g-fill { stroke: var(--teal); stroke-linecap: round; stroke-dasharray: 276.46; stroke-dashoffset: 276.46; opacity: .6; transition: stroke-dashoffset .18s ease-out, opacity .15s; }
.gauge.empty .g-fill { opacity: 0; }
.gauge.exact .g-fill { opacity: 1; }
.gauge.over .g-fill { stroke: var(--coral); opacity: .9; }
.g-core {
  position: absolute; inset: 12px; border-radius: 50%; display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 28%, #1a4f83, #0a2747 75%); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .2); transition: box-shadow .15s;
}
.g-core b { font-size: 28px; line-height: 1; font-weight: 800; }
.g-core span { font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted-hi); }
.gauge.exact .g-core { box-shadow: inset 0 1px 0 rgba(255, 255, 255, .2), 0 0 0 2px var(--teal), 0 0 24px rgba(45, 212, 222, .5); }
.gauge.exact .g-core b { color: var(--teal); }

.sumline { margin: 10px 0 6px; min-height: 30px; text-align: center; font-size: 19px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sumline.idle { color: var(--muted); }
.sumline.hint { color: var(--cream); font-size: 20px; }
.sumline.exact { color: var(--teal); }
.sumline.over { color: var(--coral); }
.sumline.long { font-size: 15px; }

/* Board */
.stage { position: relative; flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }
.board-wrap { padding: 10px; border-radius: 24px; background: rgba(2, 10, 24, .4); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .05), inset 0 0 0 1px rgba(255, 255, 255, .03); }
.board { position: relative; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; clip-path: inset(-10px -40px -40px -40px); }
.tile { position: absolute; left: 0; top: 0; width: var(--t); height: var(--t); border-radius: 14px; cursor: pointer; transition: transform var(--drop-ms) cubic-bezier(.34, 1.3, .64, 1); will-change: transform; }
.board.snap .tile { transition: none; }
.face {
  position: absolute; inset: 0; display: grid; place-items: center; border-radius: inherit;
  background: var(--glass); border: 1px solid var(--edge); box-shadow: var(--glass-shadow); transition: transform 90ms ease-out;
}
.tile.press .face { transform: scale(var(--press, .96)); }
.l { font: 700 calc(var(--t) * .54)/1 var(--heb); color: var(--cream); text-shadow: 0 1px 0 rgba(0, 0, 0, .35); margin-top: -.08em; }
.n { position: absolute; right: 7px; bottom: 4px; font-size: max(11px, calc(var(--t) * .19)); font-weight: 650; line-height: 1; color: #b9d0e6; transition: opacity .3s; }
.tile.mastered .n { opacity: .15; } /* documented contrast exception; Peek and the Always setting restore it */
.board.peek .n, .board.always .n { opacity: 1; }
.ticks { position: absolute; left: 6px; bottom: 5px; display: none; gap: 2px; }
.board.peek .ticks { display: flex; }                 /* practice days, shown while peeking */
.ticks i { width: 4px; height: 4px; border-radius: 50%; background: rgba(255, 255, 255, .22); }
.tile[data-days="1"] .ticks i:nth-child(-n+1), .tile[data-days="2"] .ticks i:nth-child(-n+2),
.tile[data-days="3"] .ticks i:nth-child(-n+3), .tile[data-days="4"] .ticks i { background: var(--teal); }
.tile.on .ticks i { background: rgba(4, 16, 31, .25); }
.tile.on .face {
  background: linear-gradient(165deg, #ffe596 0%, #f4c842 50%, #d9a423 100%); border-color: rgba(255, 236, 170, .85);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .65), 0 0 0 1px rgba(244, 200, 66, .35), 0 8px 22px -6px rgba(244, 200, 66, .6);
}
.tile.on .l, .tile.on .n { color: var(--ink); text-shadow: none; }
.tile.demo .face { box-shadow: var(--glass-shadow), 0 0 0 2px var(--cream); }
.tile.miss .face { animation: miss var(--miss-ms, .32s) ease-out; }
.tile.hint .face { animation: hint var(--hint-ms, .4s) ease-in-out; }
@keyframes miss { 20% { transform: translateX(-5px); } 45% { transform: translateX(4px); } 70% { transform: translateX(-2px); } }
@keyframes hint { 50% { transform: scale(1.08); box-shadow: var(--glass-shadow), 0 0 0 3px var(--teal), 0 0 18px rgba(45, 212, 222, .6); } }
@keyframes missr { 50% { box-shadow: var(--glass-shadow), 0 0 0 3px var(--coral); } }
.links { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; z-index: 2; }
.links path { fill: none; stroke-linecap: round; }
.l-under { stroke: rgba(4, 16, 31, .6); stroke-width: 12; }
.l-gold { stroke: var(--gold); stroke-width: 6; }
.ghost {
  position: absolute; left: -22px; top: -22px; width: 44px; height: 44px; border-radius: 50%; pointer-events: none; z-index: 3;
  background: radial-gradient(circle, rgba(255, 250, 235, .95) 0 30%, rgba(255, 250, 235, .35) 58%, transparent 70%);
  box-shadow: 0 0 0 2px rgba(255, 250, 235, .7), 0 0 22px rgba(255, 250, 235, .45);
}
.ghost.still { background: radial-gradient(circle, transparent 0 50%, rgba(255, 250, 235, .3) 62%, transparent 72%); width: 56px; height: 56px; left: -28px; top: -28px; }
.toast {
  position: absolute; left: 50%; top: 2px; z-index: 5; padding: 10px 18px; border-radius: 999px; white-space: nowrap; pointer-events: none;
  background: #071c33; border: 1px solid rgba(244, 200, 66, .55); box-shadow: 0 12px 30px -8px rgba(0, 0, 0, .8);
  font-weight: 650; opacity: 0; transform: translate(-50%, -6px); transition: opacity .15s, transform .2s ease-out;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast .heb { font: 700 24px/1 var(--heb); color: var(--gold); margin-inline-end: 8px; }

.info { display: flex; align-items: center; gap: 16px; margin: 12px 0 10px; font-size: 14px; color: var(--muted); }
.meter { flex: 1; min-width: 0; }
.bar { height: 6px; margin-top: 6px; border-radius: 3px; background: rgba(255, 255, 255, .12); overflow: hidden; }
.bar i { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--teal); transition: width .4s ease-out; }
.actions { display: flex; gap: 10px; }
.actions .btn { flex: 1; }
#btn-submit { flex: 1.5; }

/* Overlays */
.overlay { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; padding: 24px; background: rgba(2, 8, 18, .74); }
.panel {
  width: 100%; max-width: 340px; padding: 26px 22px 22px; border-radius: 26px; text-align: center;
  background: linear-gradient(170deg, #144172, #0a2746); border: 1px solid var(--edge);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .2), 0 24px 60px -12px rgba(0, 0, 0, .85); animation: rise .32s cubic-bezier(.34, 1.4, .64, 1);
}
@keyframes rise { from { transform: translateY(14px) scale(.92); opacity: 0; } }
.panel h2 { font-size: 24px; margin-bottom: 8px; }
.panel .btn { display: block; width: 100%; margin-top: 10px; }
.kicker { margin: 0; font-size: 12px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--gold); }
.card-num { margin-top: 6px; font-size: 68px !important; line-height: 1; color: var(--gold); text-shadow: 0 0 32px rgba(244, 200, 66, .35); }
#card .panel { border-color: rgba(244, 200, 66, .5); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .2), 0 0 44px -8px rgba(244, 200, 66, .4), 0 24px 60px -12px rgba(0, 0, 0, .85); } /* the reward screen carries the reward colour */
.card-heb { margin: 10px 0 4px; font: 800 42px/1.2 var(--heb); }
.card-line { margin: 10px 0; font-size: 16px; }
.card-src { margin: 0 0 12px; font-size: 13px; color: var(--muted); }

/* Results */
.results { justify-content: center; gap: 10px; text-align: center; overflow-y: auto; }
.results h1 { font: 800 32px/1.1 var(--heb); }
.score-big { font-size: 68px; font-weight: 800; line-height: 1.05; color: var(--gold); text-shadow: 0 0 32px rgba(244, 200, 66, .35); }
.badge { align-self: center; margin: 0; padding: 6px 16px; border-radius: 999px; background: var(--gold); color: var(--ink); font-weight: 750; }
.results-meta { margin: 0; color: var(--muted); }
.rlist { display: grid; gap: 6px; margin: 4px 0; padding: 0; list-style: none; }
.rlist li { display: flex; justify-content: space-between; padding: 10px 14px; border-radius: 12px; background: rgba(255, 255, 255, .06); }
.rlist b { font-weight: 750; }
.rlist span { color: var(--muted); }
.rlist .word { margin-left: 8px; padding: 2px 9px; border-radius: 999px; background: var(--gold); color: var(--ink); font-size: 12px; font-style: normal; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
#share-box { display: grid; gap: 10px; }
.share { margin: 0; padding: 12px 14px; border-radius: 12px; text-align: left; white-space: pre-wrap; background: rgba(2, 10, 24, .5); border: 1px solid var(--edge); font: 600 14px/1.6 var(--ui); }

/* Collection and Settings */
.page-head { display: flex; align-items: center; gap: 14px; margin-bottom: 6px; }
.page h1 { font: 800 30px/1.1 var(--heb); }
.page h2 { margin: 22px 0 10px; font-size: 13px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.cards-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 0; padding: 0; list-style: none; }
.cards-grid button, .cards-grid .locked { width: 100%; min-height: 64px; padding: 6px 2px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; border-radius: 14px; }
.cards-grid button b { font-size: 20px; color: var(--gold); }
.cards-grid button span { font: 700 16px/1.1 var(--heb); }
.cards-grid .locked { border: 1px dashed rgba(160, 200, 240, .3); color: var(--muted); font-weight: 650; }
.words { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; list-style: none; }
.words li { padding: 8px 14px; border-radius: 999px; background: rgba(255, 255, 255, .07); }
.words .heb { font: 700 21px/1 var(--heb); margin-inline-end: 6px; }
.empty-note { color: var(--muted); }
.practice-note { margin: -4px 0 10px; font-size: 13px; color: var(--muted); }
.practice { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 0; padding: 0; list-style: none; }
.practice li { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 4px; border-radius: 12px; background: rgba(255, 255, 255, .06); }
.practice .heb { font: 700 22px/1 var(--heb); }
.practice small { font-size: 11px; color: var(--muted); }
.dots { display: flex; gap: 4px; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: rgba(255, 255, 255, .14); }
.dots i.on { background: var(--teal); }
.pilot { display: grid; gap: 8px; justify-items: center; }
.btn.small { min-height: 44px; padding: 0 14px; font-size: 13px; color: var(--muted); }
.settings fieldset { margin: 18px 0 0; padding: 0; border: 0; }
.settings legend { margin-bottom: 8px; font-weight: 650; }
.seg { display: flex; gap: 4px; padding: 4px; border-radius: 18px; background: rgba(2, 10, 24, .45); }
.seg label { position: relative; flex: 1; }
.seg input { position: absolute; inset: 0; margin: 0; opacity: 0; cursor: pointer; }
.seg span { display: flex; align-items: center; justify-content: center; min-height: 56px; padding: 0 6px; border-radius: 14px; text-align: center; color: var(--muted); font-weight: 650; }
.seg input:checked + span { background: var(--cream); color: var(--ink); }
.seg input:focus-visible + span { outline: 3px solid var(--cream); outline-offset: 2px; }

/* Effects */
#fx { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 30; pointer-events: none; }
#flash { position: fixed; inset: 0; z-index: 29; pointer-events: none; background: #fff8e6; opacity: 0; }
.numpop { position: fixed; z-index: 31; pointer-events: none; font-size: 28px; font-weight: 800; color: var(--gold); text-shadow: 0 2px 12px rgba(0, 0, 0, .6); transform: translate(-50%, -50%); }

/* Short phones: give the height to the board so tiles stay near 56 px */
@media (max-height: 700px) {
  .gauge { width: 72px; height: 72px; }
  .g-core { inset: 9px; }
  .g-core b { font-size: 23px; }
  .stat b { font-size: 20px; }
  .sumline { margin: 4px 0 2px; font-size: 17px; }
  .board-wrap { padding: 6px; border-radius: 18px; }
  .info { margin: 6px 0; }
  .home { gap: 20px; }
}

/* Reduced motion (system or setting): no overshoot, no shake, no slide-in */
[data-motion="reduce"] .tile { transition: transform 120ms ease-out; }
[data-motion="reduce"] .tile.miss .face { animation: missr var(--miss-ms, .32s); }
[data-motion="reduce"] .tile.hint .face { animation: none; box-shadow: var(--glass-shadow), 0 0 0 3px var(--teal); }
[data-motion="reduce"] .panel { animation: none; }
[data-motion="reduce"] .toast { transition: opacity .15s; transform: translate(-50%, 0); }
