:root {
  color-scheme: light;
  --paper: #e8e9e5;
  --paper-warm: #e5dcc7;
  --ink: #171816;
  --muted: #74776e;
  --line: rgb(23 24 22 / 22%);
  --line-faint: rgb(23 24 22 / 9%);
  --signal: #c75247;
  --gold: #be893a;
  --accent: #8f9189;
  --page-bg: rgb(232 233 229);
  --stage-glow: rgb(190 137 58 / 0%);
  --display: Georgia, "Times New Roman", "Songti SC", serif;
  --body: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--page-bg);
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 50% 35%, var(--stage-glow), transparent 38%),
    var(--page-bg);
  font-family: var(--body);
  transition: background-color 220ms linear;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

.page-grain {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  opacity: 0.22;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.14'/%3E%3C/svg%3E");
  mix-blend-mode: multiply;
}

.instrument {
  width: min(100% - 56px, 980px);
  margin: 0 auto;
  padding: 24px 0 28px;
}

.instrument__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 28px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font: 600 10px/1.2 var(--mono);
  letter-spacing: 0.22em;
}

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

h1 {
  margin-bottom: 0;
  font: 700 clamp(35px, 6vw, 58px)/0.96 var(--display);
  letter-spacing: -0.06em;
}

.counter {
  min-width: 118px;
  padding-top: 5px;
  text-align: right;
  border-top: 1px solid var(--ink);
}

.counter span {
  display: block;
  color: var(--muted);
  font: 500 9px/1.5 var(--mono);
  letter-spacing: 0.12em;
}

.counter strong {
  display: block;
  margin-top: 4px;
  font: 400 24px/1 var(--mono);
  letter-spacing: -0.08em;
}

.counter b {
  font-weight: 700;
}

.calibrator {
  position: relative;
  width: min(100%, 790px);
  margin: 6px auto 0;
}

.portrait-rig {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 430px;
}

.ghost-word {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 100vw;
  transform: translate(-50%, -50%);
  color: rgb(23 24 22 / 4%);
  font: 700 clamp(120px, 31vw, 310px)/0.8 var(--display);
  letter-spacing: -0.09em;
  text-align: center;
  white-space: nowrap;
  user-select: none;
  transition: color 180ms linear;
}

.portrait-frame {
  position: relative;
  z-index: 1;
  width: min(390px, 72vw);
  aspect-ratio: 1;
  filter: drop-shadow(0 22px 26px rgb(25 24 20 / 12%));
  transition: filter 220ms ease;
}

.portrait-frame.is-mythic {
  filter:
    drop-shadow(0 22px 34px rgb(74 53 32 / 28%))
    drop-shadow(0 0 24px rgb(190 137 58 / 25%));
}

.portrait-stack {
  position: absolute;
  inset: 9px;
  overflow: hidden;
  background: #252724;
}

.portrait-stack img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  user-select: none;
  -webkit-user-drag: none;
}

.portrait-scan {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background:
    linear-gradient(180deg, transparent 0 49.7%, rgb(255 255 255 / 13%) 50%, transparent 50.3%),
    repeating-linear-gradient(0deg, transparent 0 3px, rgb(0 0 0 / 4%) 4px);
  opacity: 0.18;
  mix-blend-mode: soft-light;
}

.loading-state {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  color: #f2f0e9;
  background: #252724;
  font: 600 11px/1 var(--mono);
  letter-spacing: 0.1em;
  transition: opacity 180ms ease;
}

body:not(.is-loading) .loading-state {
  pointer-events: none;
  opacity: 0;
}

.corner {
  position: absolute;
  width: 20px;
  height: 20px;
  border-color: var(--ink);
  opacity: 0.7;
}

.corner--tl {
  top: 0;
  left: 0;
  border-top: 2px solid;
  border-left: 2px solid;
}

.corner--tr {
  top: 0;
  right: 0;
  border-top: 2px solid;
  border-right: 2px solid;
}

.corner--bl {
  bottom: 0;
  left: 0;
  border-bottom: 2px solid;
  border-left: 2px solid;
}

.corner--br {
  right: 0;
  bottom: 0;
  border-right: 2px solid;
  border-bottom: 2px solid;
}

.state-readout {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: end;
  gap: 22px;
  padding: 2px 8px 10px;
}

.state-readout span {
  color: var(--muted);
  font: 500 9px/1 var(--mono);
  letter-spacing: 0.1em;
}

.state-readout span:last-child {
  text-align: right;
}

.state-readout b {
  color: var(--ink);
}

.state-readout h2 {
  margin: 0;
  font: 700 clamp(30px, 5vw, 46px)/0.9 var(--display);
  letter-spacing: -0.055em;
}

.range-panel {
  position: relative;
  padding-bottom: 2px;
}

.range-track {
  position: relative;
  height: 34px;
}

.range-track::before,
.range-progress {
  position: absolute;
  top: 16px;
  right: 0;
  left: 0;
  height: 1px;
  content: "";
}

.range-track::before {
  background: var(--line);
}

.range-progress {
  right: auto;
  width: 48.28%;
  background: linear-gradient(90deg, var(--signal), var(--gold));
}

.ticks {
  position: absolute;
  inset: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(30, 1fr);
  align-items: center;
  height: 34px;
  pointer-events: none;
}

.tick {
  justify-self: start;
  width: 1px;
  height: 8px;
  background: var(--line);
  transition: height 120ms ease, background-color 120ms ease;
}

.tick:nth-child(5n + 1),
.tick:last-child {
  height: 18px;
}

.tick.is-active {
  background: var(--accent);
}

#intensity {
  position: absolute;
  inset: 0;
  z-index: 3;
  width: 100%;
  height: 34px;
  margin: 0;
  cursor: ew-resize;
  opacity: 0;
}

.range-track::after {
  position: absolute;
  top: 7px;
  left: var(--thumb-position, 48.28%);
  z-index: 2;
  width: 18px;
  height: 18px;
  border: 2px solid var(--page-bg);
  border-radius: 50%;
  background: var(--accent);
  box-shadow:
    0 0 0 1px var(--ink),
    0 0 0 6px rgb(232 233 229 / 68%);
  content: "";
  pointer-events: none;
  transform: translateX(-50%);
}

.range-track:focus-within::after {
  box-shadow:
    0 0 0 2px var(--page-bg),
    0 0 0 4px var(--ink),
    0 0 0 8px rgb(255 255 255 / 48%);
}

.stage-labels {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-top: 1px;
}

.stage-label {
  min-width: 0;
  padding: 7px 2px;
  overflow: hidden;
  border: 0;
  color: var(--muted);
  background: transparent;
  font: 600 10px/1 var(--mono);
  text-overflow: ellipsis;
  cursor: pointer;
  transition: color 140ms ease, transform 140ms ease;
}

.stage-label:hover {
  color: var(--ink);
  transform: translateY(-1px);
}

.stage-label.is-current {
  color: var(--accent);
}

.stage-label:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
}

.range-hint {
  margin: 1px 0 0;
  color: var(--muted);
  font: 500 9px/1.4 var(--mono);
  text-align: center;
  letter-spacing: 0.04em;
}

.report {
  margin-top: 22px;
  padding: 18px;
  border: 1px solid var(--line);
  background: rgb(255 255 255 / 12%);
  box-shadow: inset 0 1px rgb(255 255 255 / 20%);
}

.report__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.report__header h2 {
  margin: 0;
  font: 700 22px/1 var(--display);
  letter-spacing: -0.035em;
}

.report__code {
  padding-top: 2px;
  color: var(--accent);
  font: 700 15px/1 var(--mono);
  letter-spacing: 0.05em;
}

.report__body {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(280px, 0.9fr);
  gap: 34px;
  padding-top: 18px;
}

.report__identity > span {
  color: var(--muted);
  font: 500 9px/1 var(--mono);
  letter-spacing: 0.1em;
}

.report__identity h3 {
  margin: 6px 0 8px;
  font: 700 clamp(28px, 4vw, 42px)/0.95 var(--display);
  letter-spacing: -0.055em;
}

.report__identity p {
  max-width: 24em;
  margin: 0;
  font: 500 14px/1.65 var(--body);
}

.metrics {
  display: grid;
  align-content: center;
  gap: 13px;
}

.metric__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 5px;
  color: var(--muted);
  font: 500 9px/1 var(--mono);
  letter-spacing: 0.08em;
}

.metric__head strong {
  color: var(--ink);
  font-size: 12px;
}

.metric__track {
  height: 3px;
  overflow: hidden;
  background: var(--line-faint);
}

.metric__track i {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--signal), var(--accent));
  transition: width 120ms linear;
}

.instrument__footer {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  margin-top: 14px;
  padding-top: 9px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font: 500 8px/1.2 var(--mono);
  letter-spacing: 0.08em;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 700px) {
  .instrument {
    width: min(100% - 28px, 540px);
    padding-top: 16px;
  }

  .instrument__header {
    gap: 14px;
  }

  .counter {
    min-width: 92px;
  }

  .portrait-rig {
    min-height: auto;
    padding: 28px 0 20px;
  }

  .portrait-frame {
    width: min(350px, 87vw);
  }

  .state-readout {
    gap: 8px;
    padding-inline: 0;
  }

  .state-readout h2 {
    font-size: 32px;
  }

  .state-readout span {
    font-size: 8px;
  }

  .stage-label {
    padding-inline: 0;
    font-size: 8px;
    letter-spacing: -0.06em;
  }

  .report {
    margin-top: 16px;
    padding: 14px;
  }

  .report__body {
    grid-template-columns: 1fr;
    gap: 20px;
  }
}

@media (max-width: 430px) {
  .eyebrow {
    font-size: 8px;
    letter-spacing: 0.13em;
  }

  h1 {
    font-size: 34px;
  }

  .counter strong {
    font-size: 20px;
  }

  .report__identity p {
    font-size: 13px;
  }

  .instrument__footer {
    display: grid;
    gap: 5px;
  }
}

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