:root {
  color-scheme: light;
  --paper: #ece9e1;
  --ink: #171713;
  --line: rgba(23, 23, 19, 0.22);
  --muted: rgba(23, 23, 19, 0.58);
}

* { box-sizing: border-box; }

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

body {
  background: var(--paper);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; }

.stage {
  width: min(1440px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 22px clamp(18px, 3vw, 48px) 24px;
  display: grid;
  grid-template-rows: auto minmax(360px, 1fr) auto;
  gap: 16px;
}

.masthead, .title-group, .status, .control-label, .reset-button, .pause-button, .stats-heading {
  display: flex;
  align-items: center;
}

.masthead { justify-content: space-between; }
.title-group { gap: 26px; }

.status, .control-label, .pause-button, .reset-button {
  font-size: 12px;
}

h1 { margin: 0; font-size: 20px; line-height: 1; letter-spacing: -0.025em; font-weight: 600; }

.stats-toggle {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 10px;
  border: 1px solid var(--ink);
  color: var(--ink);
  background: transparent;
  font-size: 14px;
  cursor: pointer;
}
.stats-toggle span { font-size: 17px; line-height: 0; }
.stats-toggle:hover, .stats-toggle:focus-visible, .stats-toggle[aria-expanded="true"] { color: var(--paper); background: var(--ink); }

.status { align-self: flex-end; gap: 28px; color: var(--muted); }
.status span:first-child { display: flex; align-items: center; gap: 7px; }
.status b { color: inherit; font-weight: 400; }
.status-dot { width: 6px; height: 6px; border-radius: 50%; background: #2b9a63; }
.status-dot.paused { background: var(--muted); }

.frame {
  position: relative;
  min-height: 360px;
  overflow: hidden;
  border: 1px solid var(--ink);
  background: #d8d4ca;
}

#world { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }

.stats-panel {
  position: absolute;
  z-index: 2;
  inset: 10px;
  display: grid;
  grid-template-rows: auto minmax(170px, 1fr) auto;
  gap: 10px;
  padding: 12px;
  overflow: auto;
  border: 1px solid var(--ink);
  background: rgba(236, 233, 225, 0.86);
}
.stats-panel[hidden] { display: none; }
.stats-heading { justify-content: space-between; min-height: 26px; color: var(--muted); font-size: 13px; }
.stats-close { width: 28px; height: 28px; padding: 0; border: 1px solid var(--ink); color: var(--ink); background: rgba(236, 233, 225, 0.72); font-size: 21px; line-height: 24px; cursor: pointer; }
.stats-close:hover, .stats-close:focus-visible { color: var(--paper); background: var(--ink); }
.stats-chart-wrap { position: relative; min-height: 170px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
#stats-chart { display: block; width: 100%; height: 100%; }
.stats-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 26px; }
.stats-row { display: grid; grid-template-columns: 10px minmax(74px, 1fr) auto auto; gap: 9px; align-items: center; min-height: 27px; padding: 0 2px; border-bottom: 1px solid var(--line); font-size: 12px; }
.stats-row.is-active { background: rgba(23, 23, 19, 0.07); }
.stats-swatch { width: 7px; height: 7px; border-radius: 50%; }
.stats-name { overflow: hidden; color: var(--muted); text-overflow: ellipsis; white-space: nowrap; }
.stats-count { font-variant-numeric: tabular-nums; }
.stats-percent { min-width: 48px; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }

.pause-button {
  position: absolute;
  right: 12px;
  bottom: 12px;
  gap: 8px;
  height: 34px;
  padding: 0 12px;
  color: var(--ink);
  background: rgba(236, 233, 225, 0.9);
  border: 1px solid var(--ink);
  cursor: pointer;
}

.pause-button:hover, .pause-button:focus-visible { background: var(--ink); color: var(--paper); }
.pause-icon { width: 8px; height: 9px; border-left: 2px solid currentColor; border-right: 2px solid currentColor; }
.paused .pause-icon { border: 0; width: 0; height: 0; border-top: 5px solid transparent; border-bottom: 5px solid transparent; border-left: 8px solid currentColor; }

.controls {
  display: grid;
  grid-template-columns: repeat(5, minmax(105px, 1fr)) minmax(142px, 0.8fr);
  border: 1px solid var(--ink);
}

.control { padding: 13px 16px 14px; border-right: 1px solid var(--line); }
.control-label { justify-content: space-between; margin-bottom: 10px; color: var(--muted); font-size: 14px; }
.control-label output { color: var(--ink); }

input[type="range"] {
  display: block;
  width: 100%;
  height: 12px;
  margin: 0;
  appearance: none;
  background: transparent;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track { height: 1px; background: var(--ink); }
input[type="range"]::-moz-range-track { height: 1px; background: var(--ink); }
input[type="range"]::-webkit-slider-thumb { appearance: none; width: 9px; height: 9px; margin-top: -4px; border: 1px solid var(--ink); border-radius: 50%; background: var(--paper); }
input[type="range"]::-moz-range-thumb { width: 8px; height: 8px; border: 1px solid var(--ink); border-radius: 50%; background: var(--paper); }

.reset-button {
  justify-content: space-between;
  padding: 0 18px;
  border: 0;
  color: var(--paper);
  background: var(--ink);
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
}
.reset-button:hover, .reset-button:focus-visible { background: #35352f; }
.reset-button span:last-child { font-size: 16px; }

@media (max-width: 850px) {
  .stage { grid-template-rows: auto minmax(390px, 1fr) auto; }
  .controls { grid-template-columns: repeat(2, 1fr); }
  .control:nth-child(2n) { border-right: 0; }
  .control:nth-child(n+3) { border-top: 1px solid var(--line); }
  .reset-button { min-height: 52px; border-top: 1px solid var(--ink); grid-column: 2; }
}

@media (max-width: 520px) {
  .stage { padding: 8px; gap: 8px; }
  .status { gap: 10px; }
  .status span:first-child { display: none; }
  .frame { min-height: 430px; }
  .controls { grid-template-columns: 1fr 1fr; }
  .control { padding-top: 11px; padding-bottom: 11px; }
  .control:nth-child(5) { grid-column: 1; }
  .title-group { gap: 18px; }
  .stats-panel { inset: 7px; padding: 10px; }
  .stats-chart-wrap { min-height: 150px; }
  .stats-list { grid-template-columns: 1fr; }
}
