/* Sudoku Cubes: main styles. Mobile first. 3D comes from pre-rendered sprites plus CSS 3D transforms (board tilt,
 * lifted selection, spinning title cube); body.lite removes the transforms and animations. */
@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 {
  --bg: #f3f5fb; --bg-grad: linear-gradient(180deg, #f6f7fc 0%, #eceff8 100%); --ink: #26315f; --ink-soft: #5b6690; --card: #ffffff; --card-2: #f4f6ff; --line: #d7dcf3;
  --brand: #3d5afe; --brand-2: #2f45d6; --green: #2fbf62; --red: #e23a4a; --gold: #f4a300;
  --slab: #3048d8; --slab-edge: #1f2f9e; --box-gap: 5px; --cell-gap: 2px;
  --easy: #2fbf62; --medium: #18b4c9; --hard: #ff9f1c; --expert: #ef476f; --master: #8f5cf7;
  --bs: 340px; --safe-top: env(safe-area-inset-top, 0px); --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
body.dark {
  --bg: #171a2b; --bg-grad: linear-gradient(180deg, #1b1e31 0%, #141626 100%); --ink: #e8ebff; --ink-soft: #a6aed6; --card: #232849; --card-2: #2b3157; --line: #3a4170;
  --slab: #2b3a9e; --slab-edge: #18205e;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  font-family: 'Fredoka', system-ui, sans-serif; color: var(--ink); background: var(--bg-grad);
  -webkit-user-select: none; user-select: none; touch-action: manipulation;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
img { -webkit-user-drag: none; }
h1, h2, b.title { font-family: 'Lilita One', 'Fredoka', sans-serif; font-weight: 400; letter-spacing: .3px; }
#app { position: relative; height: 100%; max-width: 760px; margin: 0 auto; }
.screen { position: absolute; inset: 0; display: none; flex-direction: column; padding: calc(8px + var(--safe-top)) 12px calc(8px + var(--safe-bottom)); }
.screen.active { display: flex; }
.noscript { padding: 2em; text-align: center; }

/* ---------- shared widgets ---------- */
.pill { display: inline-flex; align-items: center; gap: 4px; background: var(--card); border-radius: 999px; padding: 3px 12px 3px 4px; font-weight: 600;
  box-shadow: 0 3px 0 var(--line), 0 6px 14px rgba(40, 50, 120, .12); min-width: 64px; }
.pill img { width: 28px; height: 28px; }
.icon-btn { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; transition: transform .12s; }
.icon-btn img { width: 46px; height: 46px; }
.icon-btn:active, .btn:active, .tool:active { transform: translateY(2px) scale(.97); }
.btn { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 52px; padding: 6px 18px 6px 8px; border-radius: 18px;
  font-family: 'Lilita One', sans-serif; font-size: 20px; letter-spacing: .4px; transition: transform .12s, box-shadow .12s; }
.btn img { width: 40px; height: 40px; }
.btn.primary { background: linear-gradient(180deg, #5c78ff, var(--brand)); color: #fff; box-shadow: 0 5px 0 var(--brand-2), 0 10px 22px rgba(61, 90, 254, .35); }
.btn.secondary { background: var(--card); box-shadow: 0 5px 0 var(--line), 0 8px 18px rgba(40, 50, 120, .12); }
.btn.ghost { background: transparent; color: var(--ink-soft); min-height: 44px; font-size: 17px; }
.btn.danger { color: #fff; background: linear-gradient(180deg, #ff6b7a, var(--red)); box-shadow: 0 5px 0 #a8202e; }
.btn.ghost.danger { background: transparent; color: var(--red); box-shadow: none; }
.btn.big { min-height: 64px; font-size: 24px; }
.btn.big img { width: 50px; height: 50px; }
.bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 50px; }
.bar h2 { margin: 0; font-size: 26px; }
.center { text-align: center; }
.sub { color: var(--ink-soft); font-size: 14px; }

/* ---------- home ---------- */
.home-top { display: flex; gap: 8px; align-items: center; }
.home-top .icon-btn { margin-left: auto; }
.hero { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 0; }
.logo { width: min(86vw, 420px); height: auto; margin-top: -6px; }
.tagline { margin: 0; color: var(--ink-soft); font-weight: 500; }
.cube-stage { width: 96px; height: 96px; perspective: 600px; margin-bottom: 4px; }
.cube3d { position: relative; width: 96px; height: 96px; transform-style: preserve-3d; transform: rotateX(-24deg) rotateY(36deg); animation: spin 14s linear infinite; }
.cube3d > i { position: absolute; inset: 0; border-radius: 16px; overflow: hidden; background: #fff3dc; box-shadow: inset 0 0 0 2px rgba(0, 0, 0, .04); }
.cube3d > i .tile, .cube3d > i .dg { position: absolute; inset: -6%; background: url('../assets/images/tiles/tiles.webp') 0 0 / 1000% 100% no-repeat; }
.cube3d > i .dg { inset: 0; background-image: url('../assets/images/tiles/digits.webp'); background-size: 900% 500%; }
.cube3d .f1 { transform: translateZ(48px); } .cube3d .f2 { transform: rotateY(90deg) translateZ(48px); } .cube3d .f3 { transform: rotateY(180deg) translateZ(48px); }
.cube3d .f4 { transform: rotateY(-90deg) translateZ(48px); } .cube3d .f5 { transform: rotateX(90deg) translateZ(48px); } .cube3d .f6 { transform: rotateX(-90deg) translateZ(48px); }
@keyframes spin { from { transform: rotateX(-24deg) rotateY(0deg); } to { transform: rotateX(-24deg) rotateY(360deg); } }
.home-actions { display: flex; flex-direction: column; gap: 12px; width: min(100%, 420px); margin: 0 auto; }
.home-actions .row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.home-stats { display: flex; justify-content: center; gap: 18px; margin: 12px 0 0; color: var(--ink-soft); font-size: 15px; }
.home-stats b { color: var(--ink); }
.credit { text-align: center; color: var(--ink-soft); font-size: 12px; margin: 6px 0 0; }
.mascot-home { position: absolute; right: 10px; top: 12%; width: 88px; height: 88px; pointer-events: none; animation: bob 3s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-8px) rotate(-3deg); } }

/* ---------- levels ---------- */
.tabs { display: flex; gap: 6px; overflow-x: auto; padding: 6px 2px 4px; scrollbar-width: none; }
.tab { flex: 1 0 auto; padding: 8px 12px; border-radius: 14px; background: var(--card); font-weight: 600; box-shadow: 0 3px 0 var(--line); }
.tab.on { color: #fff; }
.tab.on.easy { background: var(--easy); } .tab.on.medium { background: var(--medium); } .tab.on.hard { background: var(--hard); }
.tab.on.expert { background: var(--expert); } .tab.on.master { background: var(--master); }
.tier-note { margin: 4px 2px 8px; color: var(--ink-soft); font-size: 14px; }
.level-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; overflow-y: auto; padding: 4px 2px 16px; align-content: start; }
.lvl { position: relative; aspect-ratio: 1; border-radius: 16px; background: var(--card); display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-family: 'Lilita One', sans-serif; font-size: 22px; box-shadow: 0 5px 0 var(--line), 0 8px 14px rgba(40, 50, 120, .1); }
.lvl.done { color: #fff; }
.lvl.done.easy { background: var(--easy); box-shadow: 0 5px 0 #1e8a45; } .lvl.done.medium { background: var(--medium); box-shadow: 0 5px 0 #0f8090; }
.lvl.done.hard { background: var(--hard); box-shadow: 0 5px 0 #c4720a; } .lvl.done.expert { background: var(--expert); box-shadow: 0 5px 0 #b52a4b; }
.lvl.done.master { background: var(--master); box-shadow: 0 5px 0 #6538c4; }
.lvl.next { outline: 3px solid var(--brand); animation: glow 1.6s ease-in-out infinite; }
.lvl.locked { opacity: .55; }
.lvl .lk { width: 26px; height: 26px; position: absolute; bottom: 4px; }
.lvl .st { display: flex; position: absolute; bottom: 3px; }
.lvl .st img { width: 20px; height: 20px; margin: 0 -2px; filter: drop-shadow(0 1px 1px rgba(0,0,0,.25)); }
@keyframes glow { 50% { outline-color: rgba(61, 90, 254, .25); } }

/* ---------- play ---------- */
#play { padding-bottom: calc(6px + var(--safe-bottom)); }
.title-block { display: flex; flex-direction: column; align-items: center; line-height: 1.05; }
.title-block b { font-family: 'Lilita One', sans-serif; font-size: 22px; font-weight: 400; }
.tier { font-size: 13px; font-weight: 600; padding: 1px 10px; border-radius: 999px; color: #fff; margin-top: 2px; }
.tier.easy { background: var(--easy); } .tier.medium { background: var(--medium); } .tier.hard { background: var(--hard); }
.tier.expert { background: var(--expert); } .tier.master { background: var(--master); }
.hud { display: flex; align-items: center; justify-content: space-between; padding: 2px 4px 0; min-height: 30px; font-weight: 600; }
.hearts { display: flex; } .hearts img { width: 26px; height: 26px; }
.clock { font-variant-numeric: tabular-nums; color: var(--ink-soft); }
.score { font-family: 'Lilita One', sans-serif; font-size: 20px; color: var(--brand); min-width: 60px; text-align: right; }
.board-wrap { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }
.board-stage { perspective: 1200px; perspective-origin: 50% 0%; }
.board { width: var(--bs); height: var(--bs); display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); gap: var(--box-gap);
  padding: calc(var(--bs) * .018); border-radius: calc(var(--bs) * .05);
  background: linear-gradient(160deg, #5370ff, var(--slab)); transform-style: preserve-3d;
  box-shadow: 0 2px 0 #4a64f0, 0 5px 0 var(--slab-edge), 0 9px 0 var(--slab-edge), 0 14px 26px rgba(20, 30, 100, .35); touch-action: none; }
.box { display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); gap: var(--cell-gap); background: rgba(10, 20, 90, .25);
  border-radius: calc(var(--bs) * .02); padding: 1px; }
.cell { position: relative; cursor: pointer; min-width: 0; min-height: 0; }
.cell .tile, .cell .dg, .key .tile, .key .dg { position: absolute; pointer-events: none; background-repeat: no-repeat; }
.cell .tile { inset: -4%; background-image: url('../assets/images/tiles/tiles.webp'); background-size: 1000% 100%; }
.cell .dg { inset: -2% -2% 2% -2%; background-image: url('../assets/images/tiles/digits.webp'); background-size: 900% 500%; display: none; }
.cell.has .dg { display: block; }
.cell .notes { position: absolute; inset: 6% 6% 10%; display: none; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); pointer-events: none;
  font-size: calc(var(--bs) / 9 * .25); font-weight: 600; color: #4a5584; line-height: 1; text-align: center; align-items: center; }
.cell.noted .notes { display: grid; }
.cell .notes b { visibility: hidden; font-weight: 600; }
.cell .notes b.on { visibility: visible; }
.cell .notes b.hi { color: #fff; background: var(--brand); border-radius: 4px; }
.cell.t-select { z-index: 2; }
.cell.t-select .tile, .cell.t-select .dg { transform: translateZ(10px) translateY(-3%) scale(1.06); }
.cell.pop .dg, .cell.pop .tile { animation: pop .4s cubic-bezier(.3, 1.6, .5, 1); }
.cell.shake { animation: shake .4s; }
.cell.wave .tile, .cell.wave .dg { animation: wave .6s ease-out; }
.cell.clash::after { content: ''; position: absolute; inset: 4%; border-radius: 18%; box-shadow: 0 0 0 3px var(--red) inset; animation: fade .9s ease-out forwards; pointer-events: none; }
.cell.hl::before { content: ''; position: absolute; inset: -1px; border-radius: 16%; box-shadow: 0 0 0 2px #2fbf62 inset, 0 0 10px rgba(47, 191, 98, .7); z-index: 3; pointer-events: none; }
@keyframes pop { 0% { transform: scale(.4) translateY(-30%); } 100% { transform: none; } }
@keyframes shake { 20%, 60% { transform: translateX(-6%); } 40%, 80% { transform: translateX(6%); } }
@keyframes wave { 40% { transform: translateY(-14%) scale(1.08); filter: brightness(1.15); } }
@keyframes fade { from { opacity: 1; } to { opacity: 0; } }

.tools { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 8px 0 6px; }
.tool { position: relative; display: flex; flex-direction: column; align-items: center; font-size: 13px; font-weight: 600; color: var(--ink-soft); padding-top: 2px; }
.tool img { width: 44px; height: 44px; }
.tool.on img { filter: drop-shadow(0 0 6px rgba(143, 92, 247, .8)); }
.tool .badge { position: absolute; top: -2px; left: calc(50% + 10px); font-style: normal; font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 999px; background: #b9bfd3; color: #fff; display: flex; align-items: center; gap: 1px; }
.tool.on .badge { background: #8f5cf7; }
.tool .badge.cost { background: var(--card); color: var(--ink); box-shadow: 0 1px 4px rgba(0, 0, 0, .2); padding-left: 2px; }
.tool .badge.cost img { width: 15px; height: 15px; }
.pad { display: grid; grid-template-columns: repeat(9, 1fr); gap: 4px; }
.key { position: relative; aspect-ratio: .78; max-height: 72px; }
.key .tile { inset: -6% -6% -2%; background-image: url('../assets/images/tiles/tiles.webp'); background-size: 1000% 100%; }
.key .dg { inset: 4% -2% 18%; background-image: url('../assets/images/tiles/digits.webp'); background-size: 900% 500%; }
.key small { position: absolute; bottom: 1px; left: 0; right: 0; text-align: center; font-size: 11px; font-weight: 700; color: rgba(255, 255, 255, .85); }
.key.notes .dg { transform: scale(.72); opacity: .85; }
.key.done { opacity: .5; }
.key.press .tile, .key.press .dg { animation: press .18s; }
@keyframes press { 50% { transform: translateY(6%) scale(.94); } }

/* ---------- modal, hint bar, toast ---------- */
.modal { position: fixed; inset: 0; background: rgba(15, 20, 50, .55); display: flex; align-items: center; justify-content: center; z-index: 20; padding: 16px; }
.modal[hidden] { display: none; }
.sheet { position: relative; width: min(100%, 420px); max-height: calc(100% - 20px); overflow-y: auto; background: var(--card); border-radius: 24px; padding: 18px 18px 16px;
  box-shadow: 0 8px 0 var(--line), 0 20px 50px rgba(0, 0, 0, .35); animation: rise .25s ease-out; }
@keyframes rise { from { transform: translateY(24px) scale(.96); opacity: 0; } }
.sheet h2 { text-align: center; margin: 0 0 8px; font-size: 28px; }
.modal-mascot { display: block; width: 96px; height: 96px; margin: -6px auto 0; }
.modal-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.stars-big { display: flex; justify-content: center; gap: 4px; }
.stars-big img { width: 64px; height: 64px; transform: scale(0); transition: transform .35s cubic-bezier(.3, 1.8, .5, 1); }
.stars-big img:nth-child(2) { transform: scale(0) translateY(-10px); width: 76px; height: 76px; }
.stars-big img.in { transform: scale(1); } .stars-big img:nth-child(2).in { transform: scale(1) translateY(-10px); }
.big-score { font-family: 'Lilita One', sans-serif; font-size: 44px; text-align: center; margin: 0; color: var(--brand); }
.breakdown { width: 100%; border-collapse: collapse; margin: 8px 0; font-size: 15px; }
.breakdown td { padding: 5px 4px; border-bottom: 1px solid var(--line); }
.breakdown td:last-child { text-align: right; font-weight: 600; }
.coins-won { display: flex; align-items: center; justify-content: center; gap: 6px; font-weight: 700; flex-wrap: wrap; }
.coins-won img, img.tiny { width: 24px; height: 24px; vertical-align: middle; }
.coins-won small { width: 100%; text-align: center; color: var(--ink-soft); font-weight: 500; }
.warn { color: var(--red); font-size: 13px; text-align: center; }
.help { padding-left: 18px; margin: 4px 0; line-height: 1.4; }
.help li { margin: 6px 0; }
.red { color: var(--red); }
.settings { display: flex; flex-direction: column; gap: 4px; }
.switch, .select { display: flex; align-items: center; justify-content: space-between; min-height: 44px; border-bottom: 1px solid var(--line); gap: 10px; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch i { width: 48px; height: 28px; border-radius: 999px; background: #c6cbe0; position: relative; transition: background .2s; flex: none; }
.switch i::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 2px 4px rgba(0, 0, 0, .2); }
.switch input:checked + i { background: var(--green); }
.switch input:checked + i::after { transform: translateX(20px); }
.switch input:focus-visible + i { outline: 2px solid var(--brand); }
.select select { font: inherit; padding: 6px 8px; border-radius: 10px; border: 1px solid var(--line); background: var(--card-2); color: var(--ink); }
.hintbar { position: fixed; left: 50%; transform: translateX(-50%); top: calc(52px + var(--safe-top)); width: min(94vw, 460px); display: flex; align-items: center; gap: 8px;
  background: var(--card); border-radius: 18px; padding: 8px 12px 8px 6px; box-shadow: 0 6px 0 var(--line), 0 12px 30px rgba(0, 0, 0, .25); z-index: 15; animation: rise .2s ease-out; }
.hintbar[hidden] { display: none; }
.hintbar img { width: 56px; height: 56px; flex: none; }
.hintbar p { margin: 0; font-size: 15px; line-height: 1.3; }
.toast { position: fixed; left: 50%; top: calc(64px + var(--safe-top)); transform: translate(-50%, -20px); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 14px;
  font-weight: 600; 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; display: none; }

/* ---------- lite mode and reduced motion ---------- */
body.lite .board { transform: none; box-shadow: 0 6px 0 var(--slab-edge); }
body.lite .cube3d, body.reduce-motion .cube3d { animation: none; }
body.lite .cell.t-select .tile, body.lite .cell.t-select .dg { transform: none; }
body.lite *, body.reduce-motion * { animation-duration: .001s !important; transition-duration: .001s !important; }
body.lite .mascot-home { animation: none; }
body.lite .btn.primary, body.lite .btn.secondary, body.lite .pill, body.lite .lvl, body.lite .sheet { box-shadow: 0 4px 0 var(--line); }
body.lite .btn.primary { box-shadow: 0 4px 0 var(--brand-2); }
body.dark .logo { filter: drop-shadow(0 0 2px rgba(255, 255, 255, .55)) drop-shadow(0 0 10px rgba(160, 180, 255, .25)); }

/* BrainCooker: keep the top bar clear of the platform Home button (set by the BrainCooker SDK). */
.bar { padding-left: var(--bc-home-inset, 0px); }
