:root {
  color-scheme: dark;
  --bg: #1e1b1b;
  --text: #f6f2eb;
  --muted: #a5a09a;
  --line: rgba(255, 255, 255, 0.16);
  --yellow: #ffdf22;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: 100vw;
  height: 100vh;
  min-height: 720px;
  padding: clamp(18px, 3vh, 34px) clamp(18px, 4vw, 54px) 22px;
}

.topline {
  display: grid;
  justify-items: center;
  gap: 6px;
  min-height: 78px;
}

.kicker,
.source {
  margin: 0;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(1.5rem, 4vw, 2.6rem);
  line-height: 1;
  letter-spacing: 0;
}

.stage {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  justify-items: center;
  min-height: 0;
}

.period {
  display: grid;
  justify-items: center;
  gap: 4px;
  min-height: 60px;
  text-align: center;
}

.period span {
  display: block;
  font-size: clamp(2rem, 4.8vw, 4.7rem);
  font-weight: 900;
  line-height: 0.95;
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.18), 0 4px 10px rgba(0, 0, 0, 0.6);
}

.period small {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.viz-frame {
  position: relative;
  width: min(78vh, 78vw, 760px);
  aspect-ratio: 1;
  min-width: 320px;
  margin: clamp(8px, 1.8vh, 18px) auto;
  overflow: hidden;
  background:
    linear-gradient(rgba(255, 255, 255, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.045) 1px, transparent 1px),
    #161616;
  background-size: 8px 8px;
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.42);
}

#treemap {
  display: block;
  width: 100%;
  height: 100%;
}

.cell path {
  stroke: rgba(0, 0, 0, 0.42);
  stroke-width: 1.2;
  vector-effect: non-scaling-stroke;
}

.cell-label {
  pointer-events: none;
  fill: #ffffff;
  font-weight: 900;
  letter-spacing: 0;
  text-anchor: middle;
  paint-order: stroke;
  stroke: rgba(0, 0, 0, 0.66);
  stroke-width: 6px;
  stroke-linejoin: round;
}

.cell-meta {
  pointer-events: none;
  fill: var(--yellow);
  font-size: clamp(0.78rem, 1.8vw, 1.15rem);
  font-weight: 900;
  text-anchor: middle;
  paint-order: stroke;
  stroke: rgba(0, 0, 0, 0.66);
  stroke-width: 5px;
  stroke-linejoin: round;
}

.source {
  max-width: min(760px, 90vw);
  text-align: center;
  text-transform: none;
}

.control-deck {
  display: grid;
  align-items: center;
  width: min(760px, 100%);
  margin: 14px auto 0;
}

.timeline {
  display: grid;
  grid-template-columns: 44px 44px minmax(0, 1fr) 44px;
  align-items: center;
  gap: 12px;
}

.icon-button {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  cursor: pointer;
}

.icon-button span {
  transform: translateY(-1px);
  font-size: 1.55rem;
  line-height: 1;
}

.icon-button[data-state="playing"] {
  border-color: rgba(255, 223, 34, 0.72);
  background: rgba(255, 223, 34, 0.18);
  color: var(--yellow);
}

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

@media (max-width: 900px) {
  body {
    overflow: auto;
  }

  .app-shell {
    height: auto;
    min-height: 100vh;
  }

  .control-deck {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .app-shell {
    padding: 18px 14px 20px;
  }

  .topline {
    min-height: 64px;
  }

  .period {
    min-height: 54px;
  }

  .viz-frame {
    width: min(92vw, 540px);
    min-width: 0;
  }
}
