:root {
  --bg: #07110c;
  --ink: #e8f6ec;
  --muted: #8eaa98;
  --amber: #ffc857;
  --amber-deep: #d4891a;
  --ink-amber: #2a1700;
  --line: rgba(255, 206, 130, 0.32);
  --panel: rgba(6, 16, 12, 0.82);
  --danger: #ff5d6c;
  --good: #3ee0a0;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.38);
  font-family: "Trebuchet MS", "Avenir Next", "Segoe UI", sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

button, summary { font-family: inherit; }

#app {
  position: relative;
  height: 100%;
  width: 100%;
  overflow: hidden;
}

#view {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
  touch-action: none;
}

#hud-top, #hud-bottom, #combo-banner, #alert-banner {
  position: absolute;
  z-index: 3;
  pointer-events: none;
}

#hud-top {
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: flex-start;
  justify-content: space-between;
  padding: max(10px, env(safe-area-inset-top)) 12px 0;
}

#hud-bottom {
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  padding: 0 12px max(10px, env(safe-area-inset-bottom));
}

.cluster, .stat, .icon-btn, .ctrl, .bead-wrap, .swap, .special, .launch {
  pointer-events: auto;
}

.cluster {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.stat {
  min-width: 92px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 7px 12px 8px;
  box-shadow: var(--shadow);
}

.stat b {
  display: block;
  font-family: "Arial Black", Impact, "Trebuchet MS", sans-serif;
  font-size: 18px;
  letter-spacing: 0.03em;
  font-weight: 800;
}

.stat span, .bead-wrap small, .hint, .muted {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.level-stat { text-align: center; min-width: 160px; }
.level-stat b { font-size: 16px; }
.level-stat em { font-style: normal; color: var(--amber); font-size: 12px; letter-spacing: 0.08em; }

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  display: grid;
  place-items: center;
  cursor: pointer;
}

.icon-btn:hover, .swap:hover, .special:hover, .launch:hover, .primary:hover, .ghost:hover {
  filter: brightness(1.08);
}

.icon-btn:focus-visible, .swap:focus-visible, .special:focus-visible,
.launch:focus-visible, .primary:focus-visible, .ghost:focus-visible, .pip:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}

.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; }

#effect-pills { display: flex; gap: 6px; flex-wrap: wrap; }
.pill {
  pointer-events: none;
  background: rgba(8, 20, 14, 0.9);
  border: 1px solid var(--line);
  color: var(--amber);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  letter-spacing: 0.06em;
}

.meter {
  width: min(560px, 100%);
  height: 16px;
  border-radius: 999px;
  background: rgba(6, 14, 10, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.08);
  position: relative;
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, #3ee0a0, #ffe08a 55%, #ff5d6c);
  transition: width 0.12s linear;
}

.meter i {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-style: normal;
  font-size: 10px;
  letter-spacing: 0.16em;
  color: #f4fff6;
  font-weight: 800;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.85);
  pointer-events: none;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: center;
}

.bead-wrap {
  width: 156px;
  height: 156px;
  border-radius: 50%;
  padding: 4px;
  background: conic-gradient(var(--amber) calc(var(--cool, 100) * 1%), rgba(255, 255, 255, 0.08) 0);
  display: grid;
  place-items: center;
  position: relative;
  box-shadow: var(--shadow);
}

.bead-wrap canvas, .next-wrap canvas {
  width: 136px;
  height: 136px;
  border-radius: 50%;
  background: #102018;
}

.next-wrap {
  width: 112px;
  height: 112px;
  border-radius: 50%;
  border: 1px solid var(--line);
  overflow: hidden;
  background: #102018;
  box-shadow: var(--shadow);
}

.next-wrap canvas { width: 112px; height: 112px; }

.bead-wrap small {
  position: absolute;
  bottom: -2px;
  background: #102018;
  border-radius: 999px;
  padding: 1px 6px;
  border: 1px solid var(--line);
}

.swap, .special, .launch, .primary, .ghost, .pip {
  border: 0;
  cursor: pointer;
}

.swap, .special, .launch {
  min-height: 52px;
  border-radius: 999px;
  padding: 0 16px;
  letter-spacing: 0.12em;
  font-weight: 800;
}

.swap, .special {
  background: rgba(10, 22, 16, 0.9);
  color: var(--ink);
  border: 1px solid var(--line);
}

.special[disabled] { opacity: 0.45; cursor: default; }
.special.armed {
  color: #1a1008;
  border-color: transparent;
  animation: pulse 1.1s ease-in-out infinite;
}

.launch, .primary {
  background: linear-gradient(180deg, #ffd36e, #f0a322);
  color: var(--ink-amber);
}

.launch { min-width: 112px; }

.hint {
  text-align: center;
  text-shadow: 0 1px 2px #000;
}

#combo-banner {
  top: 86px;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  text-shadow: 0 6px 18px rgba(0, 0, 0, 0.55);
}

#combo-banner strong {
  display: block;
  font-family: "Arial Black", Impact, sans-serif;
  font-size: clamp(28px, 5vw, 52px);
  letter-spacing: 0.08em;
  color: var(--amber);
}

#combo-banner span {
  font-size: 18px;
  letter-spacing: 0.2em;
}

#combo-banner.pop strong { animation: pop 0.38s ease-out; }

#alert-banner {
  top: 78px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(90, 12, 22, 0.88);
  color: #ffe4e7;
  border: 1px solid rgba(255, 140, 150, 0.7);
  border-radius: 999px;
  padding: 6px 14px;
  letter-spacing: 0.16em;
  font-size: 13px;
  font-weight: 800;
  animation: blink 0.8s steps(2, end) infinite;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 18px;
  background: radial-gradient(ellipse at center, rgba(4, 12, 8, 0.2), rgba(4, 10, 8, 0.74));
}

.overlay[hidden], [hidden] { display: none !important; }

.card {
  width: min(480px, 100%);
  background: rgba(7, 18, 14, 0.9);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 26px 24px 20px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.card.wide { width: min(560px, 100%); }

.kicker {
  margin: 0 0 6px;
  color: var(--amber);
  letter-spacing: 0.22em;
  font-size: 12px;
}

h1, h2 { font-family: "Arial Black", Impact, "Trebuchet MS", sans-serif; margin: 0; letter-spacing: 0.06em; }
h1 { font-size: clamp(36px, 8vw, 58px); line-height: 0.95; }
h2 { font-size: clamp(28px, 6vw, 40px); }
.card p { color: #d5e6da; line-height: 1.45; }
.lede { font-size: 16px; }

.mark {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 12px var(--amber);
  display: inline-block;
  margin-right: 8px;
  animation: blink 1.4s steps(2, end) infinite;
  vertical-align: middle;
}

.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.spread { justify-content: space-between; }
.actions { margin-top: 14px; }

.primary, .ghost {
  min-height: 48px;
  border-radius: 999px;
  padding: 0 18px;
  letter-spacing: 0.12em;
  font-weight: 800;
}

.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}

.pips { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0 4px; }
.pip {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  border: 1px solid var(--line);
  font-weight: 800;
}
.pip[disabled] { opacity: 0.35; cursor: default; }
.pip.cleared { box-shadow: inset 0 0 0 2px var(--good); }
.pip.current { background: var(--amber); color: var(--ink-amber); border-color: transparent; }

.how { margin-top: 12px; color: #d5e6da; }
.how summary { cursor: pointer; letter-spacing: 0.12em; color: var(--amber); }
.how ul { padding-left: 18px; }
.how li { margin: 4px 0; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0; }
.stats div {
  background: rgba(255, 255, 255, 0.04);
  border-radius: 12px;
  padding: 8px 10px;
}
.stats b { display: block; font-size: 20px; }
.record { color: var(--amber); letter-spacing: 0.14em; font-weight: 800; }

#rotate-hint {
  position: absolute;
  z-index: 6;
  left: 50%;
  top: max(8px, env(safe-area-inset-top));
  transform: translateX(-50%);
  font-size: 12px;
  letter-spacing: 0.08em;
  color: var(--muted);
  display: none;
  pointer-events: none;
  background: rgba(7, 17, 12, 0.8);
  border-radius: 999px;
  padding: 4px 10px;
}

#effect-pills:empty { display: none; }

@media (orientation: portrait) and (max-width: 820px) {
  #app:has(#overlay-title:not([hidden])) #rotate-hint { display: block; }
  .hint { display: none; }

  #hud-top {
    flex-wrap: nowrap;
    gap: 4px;
    align-items: center;
    padding: max(4px, env(safe-area-inset-top)) 6px 0;
  }
  #hud-top .cluster { gap: 4px; flex-wrap: nowrap; }
  .stat {
    min-width: 0;
    padding: 3px 7px 3px;
    border-radius: 10px;
  }
  .stat b { font-size: 14px; line-height: 1.1; }
  .stat span, .bead-wrap small, .hint, .muted {
    font-size: 8px;
    letter-spacing: 0.08em;
  }
  .level-stat { min-width: 0; flex: 1; text-align: center; padding: 3px 6px; }
  .level-stat b { font-size: 13px; }
  .level-stat em { font-size: 9px; }
  .level-stat span { display: none; }
  .stat-best, .stat-chain { display: none; }
  .icon-btn { width: 36px; height: 36px; border-radius: 10px; flex: 0 0 36px; }
  .icon-btn svg { width: 16px; height: 16px; }

  #hud-bottom {
    gap: 4px;
    padding: 0 6px max(4px, env(safe-area-inset-bottom));
  }
  .meter { height: 10px; }
  .meter i { font-size: 8px; }
  .controls { gap: 6px; }
  .bead-wrap { width: 96px; height: 96px; }
  .bead-wrap canvas { width: 88px; height: 88px; }
  .next-wrap, .next-wrap canvas { width: 80px; height: 80px; }
  .controls { flex-wrap: wrap; }
  .swap, .special, .launch {
    min-height: 44px;
    padding: 0 10px;
    font-size: 12px;
    letter-spacing: 0.08em;
  }
  .launch { min-width: 84px; }
  #combo-banner { top: 48px; }
  #alert-banner { top: 46px; padding: 4px 10px; font-size: 11px; }
  #effect-pills {
    position: absolute;
    left: 6px;
    top: calc(100% + 4px);
  }
  .pill { padding: 3px 8px; font-size: 10px; }
}

@media (max-width: 720px) {
  .hint { display: none; }
  .stat b { font-size: 14px; }
}

@keyframes pop {
  from { transform: scale(0.72); filter: brightness(1.6); }
  to { transform: scale(1); }
}

@keyframes pulse {
  50% { filter: brightness(1.25); transform: scale(1.04); }
}

@keyframes blink {
  50% { opacity: 0.45; }
}

@media (prefers-reduced-motion: reduce) {
  .mark, #alert-banner, .special.armed { animation: none; }
}
