/* Lost Letters — original styles. Colours are tokens so lite mode and themes can adjust them in one place. */
@font-face { font-family: 'Lilita One'; src: url('../assets/fonts/LilitaOne.woff2') format('woff2'); font-display: swap; }
@font-face { font-family: 'Fredoka'; src: url('../assets/fonts/Fredoka.woff2') format('woff2'); font-weight: 300 700; font-display: swap; }

:root {
  --bg1: #0d5f6a; --bg2: #1d9a8f; --bg3: #7fd1b9;
  --tile: #fff8ec; --tile-edge: #e8d9bf; --ink: #16324a; --muted: #5d7686;
  --coral: #ff7a59; --coral-dark: #e0573a; --gold: #ffc83d; --mint: #33c286; --mint-dark: #1f9a68;
  --sheet: #fffdf8; --chip: #ffffff; --chip-edge: #cfe3e0; --blank: #ffe3d6;
  --sel: rgba(255, 122, 89, .55);
  --radius: 16px; --shadow: 0 4px 0 rgba(0, 0, 0, .12), 0 8px 18px rgba(0, 0, 0, .12);
  --cell: 40px; --font: 'Fredoka', 'Trebuchet MS', system-ui, sans-serif; --display: 'Lilita One', 'Arial Black', sans-serif;
  --safe-top: env(safe-area-inset-top, 0px); --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  font-family: var(--font); color: var(--ink); background: var(--bg1);
  background-image: radial-gradient(circle at 20% 10%, rgba(255, 255, 255, .14) 0 2px, transparent 3px),
    linear-gradient(170deg, var(--bg2) 0%, var(--bg1) 70%);
  background-size: 26px 26px, 100% 100%;
  -webkit-user-select: none; user-select: none; touch-action: manipulation;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
button:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
img { display: block; }
#app { position: fixed; inset: 0; display: flex; justify-content: center; }

.screen { position: absolute; inset: 0; margin: 0 auto; max-width: 560px; display: none; flex-direction: column;
  padding: calc(10px + var(--safe-top)) 14px calc(12px + var(--safe-bottom)); }
.screen.active { display: flex; animation: fadein .25s ease-out; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* Shared bits */
.pill { display: inline-flex; align-items: center; gap: 6px; background: rgba(255, 255, 255, .92); border-radius: 999px;
  padding: 5px 12px 5px 7px; font-weight: 600; font-size: 16px; box-shadow: 0 2px 0 rgba(0, 0, 0, .12); }
.pill img { width: 22px; height: 22px; }
.icon-btn { width: 44px; height: 44px; border-radius: 14px; background: rgba(255, 255, 255, .92); display: grid; place-items: center;
  box-shadow: 0 3px 0 rgba(0, 0, 0, .14); transition: transform .08s; flex: none; }
.icon-btn img { width: 24px; height: 24px; }
.icon-btn:active, .btn:active, .tool:active { transform: translateY(2px); }
.icon-btn.flip img { transform: scaleX(-1); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 10px; min-height: 52px; padding: 0 22px; border-radius: 18px;
  font-weight: 600; font-size: 19px; transition: transform .08s; }
.btn img { width: 24px; height: 24px; }
.btn.primary { background: var(--coral); color: #fff; box-shadow: 0 5px 0 var(--coral-dark), 0 10px 20px rgba(0, 0, 0, .18); }
.btn.secondary { background: var(--tile); box-shadow: 0 5px 0 var(--tile-edge), 0 10px 20px rgba(0, 0, 0, .12); }
.btn.ghost { background: rgba(255, 255, 255, .16); color: #fff; }
.btn.ghost img { filter: brightness(0) invert(1); }
.btn.mint { background: var(--mint); color: #fff; box-shadow: 0 5px 0 var(--mint-dark); }
.btn.big { min-height: 64px; font-size: 24px; }
.btn.small { min-height: 42px; font-size: 16px; padding: 0 16px; }
.btn[disabled] { opacity: .5; }

/* Home */
.home-top { display: flex; gap: 8px; justify-content: flex-end; align-items: center; }
.home-top .pill:first-child { margin-right: auto; }
.logo { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; min-height: 180px; }
.logo-row { display: flex; gap: 6px; }
.logo-row span { width: 46px; height: 52px; display: grid; place-items: center; font-family: var(--display); font-size: 34px;
  background: var(--tile); border-radius: 12px; box-shadow: 0 5px 0 var(--tile-edge), 0 10px 18px rgba(0, 0, 0, .18); transform: rotate(var(--r, 0deg)); }
.logo-row span:nth-child(odd) { --r: -3deg; } .logo-row span:nth-child(3n) { --r: 2deg; }
.logo-row span.gap { background: var(--blank); color: transparent; border: 3px dashed var(--coral); animation: gap 3.2s ease-in-out infinite; }
@keyframes gap { 0%, 55% { color: transparent; } 65%, 90% { color: var(--coral); background: var(--tile); border-color: transparent; } 100% { color: transparent; } }
.tagline { color: #fff; font-size: 17px; margin: 14px 0 0; opacity: .95; text-align: center; }
.home-actions { display: flex; flex-direction: column; gap: 14px; align-items: stretch; width: min(100%, 360px); margin: 0 auto; }
.home-actions .row { display: flex; gap: 12px; } .home-actions .row .btn { flex: 1; }
.home-stats { display: flex; justify-content: center; gap: 18px; color: #fff; margin-top: 18px; font-size: 15px; opacity: .95; flex-wrap: wrap; }
.credit { text-align: center; color: rgba(255, 255, 255, .75); font-size: 12px; letter-spacing: .06em; margin: 10px 0 0; text-transform: uppercase; }

/* Bars */
.bar { display: flex; align-items: center; gap: 8px; }
.bar h2 { flex: 1; margin: 0; color: #fff; font-family: var(--display); font-weight: 400; font-size: 26px; text-align: center; }
.level-pill { margin-right: auto; background: var(--ink); color: #fff; font-weight: 600; border-radius: 999px; padding: 8px 14px; font-size: 16px; white-space: nowrap; }

/* Level select */
.chapter-nav { display: flex; align-items: center; gap: 10px; margin: 14px 0 10px; color: #fff; text-align: center; }
.chapter-nav > div { flex: 1; display: flex; flex-direction: column; } .chapter-nav b { font-size: 20px; } .chapter-nav small { opacity: .85; }
.level-grid { flex: 1; overflow-y: auto; display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; align-content: start; padding: 4px 2px 20px;
  -webkit-overflow-scrolling: touch; }
.lvl { aspect-ratio: 1; border-radius: 14px; background: var(--tile); box-shadow: 0 4px 0 var(--tile-edge); display: flex; flex-direction: column;
  align-items: center; justify-content: center; font-weight: 700; font-size: 19px; position: relative; }
.lvl .st { display: flex; gap: 1px; margin-top: 2px; } .lvl .st img { width: 13px; height: 13px; }
.lvl.locked { background: rgba(255, 255, 255, .25); box-shadow: none; color: rgba(255, 255, 255, .7); }
.lvl.locked img.lock { width: 20px; height: 20px; filter: brightness(0) invert(1); opacity: .75; }
.lvl.current { background: var(--coral); color: #fff; box-shadow: 0 4px 0 var(--coral-dark); }

/* Play */
.hud { text-align: center; color: #fff; }
.hud h1 { font-family: var(--display); font-weight: 400; font-size: 28px; margin: 8px 0 4px; letter-spacing: .03em; text-shadow: 0 3px 0 rgba(0, 0, 0, .18); }
.hud-row { display: flex; align-items: center; gap: 10px; }
.clock, .score { min-width: 58px; font-weight: 600; font-variant-numeric: tabular-nums; font-size: 16px; }
.score { text-align: right; } .clock { text-align: left; }
.progress { flex: 1; height: 20px; border-radius: 999px; background: rgba(255, 255, 255, .25); position: relative; overflow: hidden; }
.progress i { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--gold); border-radius: 999px; transition: width .3s; }
.progress span { position: relative; font-size: 13px; font-weight: 700; color: var(--ink); line-height: 20px; }
.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin: 10px 0 8px; min-height: 36px; }
.chip { display: inline-flex; align-items: center; gap: 1px; background: var(--chip); border-radius: 12px; padding: 5px 9px; box-shadow: 0 3px 0 var(--chip-edge);
  font-weight: 700; font-size: var(--chip-font, 16px); letter-spacing: .04em; color: var(--ink); transition: background .2s, transform .2s; }
.chip .b { display: inline-grid; place-items: center; min-width: 1.05em; height: 1.25em; padding: 0 1px; border-radius: 5px; background: var(--blank); border: 1.5px dashed var(--coral);
  color: var(--coral-dark); margin: 0 2px; line-height: 1; font-size: .92em; }
.chip .b.rev { border-style: solid; background: #fff1c4; border-color: var(--gold); color: #a46a00; }
.chip.found { background: var(--mint); color: #fff; box-shadow: 0 3px 0 var(--mint-dark); }
.chip.found .b { background: transparent; border-color: transparent; color: #fff; }
.chip.found::before { content: '✓'; margin-right: 4px; }
.chip.pop { animation: pop .45s ease-out; }
@keyframes pop { 30% { transform: scale(1.18); } 100% { transform: none; } }

.board-wrap { flex: 1; display: flex; align-items: center; justify-content: center; min-height: 0; }
.board { --pad: 8px; position: relative; background: rgba(255, 255, 255, .2); border-radius: 22px; padding: var(--pad); touch-action: none; }
.cells { position: relative; display: grid; gap: var(--gap, 5px); grid-template-columns: repeat(var(--n, 5), var(--cell)); z-index: 1; }
.cell { width: var(--cell); height: var(--cell); border-radius: calc(var(--cell) * .22); background: var(--tile); box-shadow: 0 3px 0 var(--tile-edge);
  display: grid; place-items: center; font-weight: 700; font-size: calc(var(--cell) * .52); color: var(--ink); transition: transform .12s, background .12s; }
.cell.sel { background: #fff; transform: scale(1.08); color: var(--coral-dark); }
.cell.spot { animation: spot 1s ease-in-out 4; background: #fff1c4; }
@keyframes spot { 50% { transform: scale(1.18); box-shadow: 0 0 0 5px var(--gold); } }
.cell.anchor { box-shadow: 0 0 0 3px var(--coral), 0 3px 0 var(--tile-edge); }
.marks { position: absolute; left: var(--pad); top: var(--pad); overflow: visible; pointer-events: none; z-index: 2; mix-blend-mode: multiply; }
.board.shake { animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.combo { position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%); z-index: 3; pointer-events: none; color: #fff; font-family: var(--display);
  font-size: 24px; background: rgba(22, 50, 74, .82); padding: 6px 16px; border-radius: 999px; opacity: 0; white-space: nowrap; }
.combo.show { animation: combo 1s ease-out; }
@keyframes combo { 15% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); } 70% { opacity: 1; transform: translate(-50%, -60%); } 100% { opacity: 0; transform: translate(-50%, -90%); } }

.actions { display: flex; justify-content: center; gap: 14px; padding-top: 10px; }
.tool { width: 92px; border-radius: 18px; background: var(--tile); box-shadow: 0 4px 0 var(--tile-edge); padding: 8px 4px 6px; display: flex; flex-direction: column;
  align-items: center; gap: 2px; font-size: 13px; font-weight: 600; position: relative; transition: transform .08s; }
.tool > img { width: 30px; height: 30px; }
.tool .cost { position: absolute; top: -8px; right: -6px; display: inline-flex; align-items: center; gap: 2px; background: var(--ink); color: #fff;
  border-radius: 999px; padding: 2px 7px 2px 3px; font-style: normal; font-size: 12px; }
.tool .cost img { width: 15px; height: 15px; } .tool .cost.free { padding: 2px 7px; background: var(--mint-dark); }
.tool[disabled] { opacity: .45; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(6, 35, 42, .55); display: grid; place-items: center; z-index: 20; padding: 16px; }
.modal[hidden] { display: none; }
.sheet { width: min(100%, 400px); max-height: calc(100% - 20px); overflow-y: auto; background: var(--sheet); border-radius: 24px; padding: 20px 18px 18px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, .3); animation: rise .25s ease-out; text-align: center; }
@keyframes rise { from { transform: translateY(20px) scale(.97); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet h2 { font-family: var(--display); font-weight: 400; font-size: 28px; margin: 0 0 8px; color: var(--ink); }
.modal-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 16px; }
.modal-actions .btn { flex: 1 1 120px; }
.stars { display: flex; justify-content: center; gap: 6px; margin: 4px 0 8px; }
.stars img { width: 54px; height: 54px; transform: scale(0); animation: starin .4s cubic-bezier(.3, 1.6, .5, 1) forwards; }
.stars img:nth-child(2) { width: 68px; height: 68px; margin-top: -10px; }
@keyframes starin { to { transform: scale(1); } }
.big-score { font-family: var(--display); font-size: 44px; color: var(--coral); line-height: 1; margin: 4px 0; }
.sub { color: var(--muted); font-size: 14px; margin: 2px 0 10px; }
.breakdown { width: 100%; border-collapse: collapse; font-size: 15px; text-align: left; }
.breakdown td { padding: 4px 4px; border-bottom: 1px dashed #e3e3e3; } .breakdown td:last-child { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.breakdown tr.neg td:last-child { color: var(--coral-dark); } .breakdown tr.tot td { border: 0; font-size: 17px; }
.help { text-align: left; font-size: 15px; line-height: 1.45; } .help p { margin: 6px 0; } .help b { color: var(--coral-dark); }
.demo { display: flex; justify-content: center; gap: 4px; margin: 8px 0; }
.demo span { width: 32px; height: 34px; border-radius: 8px; background: var(--tile); box-shadow: 0 3px 0 var(--tile-edge); display: grid; place-items: center; font-weight: 700; }
.demo span.b { background: var(--blank); border: 2px dashed var(--coral); color: var(--coral); }
.setting { display: flex; align-items: center; justify-content: space-between; padding: 10px 2px; border-bottom: 1px dashed #e3e3e3; text-align: left; gap: 10px; }
.switch { width: 54px; height: 32px; border-radius: 999px; background: #cfd8dc; position: relative; transition: background .2s; flex: none; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); }
.switch[aria-checked="true"] { background: var(--mint); } .switch[aria-checked="true"]::after { transform: translateX(22px); }
.seg { display: inline-flex; background: #eef3f4; border-radius: 10px; padding: 3px; }
.seg button { padding: 5px 10px; border-radius: 8px; font-size: 14px; } .seg button[aria-pressed="true"] { background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .15); font-weight: 700; }
.note { font-size: 13px; color: var(--muted); margin-top: 10px; }
.warn { background: #fff1e8; border: 1px solid #ffc6b2; color: #8a3418; border-radius: 12px; padding: 10px; font-size: 14px; text-align: left; }

.toast { position: fixed; left: 50%; bottom: calc(110px + var(--safe-bottom)); transform: translate(-50%, 20px); background: var(--ink); color: #fff; padding: 10px 16px;
  border-radius: 14px; font-size: 15px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 30; max-width: 90vw; text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.fx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 25; }
.noscript { color: #fff; text-align: center; padding: 40px; }

/* Lite mode: cheaper paint on low-end phones */
.lite * { animation-duration: .01s !important; transition: none !important; }
.lite .screen.active, .lite .sheet { animation: none; }
.lite .cell, .lite .chip, .lite .tool, .lite .btn, .lite .lvl, .lite .logo-row span { box-shadow: none; }
.lite .marks { mix-blend-mode: normal; }
.lite body, body.lite { background-image: none; }
.reduce-motion .logo-row span.gap { animation: none; color: var(--coral); }
.btn.ghost-dark { background: #eef3f4; color: var(--muted); font-size: 16px; }
