:root {
  --bg: #15100c;
  --surface: rgba(29, 22, 16, 0.92);
  --border: rgba(217, 175, 108, 0.34);
  --border-soft: rgba(217, 175, 108, 0.18);
  --text: #f7efe2;
  --muted: #b7a48a;
  --gold: #f59e0b;
  --gold-bright: #fde047;
  --jade: #10b981;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(circle at 50% 20%, #271c13, #110c08);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  touch-action: none;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

.masthead {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: max(8px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left));
  background: rgba(18, 13, 9, 0.95);
  border-bottom: 1px solid var(--border-soft);
  z-index: 30;
}

.masthead h1 {
  margin: 0;
  font-size: 16px;
  letter-spacing: 0.08em;
  color: var(--gold-bright);
  white-space: nowrap;
}

.masthead nav {
  display: flex;
  align-items: center;
  gap: 6px;
}

.masthead nav button {
  appearance: none;
  border: 1px solid var(--border);
  background: rgba(42, 31, 22, 0.9);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  padding: 6px 11px;
  border-radius: 999px;
  cursor: pointer;
}

.masthead nav button[aria-pressed="true"] {
  border-color: var(--gold-bright);
  color: var(--gold-bright);
  background: rgba(245, 158, 11, 0.18);
}

.shell {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px max(8px, env(safe-area-inset-bottom));
  gap: 6px;
  overflow: hidden;
}

.hud-top {
  flex: 0 0 auto;
  width: min(520px, 100%);
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px 10px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--border-soft);
}

.hud-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.hud-stage {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hud-score {
  font-size: 15px;
  font-weight: 900;
  color: var(--gold-bright);
  font-variant-numeric: tabular-nums;
}

.gauge-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.gauge-label {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.gauge-track {
  flex: 1;
  height: 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid var(--border-soft);
  overflow: hidden;
}

.gauge-track i {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #10b981, #f59e0b, #fde047);
  transition: width 0.2s ease;
}

.gauge-val {
  font-size: 11px;
  font-weight: 800;
  color: var(--gold-bright);
  min-width: 34px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.zuma-banner {
  text-align: center;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.05em;
  color: #1c1308;
  background: linear-gradient(90deg, #f59e0b, #fde047, #f59e0b);
  border-radius: 8px;
  padding: 3px 8px;
}

.board-wrap {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

#coil-canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 3 / 4;
  border-radius: 16px;
  border: 2px solid var(--border);
  box-shadow: 0 18px 46px rgba(0, 0, 0, 0.65);
  touch-action: none;
  cursor: crosshair;
}

.hud-bottom {
  flex: 0 0 auto;
  width: min(520px, 100%);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.buff-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  flex: 1;
}

.buff-pill {
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  background: rgba(42, 31, 22, 0.92);
  border: 1px solid var(--border);
  color: var(--gold-bright);
  font-variant-numeric: tabular-nums;
}

.swap-dock {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px 5px 12px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
}

.orb-preview {
  display: flex;
  align-items: center;
  gap: 5px;
}

.orb-dot {
  display: inline-block;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.65);
  box-shadow: inset -3px -3px 6px rgba(0, 0, 0, 0.45);
}

.orb-dot.sm {
  width: 16px;
  height: 16px;
  opacity: 0.9;
}

.orb-arrow {
  font-size: 12px;
  color: var(--muted);
}

.swap-btn {
  appearance: none;
  border: 1px solid var(--gold);
  background: linear-gradient(135deg, #d97706, #b45309);
  color: #fffbeb;
  border-radius: 999px;
  min-height: 36px;
  padding: 0 16px;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

.swap-btn:active {
  transform: scale(0.96);
}

.rotate-banner {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(120, 53, 15, 0.92);
  border: 1px solid var(--gold);
  color: #fef3c7;
  font-size: 11px;
  font-weight: 700;
  z-index: 25;
  pointer-events: none;
}

/* Modal & Lobby */
.overlay-root {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(14px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom));
  background: rgba(10, 7, 5, 0.78);
  backdrop-filter: blur(8px);
  z-index: 40;
}

.overlay-card {
  width: min(700px, 100%);
  max-height: min(86dvh, 760px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  padding: 18px;
  border-radius: 20px;
  background: linear-gradient(165deg, rgba(38, 28, 20, 0.97), rgba(20, 14, 10, 0.98));
  border: 1px solid var(--border);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.7);
  display: flex;
  flex-direction: column;
  gap: 13px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.modal-header h2 {
  margin: 0;
  font-size: 20px;
  color: var(--gold-bright);
  letter-spacing: 0.05em;
}

.sub-line {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
}

.tab-row {
  display: flex;
  gap: 8px;
}

.tab-btn {
  flex: 1;
  min-height: 40px;
  border-radius: 12px;
  border: 1px solid var(--border-soft);
  background: rgba(45, 34, 24, 0.72);
  color: var(--muted);
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
}

.tab-btn.active {
  border-color: var(--gold);
  background: rgba(245, 158, 11, 0.2);
  color: #fffbeb;
}

.temple-pills {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.t-pill {
  flex: 0 0 auto;
  border: 1px solid var(--border-soft);
  background: rgba(42, 31, 22, 0.72);
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.t-pill.active {
  border-color: var(--gold);
  color: var(--gold-bright);
  background: rgba(245, 158, 11, 0.18);
}

.stage-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(128px, 1fr));
  gap: 8px;
}

.stage-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 10px 11px;
  border-radius: 14px;
  border: 1px solid var(--border-soft);
  background: rgba(34, 25, 18, 0.82);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.stage-card.selected {
  border-color: var(--gold-bright);
  background: rgba(180, 83, 9, 0.28);
  box-shadow: 0 0 0 1px rgba(253, 224, 71, 0.35);
}

.stage-card.locked {
  opacity: 0.45;
  cursor: not-allowed;
}

.stage-num {
  font-size: 11px;
  color: var(--gold-bright);
  font-weight: 700;
}

.stage-name {
  font-size: 13px;
  font-weight: 700;
}

.stage-stars {
  font-size: 12px;
  color: var(--gold-bright);
  letter-spacing: 0.08em;
}

.stage-preview {
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(20, 14, 10, 0.76);
  border: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btn {
  flex: 1 1 140px;
  min-height: 44px;
  padding: 10px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(46, 35, 25, 0.88);
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.btn.primary {
  border-color: var(--gold-bright);
  background: linear-gradient(135deg, #d97706, #b45309);
  color: #fffbeb;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.stat-tile {
  padding: 10px;
  border-radius: 12px;
  background: rgba(20, 14, 10, 0.8);
  border: 1px solid var(--border-soft);
  text-align: center;
}

.stat-tile b {
  display: block;
  font-size: 18px;
  color: var(--gold-bright);
}

.stat-tile span {
  font-size: 11px;
  color: var(--muted);
}

.star-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
}

.star-list .met { color: var(--gold-bright); }
.star-list .miss { color: var(--muted); }

.guide-block {
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(20, 14, 10, 0.72);
  border: 1px solid var(--border-soft);
}

.guide-block h3 {
  margin: 0 0 4px;
  font-size: 14px;
  color: var(--gold-bright);
}

.guide-block p {
  margin: 0;
  font-size: 13px;
  line-height: 1.55;
  color: #e2d5c1;
}
