:root {
  color-scheme: light;
  --paper: #e7e7e2;
  --paper-bright: #f2f2ed;
  --ink: #181a18;
  --muted: #6f746e;
  --rule: rgba(24, 26, 24, 0.24);
  --rule-soft: rgba(24, 26, 24, 0.11);
  --accent: #a93630;
  --cool: #526b66;
  --stage-color: #a93630;
  --portrait-size: min(46vh, 35vw, 430px);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  min-height: 100%;
  background: var(--paper);
}

body {
  min-width: 320px;
  min-height: 100svh;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  background-color: var(--paper);
  font-family: "Segoe UI", "Microsoft YaHei", sans-serif;
}

button,
input {
  font: inherit;
}

button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
}

.app-shell {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(100%, 1480px);
  min-height: 100svh;
  margin: 0 auto;
  padding: 22px 44px 26px;
  isolation: isolate;
}

.app-shell::before,
.app-shell::after {
  position: fixed;
  z-index: -1;
  top: 0;
  bottom: 0;
  width: 1px;
  content: "";
  background: var(--rule-soft);
}

.app-shell::before {
  left: 3.2vw;
}

.app-shell::after {
  right: 3.2vw;
}

.masthead {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 32px;
  border-top: 1px solid var(--ink);
  padding-top: 10px;
}

.title-block {
  min-width: 0;
}

.eyebrow {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 3px;
  color: var(--muted);
  font-family: Consolas, "Courier New", monospace;
  font-size: 10px;
  line-height: 1.4;
  letter-spacing: 0;
}

.eyebrow span {
  color: var(--accent);
}

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

h1 {
  margin-bottom: 0;
  font-family: "Songti SC", SimSun, serif;
  font-size: 42px;
  font-weight: 400;
  line-height: 1.08;
  letter-spacing: 0;
}

.readout {
  display: grid;
  grid-template-columns: auto auto;
  align-items: baseline;
  min-width: 140px;
  font-family: Consolas, "Courier New", monospace;
  text-align: right;
}

.readout-label {
  grid-column: 1 / -1;
  border-bottom: 1px solid var(--ink);
  padding-bottom: 4px;
  color: var(--muted);
  font-size: 10px;
}

.readout strong {
  min-width: 3.2ch;
  margin-top: 5px;
  color: var(--stage-color);
  font-size: 28px;
  font-weight: 500;
  line-height: 1;
}

.readout > span:last-child {
  align-self: center;
  margin-left: 8px;
  color: var(--muted);
  font-size: 9px;
  writing-mode: vertical-rl;
}

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

.portrait-section {
  position: relative;
  display: grid;
  min-height: 0;
  place-items: center;
  padding: 12px 0 6px;
}

.stage-glyph {
  position: absolute;
  z-index: -1;
  top: 50%;
  left: 50%;
  color: rgba(24, 26, 24, 0.042);
  font-family: "Songti SC", SimSun, serif;
  font-size: 340px;
  line-height: 1;
  transform: translate(-50%, -53%);
  user-select: none;
}

.portrait-cluster {
  width: var(--portrait-size);
}

.portrait-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
}

.image-stack {
  position: absolute;
  inset: 10px;
  overflow: hidden;
  background: #c9cbc7;
  box-shadow: 0 18px 42px rgba(24, 26, 24, 0.13);
}

.stage-image {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  opacity: 0;
  object-fit: cover;
  transition: opacity 90ms linear, filter 180ms ease;
  will-change: opacity;
}

.stage-image[fetchpriority="high"] {
  opacity: 1;
}

.scan-grid {
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}

.scan-grid::before,
.scan-grid::after {
  position: absolute;
  content: "";
  background: rgba(255, 255, 255, 0.22);
}

.scan-grid::before {
  top: 50%;
  left: 0;
  width: 100%;
  height: 1px;
}

.scan-grid::after {
  top: 0;
  left: 50%;
  width: 1px;
  height: 100%;
}

.frame-corner {
  position: absolute;
  z-index: 2;
  width: 25px;
  height: 25px;
  border-color: var(--stage-color);
  border-style: solid;
  transition: border-color 180ms ease;
}

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

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

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

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

.state-caption {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  min-height: 53px;
  padding: 7px 10px 0;
}

.state-caption span,
.state-caption p {
  color: var(--muted);
  font-family: Consolas, "Courier New", monospace;
  font-size: 9px;
}

.state-caption span {
  display: block;
}

.state-caption h2 {
  margin: 0;
  color: var(--stage-color);
  font-family: "Songti SC", SimSun, serif;
  font-size: 30px;
  font-weight: 400;
  line-height: 1;
  letter-spacing: 0;
  transition: color 180ms ease;
}

.state-caption p {
  margin-bottom: 3px;
}

.side-ruler {
  position: absolute;
  top: 50%;
  right: 1.5%;
  display: grid;
  grid-template-rows: auto repeat(5, 1fr) auto;
  align-items: center;
  width: 46px;
  height: min(42vh, 340px);
  color: var(--muted);
  font: 9px/1 Consolas, "Courier New", monospace;
  transform: translateY(-50%);
}

.side-ruler::before {
  position: absolute;
  top: 8px;
  bottom: 8px;
  left: 25px;
  width: 1px;
  content: "";
  background: var(--rule);
}

.side-ruler i {
  position: relative;
  display: block;
  width: 9px;
  height: 1px;
  margin-left: 21px;
  background: var(--rule);
}

.control-panel {
  width: min(100%, 980px);
  margin: 0 auto;
  padding: 4px 0 0;
}

.scale-meta {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  margin-bottom: 2px;
  color: var(--muted);
  font: 10px/1.2 Consolas, "Courier New", monospace;
}

.scale-meta span:last-child {
  text-align: right;
}

.scale-code {
  color: var(--cool);
}

.range-wrap {
  position: relative;
  height: 42px;
}

.tick-field {
  position: absolute;
  top: 20px;
  right: 10px;
  left: 10px;
  height: 12px;
  border-top: 1px solid var(--rule);
  pointer-events: none;
}

.tick-field::after {
  position: absolute;
  inset: -5px 0 0;
  content: "";
  background: repeating-linear-gradient(90deg, transparent 0, transparent calc(3.333% - 1px), var(--rule-soft) calc(3.333% - 1px), var(--rule-soft) 3.333%);
}

#intensity {
  position: relative;
  z-index: 2;
  width: 100%;
  height: 42px;
  margin: 0;
  padding: 0;
  cursor: ew-resize;
  background: transparent;
  appearance: none;
  -webkit-appearance: none;
}

#intensity::-webkit-slider-runnable-track {
  height: 2px;
  background: transparent;
}

#intensity::-webkit-slider-thumb {
  width: 22px;
  height: 22px;
  margin-top: -10px;
  border: 7px solid var(--paper-bright);
  border-radius: 50%;
  background: var(--stage-color);
  box-shadow: 0 0 0 1px rgba(24, 26, 24, 0.34), 0 3px 10px rgba(24, 26, 24, 0.2);
  appearance: none;
  -webkit-appearance: none;
}

#intensity::-moz-range-track {
  height: 2px;
  background: transparent;
}

#intensity::-moz-range-thumb {
  width: 9px;
  height: 9px;
  border: 7px solid var(--paper-bright);
  border-radius: 50%;
  background: var(--stage-color);
  box-shadow: 0 0 0 1px rgba(24, 26, 24, 0.34), 0 3px 10px rgba(24, 26, 24, 0.2);
}

.stage-labels {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  margin: -2px 0 0;
  padding: 0;
  list-style: none;
}

.stage-labels li {
  min-width: 0;
  text-align: center;
}

.stage-button {
  position: relative;
  width: 100%;
  min-height: 34px;
  border: 0;
  padding: 8px 2px 4px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-size: 13px;
  letter-spacing: 0;
  transition: color 150ms ease;
}

.stage-button::before {
  position: absolute;
  top: 0;
  left: 50%;
  width: 1px;
  height: 5px;
  content: "";
  background: var(--rule);
  transform: translateX(-50%);
}

.stage-button:hover,
.stage-button.is-active {
  color: var(--ink);
}

.stage-button.is-active::before {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--stage-color);
}

@media (max-width: 760px) {
  :root {
    --portrait-size: min(72vw, 45vh, 380px);
  }

  .app-shell {
    padding: 16px 18px 18px;
  }

  .app-shell::before,
  .app-shell::after {
    display: none;
  }

  .masthead {
    gap: 16px;
  }

  h1 {
    font-size: 30px;
  }

  .eyebrow {
    max-width: 205px;
    flex-wrap: wrap;
    gap: 2px 8px;
    font-size: 9px;
  }

  .readout {
    min-width: 92px;
  }

  .readout strong {
    font-size: 23px;
  }

  .portrait-section {
    padding-top: 8px;
  }

  .stage-glyph {
    display: none;
  }

  .state-caption h2 {
    font-size: 25px;
  }

  .side-ruler {
    display: none;
  }

  .scale-code {
    font-size: 8px;
  }

  .stage-button {
    min-height: 40px;
    font-size: 12px;
  }
}

@media (max-width: 360px) {
  .masthead {
    gap: 8px;
  }

  h1 {
    font-size: 26px;
  }

  .readout {
    min-width: 72px;
  }

  .readout strong {
    font-size: 21px;
  }
}

@media (max-height: 680px) and (min-width: 761px) {
  :root {
    --portrait-size: min(40vh, 330px);
  }

  .app-shell {
    padding-top: 14px;
    padding-bottom: 14px;
  }

  h1 {
    font-size: 34px;
  }

  .state-caption {
    min-height: 45px;
  }

  .state-caption h2 {
    font-size: 25px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
/* Continuous portrait blending follows the input without a trailing CSS animation. */
.stage-image { transition: none; }
/* Mid-transition the incoming frame grows out of a soft circle over the face, so
   no pixel ever draws both faces on top of each other the way a cross-fade does.
   #fff rather than #000 keeps this correct under either mask-mode. */
.stage-image.is-reveal {
  -webkit-mask-image: radial-gradient(circle at 50% 42%, #fff var(--reveal-solid), transparent var(--reveal-fade));
  mask-image: radial-gradient(circle at 50% 42%, #fff var(--reveal-solid), transparent var(--reveal-fade));
}
.image-stack { isolation: isolate; contain: paint; }
#intensity { --progress: 40%; touch-action: pan-y; }
#intensity::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 4px;
  background: linear-gradient(to right, var(--stage-color) var(--progress), #c2c5bd var(--progress));
}
#intensity::-webkit-slider-thumb { width: 28px; height: 28px; margin-top: -12px; }
#intensity::-moz-range-track { height: 4px; border-radius: 4px; background: #c2c5bd; }
#intensity::-moz-range-progress { height: 4px; background: var(--stage-color); }
#intensity::-moz-range-thumb { width: 14px; height: 14px; }
.stage-description { margin: 12px 10px 0; color: var(--muted); font-size: 13px; letter-spacing: 2px; }
.asset-message { min-height: 24px; margin: 10px 10px 0; font-size: 12px; color: var(--muted); }
.asset-message p { display: inline; }
.asset-message [hidden] { display: none; }
#retry-assets { border: 0; background: transparent; color: var(--accent); text-decoration: underline; cursor: pointer; }
.control-hint { margin: 18px 0 0; color: var(--muted); text-align: center; font-size: 12px; }
.control-panel { padding-bottom: 10px; }
.scale-meta { font-size: 12px; }
.stage-labels { display: flex; justify-content: space-between; margin: 0 14px; }
.stage-labels li { position: relative; width: 0; }
.stage-button { width: 64px; margin-left: -32px; min-height: 44px; }
@media (max-width: 760px) {
  .stage-button { width: 48px; margin-left: -24px; }
  .scale-code { font-size: 10px; }
  .control-hint { font-size: 11px; }
  .stage-description { font-size: 12px; letter-spacing: 1px; }
}
.today-readout { text-align: right; display:flex; flex-direction:column; gap:8px; max-width:45%; padding-top:5px; }
#today-state { font-family:"Songti SC",SimSun,serif; font-size:24px; color:var(--accent); line-height:1.45; }
.today-caption { color:var(--muted); font-size:11px; }
.calibrator { grid-template-rows:minmax(0,1fr) auto auto; }
.vote-feedback { text-align:center; margin-top:8px; }
#vote-status { margin:0; font-size:13px; color:var(--ink); }
.vote-rule { font-size:11px; color:var(--muted); margin:8px 0 0; }
#retry-vote { color:var(--accent); background:none; border:0; text-decoration:underline; cursor:pointer; padding:8px; }
@media (max-width:760px) {
 .masthead { gap:12px; }
 h1 {font-size:25px;}
 #today-state {font-size:18px;}
 .today-readout {max-width:44%;}
 .today-caption {font-size:10px;}
 .vote-rule {font-size:10px;}
}
@media (max-width:400px) { h1 { font-size:21px; } #today-state {font-size:16px;} }
