:root {
  --bg: #f3efe8;
  --surface: rgba(251, 248, 242, 0.92);
  --surface-solid: #fbf8f2;
  --text: #292725;
  --muted: #716c66;
  --line: rgba(41, 39, 37, 0.16);
  --faint: rgba(41, 39, 37, 0.055);
  --accent: #625e59;
  --accent-soft: rgba(98, 94, 89, 0.14);
  --danger: #9f1f2e;
  --danger-soft: rgba(159, 31, 46, 0.14);
  --shadow: 0 20px 54px rgba(46, 48, 42, 0.09);
  --radius: 5px;
  --font-main: "Noto Sans SC", "Source Han Sans SC", "Microsoft YaHei UI", "PingFang SC", system-ui, sans-serif;
  --font-mono: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: linear-gradient(90deg, #e3e0db 0 18%, var(--bg) 18% 100%);
  color: var(--text);
  font-family: var(--font-main);
  letter-spacing: 0;
  transition: background-color 500ms ease, color 500ms ease;
}

body.color-drift {
  background: linear-gradient(
    90deg,
    color-mix(in srgb, var(--player-color, var(--accent)) 18%, #e7e3de) 0 18%,
    color-mix(in srgb, var(--player-color, var(--bg)) 9%, #f3efe8) 18% 100%
  );
}

body.deleted {
  --bg: #f3f3f3;
  --surface: #f9f9f9;
  --surface-solid: #ffffff;
  --text: #1f1f1f;
  --muted: #7c7c7c;
  --line: rgba(0, 0, 0, 0.16);
  --accent: #777777;
  --shadow: none;
  background: #f3f3f3;
}

button,
input,
select {
  font: inherit;
}

button {
  color: inherit;
}

.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  opacity: 0.08;
  background-image:
    repeating-radial-gradient(circle at 18% 22%, rgba(37, 34, 29, 0.055) 0 1px, transparent 1px 5px);
  mix-blend-mode: multiply;
}

body.breach-flash .grain {
  opacity: 0.38;
  animation: grainFault 120ms steps(2) infinite;
}

.app-shell {
  width: 100%;
  min-height: 100dvh;
  margin: 0 auto;
  padding: 44px 0 140px;
  display: grid;
  align-items: center;
}

.game-grid {
  display: grid;
  width: min(900px, calc(100% - 40px));
  margin: 0 auto;
  grid-template-columns: minmax(0, 1fr);
  justify-content: center;
  align-items: center;
}

.deleted-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.test-card {
  width: 100%;
  min-height: min(680px, calc(100dvh - 88px));
  padding: clamp(34px, 5.5vw, 70px) clamp(28px, 6.5vw, 82px);
  display: grid;
  grid-template-rows: auto 1fr auto;
  position: relative;
  overflow: hidden;
  background: transparent;
}

.stage-haunted .test-card,
.stage-deleting .test-card {
  filter: contrast(1.01);
}

.topline {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  align-items: start;
  margin-bottom: clamp(50px, 8vh, 90px);
}

.brand {
  margin: 0 0 10px;
  font-size: clamp(32px, 4vw, 50px);
  line-height: 1.12;
  font-weight: 600;
  letter-spacing: 0;
}

.subtitle,
.counter,
.memory-line,
.field-help {
  color: var(--muted);
}

.subtitle {
  margin: 0;
  max-width: 48ch;
  line-height: 1.75;
  font-size: 14px;
}

.counter {
  font-family: var(--font-mono);
  font-size: 13px;
  white-space: nowrap;
}

.question-area {
  display: grid;
  align-content: start;
  width: min(100%, 720px);
  margin-inline: auto;
  padding-top: clamp(14px, 3vh, 34px);
}

.phase-intro .question-area {
  padding-top: 0;
}

.question-text {
  max-width: 700px;
  margin: 0 0 clamp(28px, 5vh, 46px);
  font-size: clamp(26px, 3.2vw, 38px);
  line-height: 1.42;
  font-weight: 500;
  letter-spacing: 0;
  animation: softIn 480ms ease both;
}

.question-text.small {
  font-size: clamp(22px, 2.6vw, 31px);
  line-height: 1.5;
  font-weight: 500;
}

.question-note {
  min-height: 34px;
  margin: 0 0 22px;
  max-width: 58ch;
  color: color-mix(in srgb, var(--accent) 82%, var(--text));
  line-height: 1.8;
}

.typed {
  position: relative;
}

.typed::after {
  content: "";
  display: inline-block;
  width: 0.55em;
  height: 1.05em;
  margin-left: 4px;
  transform: translateY(2px);
  border-right: 2px solid currentColor;
  animation: blink 760ms step-end infinite;
}

.typed.done::after {
  display: none;
}

.options {
  display: grid;
  gap: 9px;
  max-width: 680px;
}

.options.reacting .option-btn {
  pointer-events: none;
  opacity: 0.34;
}

.options.reacting .option-btn.selected-answer {
  border-color: color-mix(in srgb, var(--accent) 58%, var(--line));
  background: color-mix(in srgb, var(--accent) 7%, rgba(255, 255, 252, 0.9));
  box-shadow: inset 3px 0 0 color-mix(in srgb, var(--accent) 72%, transparent);
  opacity: 1;
}

.reaction-note {
  margin-top: -12px;
  margin-bottom: 24px;
}

.option-btn,
.ghost-btn,
.field-submit,
.debug-panel button,
.debug-panel select,
.debug-panel input {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 252, 0.58);
  color: var(--text);
  min-height: 52px;
  padding: 14px 17px;
  text-align: left;
  cursor: pointer;
  transition:
    border-color 180ms ease,
    background 180ms ease,
    transform 180ms ease,
    color 180ms ease,
    opacity 180ms ease,
    box-shadow 180ms ease;
}

.option-btn:hover,
.ghost-btn:hover,
.field-submit:hover,
.debug-panel button:hover {
  border-color: color-mix(in srgb, var(--accent) 58%, var(--line));
  background: color-mix(in srgb, var(--accent) 7%, rgba(255, 255, 252, 0.9));
  box-shadow: inset 3px 0 0 color-mix(in srgb, var(--accent) 72%, transparent);
  transform: translateX(3px);
}

.option-btn:active,
.ghost-btn:active,
.field-submit:active,
.debug-panel button:active {
  transform: translate(3px, 1px);
}

.option-btn.special-peace {
  animation: optionAppear 320ms ease both;
}

.option-btn.special-aggressive {
  animation: optionAppear 320ms 70ms ease both;
}

.option-btn.disabled,
.option-btn:disabled {
  color: rgba(112, 105, 95, 0.62);
  background: rgba(242, 238, 229, 0.56);
  cursor: not-allowed;
}

.option-btn.disabled {
  color: rgba(112, 105, 95, 0.62);
  background: rgba(242, 238, 229, 0.56);
  cursor: pointer;
}

.option-btn.danger {
  border-color: rgba(159, 31, 46, 0.58);
  background: rgba(159, 31, 46, 0.08);
  color: #7d1220;
  animation: glitch 820ms infinite steps(2);
}

.option-btn.stuck {
  pointer-events: none;
  transform: translateX(2px);
  opacity: 0.74;
}

.result-advice {
  max-width: 62ch;
  margin: 0 0 24px;
  color: var(--muted);
  line-height: 1.8;
}

.option-btn.delete {
  border-color: #b00020;
  background: #b00020;
  color: #fff7f7;
  text-transform: lowercase;
  font-family: var(--font-mono);
  text-align: center;
  letter-spacing: 0.06em;
}

.assault-screen {
  position: fixed;
  inset: 0;
  z-index: 10;
  overflow: hidden;
  background:
    repeating-linear-gradient(0deg, transparent 0 5px, rgba(37, 34, 29, 0.035) 5px 6px),
    color-mix(in srgb, var(--bg) 91%, #fff);
}

.assault-screen::before,
.assault-screen::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
}

.assault-screen::before {
  z-index: 4;
  background: repeating-linear-gradient(90deg, transparent 0 17%, rgba(159, 31, 46, 0.09) 17% 17.3%);
}

.assault-screen::after {
  z-index: 5;
  background: rgba(255, 255, 255, 0.22);
  mix-blend-mode: difference;
}

.swarm-option {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: clamp(180px, var(--w), 430px);
  min-height: 48px;
  padding: 13px 16px;
  border: 1px solid color-mix(in srgb, var(--danger) 44%, var(--line));
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--danger) 7%, rgba(255, 252, 245, 0.94));
  box-shadow: 0 8px 28px rgba(83, 18, 27, 0.08);
  color: color-mix(in srgb, var(--danger) 78%, var(--text));
  text-align: left;
  cursor: pointer;
  transform: rotate(var(--tilt));
  animation: swarmCycle var(--life) var(--delay) cubic-bezier(0.16, 1, 0.3, 1) both;
}

.swarm-option:hover {
  z-index: 3;
  background: color-mix(in srgb, var(--danger) 15%, rgba(255, 252, 245, 0.94));
}

.swarm-option.delete-decoy {
  border-color: rgba(176, 0, 32, 0.82);
  background: rgba(176, 0, 32, 0.88);
  color: #fff7f7;
  font-family: var(--font-mono);
  text-align: center;
  text-transform: lowercase;
}

.swarm-option.evaded {
  pointer-events: none;
  animation: optionRejected 110ms steps(2) both;
}

.assault-screen.selection-made::before {
  animation: breachBands 90ms steps(2) 8;
}

.assault-screen.selection-made::after {
  animation: breachWash 110ms steps(2) 5;
}

.assault-screen.selection-made .swarm-option:not(.chosen) {
  opacity: 0.58;
  animation: swarmPanic 130ms steps(2) infinite;
}

.swarm-option.chosen {
  z-index: 8;
  pointer-events: auto;
  animation: chosenFlash 105ms steps(2) 5;
}

.swarm-option.delete-ready {
  border-color: #b00020;
  background: #b00020;
  box-shadow: 0 0 0 2px rgba(176, 0, 32, 0.22), 0 12px 42px rgba(176, 0, 32, 0.34);
  color: #fff7f7;
  font-family: var(--font-mono);
  text-align: center;
  text-transform: lowercase;
  animation: deletePulse 560ms steps(2) infinite;
}

.field-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  max-width: 640px;
}

.text-input {
  width: 100%;
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 252, 0.7);
  color: var(--text);
  padding: 13px 16px;
  outline: none;
}

.text-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.swatches {
  display: grid;
  grid-template-columns: repeat(5, 52px);
  gap: 14px;
  max-width: 100%;
}

.swatch {
  width: 52px;
  aspect-ratio: 1;
  border: 4px solid var(--surface-solid);
  border-radius: 50%;
  box-shadow: 0 0 0 1px var(--line);
  cursor: pointer;
  transition: transform 180ms ease, box-shadow 180ms ease;
}

.swatch:hover {
  transform: translateY(-3px);
  box-shadow: 0 0 0 1px var(--text), 0 8px 20px rgba(36, 37, 33, 0.13);
}

.swatch:focus-visible,
.option-btn:focus-visible,
.ghost-btn:focus-visible,
.field-submit:focus-visible,
.debug-panel button:focus-visible,
.debug-panel select:focus-visible,
.debug-panel input:focus-visible {
  outline: 3px solid var(--accent-soft);
  outline-offset: 2px;
}

.memory-line {
  width: min(100%, 680px);
  margin: 42px auto 0;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  min-height: 28px;
  font-size: 13px;
  line-height: 1.8;
}

.side-panel {
  padding: 20px;
  display: grid;
  align-content: space-between;
  gap: 28px;
}

.side-title {
  margin: 0 0 18px;
  font-size: 15px;
  color: var(--muted);
}

.meter-group {
  display: grid;
  gap: 18px;
}

.meter-label {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
}

.meter-track {
  height: 7px;
  border-radius: 999px;
  background: rgba(37, 34, 29, 0.08);
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--accent);
  transition: width 360ms ease;
}

.meter-fill.danger-fill {
  background: var(--danger);
}

.visit-note {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.8;
}

.ghost-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  text-align: center;
}

.deleted-wrap {
  min-height: 100dvh;
  display: grid;
  place-items: center;
}

.deleted-card {
  width: min(720px, 92vw);
  padding: clamp(28px, 6vw, 64px);
  box-shadow: none;
}

.deleted-code {
  margin: 0 0 12px;
  font-family: var(--font-mono);
  font-size: clamp(64px, 12vw, 132px);
  line-height: 0.95;
  letter-spacing: 0;
}

.deleted-title {
  margin: 0 0 14px;
  font-size: clamp(22px, 4vw, 38px);
}

.deleted-copy {
  color: #595959;
  line-height: 1.8;
}

.debug-panel {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 10;
  width: min(390px, calc(100% - 32px));
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: var(--radius);
  background: rgba(38, 40, 36, 0.94);
  box-shadow: 0 16px 42px rgba(20, 22, 19, 0.2);
  color: #edf0e8;
}

.debug-panel[hidden] {
  display: none;
}

.debug-panel.collapsed .debug-body {
  display: none;
}

.debug-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.debug-title {
  font-size: 13px;
  color: #c9cec3;
}

.debug-body {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  max-height: 270px;
  overflow: auto;
  padding: 12px;
}

.debug-panel button,
.debug-panel select,
.debug-panel input {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  font-size: 12px;
  border-color: rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.07);
  color: #edf0e8;
}

.debug-panel input {
  cursor: text;
}

.debug-wide {
  grid-column: span 2;
}

.debug-json {
  grid-column: span 2;
  max-height: 104px;
  overflow: auto;
  margin: 0;
  padding: 10px;
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.18);
  color: #bfc6b9;
  font: 11px/1.5 var(--font-mono);
  white-space: pre-wrap;
}

.no-script {
  min-height: 100dvh;
  display: grid;
  place-content: center;
  padding: 24px;
  text-align: center;
}

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

.shake {
  animation: shake 300ms linear both;
}

@keyframes softIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes optionAppear {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes blink {
  0%,
  50% {
    opacity: 1;
  }
  51%,
  100% {
    opacity: 0;
  }
}

@keyframes glitch {
  0% {
    transform: translate(0, 0);
  }
  25% {
    transform: translate(1px, 0);
  }
  50% {
    transform: translate(-1px, 1px);
  }
  75% {
    transform: translate(0, -1px);
  }
  100% {
    transform: translate(0, 0);
  }
}

@keyframes swarmCycle {
  0% {
    opacity: 0;
    transform: translateY(14px) rotate(var(--tilt)) scale(0.94);
  }
  13%,
  72% {
    opacity: 1;
    transform: translateY(0) rotate(var(--tilt)) scale(1);
  }
  100% {
    opacity: 0;
    transform: translateY(-8px) rotate(var(--tilt)) scale(1.02);
  }
}

@keyframes optionRejected {
  0% {
    opacity: 1;
    filter: none;
  }
  45% {
    opacity: 1;
    filter: invert(1);
  }
  100% {
    opacity: 0;
    filter: none;
    transform: translateX(14px) rotate(var(--tilt));
  }
}

@keyframes swarmPanic {
  0%,
  100% {
    transform: translate(0, 0) rotate(var(--tilt));
  }
  50% {
    transform: translate(2px, -1px) rotate(var(--tilt));
  }
}

@keyframes chosenFlash {
  0%,
  100% {
    filter: none;
    transform: rotate(var(--tilt));
  }
  50% {
    filter: invert(1);
    transform: translateX(3px) rotate(var(--tilt));
  }
}

@keyframes deletePulse {
  0%,
  100% {
    filter: brightness(1);
    transform: rotate(var(--tilt)) scale(1);
  }
  50% {
    filter: brightness(1.35);
    transform: rotate(var(--tilt)) scale(1.025);
  }
}

@keyframes breachBands {
  0%,
  100% {
    opacity: 0;
    transform: translateX(0);
  }
  50% {
    opacity: 1;
    transform: translateX(11px);
  }
}

@keyframes breachWash {
  0%,
  100% {
    opacity: 0;
  }
  50% {
    opacity: 0.7;
  }
}

@keyframes grainFault {
  0%,
  100% {
    transform: translate(0, 0);
  }
  50% {
    transform: translate(-3px, 2px);
  }
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-5px);
  }
  50% {
    transform: translateX(4px);
  }
  75% {
    transform: translateX(-2px);
  }
}

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

  .typed::after {
    display: none;
  }
}

@media (max-width: 860px) {
  body,
  body.color-drift {
    background: var(--bg);
  }

  .app-shell {
    width: min(100% - 20px, 720px);
    padding: 10px 0 170px;
  }

  .game-grid {
    width: 100%;
    margin-left: 0;
    grid-template-columns: 1fr;
  }

  .test-card {
    min-height: min(650px, calc(100dvh - 20px));
    padding: 30px 22px 40px;
  }

  .topline {
    grid-template-columns: 1fr;
    margin-bottom: 50px;
  }

  .swarm-option {
    width: clamp(150px, 62vw, 300px);
    min-height: 44px;
    padding: 11px 13px;
    font-size: 14px;
  }

  .counter {
    white-space: normal;
  }

  .field-row {
    grid-template-columns: 1fr;
  }

  .question-text {
    font-size: clamp(23px, 7vw, 31px);
  }

  .options {
    gap: 8px;
  }

  .swatches {
    grid-template-columns: repeat(5, minmax(40px, 52px));
    gap: 8px;
  }

  .swatch {
    width: 100%;
  }

  .debug-body {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .debug-wide,
  .debug-json {
    grid-column: span 2;
  }
}
