* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; height: 100dvh; overscroll-behavior: none; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  color: #eef0ff;
  background: radial-gradient(circle at 50% 0%, #3a2a7a 0%, #17123a 55%, #0b0920 100%) fixed;
  overflow: hidden;
  -webkit-user-select: none; user-select: none;
}
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }

#app { height: 100%; display: flex; justify-content: center; }
.screen { width: 100%; max-width: 680px; height: 100%; display: flex; flex-direction: column; align-items: center;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); }

/* Menu */
#menu, #levels { overflow-y: auto; }
#menu { justify-content: safe center; gap: 14px; }
.logo { font-size: clamp(44px, 12vw, 76px); margin: 0; letter-spacing: -1px; font-weight: 800;
  background: linear-gradient(90deg, #ff5a7a, #ffb347, #ffe45c, #4de38a, #4dbbff, #b77dff);
  -webkit-background-clip: text; background-clip: text; color: transparent; }
.logo span { margin-left: .15em; }
.tag { margin: -8px 0 18px; opacity: .7; letter-spacing: 3px; text-transform: uppercase; font-size: 13px; }
.big { width: min(360px, 90%); padding: 16px 20px; border-radius: 16px; border: 1px solid rgba(255,255,255,.18);
  background: linear-gradient(180deg, rgba(255,255,255,.14), rgba(255,255,255,.05)); font-size: 22px; font-weight: 700;
  text-align: left; transition: transform .1s, background .2s; }
.big:hover { background: linear-gradient(180deg, rgba(255,255,255,.22), rgba(255,255,255,.08)); }
.big:active { transform: scale(.98); }
.big small { display: block; font-size: 13px; font-weight: 400; opacity: .75; margin-top: 4px; }
.opts { width: min(360px, 90%); display: flex; flex-direction: column; gap: 8px; margin: -4px 0 6px; }
.seg { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.seg span { flex: 1; opacity: .75; }
.seg button { padding: 5px 12px; border-radius: 10px; border: 1px solid rgba(255,255,255,.15); background: rgba(255,255,255,.05); font-size: 13px; }
.seg button.on { background: linear-gradient(180deg, #7b5cff, #5a3de0); border-color: transparent; font-weight: 700; }
#menu { position: relative; }
.lang { position: absolute; top: 12px; right: 12px; padding: 6px 12px; border-radius: 10px;
  border: 1px solid rgba(255,255,255,.18); background: rgba(255,255,255,.08); font-size: 14px; }
:lang(zh-Hant) body, :lang(zh-Hant) button { font-family: system-ui, -apple-system, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif; }
#best { opacity: .7; font-size: 14px; min-height: 1em; }

/* Top bar */
.topbar { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.topbar h2 { margin: 0; font-size: 18px; text-align: center; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon { width: 40px; height: 40px; border-radius: 12px; border: 1px solid rgba(255,255,255,.15);
  background: rgba(255,255,255,.08); font-size: 22px; line-height: 1; display: grid; place-items: center; }
span.icon { visibility: hidden; }
.icon.off { opacity: .4; }

/* Level select */
#levelGrid { margin-top: 20px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; width: min(440px, 100%); }
.lvl { aspect-ratio: 1; border-radius: 16px; border: 1px solid rgba(255,255,255,.18);
  background: linear-gradient(180deg, rgba(120,90,255,.45), rgba(60,40,160,.35));
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; font-size: 24px; font-weight: 800; }
.lvl .st { font-size: 13px; letter-spacing: 1px; color: #ffd84d; }
.lvl .st .e { color: rgba(255,255,255,.25); }
.lvl:disabled { opacity: .35; cursor: default; background: rgba(255,255,255,.05); }

/* HUD */
#hud { width: 100%; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 10px 18px; margin: 10px 0 8px; }
.stat { display: flex; flex-direction: column; align-items: center; min-width: 64px; }
.stat label { font-size: 11px; letter-spacing: 1.5px; text-transform: uppercase; opacity: .65; }
.stat b { font-size: 24px; font-variant-numeric: tabular-nums; }
.stat b.low { color: #ff7a8a; }
.goals { display: flex; gap: 10px; }
.goal { display: flex; align-items: center; gap: 4px; padding: 4px 8px 4px 4px; border-radius: 12px; background: rgba(255,255,255,.08); font-weight: 700; font-variant-numeric: tabular-nums; }
.goal canvas { width: 28px; height: 28px; }
.goal.done { color: #6dff9e; }
.bar { position: relative; flex-basis: 100%; height: 10px; border-radius: 6px; background: rgba(255,255,255,.1); overflow: visible; }
.bar > i { position: absolute; inset: 0 auto 0 0; border-radius: 6px; background: linear-gradient(90deg, #ff5a7a, #ffb347, #ffe45c); transition: width .3s; }
.bar .tick { position: absolute; top: -5px; transform: translateX(-50%); font-size: 13px; color: rgba(255,255,255,.35); }
.bar .tick.on { color: #ffd84d; }

/* Board */
#boardWrap { position: relative; }
#board { display: block; touch-action: none; border-radius: 14px;
  background: rgba(10,6,30,.45); box-shadow: 0 10px 40px rgba(0,0,0,.45), inset 0 0 0 1px rgba(255,255,255,.08); }
#banner { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; text-align: center;
  font-size: clamp(26px, 7vw, 44px); font-weight: 800; text-shadow: 0 3px 16px rgba(0,0,0,.7); opacity: 0; transform: scale(.8);
  transition: opacity .25s, transform .25s; padding: 0 20px; }
#banner.show { opacity: 1; transform: scale(1); }
#gameFooter { margin-top: 12px; }
#gameFooter button { padding: 8px 22px; border-radius: 12px; border: 1px solid rgba(255,255,255,.18); background: rgba(255,255,255,.08); }

/* Modal */
#modal { position: fixed; inset: 0; background: rgba(5,3,20,.65); display: grid; place-items: center; z-index: 10; backdrop-filter: blur(3px); }
.card { width: min(360px, 90vw); max-height: 90dvh; overflow-y: auto; padding: 24px; border-radius: 20px; text-align: center;
  background: linear-gradient(180deg, #33276e, #1f1850); border: 1px solid rgba(255,255,255,.18); box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.card h2 { margin: 0 0 8px; }
.card .body { opacity: .9; line-height: 1.5; }
.card .stars { font-size: 44px; color: #ffd84d; letter-spacing: 4px; margin: 6px 0; }
.card .stars .e { color: rgba(255,255,255,.2); }
.actions { display: flex; gap: 10px; justify-content: center; margin-top: 18px; flex-wrap: wrap; }
.actions button { padding: 10px 18px; border-radius: 12px; border: 1px solid rgba(255,255,255,.2); background: rgba(255,255,255,.1); font-weight: 600; }
.actions button.primary { background: linear-gradient(180deg, #7b5cff, #5a3de0); border-color: transparent; }

/* Short landscape screens (phones on their side): HUD in a sidebar, board on the right. */
@media (orientation: landscape) and (max-height: 560px) {
  #menu { gap: 8px; }
  .logo { font-size: 40px; }
  .tag { margin: -4px 0 6px; }
  .big { padding: 10px 16px; font-size: 18px; }
  #levelGrid { grid-template-columns: repeat(6, 1fr); width: min(560px, 100%); margin-top: 12px; }
  #game { max-width: none; display: grid; justify-content: center; align-content: center; column-gap: 20px;
    grid-template-columns: minmax(180px, 260px) auto; grid-template-rows: auto 1fr auto;
    grid-template-areas: "top board" "hud board" "foot board"; }
  #game .topbar { grid-area: top; }
  #game .topbar h2 { font-size: 15px; white-space: normal; }
  #hud { grid-area: hud; align-content: center; margin: 8px 0; }
  #boardWrap { grid-area: board; align-self: center; }
  #gameFooter { grid-area: foot; justify-self: center; margin: 0; }
}
