:root {
  --night: #2b1f4d; --plum: #3b2a6b; --ink: #fff6e6; --muted: #ffe2c4; --card: #2b1f4dcc; --line: #ffffff33;
  --gold: #ffc35a; --gold-dark: #c98a2a; --coral: #ff7b6b; --good: #8ce0a8;
  --frame: #6a3f2a; --frame-dark: #3f2416; --glass: #fff4e2; --sand: #ffc35a; --sand-dark: #e8973a; --glow: #fff1a8;
  --title: 'Lilita One', 'Arial Rounded MT Bold', system-ui, sans-serif;
  --font: 'Poppins', ui-rounded, 'SF Pro Rounded', system-ui, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; color: var(--ink); font-family: var(--font); font-weight: 600; background: linear-gradient(160deg, #2b1f4d, #6b3f6e); overscroll-behavior: none; -webkit-user-select: none; user-select: none; overflow: hidden; }
body.paused *, body.paused *::before, body.paused *::after { animation-play-state: paused !important; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; padding: 0; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.defs { position: absolute; width: 0; height: 0; }
.splash { height: 100%; display: grid; place-items: center; color: var(--muted); }
.screen { position: relative; height: 100%; max-width: 520px; margin: auto; display: flex; flex-direction: column; overflow: hidden; background: linear-gradient(var(--plum), #8a4e86 38%, #f0886c 70%, #ffc977); }

/* Dusk scene: stars, a low sun and two dunes along the bottom. */
.dunes { position: absolute; left: 0; right: 0; bottom: 0; width: 100%; height: 48%; pointer-events: none; }
.d-star { fill: #fff; opacity: .8; }
.d-sun { fill: #ffd27a; opacity: .9; }
.d-far { fill: #c2626f; opacity: .55; }
.d-near { fill: #e88a6a; opacity: .6; }

/* Menu */
#menu { overflow-y: auto; }
.menu-inner { position: relative; flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: max(28px, env(safe-area-inset-top)) 22px max(18px, env(safe-area-inset-bottom)); }
h1 { font-family: var(--title); font-weight: 400; font-size: clamp(50px, 16vw, 66px); line-height: 1; margin: 6px 0 0; }
.tagline { color: var(--muted); font-size: 16px; font-weight: 600; margin: 8px 0 0; }
.hero-art { flex: 1 1 auto; width: 100%; max-width: 330px; min-height: 150px; max-height: 300px; margin: 12px 0 16px; overflow: visible; }
.big-btn { position: relative; width: min(100%, 300px); min-height: 60px; border-radius: 20px; display: flex; flex-direction: column; align-items: center; justify-content: center; font-family: var(--title); font-weight: 400; font-size: 24px; line-height: 1.05; margin-bottom: 14px; transition: transform .08s, box-shadow .08s; }
.big-btn small { font-family: var(--font); font-size: 13px; font-weight: 600; opacity: .85; margin-top: 3px; }
.big-btn b { font-weight: 400; }
.big-btn.gold { background: var(--gold); color: var(--plum); box-shadow: 0 6px 0 var(--gold-dark); }
.big-btn.night { background: var(--card); color: var(--ink); box-shadow: 0 0 0 2px #ffffff55 inset; }
.big-btn.gold:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--gold-dark); }
.big-btn.night:active { transform: translateY(2px); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; width: min(100%, 300px); margin: 4px 0 0; }
.stats div { display: flex; flex-direction: column; align-items: center; background: var(--card); border-radius: 14px; padding: 6px 4px 5px; }
.stats dd { margin: 0; font-family: var(--title); font-size: 22px; line-height: 1.1; }
.stats dt { color: var(--muted); font-size: 11.5px; }

/* Play */
.top-bar { position: relative; flex: none; display: flex; align-items: center; gap: 10px; padding: max(12px, env(safe-area-inset-top)) 14px 0; }
.round-plain { position: relative; flex: none; width: 46px; height: 46px; display: grid; place-items: center; color: var(--ink); border-radius: 50%; background: var(--card); }
.round-plain svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.round-plain .fill { fill: currentColor; stroke: none; }
#sound[aria-pressed="false"] .waves { display: none; }
#sound[aria-pressed="false"] { opacity: .55; }
.hud-title { flex: 1; min-width: 0; text-align: center; font-family: var(--title); font-size: 25px; }
.hud-title strong { font-weight: 400; }
#play.no-sound .hud-title { margin-right: 56px; }
.status-row { position: relative; flex: none; display: flex; justify-content: center; gap: 8px; margin-top: 6px; }
.pill { background: var(--card); color: var(--ink); border-radius: 30px; padding: 4px 15px 3px; font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
#moves i { font-style: normal; color: var(--gold); letter-spacing: 1px; margin-right: 3px; }
.goal { position: relative; flex: none; background: var(--card); border-radius: 22px; padding: 10px 16px 8px; margin: 10px 14px 0; }
.goal-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.goal-top b { font-size: 15px; }
#goal-time { font-family: var(--title); font-size: 30px; line-height: 1; color: var(--coral); white-space: nowrap; }
.timeline { display: block; width: 100%; height: 30px; margin-top: 6px; overflow: visible; }
.tl-track { fill: #ffffff33; }
.tl-fill { fill: var(--gold); }
.tl-tick { fill: #ffffff66; }
.tl-tick.past { fill: var(--gold); }
.tl-bell { fill: var(--coral); }
.tl-bell.rung { fill: var(--good); }
.tl-bell-icon { fill: #fff; }
.tl-now { fill: #fff; stroke: var(--gold); stroke-width: 4; }
.tl-now.late { stroke: var(--coral); }
.goal-foot { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-top: 2px; font-variant-numeric: tabular-nums; }
.coach { position: relative; flex: none; min-height: 40px; margin: 4px 18px 0; text-align: center; font-size: 14.5px; font-weight: 700; color: var(--glow); line-height: 1.3; display: flex; align-items: center; justify-content: center; }
.board-wrap { position: relative; flex: 1; min-height: 0; min-width: 0; margin: 0 8px; }
#board { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.flips { position: relative; flex: none; display: flex; justify-content: space-around; gap: 8px; margin: 2px 16px 0; }
.flip { flex: 1 1 0; max-width: 132px; min-height: 48px; border-radius: 16px; display: flex; align-items: center; justify-content: center; gap: 6px; background: var(--card); font-size: 17px; font-weight: 700; transition: transform .08s; }
.flip svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.flip:active { transform: scale(.96); }
.flip.hint, .wait.hint { box-shadow: 0 0 0 3px var(--glow), 0 0 20px var(--glow); animation: nudge 1s ease-in-out infinite; }
.flip:disabled, .wait:disabled, .tool:disabled { opacity: .45; cursor: default; }
.wait { position: relative; flex: none; display: flex; align-items: baseline; justify-content: center; gap: 10px; min-height: 58px; margin: 12px 24px 10px; border-radius: 20px; background: var(--gold); color: var(--plum); box-shadow: 0 6px 0 var(--gold-dark); font-family: var(--title); font-size: 23px; padding: 0 12px; transition: transform .08s, box-shadow .08s; }
.wait small { font-family: var(--font); font-size: 14px; font-weight: 600; }
.wait:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 2px 0 var(--gold-dark); }
.tools { position: relative; flex: none; display: flex; justify-content: space-around; background: var(--card); border-radius: 26px; padding: 8px 8px 6px; margin: 0 14px max(12px, env(safe-area-inset-bottom)); }
.tool { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 76px; font-size: 13px; font-weight: 700; color: var(--ink); }
.tool-icon { position: relative; width: 46px; height: 46px; display: grid; place-items: center; border-radius: 50%; background: #ffffff1a; transition: transform .08s; }
.tool:active .tool-icon { transform: scale(.92); }
.tool svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.tool.main .tool-icon { background: var(--gold); color: var(--plum); }
.tool b { position: absolute; top: -4px; right: -5px; min-width: 20px; height: 20px; display: grid; place-items: center; background: var(--coral); color: #fff; border: 2px solid var(--night); border-radius: 50%; font-size: 11px; font-weight: 800; }

/* Hourglasses */
.glass-turn { transform-box: fill-box; transform-origin: center; }
.glass-turn.flipping { animation: turn .38s cubic-bezier(.3, .8, .4, 1); }
.glass-body { fill: var(--glass); opacity: .92; }
.glass-edge { fill: none; stroke: #fff; stroke-width: 3; opacity: .8; }
.glass-shine { fill: none; stroke: #fff; stroke-width: 4; stroke-linecap: round; opacity: .7; }
.sand { fill: var(--sand); }
.sand-shade { fill: var(--sand-dark); opacity: .45; }
.stream { stroke: var(--sand); stroke-width: 2.6; }
.plate { fill: var(--frame); }
.post { fill: var(--frame-dark); }
.lock-badge { fill: var(--gold); stroke: var(--frame-dark); stroke-width: 2.5; }
.lock-shackle { fill: none; stroke: var(--frame-dark); stroke-width: 3; }
.glass-size { font-family: var(--title); text-anchor: middle; fill: var(--ink); }
.glass-note { font-family: var(--font); font-weight: 600; text-anchor: middle; fill: var(--muted); }
.glass-glow { fill: var(--glow); opacity: .45; visibility: hidden; }
.glass.hint .glass-glow { visibility: visible; animation: glow .8s ease-in-out infinite; }
.glass.empty .stream { visibility: hidden; }

/* Result */
.overlay { position: fixed; inset: 0; background: #1a123088; display: grid; place-items: center; padding: 16px; z-index: 6; overflow-y: auto; }
.card { width: min(100%, 360px); background: var(--night); border-radius: 30px; overflow: hidden; text-align: center; box-shadow: 0 22px 50px #0006; animation: land .34s cubic-bezier(.3, 1.4, .5, 1); }
.card-top { position: relative; height: 140px; display: grid; place-items: center; background: linear-gradient(var(--plum), #b0607a 60%, #f0886c); }
.card-top .dunes { height: 100%; }
#result-art { position: relative; width: 96px; height: 112px; overflow: visible; margin-bottom: 18px; }
.card-body { position: relative; display: flex; flex-direction: column; align-items: center; background: var(--night); border-radius: 26px 26px 0 0; margin-top: -22px; padding: 12px 22px 8px; }
.card h2 { font-family: var(--title); font-weight: 400; font-size: 28px; margin: 2px 0 0; line-height: 1.15; }
.card p { color: var(--muted); font-size: 14.5px; font-weight: 600; margin: 4px 0 14px; line-height: 1.35; }
.card .big-btn { min-height: 54px; font-size: 21px; margin-bottom: 12px; }
.result-stars { font-size: 42px; line-height: 1.1; color: #ffffff33; }
.result-stars span { display: inline-block; margin: 0 1px; }
.result-stars .on { color: var(--gold); animation: stamp .42s backwards; }
.result-stars .on:nth-child(2) { animation-delay: .15s; }
.result-stars .on:nth-child(3) { animation-delay: .3s; }
.text-btn { color: var(--muted); font-weight: 700; padding: 6px 10px; font-size: 15px; min-height: 44px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--night); color: var(--ink); font-weight: 600; font-size: 15px; padding: 10px 16px; border-radius: 14px; z-index: 8; white-space: nowrap; }
.confetti { position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: 7; }
.confetti span { position: absolute; top: -24px; width: 12px; height: 12px; border-radius: 3px; animation: fall linear forwards; }

@keyframes turn { from { transform: rotate(-180deg); } }
@keyframes nudge { 50% { transform: translateY(-3px); } }
@keyframes glow { 50% { opacity: .15; } }
@keyframes stamp { 0% { transform: scale(2.2); opacity: 0; } 70% { transform: scale(.9); opacity: 1; } 100% { } }
@keyframes land { from { transform: translateY(26px) scale(.94); opacity: 0; } }
@keyframes fall { to { transform: translate3d(var(--drift), 112vh, 0) rotate(var(--spin)); } }
@keyframes ring { 15% { transform: rotate(14deg); } 35% { transform: rotate(-12deg); } 55% { transform: rotate(8deg); } 75% { transform: rotate(-4deg); } }
.ringing { animation: ring .9s ease-out; transform-box: fill-box; transform-origin: 50% 0; }

/* Larger screens: the game sits as a framed card on the dusk background. */
@media (min-width: 560px) and (min-height: 521px) {
  .screen { max-height: min(100%, 900px); top: 50%; transform: translateY(-50%); border-radius: 34px; box-shadow: 0 24px 60px #0005; height: calc(100% - 32px); }
}
/* Short, wide screens: glasses on the left, goal and controls on the right. */
@media (max-height: 520px) {
  .screen { max-width: none; }
  #menu .menu-inner { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 300px); grid-template-rows: repeat(5, auto); align-content: center; column-gap: 24px; align-items: center; justify-items: center; padding: 12px 20px; }
  #menu h1 { grid-column: 2; font-size: 46px; margin: 0; }
  #menu .tagline { grid-column: 2; font-size: 15px; margin-bottom: 10px; }
  .hero-art { grid-column: 1; grid-row: 1 / span 5; height: calc(100vh - 24px); max-height: none; min-height: 0; margin: 0; }
  #play-level, #play-daily, .stats { grid-column: 2; }
  .big-btn { min-height: 50px; margin-bottom: 10px; font-size: 21px; }
  .big-btn small { display: none; }
  .stats dd { font-size: 18px; }
  #play { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 330px); grid-template-rows: auto auto auto 1fr auto auto; }
  .top-bar { grid-column: 2; grid-row: 1; padding-top: 8px; }
  .round-plain { width: 40px; height: 40px; }
  .hud-title { font-size: 21px; }
  .status-row { grid-column: 2; grid-row: 2; margin-top: 4px; }
  .goal { grid-column: 2; grid-row: 3; margin: 6px 8px 0; padding: 6px 12px; }
  #goal-time { font-size: 24px; }
  .coach { grid-column: 2; grid-row: 4; align-self: center; font-size: 13px; margin: 0 8px; min-height: 0; }
  .board-wrap { grid-column: 1; grid-row: 1 / span 5; margin: 8px 4px 0 12px; }
  .flips { grid-column: 1; grid-row: 6; margin: 4px 12px 10px; }
  .flip { min-height: 42px; }
  .wait { grid-column: 2; grid-row: 5; margin: 0 8px 8px; min-height: 50px; font-size: 20px; }
  .tools { grid-column: 2; grid-row: 6; margin: 0 8px 8px; }
  .tool { min-width: 56px; font-size: 11.5px; }
  .tool-icon { width: 40px; height: 40px; }
  .overlay { padding: 8px; }
  .card { display: grid; grid-template-columns: 36% 1fr; width: min(100%, 560px); }
  .card-top { height: auto; }
  .card-body { margin: 0 0 0 -18px; border-radius: 22px 0 0 22px; padding: 8px 16px 2px; }
  .result-stars { font-size: 30px; }
  .card h2 { font-size: 22px; }
  .card p { margin-bottom: 8px; font-size: 13.5px; }
  .card .big-btn { min-height: 46px; margin-bottom: 8px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
