:root {
  --bg: #0B0E11;
  --bg-elev: #12161C;
  --bg-card: #1E2329;
  --line: #2B3139;
  --gold: #F0B90B;
  --gold-2: #F8D12F;
  --gold-dim: #C99400;
  --text: #EAECEF;
  --muted: #848E9C;
  --green: #0ECB81;
  --red: #F6465D;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
  --radius: 12px;
  --font: "IBM Plex Sans", "Noto Sans SC", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  user-select: none;
  overflow: hidden;
}
button { font-family: inherit; }

#app {
  min-height: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(240, 185, 11, 0.10), transparent 55%),
    radial-gradient(800px 400px at 80% 100%, rgba(240, 185, 11, 0.05), transparent 50%),
    var(--bg);
}
#app::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.18;
  background-image:
    linear-gradient(rgba(240,185,11,0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(240,185,11,0.06) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(circle at 50% 30%, #000 20%, transparent 75%);
}

.shell {
  width: 100%;
  max-width: 440px;
  height: 100%;
  position: relative;
  display: flex;
  flex-direction: column;
}

.mute-btn {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top, 0px));
  right: 14px;
  z-index: 20;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(30, 35, 41, 0.8);
  color: var(--gold);
  cursor: pointer;
  backdrop-filter: blur(8px);
}
.mute-btn .off { display: none; }
.mute-btn.is-muted .on { display: none; }
.mute-btn.is-muted .off { display: inline; color: var(--muted); }
.mute-btn svg { width: 20px; height: 20px; display: block; margin: 0 auto; }

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  padding: calc(20px + env(safe-area-inset-top, 0px)) 20px calc(20px + env(safe-area-inset-bottom, 0px));
}
.screen.is-on { display: flex; }

/* Title */
.screen-title { align-items: center; justify-content: center; text-align: center; gap: 8px; }
.logo-wrap { width: 92px; height: 92px; margin-bottom: 6px; }
.logo-wrap img { width: 100%; height: 100%; display: block; }
.kicker {
  margin: 0;
  color: var(--muted);
  letter-spacing: 0.22em;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}
.screen-title h1 {
  margin: 6px 0 0;
  font-size: 42px;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--text);
  text-shadow: 0 0 28px rgba(240, 185, 11, 0.25);
}
.tagline { margin: 10px 0 0; color: var(--muted); font-size: 15px; }
.title-coins {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin: 28px 0 32px;
}
.title-coins canvas { width: 44px; height: 44px; display: block; }
.btn-col { display: flex; flex-direction: column; gap: 12px; width: min(280px, 100%); }
.btn {
  appearance: none;
  border: 0;
  border-radius: 8px;
  padding: 13px 18px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}
.btn.primary {
  background: var(--gold);
  color: #1A1400;
  box-shadow: 0 6px 20px rgba(240, 185, 11, 0.28);
}
.btn.primary:active { transform: translateY(1px); }
.btn.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
}
.btn.ghost:active { background: var(--bg-card); }
.fine-print { margin-top: 28px; color: var(--muted); font-size: 12px; }

/* Levels */
.sheet-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  padding-right: 48px;
}
.sheet-head h2 { margin: 0; font-size: 22px; font-weight: 800; }
.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--text);
  font-size: 22px;
  cursor: pointer;
  flex-shrink: 0;
}
.star-total { margin-left: auto; color: var(--gold); font-weight: 700; font-size: 13px; }
.level-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  overflow: auto;
  padding-bottom: 8px;
  -webkit-overflow-scrolling: touch;
}
.lv-item {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 4px 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.lv-item .lv-num { font-weight: 800; font-size: 16px; }
.lv-stars { display: flex; gap: 2px; height: 10px; }
.lv-stars i {
  width: 7px; height: 7px;
  background: #2B3139;
  clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
  display: block;
}
.lv-stars i.on { background: var(--gold); }
.lv-item.is-gold { border-color: rgba(240,185,11,0.45); background: rgba(240,185,11,0.08); }
.lv-item.is-locked { opacity: 0.38; cursor: not-allowed; }
.lv-item:not(.is-locked):active { transform: scale(0.97); }

/* Play */
.screen-play { padding-left: 12px; padding-right: 12px; }
.play-top {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-right: 48px;
  margin-bottom: 8px;
}
.play-titles { flex: 1; min-width: 0; }
.play-titles h2 { margin: 0; font-size: 16px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-bottom: 8px;
}
.hud-card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
}
.goal-list { display: flex; gap: 8px; flex-wrap: wrap; }
.goal { display: flex; align-items: center; gap: 6px; }
.goal small { color: var(--muted); font-size: 10px; display: block; }
.goal b { font-size: 13px; }
.goal.is-done b { color: var(--green); }
.mini-coin { width: 22px; height: 22px; display: block; }
.g-ico {
  width: 22px; height: 22px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 800; color: #1A1400; background: var(--gold);
}
.g-ico.ice { background: #9ED0FF; }
.g-ico.chain { background: #F0B90B; }
.g-ico.brick { background: #E8B44C; }
.g-ico.score { background: var(--gold-2); }
.hud-nums { display: flex; gap: 8px; }
.stat { min-width: 72px; text-align: right; }
.stat span { display: block; color: var(--muted); font-size: 10px; letter-spacing: 0.08em; }
.stat b { font-size: 22px; font-weight: 800; color: var(--text); }
.stat b.is-low { color: var(--red); }

.board-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
  touch-action: none;
}
#board {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.play-bottom {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.play-bottom .btn { flex: 1; padding: 11px 10px; font-size: 14px; }

.tutorial-tip {
  position: absolute;
  left: 12px; right: 12px;
  bottom: calc(64px + env(safe-area-inset-bottom, 0px));
  background: rgba(30, 35, 41, 0.96);
  border: 1px solid rgba(240,185,11,0.35);
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  z-index: 8;
}
.tutorial-tip p { margin: 0 0 8px; font-size: 13px; line-height: 1.55; color: var(--text); }
.tutorial-tip .btn { width: 100%; }

#toast {
  position: absolute;
  left: 50%;
  top: 46%;
  transform: translate(-50%, -50%) scale(0.96);
  background: rgba(30, 35, 41, 0.95);
  border: 1px solid var(--gold);
  color: var(--gold);
  padding: 10px 16px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: 0.2s ease;
  z-index: 9;
  white-space: nowrap;
}
#toast.is-on { opacity: 1; transform: translate(-50%, -50%) scale(1); }

/* Result */
.result-overlay {
  position: absolute;
  inset: 0;
  background: rgba(11, 14, 17, 0.72);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 15;
}
.result-card {
  width: min(340px, 100%);
  background: linear-gradient(180deg, #1A1F27 0%, #12161C 100%);
  border: 1px solid rgba(240,185,11,0.4);
  border-radius: 16px;
  padding: 22px 20px 18px;
  text-align: center;
  box-shadow: var(--shadow);
}
.result-logo { width: 48px; height: 48px; margin: 0 auto 8px; }
.result-logo img { width: 100%; height: 100%; }
.result-card .kicker { margin-bottom: 4px; }
.result-card h2 { margin: 0; font-size: 28px; color: var(--gold); }
.result-card .sub { margin: 4px 0 10px; color: var(--muted); font-size: 13px; }
.stars.big { display: flex; justify-content: center; gap: 8px; margin: 6px 0 12px; }
.stars.big .star {
  font-size: 32px;
  color: rgba(234,236,239,0.16);
}
.stars.big .star.on {
  color: var(--gold);
  animation: starIn 0.45s ease both;
  text-shadow: 0 0 16px rgba(240,185,11,0.6);
}
@keyframes starIn {
  from { transform: scale(0.3) rotate(-20deg); opacity: 0; }
  to { transform: scale(1) rotate(0); opacity: 1; }
}
.result-stats { display: flex; justify-content: center; gap: 28px; margin: 8px 0 16px; }
.result-stats span { display: block; color: var(--muted); font-size: 11px; }
.result-stats b { font-size: 24px; }
.result-actions { display: flex; flex-direction: column; gap: 8px; }

@media (min-height: 800px) {
  .screen-title h1 { font-size: 48px; }
  .title-coins canvas { width: 52px; height: 52px; }
}
@media (max-height: 680px) {
  .title-coins { margin: 16px 0 18px; }
  .screen-title h1 { font-size: 36px; }
}
