:root {
  color-scheme: dark;
  --ink: #f7efe0;
  --muted: #b9ad9c;
  --paper: #211f1b;
  --panel: #171614;
  --line: rgba(247, 239, 224, 0.18);
  --gold: #f2b84b;
  --red: #d8523f;
  --teal: #4ab7a8;
  --violet: #8d77d8;
  --floor: #2b2924;
  --shadow: 0 22px 50px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at 18% 12%, rgba(242, 184, 75, 0.18), transparent 24rem),
    radial-gradient(circle at 88% 18%, rgba(74, 183, 168, 0.16), transparent 22rem),
    linear-gradient(135deg, #151515 0%, #1d1a17 48%, #101415 100%);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  border: 0;
  color: inherit;
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

button:focus-visible {
  outline: 3px solid rgba(242, 184, 75, 0.7);
  outline-offset: 3px;
}

.app {
  min-height: 100vh;
  padding: 18px;
}

.title-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(280px, 0.9fr) minmax(320px, 1.1fr);
  gap: clamp(24px, 5vw, 72px);
  align-items: center;
  padding: clamp(20px, 5vw, 72px);
  background:
    linear-gradient(90deg, rgba(15, 15, 14, 0.96), rgba(15, 15, 14, 0.82)),
    radial-gradient(circle at 70% 30%, rgba(216, 82, 63, 0.2), transparent 26rem);
}

.title-screen.hidden {
  display: none;
}

.key-art {
  display: grid;
  place-items: center;
  min-height: 420px;
}

.dungeon-card {
  position: relative;
  width: min(78vw, 430px);
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 22px;
  background:
    linear-gradient(45deg, rgba(255,255,255,0.05) 25%, transparent 25% 50%, rgba(255,255,255,0.05) 50% 75%, transparent 75%),
    linear-gradient(135deg, #302d27, #161614);
  background-size: 72px 72px, 100% 100%;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.dungeon-card::before {
  content: "";
  position: absolute;
  inset: 32px;
  border: 8px solid #443f35;
  border-radius: 18px;
  box-shadow: inset 0 0 0 2px rgba(0,0,0,0.35);
}

.hero-glyph,
.trap-glyph,
.relic-glyph,
.gate-glyph,
.demo-lane,
.demo-tap {
  position: absolute;
  display: block;
}

.demo-lane {
  left: 54px;
  right: 54px;
  height: 6px;
  border-radius: 99px;
  background: rgba(247,239,224,0.13);
}

.lane-a { top: 132px; }
.lane-b { top: 214px; }
.lane-c { top: 296px; }

.demo-tap {
  left: 150px;
  top: 188px;
  z-index: 2;
  border: 1px solid rgba(242,184,75,0.52);
  border-radius: 999px;
  padding: 5px 9px;
  color: var(--gold);
  font-size: 0.72rem;
  font-weight: 950;
  animation: tapPulse 1.55s ease-in-out infinite;
}

.hero-glyph {
  left: 78px;
  top: 162px;
  width: 56px;
  height: 56px;
  border-radius: 18px 18px 14px 14px;
  background: linear-gradient(180deg, #f9e6b4, #e15a44);
  box-shadow: 0 14px 30px rgba(216,82,63,0.3);
  animation: titleRun 3.2s ease-in-out infinite;
}

.hero-glyph::before {
  content: "";
  position: absolute;
  left: 16px;
  top: -18px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #f7efe0;
}

.trap-glyph {
  width: 0;
  height: 0;
  border-left: 24px solid transparent;
  border-right: 24px solid transparent;
  border-bottom: 58px solid var(--red);
  filter: drop-shadow(0 10px 16px rgba(216,82,63,0.28));
}

.trap-a { left: 238px; top: 92px; }
.trap-b { left: 178px; top: 272px; }

.relic-glyph {
  right: 84px;
  top: 172px;
  width: 42px;
  height: 42px;
  transform: rotate(45deg);
  background: var(--gold);
  box-shadow: 0 0 24px rgba(242, 184, 75, 0.58);
  animation: relicBlink 1.8s ease-in-out infinite;
}

.gate-glyph {
  right: 62px;
  bottom: 58px;
  width: 82px;
  height: 86px;
  border: 8px solid var(--teal);
  border-bottom: 0;
  border-radius: 40px 40px 0 0;
}

@keyframes titleRun {
  0%, 100% { transform: translate(0, 0); }
  35% { transform: translate(118px, 0); }
  55% { transform: translate(170px, 82px); }
  78% { transform: translate(238px, 82px); }
}

@keyframes tapPulse {
  0%, 100% { opacity: 0.35; transform: scale(0.94); }
  45% { opacity: 1; transform: scale(1.05); }
}

@keyframes relicBlink {
  0%, 100% { opacity: 0.72; }
  50% { opacity: 1; }
}

.title-copy {
  max-width: 720px;
}

.eyebrow,
.label {
  margin: 0;
  color: var(--gold);
  font-size: 0.76rem;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 16px;
  font-size: clamp(3.4rem, 8vw, 7.5rem);
  line-height: 0.9;
  letter-spacing: 0;
}

.tagline {
  max-width: 620px;
  color: var(--muted);
  font-size: clamp(1.05rem, 2vw, 1.35rem);
  line-height: 1.55;
}

.title-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 24px 0;
}

.title-badges span,
.pace-badge,
.danger-badge,
.par-badge,
.trait-badge,
.combo-pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 13px;
  background: rgba(255,255,255,0.05);
  color: var(--ink);
  font-size: 0.86rem;
  font-weight: 800;
}

.stage-badges {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.danger-badge[data-level="sharp"] {
  border-color: rgba(242, 184, 75, 0.42);
  color: var(--gold);
}

.danger-badge[data-level="brutal"] {
  border-color: rgba(216, 82, 63, 0.52);
  color: #ff8d76;
}

.par-badge {
  border-color: rgba(74, 183, 168, 0.42);
  color: #82ded3;
}

.trait-badge {
  border-color: var(--trait, var(--gold));
  color: var(--trait, var(--gold));
}

.title-actions,
.modal-actions,
.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.title-actions button,
.modal-actions button,
.actions button {
  min-height: 44px;
  border-radius: 10px;
  padding: 0 18px;
  background: #34302a;
  font-weight: 850;
}

#startBtn,
#continueClearBtn {
  background: var(--gold);
  color: #17130d;
}

.topbar,
.play-layout,
.stage-head,
.panel,
.progress-card,
.objective,
.rooms {
  border: 1px solid var(--line);
  background: rgba(23, 22, 20, 0.8);
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  border-radius: 18px;
  padding: 14px;
  margin-bottom: 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand h2 {
  margin: 2px 0 0;
  font-size: clamp(1.1rem, 3vw, 1.8rem);
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background:
    linear-gradient(135deg, transparent 40%, rgba(0,0,0,0.28) 40% 58%, transparent 58%),
    linear-gradient(180deg, var(--gold), var(--red));
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(68px, 1fr));
  gap: 8px;
  min-width: min(420px, 46vw);
}

.stats div {
  border-radius: 12px;
  padding: 8px 10px;
  background: rgba(255,255,255,0.05);
}

.stats span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.stats strong {
  font-size: 1.28rem;
}

.play-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 14px;
  border-radius: 20px;
  padding: 14px;
}

.stage-wrap {
  min-width: 0;
}

.stage-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  border-radius: 14px;
  padding: 12px;
  margin-bottom: 12px;
  box-shadow: none;
}

.stage-head h3 {
  margin: 3px 0 0;
  font-size: 1.15rem;
}

.zone {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

canvas {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  border: 1px solid rgba(247,239,224,0.22);
  border-radius: 16px;
  background: #111;
}

.run-strip {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 10px;
  min-height: 38px;
}

.message {
  min-height: 28px;
  padding: 9px 4px 0;
  color: var(--muted);
  font-weight: 750;
}

.combo-pill {
  flex: 0 0 auto;
  margin-top: 7px;
  color: var(--muted);
  transition: color 140ms ease, transform 140ms ease, border-color 140ms ease;
}

.combo-pill.hot {
  border-color: rgba(242, 184, 75, 0.72);
  color: var(--gold);
  transform: translateY(-1px);
}

.panel {
  display: grid;
  align-content: start;
  gap: 12px;
  border-radius: 16px;
  padding: 12px;
  box-shadow: none;
}

.action-btn {
  display: grid;
  gap: 4px;
  min-height: 112px;
  border-radius: 18px;
  background: linear-gradient(180deg, #f4c25d, #d8523f);
  color: #15110c;
  box-shadow: inset 0 -8px 0 rgba(0,0,0,0.18), 0 18px 36px rgba(216,82,63,0.2);
}

.action-btn span {
  font-size: 1.35rem;
  font-weight: 950;
}

.action-btn small {
  font-weight: 850;
}

.actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
}

.actions button {
  min-width: 0;
  padding: 0 8px;
  font-size: 0.9rem;
}

.objective,
.progress-card,
.zone-card,
.intel-card,
.rooms {
  border-radius: 14px;
  padding: 12px;
  box-shadow: none;
}

.objective p:last-child,
.progress-card p:last-child,
.zone-card p:last-child {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.45;
}

.zone-card h4 {
  margin: 7px 0 9px;
  font-size: 1rem;
}

.intel-card dl {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin: 10px 0 0;
}

.intel-card dl div:first-child,
.intel-card dl div:nth-child(3) {
  grid-column: 1 / -1;
}

.intel-card dl div {
  min-width: 0;
  border-radius: 10px;
  padding: 9px;
  background: rgba(255,255,255,0.05);
}

.intel-card dt {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 850;
  text-transform: uppercase;
}

.intel-card dd {
  margin: 3px 0 0;
  color: var(--ink);
  font-size: 0.94rem;
  font-weight: 900;
  overflow-wrap: anywhere;
}

.progress-track {
  height: 10px;
  overflow: hidden;
  border-radius: 99px;
  background: rgba(255,255,255,0.1);
  margin: 9px 0;
}

.progress-track span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal), var(--gold));
}

.zone-track {
  height: 8px;
  overflow: hidden;
  border-radius: 99px;
  background: rgba(255,255,255,0.1);
  margin: 0 0 9px;
}

.zone-track span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--gold), var(--red));
}

.room-buttons {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  max-height: 220px;
  overflow: auto;
  padding-right: 2px;
}

.room-buttons button {
  position: relative;
  aspect-ratio: 1;
  border-radius: 8px;
  background: rgba(255,255,255,0.06);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
}

.room-buttons button::after {
  content: "";
  position: absolute;
  right: 4px;
  bottom: 4px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: transparent;
}

.room-buttons button.active {
  background: var(--gold);
  color: #17130d;
}

.room-buttons button.cleared {
  color: var(--ink);
  border: 1px solid rgba(74,183,168,0.5);
}

.room-buttons button.medal-gate::after {
  background: var(--teal);
}

.room-buttons button.medal-relic::after {
  background: var(--gold);
  box-shadow: 0 0 8px rgba(242, 184, 75, 0.54);
}

.room-buttons button.medal-crown {
  border-color: rgba(242, 184, 75, 0.72);
}

.room-buttons button.medal-crown::after {
  background: linear-gradient(180deg, var(--gold), #fff0aa);
  box-shadow: 0 0 10px rgba(242, 184, 75, 0.72);
}

.modal-card {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: none;
  place-items: center;
  padding: 18px;
  background: rgba(12, 12, 11, 0.72);
}

.modal-card.show {
  display: grid;
}

.modal-card > div {
  width: min(460px, 100%);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 22px;
  background: #201e1a;
  box-shadow: var(--shadow);
}

.modal-card h2 {
  margin: 4px 0 8px;
  font-size: 2rem;
}

.result-strip {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin: 16px 0 18px;
}

.result-strip span {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: rgba(255,255,255,0.05);
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 850;
}

@media (max-width: 880px) {
  .app {
    padding: 10px;
  }

  .title-screen {
    grid-template-columns: 1fr;
    align-content: center;
    overflow: auto;
  }

  .key-art {
    min-height: 260px;
  }

  .dungeon-card {
    width: min(78vw, 300px);
  }

  .demo-lane {
    left: 38px;
    right: 38px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .stats {
    min-width: 0;
    width: 100%;
  }

  .play-layout {
    grid-template-columns: 1fr;
  }

  .panel {
    grid-template-columns: 1fr;
  }

  .action-btn {
    min-height: 82px;
  }

  .room-buttons {
    grid-template-columns: repeat(8, 1fr);
    max-height: none;
  }
}

@media (max-width: 520px) {
  h1 {
    font-size: 3.2rem;
  }

  .stage-head {
    align-items: stretch;
    flex-direction: column;
  }

  .stage-badges,
  .run-strip {
    justify-content: stretch;
  }

  .run-strip {
    flex-direction: column;
    gap: 0;
  }

  .combo-pill {
    width: fit-content;
  }

  .room-buttons {
    grid-template-columns: repeat(5, 1fr);
  }

  .result-strip {
    grid-template-columns: 1fr;
  }
}
