:root {
  --bg: #0c1d18;
  --panel: rgba(14, 30, 26, 0.92);
  --border: rgba(255, 206, 92, 0.34);
  --ink: #fff8ea;
  --muted: #b0cdc2;
  --gold: #ffce54;
  --emerald: #34e89e;
  --lava: #ff6238;
  --cyan: #48e5ff;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(circle at 50% 18%, #1d4a3c 0%, #0d1f1a 56%, #07100e 100%);
  color: var(--ink);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, -apple-system, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

[hidden] {
  display: none !important;
}

.shell {
  width: 100%;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 0 18px;
}

/* ─── SIDE CARDS (DESKTOP ONLY) ─── */
.side-card {
  width: 256px;
  background: var(--panel);
  border: 2px solid var(--border);
  border-radius: 18px;
  padding: 18px 16px;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.45);
}

.badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.14em;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(52, 232, 158, 0.16);
  color: var(--emerald);
  border: 1px solid rgba(52, 232, 158, 0.4);
  margin-bottom: 10px;
}

.badge.gold {
  background: rgba(255, 206, 84, 0.16);
  color: var(--gold);
  border-color: rgba(255, 206, 84, 0.42);
}

.side-card h2 {
  font-size: 24px;
  color: var(--gold);
  line-height: 1.05;
}

.side-sub {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.18em;
  color: var(--emerald);
  margin-bottom: 14px;
}

.tips-list {
  list-style: none;
  display: grid;
  gap: 10px;
  font-size: 12.5px;
  line-height: 1.45;
  color: #dceee6;
  margin-bottom: 16px;
}

.tips-list strong {
  color: var(--gold);
}

.keys-hint {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.keys-hint span {
  font-size: 11px;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: var(--muted);
}

.side-practice-btn {
  margin-top: 12px;
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(52, 232, 158, 0.45);
  background: rgba(20, 62, 52, 0.85);
  color: var(--ink);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 800;
  cursor: pointer;
}

.side-practice-btn:hover {
  background: rgba(28, 86, 72, 0.95);
  border-color: var(--emerald);
}

.stage-track {
  list-style: none;
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.stage-track li {
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stage-track li strong {
  font-size: 12.5px;
  color: var(--ink);
}

.stage-track li span {
  font-size: 10.5px;
  color: var(--muted);
}

.stage-track li.active {
  border-color: var(--gold);
  background: rgba(255, 206, 84, 0.15);
}

.stage-track li.cleared {
  border-color: rgba(52, 232, 158, 0.45);
  background: rgba(52, 232, 158, 0.12);
}

.best-box {
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 206, 84, 0.3);
  text-align: center;
  margin-bottom: 12px;
}

.best-box span {
  display: block;
  font-size: 10px;
  letter-spacing: 0.16em;
  color: var(--muted);
}

.best-box strong {
  font-size: 22px;
  color: var(--gold);
}

.home-link {
  display: block;
  text-align: center;
  color: var(--muted);
  text-decoration: none;
  font-size: 12px;
  font-weight: 700;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.home-link:hover {
  color: var(--ink);
  border-color: rgba(255, 255, 255, 0.3);
}

/* ─── 9:16 PORTRAIT STAGE ─── */
.stage-wrap {
  position: relative;
  width: min(100vw, 56.25dvh);
  height: min(100dvh, 177.7778vw);
  max-height: 100dvh;
  background: #0d1d18;
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.65), 0 0 0 2px rgba(255, 206, 84, 0.34);
}

canvas#game {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.stage-tools {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  right: 10px;
  z-index: 12;
  display: flex;
  gap: 6px;
}

.tool-btn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(11, 24, 21, 0.85);
  color: var(--ink);
  font-size: 14px;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.tool-btn:hover {
  background: rgba(26, 56, 48, 0.95);
}

/* ─── OVERLAYS INSIDE 9:16 STAGE ─── */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px 16px;
  text-align: center;
  background: linear-gradient(180deg, rgba(10, 26, 22, 0.92) 0%, rgba(16, 24, 22, 0.95) 55%, rgba(28, 13, 10, 0.96) 100%);
  backdrop-filter: blur(4px);
  overflow-y: auto;
}

.hero-art {
  position: relative;
  width: 220px;
  height: 104px;
  margin-bottom: 6px;
}

.hero-sprite {
  position: absolute;
  object-fit: contain;
  filter: drop-shadow(0 8px 12px rgba(0, 0, 0, 0.55));
}

.hero-left {
  width: 78px;
  left: 16px;
  bottom: 4px;
  animation: bob 1.5s ease-in-out infinite;
}

.hero-boss {
  width: 112px;
  right: 10px;
  bottom: 0;
  animation: bob 1.8s ease-in-out 0.3s infinite;
}

.hero-egg {
  width: 44px;
  left: 92px;
  top: 4px;
  animation: bob 1.3s ease-in-out 0.15s infinite;
}

@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.eyebrow {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.2em;
  color: var(--emerald);
  margin-bottom: 4px;
}

.game-title {
  font-size: 36px;
  font-weight: 900;
  line-height: 0.96;
  letter-spacing: 0.03em;
  color: var(--gold);
  text-shadow: 0 4px 0 #7a4610, 0 10px 22px rgba(0, 0, 0, 0.6);
}

.game-sub {
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 0.24em;
  color: #ff8a5b;
  margin-bottom: 10px;
}

.tagline {
  font-size: 12.5px;
  line-height: 1.4;
  color: #d9ece4;
  max-width: 295px;
  margin-bottom: 14px;
}

.tagline strong {
  color: var(--gold);
}

.tier-list {
  width: 100%;
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.tier-btn {
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border-radius: 12px;
  border: 2px solid rgba(255, 255, 255, 0.16);
  background: rgba(18, 36, 32, 0.86);
  color: var(--ink);
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}

.tier-btn:hover {
  transform: translateY(-1px);
  border-color: rgba(255, 206, 84, 0.6);
}

.tier-btn.selected {
  border-color: var(--emerald);
  background: linear-gradient(135deg, rgba(24, 72, 58, 0.96), rgba(16, 46, 42, 0.96));
  box-shadow: 0 0 18px rgba(52, 232, 158, 0.26);
}

.tier-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2px;
}

.tier-top strong {
  font-size: 14px;
  color: var(--gold);
}

.tier-top em {
  font-style: normal;
  font-size: 10px;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  color: #d9f7ea;
}

.tier-btn small {
  display: block;
  font-size: 11px;
  color: var(--muted);
}

.cta-btn {
  width: 100%;
  min-height: 50px;
  border: 0;
  border-radius: 14px;
  background: linear-gradient(180deg, #ffe787 0%, #ffb732 100%);
  color: #211306;
  font-family: inherit;
  font-size: 17px;
  font-weight: 900;
  letter-spacing: 0.04em;
  cursor: pointer;
  box-shadow: 0 6px 0 #9e5c0a, 0 14px 26px rgba(0, 0, 0, 0.42);
  transition: transform 0.1s ease, filter 0.1s ease;
}

.cta-btn:hover:not(:disabled) {
  filter: brightness(1.06);
  transform: translateY(-1px);
}

.cta-btn:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 3px 0 #9e5c0a;
}

.cta-btn:disabled {
  opacity: 0.55;
  cursor: wait;
}

.ghost-btn {
  width: 100%;
  min-height: 42px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  font-family: inherit;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
}

.ghost-btn:hover {
  background: rgba(255, 255, 255, 0.15);
}

.secondary-cta {
  width: 100%;
  min-height: 46px;
  margin-top: 12px;
  border-radius: 14px;
  border: 2px solid rgba(52, 232, 158, 0.58);
  background: linear-gradient(180deg, #1d6452 0%, #124438 100%);
  color: #e8fff6;
  font-family: inherit;
  font-size: 14.5px;
  font-weight: 800;
  letter-spacing: 0.02em;
  cursor: pointer;
  box-shadow: 0 5px 0 #0a2922, 0 12px 22px rgba(0, 0, 0, 0.36);
  transition: transform 0.1s ease, filter 0.12s ease;
}

.secondary-cta:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

.secondary-cta:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #0a2922;
}

/* ─── HOW TO PLAY & UNTIMED PRACTICE OVERLAY ─── */
.guide-overlay {
  justify-content: flex-start;
  padding: 12px 12px 16px;
  text-align: left;
  gap: 10px;
}

.guide-header {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.guide-tabs {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 3px;
  border-radius: 11px;
  background: rgba(7, 16, 14, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.guide-tab {
  border: 0;
  border-radius: 8px;
  padding: 8px 6px;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
}

.guide-tab.selected {
  background: linear-gradient(180deg, #ffe27c, #f2b436);
  color: #1f1306;
}

.guide-close {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(18, 34, 30, 0.9);
  color: var(--ink);
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  flex-shrink: 0;
}

.guide-pane {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

.rule-card {
  background: rgba(16, 34, 30, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  padding: 9px 10px;
}

.rule-badge {
  display: inline-block;
  font-size: 9.5px;
  font-weight: 900;
  letter-spacing: 0.12em;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(52, 232, 158, 0.18);
  color: var(--emerald);
  margin-bottom: 4px;
}

.rule-badge.red {
  background: rgba(255, 92, 92, 0.22);
  color: #ff9494;
}

.rule-badge.gold {
  background: rgba(255, 206, 84, 0.2);
  color: var(--gold);
}

.rule-badge.fire {
  background: rgba(255, 130, 56, 0.24);
  color: #ffb178;
}

.rule-card p {
  font-size: 11.8px;
  line-height: 1.38;
  color: #ddf0e8;
}

.rule-card code {
  font-family: inherit;
  font-weight: 900;
  color: var(--gold);
}

.mini-demo {
  margin-top: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  flex-wrap: wrap;
}

.demo-pack {
  padding: 4px 8px;
  border-radius: 8px;
  background: #103b32;
  border: 1.5px solid var(--emerald);
  font-size: 12px;
  font-weight: 900;
  color: #fff8d6;
}

.demo-arrow,
.demo-vs {
  font-size: 11px;
  font-weight: 800;
  color: var(--muted);
}

.demo-gate {
  padding: 4px 8px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 900;
  color: #ffffff;
  border: 1.5px solid rgba(255, 255, 255, 0.4);
}

.demo-gate em {
  font-style: normal;
  font-size: 10.5px;
  opacity: 0.92;
  margin-left: 2px;
}

.demo-gate.good {
  background: linear-gradient(180deg, #1fa6a6, #106072);
}

.demo-gate.blue {
  background: linear-gradient(180deg, #3278c9, #1b488a);
}

.demo-gate.hazard {
  background: linear-gradient(180deg, #c23636, #7a1820);
}

.demo-gate.winner {
  border-color: #ffe87c;
  box-shadow: 0 0 10px rgba(255, 232, 124, 0.45);
}

.guide-footer-actions {
  margin-top: auto;
  display: grid;
  gap: 7px;
  padding-top: 4px;
}

/* ─── UNTIMED PRACTICE SANDBOX ─── */
.practice-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.untimed-pill {
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.08em;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(52, 232, 158, 0.16);
  border: 1px solid rgba(52, 232, 158, 0.45);
  color: var(--emerald);
}

.practice-tier-pills {
  display: inline-flex;
  gap: 3px;
  padding: 2px;
  border-radius: 9px;
  background: rgba(7, 16, 14, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.ptier-btn {
  border: 0;
  border-radius: 7px;
  padding: 4px 7px;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 10.5px;
  font-weight: 800;
  cursor: pointer;
}

.ptier-btn.selected {
  background: var(--emerald);
  color: #0b221c;
}

.practice-hero-box {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(16, 52, 44, 0.94), rgba(14, 30, 32, 0.94));
  border: 2px solid rgba(52, 232, 158, 0.45);
}

.practice-dino-img {
  width: 52px;
  height: 58px;
  object-fit: contain;
  flex-shrink: 0;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.5));
}

.practice-pack-info {
  flex: 1;
}

.practice-label {
  display: block;
  font-size: 9.5px;
  letter-spacing: 0.14em;
  color: var(--muted);
  font-weight: 800;
}

.practice-pack-num {
  display: block;
  font-size: 32px;
  line-height: 1;
  color: var(--gold);
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.45);
}

.practice-stats {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  font-size: 10px;
  color: var(--muted);
  font-weight: 800;
}

.practice-stats strong {
  color: var(--ink);
  font-size: 13px;
  margin-left: 3px;
}

.practice-prompt {
  font-size: 12.5px;
  font-weight: 800;
  color: #fff2c4;
  text-align: center;
}

.practice-gates {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.practice-gates.triple {
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.prac-gate-btn {
  min-height: 82px;
  padding: 10px 6px;
  border-radius: 13px;
  border: 2.5px solid rgba(255, 255, 255, 0.48);
  color: #ffffff;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.36);
  transition: transform 0.1s ease, filter 0.12s ease, opacity 0.15s ease;
}

.prac-gate-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  filter: brightness(1.1);
}

.prac-gate-btn:disabled {
  cursor: default;
}

.prac-gate-btn.tone-0 {
  background: linear-gradient(180deg, #22b2b0, #106072);
  border-color: #7cf7ee;
}

.prac-gate-btn.tone-1 {
  background: linear-gradient(180deg, #3a84d8, #1c4c91);
  border-color: #96d8ff;
}

.prac-gate-btn.tone-2 {
  background: linear-gradient(180deg, #8b5be0, #4e2b96);
  border-color: #d2b0ff;
}

.prac-gate-btn.tone-hazard {
  background: linear-gradient(180deg, #cc3c3c, #7c1822);
  border-color: #ff948a;
}

.prac-gate-btn.is-best {
  border-color: #ffe87c;
  box-shadow: 0 0 20px rgba(255, 232, 124, 0.58);
}

.prac-gate-btn.is-dim {
  opacity: 0.56;
}

.prac-gate-label {
  font-size: 26px;
  font-weight: 900;
  text-shadow: 0 2px 5px rgba(0, 0, 0, 0.65);
  line-height: 1.05;
}

.practice-gates.triple .prac-gate-label {
  font-size: 19px;
}

.prac-gate-sub {
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: #fff3b8;
  text-transform: uppercase;
}

.prac-gate-res {
  font-size: 12px;
  font-weight: 900;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(8, 16, 20, 0.65);
  color: #ffe88a;
  margin-top: 2px;
}

.practice-hint-box {
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(255, 206, 84, 0.14);
  border: 1px solid rgba(255, 206, 84, 0.45);
  color: #fff0be;
  font-size: 11.5px;
  line-height: 1.4;
}

.practice-feedback {
  padding: 9px 11px;
  border-radius: 12px;
  background: rgba(10, 26, 22, 0.92);
  border: 1.5px solid var(--emerald);
}

.practice-feedback.miss {
  border-color: #ff9468;
}

.prac-fb-title {
  font-size: 13px;
  font-weight: 900;
  color: var(--emerald);
  margin-bottom: 4px;
}

.practice-feedback.miss .prac-fb-title {
  color: #ffb085;
}

.prac-fb-lines {
  display: grid;
  gap: 3px;
  font-size: 11.5px;
  color: #e4f4ee;
}

.prac-fb-line.best-line {
  color: #ffe885;
  font-weight: 800;
}

.practice-controls {
  display: flex;
  gap: 6px;
}

.small-btn {
  min-height: 38px;
  font-size: 12px;
  padding: 6px 8px;
}

.prac-next-btn {
  min-height: 40px;
  font-size: 14px;
}

.prac-launch-btn {
  margin-top: auto;
}

.touch-note {
  margin-top: 10px;
  font-size: 11px;
  color: var(--muted);
}

.overlay-heading {
  font-size: 32px;
  color: var(--gold);
  margin-bottom: 6px;
  text-shadow: 0 4px 0 rgba(0, 0, 0, 0.45);
}

.res-copy {
  font-size: 13px;
  color: #dceee6;
  margin-bottom: 16px;
  max-width: 280px;
  line-height: 1.4;
}

.res-grid {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.res-box {
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  padding: 10px 8px;
}

.res-box span {
  display: block;
  font-size: 9.5px;
  letter-spacing: 0.14em;
  color: var(--muted);
  font-weight: 800;
}

.res-box strong {
  display: block;
  font-size: 20px;
  color: var(--ink);
  margin-top: 2px;
}

.overlay-actions {
  width: 100%;
  display: grid;
  gap: 8px;
}

/* ─── RESPONSIVE MOBILE / NARROW VIEWPORT ─── */
@media (max-width: 960px) {
  .side-card {
    display: none;
  }

  .shell {
    padding: 0;
  }

  .stage-wrap {
    width: min(100vw, 56.25dvh);
    height: min(100dvh, 177.7778vw);
    border-radius: 0;
    box-shadow: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}
