html, body {
  margin: 0;
  height: 100%;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--font);
  overflow: hidden;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  z-index: 0;
}

#flash {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  background: radial-gradient(ellipse at center, rgba(200, 30, 30, 0) 40%, rgba(200, 30, 30, 0.55) 100%);
  opacity: 0;
}

#flash.on {
  animation: flash 420ms var(--ease);
}

@keyframes flash {
  0% { opacity: 1; }
  100% { opacity: 0; }
}

.hud {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  padding: var(--space-5) var(--space-6);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.hud[hidden] {
  display: none;
}

.hud-top,
.hud-bottom {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-5);
  flex-wrap: wrap;
}

.hud-block p {
  margin: 0;
}

.hud-right {
  text-align: right;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--space-1);
}

.eyebrow {
  font-size: var(--text-small);
  font-weight: var(--weight-small);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent-text);
  margin: 0 0 var(--space-2);
}

.hud-wave {
  font-size: var(--text-title);
  font-weight: var(--weight-title);
  color: var(--ink);
  margin: 0;
}

.lanterns {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

.lantern {
  width: 18px;
  height: 24px;
  border-radius: 9px 9px 5px 5px;
  background: radial-gradient(circle at 50% 40%, #fff1c4, var(--accent) 70%);
  box-shadow: 0 0 12px rgba(232, 165, 72, 0.6);
  transition: opacity var(--motion-base) var(--ease), filter var(--motion-base) var(--ease);
}

.lantern.out {
  opacity: 0.18;
  filter: grayscale(1);
  box-shadow: none;
}

.hud-score {
  font-size: var(--text-display);
  font-weight: var(--weight-display);
  line-height: 1;
  margin: 0;
  font-variant-numeric: tabular-nums;
}

.hud-meta {
  font-size: var(--text-small);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.hud-meta strong {
  color: var(--ink);
  font-weight: 700;
}

.mult {
  color: var(--on-accent);
  background: var(--accent);
  border-radius: var(--radius-pill);
  padding: 0 var(--space-2);
  font-weight: 700;
}

.boss-bar {
  align-self: center;
  width: min(480px, 70vw);
  text-align: center;
}

.boss-bar[hidden] {
  display: none;
}

.boss-bar .eyebrow {
  color: var(--secondary-text);
}

.boss-track {
  height: 10px;
  border-radius: var(--radius-pill);
  background: var(--raised);
  border: 1px solid var(--line-strong);
  overflow: hidden;
}

.boss-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #3ea8c7, #9ff0ff);
  transition: width var(--motion-base) var(--ease);
}

.portrait-wrap {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  align-items: flex-start;
}

#portrait {
  width: 144px;
  height: 144px;
  border-radius: var(--radius-card);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

.speaker {
  margin: 0;
  font-size: var(--text-small);
  color: var(--muted);
}

.typing {
  flex: 1 1 360px;
  max-width: 640px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  text-align: center;
  margin-left: auto;
}

.subtitle {
  min-height: 3em;
  margin: 0;
  font-size: var(--text-body);
  line-height: 1.45;
  color: var(--ink);
  background: rgba(11, 14, 20, 0.6);
  border-radius: var(--radius-control);
  padding: var(--space-2) var(--space-4);
  backdrop-filter: blur(2px);
}

.target {
  margin: 0;
  font-size: 40px;
  font-weight: 600;
  letter-spacing: 0.06em;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.7);
  min-height: 1.2em;
}

.target.locked .rest {
  color: var(--accent-text);
}

.target .typed {
  color: var(--hue-1);
}

.hint {
  margin: 0;
  font-size: var(--text-small);
  color: var(--muted);
}

.banner {
  position: absolute;
  top: 30%;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  font-size: var(--text-heading);
  font-weight: 650;
  color: var(--ink);
  text-shadow: 0 2px 16px rgba(0, 0, 0, 0.8);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
}

.banner[data-tone="boss"] {
  color: var(--secondary-text);
}

.banner.show {
  animation: banner 2.4s var(--ease) forwards;
}

@keyframes banner {
  0% { opacity: 0; transform: translate(-50%, 8px); }
  15% { opacity: 1; transform: translate(-50%, 0); }
  80% { opacity: 1; }
  100% { opacity: 0; }
}

.screen {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--space-6);
  background: radial-gradient(ellipse at 50% 30%, rgba(11, 14, 20, 0.55), rgba(5, 7, 10, 0.92));
  overflow-y: auto;
}

.screen.active {
  display: flex;
}

.panel {
  width: min(560px, 100%);
  background: var(--surface);
  border: var(--border);
  border-radius: var(--radius-card);
  padding: var(--space-8);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
  animation: rise 320ms var(--ease);
}

.panel.narrow {
  width: min(440px, 100%);
}

@keyframes rise {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}

.panel h1 {
  font-size: var(--text-display);
  font-weight: var(--weight-display);
  line-height: 1.1;
  margin: 0 0 var(--space-4);
  letter-spacing: -0.01em;
}

.panel h2 {
  font-size: var(--text-heading);
  font-weight: var(--weight-heading);
  margin: 0 0 var(--space-5);
}

.lead {
  font-size: var(--text-body);
  line-height: 1.55;
  color: var(--muted);
  margin: 0 0 var(--space-6);
}

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.row {
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-top: var(--space-5);
}

.row.end {
  justify-content: flex-end;
}

button {
  font: inherit;
  font-size: var(--text-body);
  font-weight: 600;
  min-height: var(--hit);
  padding: 0 var(--space-6);
  border-radius: var(--radius-control);
  cursor: pointer;
  transition: background var(--motion-base) var(--ease), color var(--motion-base) var(--ease), transform 150ms var(--ease), border-color var(--motion-base) var(--ease);
  pointer-events: auto;
}

button:active {
  transform: translateY(1px) scale(0.99);
}

button:focus-visible {
  outline: 3px solid var(--highlight);
  outline-offset: 3px;
}

button.primary {
  background: var(--accent);
  color: var(--on-accent);
  border: 1px solid var(--accent);
}

button.primary:hover {
  background: #f0b35c;
}

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

button.ghost:hover {
  background: var(--raised);
  border-color: var(--muted);
}

button.small {
  min-height: 40px;
  padding: 0 var(--space-4);
  font-size: var(--text-small);
  margin-top: var(--space-2);
  pointer-events: auto;
}

.hud-right button {
  pointer-events: auto;
}

.difficulty {
  border: 0;
  margin: var(--space-3) 0 0;
  padding: 0;
}

.difficulty legend {
  font-size: var(--text-small);
  color: var(--muted);
  margin-bottom: var(--space-2);
  padding: 0;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-control);
  overflow: hidden;
}

.segmented button {
  background: transparent;
  color: var(--muted);
  border: 0;
  border-radius: 0;
  min-height: var(--hit);
}

.segmented button + button {
  border-left: 1px solid var(--line-strong);
}

.segmented button[aria-pressed="true"] {
  background: var(--raised);
  color: var(--accent-text);
}

.segmented button:hover {
  color: var(--ink);
}

.note {
  margin: var(--space-2) 0 0;
  font-size: var(--text-small);
  color: var(--muted);
}

.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-bottom: var(--space-5);
}

.field label {
  display: flex;
  justify-content: space-between;
  font-size: var(--text-body);
  font-weight: 600;
}

.field output {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  width: 100%;
  min-height: var(--hit);
  accent-color: var(--accent);
  cursor: pointer;
}

.credits {
  margin: 0;
  display: grid;
  gap: var(--space-2) var(--space-5);
}

.credits dt {
  font-weight: 600;
  color: var(--accent-text);
  margin-top: var(--space-3);
}

.credits dd {
  margin: 0;
  color: var(--muted);
  font-size: var(--text-small);
  line-height: 1.5;
}

.grade-row {
  display: flex;
  gap: var(--space-7);
  align-items: center;
  flex-wrap: wrap;
}

.grade {
  font-size: 120px;
  font-weight: 700;
  line-height: 1;
  margin: 0;
  color: var(--accent-text);
}

.stats {
  margin: 0;
  display: grid;
  gap: var(--space-3);
  flex: 1 1 200px;
}

.stats > div {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  padding-bottom: var(--space-2);
}

.stats dt {
  color: var(--muted);
  font-size: var(--text-small);
}

.stats dd {
  margin: 0;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

#gameover-text {
  color: var(--ink);
}

@media (max-width: 720px) {
  .hud {
    padding: var(--space-3) var(--space-4);
  }
  .hud-top {
    flex-direction: column;
  }
  .hud-right {
    align-items: flex-start;
    text-align: left;
  }
  #portrait {
    width: 96px;
    height: 96px;
  }
  .target {
    font-size: 28px;
  }
  .hud-score {
    font-size: var(--text-heading);
  }
  .panel {
    padding: var(--space-6);
  }
  .grade {
    font-size: 88px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .panel,
  .banner.show,
  #flash.on {
    animation: none;
  }
}
