:root {
  --bg: #05060f;
  --c0: #2af4ff;
  --c1: #ff3df0;
  --c2: #ffd23a;
  --text: #e2eaff;
  --dim: #7f8cb8;
  --panel: rgba(10, 15, 34, 0.92);
  --edge: rgba(80, 130, 230, 0.28);
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --font: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", "Menlo", "Consolas", monospace;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body {
  margin: 0; padding: 0; height: 100%; width: 100%; overflow: hidden;
  background: var(--bg); color: var(--text); font-family: var(--font);
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  touch-action: manipulation; overscroll-behavior: none; -webkit-text-size-adjust: 100%;
}
body { position: fixed; inset: 0; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; touch-action: manipulation; }
svg { width: 1em; height: 1em; flex: none; }
img { -webkit-user-drag: none; }

#fx { position: fixed; inset: 0; width: 100%; height: 100%; display: block; pointer-events: none; z-index: 0; }
#fx-top { position: fixed; inset: 0; width: 100%; height: 100%; display: block; pointer-events: none; z-index: 25; }
#app { position: fixed; inset: 0; z-index: 1; }

.screen {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  padding: calc(var(--sat) + 8px) calc(var(--sar) + 12px) calc(var(--sab) + 10px) calc(var(--sal) + 12px);
  opacity: 0; visibility: hidden; transform: scale(1.02);
  transition: opacity .28s ease, transform .28s ease, visibility 0s linear .28s;
}
.screen.active { opacity: 1; visibility: visible; transform: none; transition: opacity .28s ease, transform .28s ease; }

.topbar { display: flex; align-items: center; justify-content: space-between; min-height: 48px; gap: 8px; position: relative; z-index: 2; }
.topbar h2 { margin: 0; font-size: 18px; letter-spacing: .3em; font-weight: 800; text-shadow: 0 0 12px rgba(42,244,255,.55); padding-left: .3em; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; font-size: 22px;
  background: rgba(14, 22, 48, .6); border: 1px solid var(--edge); color: #cfe0ff;
  box-shadow: 0 0 0 0 rgba(42,244,255,0), inset 0 1px 0 rgba(255,255,255,.05);
  transition: transform .12s ease, box-shadow .2s ease;
}
.icon-btn:active { transform: scale(.92); box-shadow: 0 0 16px rgba(42,244,255,.4); }
.icon-btn.corner { position: absolute; top: 12px; right: 12px; }

/* ---------- HOME ---------- */
.stars-total { display: inline-flex; align-items: center; gap: 6px; font-weight: 800; font-size: 16px; padding: 8px 12px; border-radius: 12px; background: rgba(14,22,48,.55); border: 1px solid var(--edge); }
.stars-total svg { color: var(--c2); filter: drop-shadow(0 0 6px rgba(255,210,58,.8)); font-size: 18px; }
.home-center { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: clamp(18px, 6vh, 56px); padding-bottom: 4vh; }
.logo-wrap { text-align: center; }
.logo-icon { width: 84px; height: 84px; margin: 0 auto 10px; border-radius: 22px; overflow: hidden; box-shadow: 0 0 34px rgba(42,244,255,.35), 0 0 0 1px rgba(42,244,255,.25); animation: float 5s ease-in-out infinite; }
.logo-icon img { width: 100%; height: 100%; display: block; }
@keyframes float { 50% { transform: translateY(-6px); } }
.logo {
  margin: 0; font-size: clamp(54px, 17vw, 96px); font-weight: 900; letter-spacing: .14em; padding-left: .14em; line-height: 1;
  color: #e9fdff;
  text-shadow: 0 0 4px #fff, 0 0 12px var(--c0), 0 0 28px var(--c0), 0 0 60px rgba(42,244,255,.6);
}
.logo.small { font-size: 52px; }
.logo span { display: inline-block; }
.logo .flick { animation: flick 6s infinite; }
@keyframes flick {
  0%, 18%, 22%, 25%, 53%, 57%, 100% { opacity: 1; text-shadow: 0 0 4px #fff, 0 0 12px var(--c1), 0 0 28px var(--c1), 0 0 60px rgba(255,61,240,.6); color: #ffe9fd; }
  20%, 24%, 55% { opacity: .35; text-shadow: none; }
}
.tagline { margin: 12px 0 0; color: var(--dim); font-size: 15px; letter-spacing: .04em; }

.menu { display: flex; flex-direction: column; gap: 12px; width: min(340px, 86vw); }
.btn {
  position: relative; display: flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 52px; padding: 10px 18px; border-radius: 16px; font-weight: 800; letter-spacing: .12em; font-size: 16px;
  background: linear-gradient(180deg, rgba(20,30,64,.85), rgba(10,15,36,.9));
  border: 1px solid rgba(90,140,255,.35); color: #e3ecff;
  box-shadow: 0 0 18px rgba(42,120,255,.12), inset 0 1px 0 rgba(255,255,255,.06);
  transition: transform .12s ease, box-shadow .2s ease, filter .2s;
}
.btn svg { font-size: 20px; }
.btn small { font-weight: 600; letter-spacing: .04em; font-size: 13px; color: var(--dim); }
.btn:active { transform: scale(.96); }
.btn.primary {
  background: linear-gradient(180deg, rgba(42,244,255,.25), rgba(20,120,170,.25));
  border-color: rgba(42,244,255,.85); color: #eaffff;
  box-shadow: 0 0 22px rgba(42,244,255,.4), inset 0 0 18px rgba(42,244,255,.18);
  text-shadow: 0 0 10px rgba(42,244,255,.9);
}
.btn.primary small { color: #a8f6ff; }
.btn.big { min-height: 64px; font-size: 20px; }
.btn.wide { width: 100%; }
.btn.small { min-height: 46px; font-size: 14px; letter-spacing: .06em; padding: 8px 14px; }
.btn.grow { flex: 1; }
.btn.danger { border-color: rgba(255,70,110,.6); color: #ffc1cf; box-shadow: 0 0 14px rgba(255,45,85,.2); }
.menu .btn { justify-content: flex-start; padding-left: 20px; }
.menu .btn .lbl { flex: none; }
.menu .btn small { margin-left: auto; }
.btn.daily { border-color: rgba(255,61,240,.6); box-shadow: 0 0 18px rgba(255,61,240,.2), inset 0 0 14px rgba(255,61,240,.08); }
.btn.daily > svg { color: var(--c1); }
.btn.daily.done small::after { content: " ✓"; color: #6dffb4; }
.streak { display: inline-flex; align-items: center; gap: 3px; color: #ffb347; font-size: 14px; letter-spacing: 0; margin-left: 8px; }
.streak svg { font-size: 16px; filter: drop-shadow(0 0 5px rgba(255,140,40,.9)); }
.streak.zero { color: #59648a; }
.streak.zero svg { filter: none; }

/* ---------- LEVELS ---------- */
.levels-scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; touch-action: pan-y; margin: 6px -4px 0; padding: 6px 4px 20px; }
.level-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 10px; }
.lvl {
  aspect-ratio: 1; border-radius: 16px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  background: linear-gradient(180deg, rgba(18,27,58,.85), rgba(9,14,32,.9)); border: 1px solid rgba(80,120,220,.3);
  font-weight: 800; font-size: 20px; position: relative; font-family: var(--mono);
}
.lvl .st { display: flex; gap: 1px; font-size: 11px; color: #2a3557; }
.lvl .st svg.on { color: var(--c2); filter: drop-shadow(0 0 3px rgba(255,210,58,.9)); }
.lvl.done { border-color: rgba(42,244,255,.45); }
.lvl.current { border-color: var(--c0); box-shadow: 0 0 16px rgba(42,244,255,.45), inset 0 0 12px rgba(42,244,255,.15); animation: pulse 1.8s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 26px rgba(42,244,255,.7), inset 0 0 16px rgba(42,244,255,.25); } }
.lvl.locked { opacity: .38; color: #6c78a3; }
.lvl.locked svg.lk { font-size: 16px; }
.lvl .new { position: absolute; top: -6px; right: -4px; font-size: 9px; font-family: var(--font); letter-spacing: .08em; padding: 2px 5px; border-radius: 6px; background: var(--c1); color: #20001c; box-shadow: 0 0 8px rgba(255,61,240,.8); }
.lvl:active:not(.locked) { transform: scale(.94); }
.lv-sep { grid-column: 1 / -1; font-size: 12px; letter-spacing: .25em; color: var(--dim); padding: 10px 2px 0; font-weight: 700; }

/* ---------- GAME ---------- */
#game { pointer-events: none; }
#game .topbar, #game .bottombar, #game .g-info, #board-area { pointer-events: auto; }
.g-title { text-align: center; flex: 1; min-width: 0; }
#g-title { font-weight: 900; letter-spacing: .22em; font-size: 17px; text-shadow: 0 0 10px rgba(42,244,255,.6); }
.g-sub { font-size: 11px; letter-spacing: .14em; color: var(--dim); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; min-height: 14px; }
.g-sub .chip { display: inline-block; padding: 1px 6px; border-radius: 6px; border: 1px solid rgba(255,61,240,.5); color: #ffb6f6; margin: 0 2px; }
.g-info { display: flex; align-items: center; justify-content: space-between; padding: 6px 6px 0; }
.g-stat { display: flex; flex-direction: column; min-width: 64px; }
.g-stat.right { text-align: right; }
.g-stat span { font-size: 10px; letter-spacing: .2em; color: var(--dim); }
.g-stat b { font-family: var(--mono); font-size: 22px; }
.g-stars { display: flex; gap: 4px; font-size: 22px; }
.g-stars svg { color: #26304f; transition: color .3s, filter .3s; }
.g-stars svg.on { color: var(--c2); filter: drop-shadow(0 0 6px rgba(255,210,58,.85)); }
#board-area { flex: 1; margin: 8px 0; touch-action: none; }
.bottombar { display: flex; justify-content: center; gap: 14px; padding-bottom: 4px; }
.tool {
  display: flex; align-items: center; gap: 8px; height: 50px; padding: 0 20px; border-radius: 16px;
  background: rgba(14,22,48,.7); border: 1px solid var(--edge); font-weight: 700; letter-spacing: .06em; font-size: 15px;
  transition: transform .12s;
}
.tool svg { font-size: 20px; }
.tool:active { transform: scale(.94); }
.tool.hint { border-color: rgba(90,255,170,.45); }
.tool.hint svg { color: #7dffc0; filter: drop-shadow(0 0 5px rgba(90,255,170,.7)); }
.tool.hint b { background: #5dffb0; color: #002515; border-radius: 9px; padding: 1px 7px; font-size: 13px; font-family: var(--mono); }
.tool.hint.empty b { background: #3a4466; color: #9aa6cc; }

/* ---------- OVERLAYS ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center;
  padding: calc(var(--sat) + 16px) calc(var(--sar) + 16px) calc(var(--sab) + 16px) calc(var(--sal) + 16px);
  background: rgba(2, 3, 10, .72); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  opacity: 0; visibility: hidden; transition: opacity .25s ease, visibility 0s linear .25s;
}
.overlay.open { opacity: 1; visibility: visible; transition: opacity .25s ease; }
.panel {
  position: relative; width: min(380px, 100%); max-height: 100%; overflow-y: auto;
  background: var(--panel); border: 1px solid rgba(42,244,255,.35); border-radius: 24px; padding: 24px 20px 20px;
  box-shadow: 0 0 40px rgba(42,244,255,.18), inset 0 0 30px rgba(42,244,255,.05);
  transform: translateY(16px) scale(.97); transition: transform .3s cubic-bezier(.2,1.3,.4,1);
}
.overlay.open .panel { transform: none; }
.panel h3 { margin: 0 0 16px; text-align: center; letter-spacing: .3em; font-size: 16px; text-shadow: 0 0 10px rgba(42,244,255,.6); }
.row { display: flex; gap: 10px; margin-top: 16px; }

.toggle { display: flex; align-items: center; justify-content: space-between; padding: 14px 4px; border-bottom: 1px solid rgba(80,120,220,.15); font-weight: 700; font-size: 16px; cursor: pointer; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle i { width: 54px; height: 30px; border-radius: 15px; background: #1a2240; border: 1px solid #2d3a66; position: relative; transition: background .2s, box-shadow .2s, border-color .2s; }
.toggle i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #6b77a0; transition: transform .2s cubic-bezier(.3,1.4,.5,1), background .2s, box-shadow .2s; }
.toggle input:checked + i { background: rgba(42,244,255,.2); border-color: var(--c0); box-shadow: 0 0 12px rgba(42,244,255,.45); }
.toggle input:checked + i::after { transform: translateX(24px); background: #eaffff; box-shadow: 0 0 10px var(--c0); }
.set-links { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.fine { text-align: center; color: #56628a; font-size: 12px; margin: 16px 0 0; }
.confirm-text { color: var(--dim); text-align: center; line-height: 1.45; margin: 0; }
.guide-list { display: flex; flex-direction: column; gap: 8px; }
.guide-list .btn { justify-content: space-between; letter-spacing: .04em; font-size: 15px; }
.guide-list .btn small { font-size: 11px; }
.guide-list .btn.locked { opacity: .45; }

/* win */
.win-panel { text-align: center; border-color: rgba(42,244,255,.6); }
.win-kicker { font-size: 12px; letter-spacing: .3em; color: var(--dim); }
.win-title { font-size: 26px; font-weight: 900; letter-spacing: .12em; margin: 6px 0 12px; color: #effeff; text-shadow: 0 0 6px #fff, 0 0 18px var(--c0), 0 0 36px var(--c0); }
.win-stars { display: flex; justify-content: center; gap: 10px; font-size: 50px; margin: 6px 0 10px; }
.win-stars svg { color: #1f2846; transform: scale(.6); transition: color .2s; }
.win-stars svg.on { color: var(--c2); filter: drop-shadow(0 0 10px rgba(255,210,58,.9)); animation: starpop .45s cubic-bezier(.2,1.6,.4,1) forwards; }
.win-stars svg:nth-child(2) { transform: scale(.75) translateY(-8px); }
@keyframes starpop { 0% { transform: scale(.2) rotate(-40deg); } 100% { transform: scale(1) rotate(0); } }
.win-stars svg:nth-child(2).on { animation-name: starpop2; }
@keyframes starpop2 { 0% { transform: scale(.2) translateY(-10px) rotate(-40deg); } 100% { transform: scale(1.12) translateY(-10px) rotate(0); } }
.win-stats { color: var(--dim); font-size: 15px; font-family: var(--mono); }
.win-extra { min-height: 20px; margin-top: 10px; font-size: 14px; color: #ffd27a; display: flex; flex-direction: column; gap: 4px; align-items: center; }
.win-extra .streakline { display: inline-flex; align-items: center; gap: 6px; color: #ffb347; font-weight: 800; font-size: 18px; }
.win-extra .streakline svg { font-size: 22px; filter: drop-shadow(0 0 6px rgba(255,140,40,.9)); }
.win-extra .gain { color: #7dffc0; }

/* intro */
.intro-panel { text-align: center; border-color: rgba(255,61,240,.55); box-shadow: 0 0 40px rgba(255,61,240,.2), inset 0 0 30px rgba(255,61,240,.05); }
.intro-tag { display: inline-block; font-size: 11px; letter-spacing: .3em; padding: 4px 10px 4px 13px; border-radius: 8px; background: rgba(255,61,240,.15); color: #ff9df5; border: 1px solid rgba(255,61,240,.5); }
.intro-title { font-size: 26px; font-weight: 900; letter-spacing: .06em; margin: 12px 0 10px; text-shadow: 0 0 14px rgba(255,61,240,.7); }
.intro-demo { width: 100%; height: 190px; display: block; border-radius: 16px; background: rgba(3,5,14,.75); border: 1px solid rgba(80,120,220,.2); }
.intro-text { color: #c4cff0; line-height: 1.5; font-size: 15.5px; margin: 14px 4px 18px; }
.intro-text b { color: #fff; }
.intro-text b.c0 { color: var(--c0); }
.intro-text b.tw { color: #7dff6b; }
.intro-text b.rv { color: #c3a0ff; }
.intro-text b.sh { color: #ff6b8a; }
.intro-text b.wn { color: #ffb35c; }

/* install */
.overlay.install { background: radial-gradient(ellipse at 50% 30%, #0e1a42, #03040c 70%); z-index: 30; -webkit-backdrop-filter: none; backdrop-filter: none; }
.overlay.install { align-items: flex-start; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; touch-action: pan-y; }
.install-body { width: min(400px, 100%); margin: auto; display: flex; flex-direction: column; align-items: center; text-align: center; gap: 14px; padding: 24px 4px; }
.install-icon { width: 132px; height: 132px; border-radius: 30px; box-shadow: 0 0 50px rgba(42,244,255,.45), 0 0 0 1px rgba(42,244,255,.35); animation: float 5s ease-in-out infinite; }
.install-lead { margin: 0; color: #c4cff0; font-size: 16px; line-height: 1.45; }
.install-perks { list-style: none; padding: 0; margin: 2px 0 6px; display: flex; flex-direction: column; gap: 8px; color: var(--dim); font-size: 14.5px; }
.install-perks li { display: flex; align-items: center; gap: 10px; justify-content: center; }
.install-perks svg { color: var(--c0); font-size: 18px; filter: drop-shadow(0 0 4px rgba(42,244,255,.8)); }
.install-steps { width: 100%; text-align: left; background: rgba(10,16,38,.85); border: 1px solid rgba(42,244,255,.35); border-radius: 18px; padding: 14px 16px; display: flex; flex-direction: column; gap: 12px; }
.install-steps .step { display: flex; gap: 12px; align-items: flex-start; font-size: 15px; line-height: 1.4; color: #d7e1ff; }
.install-steps .num { flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: 13px; background: rgba(42,244,255,.18); border: 1px solid var(--c0); color: #bff9ff; }
.install-steps .ico { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; background: #1b2a52; color: #6fb6ff; vertical-align: middle; margin: 0 2px; font-size: 18px; }
.install-steps .note { font-size: 13px; color: var(--dim); }
.install.steps .install-perks { display: none; }
.install.steps .install-icon { width: 76px; height: 76px; border-radius: 18px; }
.install.steps .logo.small { font-size: 38px; }
.linkish { color: var(--dim); font-size: 15px; padding: 12px 18px; text-decoration: underline; text-underline-offset: 4px; }
.ios-arrow { position: fixed; left: 50%; bottom: calc(var(--sab) + 6px); width: 30px; height: 46px; margin-left: -15px; z-index: 31; pointer-events: none; animation: bob 1s ease-in-out infinite; }
.ios-arrow::before { content: ""; position: absolute; left: 13px; top: 0; width: 4px; height: 34px; border-radius: 2px; background: var(--c0); box-shadow: 0 0 10px var(--c0); }
.ios-arrow::after { content: ""; position: absolute; left: 3px; bottom: 0; border: 12px solid transparent; border-top: 14px solid var(--c0); border-bottom: 0; filter: drop-shadow(0 0 6px var(--c0)); }
.ios-arrow.top { top: calc(var(--sat) + 6px); bottom: auto; right: 70px; left: auto; transform: rotate(180deg); }
@keyframes bob { 50% { translate: 0 8px; } }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--sab) + 84px); transform: translate(-50%, 20px); z-index: 40;
  max-width: min(92vw, 420px); padding: 12px 18px; border-radius: 14px; font-size: 14.5px; text-align: center;
  background: rgba(12,18,40,.95); border: 1px solid rgba(42,244,255,.45); box-shadow: 0 0 20px rgba(42,244,255,.25);
  opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.flash { position: fixed; inset: 0; z-index: 5; pointer-events: none; background: radial-gradient(circle at 50% 50%, rgba(160,250,255,.35), rgba(42,244,255,0) 70%); animation: flash .7s ease-out forwards; }
@keyframes flash { from { opacity: 1; } to { opacity: 0; } }

@media (min-height: 760px) { .tool { height: 54px; } }
@media (orientation: landscape) and (max-height: 500px) {
  .home-center { flex-direction: row; gap: 40px; }
  .logo-icon { display: none; }
  .logo { font-size: 56px; }
  .intro-panel { width: min(640px, 100%); display: grid; grid-template-columns: 1fr 1fr; column-gap: 18px; align-items: center; text-align: left; padding: 16px; }
  .intro-panel > :not(.intro-demo) { grid-column: 2; }
  .intro-panel .intro-tag { justify-self: start; }
  .intro-panel .intro-demo { grid-column: 1; grid-row: 1 / span 4; height: 100%; min-height: 180px; }
  .intro-panel .intro-title { font-size: 22px; margin: 8px 0 4px; }
  .intro-panel .intro-text { margin: 4px 0 12px; font-size: 14.5px; }
  .win-stars { font-size: 38px; }
  .panel { padding: 16px; }
}
