/* ============ TOKENS ============ */
:root {
  --bg: #050607;
  --bg-panel: #0b0d0f;
  --bg-card: #101316;
  --ink: #c9d4cf;
  --ink-dim: #5e6a66;
  --accent: #7df9aa;
  --accent-dim: rgba(125, 249, 170, 0.18);
  --danger: #ff5470;
  --warn: #ffd166;
  --font-mono: "Cascadia Code", "Consolas", "SF Mono", "Fira Code", monospace;
  --font-display: "Georgia", "Times New Roman", serif;
  --dur-fast: 150ms;
  --dur-normal: 320ms;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

body.theme-void   { --accent: #7df9aa; --accent-dim: rgba(125,249,170,.18); }
body.theme-blood  { --accent: #ff5470; --accent-dim: rgba(255,84,112,.18);  --bg:#070405; --bg-panel:#100a0c; --bg-card:#160d10; }
body.theme-bone   { --accent: #e8e3d5; --accent-dim: rgba(232,227,213,.16); --bg:#0a0a09; --bg-panel:#121210; --bg-card:#171715; --ink:#d8d4c8; }
body.theme-cobalt { --accent: #6aa6ff; --accent-dim: rgba(106,166,255,.18); --bg:#04060a; --bg-panel:#0a0e16; --bg-card:#0e131d; }
body.theme-gold   { --accent: #ffd166; --accent-dim: rgba(255,209,102,.16); --bg:#080604; --bg-panel:#110d08; --bg-card:#16110a; }
body.theme-ash    { --accent: #b8a6e8; --accent-dim: rgba(184,166,232,.18); --bg:#060508; --bg-panel:#0d0b12; --bg-card:#120f18; }

/* ============ BASE ============ */
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.55;
  overflow-x: hidden;
  transition: background-color 900ms var(--ease);
}
button {
  font-family: var(--font-mono);
  cursor: pointer;
  touch-action: manipulation;
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 0.5rem 1.1rem;
  letter-spacing: 0.08em;
  font-size: 0.8rem;
  transition: background var(--dur-fast), color var(--dur-fast), transform var(--dur-fast);
}
button:hover { background: var(--accent); color: var(--bg); }
button:focus-visible { outline: 2px dashed var(--accent); outline-offset: 3px; }
button:active { transform: translateY(1px); }
input[type="text"], textarea {
  font-family: var(--font-mono);
  background: var(--bg);
  border: 1px solid var(--ink-dim);
  color: var(--ink);
  padding: 0.55rem 0.7rem;
  font-size: 0.85rem;
  width: 100%;
}
input[type="text"]:focus, textarea:focus { outline: none; border-color: var(--accent); }
input[type="range"] { width: 100%; accent-color: var(--accent); }
.hidden { display: none !important; }
.noscript {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: #000; color: #7df9aa; font-family: monospace; font-size: 1.2rem;
  text-align: center; padding: 2rem; z-index: 999;
}

/* ============ BOOT ============ */
.boot {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center;
  background: #000;
  transition: opacity 1200ms var(--ease);
}
.boot.fading { opacity: 0; pointer-events: none; }
.boot-inner { text-align: center; }
.boot-eye {
  width: 140px; height: 8px; margin: 0 auto 2rem;
  background: var(--accent);
  border-radius: 50%;
  animation: bootOpen 2.6s var(--ease) forwards;
  box-shadow: 0 0 40px var(--accent-dim), 0 0 80px var(--accent-dim);
}
@keyframes bootOpen {
  0% { height: 2px; opacity: 0.2; }
  35% { height: 2px; opacity: 0.9; }
  60% { height: 60px; }
  75% { height: 30px; }
  100% { height: 70px; opacity: 1; }
}
.boot-line {
  color: var(--ink-dim); letter-spacing: 0.35em; font-size: 0.75rem;
  animation: bootBlink 1.2s steps(2) infinite;
}
@keyframes bootBlink { 50% { opacity: 0.35; } }

/* ============ THE CHAMBER (WebGL backdrop) ============ */
#chamber {
  position: fixed; inset: 0; z-index: 0;
  width: 100vw; height: 100vh; height: 100dvh;
  pointer-events: none;
}
.game, .overlay, .boot, .flash { position: relative; z-index: 1; }
.overlay { position: fixed; }
.boot { position: fixed; }
.flash { position: fixed; }
/* when the chamber renders, surfaces thin out so the orb breathes through */
body.has-chamber .col { background: transparent; }
body.has-chamber .columns { background: transparent; }
body.has-chamber .masthead,
body.has-chamber .footer { background: color-mix(in srgb, var(--bg-panel) 80%, transparent); backdrop-filter: blur(2px); }
body.has-chamber .directive-card,
body.has-chamber .rank-box { background: color-mix(in srgb, var(--bg-card) 78%, transparent); backdrop-filter: blur(3px); }
body.has-chamber .dialogue .msg-ai,
body.has-chamber .dialogue .msg-judgment-good,
body.has-chamber .dialogue .msg-judgment-bad { text-shadow: 0 1px 8px rgba(0, 0, 0, 0.9); }

/* ============ LAYOUT ============ */
.game { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }
.masthead {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.8rem 1.4rem;
  border-bottom: 1px solid var(--accent-dim);
  background: var(--bg-panel);
  position: relative;
}
.masthead-left, .masthead-right { display: flex; align-items: center; gap: 0.8rem; flex: 1; }
.masthead-right { justify-content: flex-end; }
.epoch { color: var(--ink-dim); letter-spacing: 0.2em; font-size: 0.7rem; }
.sep { color: var(--ink-dim); }
.ai-name {
  font-family: var(--font-display); font-style: italic;
  color: var(--accent); font-size: 1.15rem; letter-spacing: 0.05em;
}
.mood-label { color: var(--ink-dim); font-size: 0.65rem; letter-spacing: 0.2em; }
.mood-value { color: var(--accent); font-size: 0.8rem; letter-spacing: 0.15em; }
.sound-toggle { font-size: 0.65rem; padding: 0.3rem 0.6rem; border-color: var(--ink-dim); color: var(--ink-dim); }
.sound-toggle:hover { border-color: var(--accent); color: var(--bg); }

/* ============ THE EYE ============ */
.eye-wrap { width: 110px; height: 64px; cursor: pointer; flex-shrink: 0; }
.eye {
  position: relative; width: 100%; height: 100%;
  background: radial-gradient(ellipse at center, #18201c 0%, #070908 75%);
  border: 1px solid var(--accent);
  border-radius: 50%;
  overflow: hidden;
  box-shadow: 0 0 24px var(--accent-dim), inset 0 0 18px rgba(0,0,0,0.8);
  transition: box-shadow 600ms var(--ease), border-color 600ms var(--ease);
}
.iris {
  position: absolute; top: 50%; left: 50%;
  width: 38px; height: 38px;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle, var(--accent) 0%, transparent 72%);
  border-radius: 50%;
  display: grid; place-items: center;
  transition: width 500ms var(--ease), height 500ms var(--ease);
}
.pupil {
  width: 14px; height: 14px; background: #000; border-radius: 50%;
  transition: width 400ms var(--ease), height 400ms var(--ease);
}
.glint {
  position: absolute; top: 22%; left: 28%;
  width: 6px; height: 6px; background: rgba(255,255,255,0.85); border-radius: 50%;
}
.eye-lid {
  position: absolute; left: -5%; width: 110%; height: 55%;
  background: var(--bg-panel); z-index: 2;
  transition: transform 180ms ease-in;
}
.eye-lid-top { top: 0; transform: translateY(-100%); }
.eye-lid-bot { bottom: 0; transform: translateY(100%); }
.eye.blinking .eye-lid-top { transform: translateY(-42%); }
.eye.blinking .eye-lid-bot { transform: translateY(42%); }
.eye.hint { box-shadow: 0 0 36px var(--accent), inset 0 0 18px rgba(0,0,0,0.8); }
.eye.furious { border-color: var(--danger); box-shadow: 0 0 32px rgba(255,84,112,0.5); }

/* ============ COLUMNS ============ */
.columns {
  flex: 1; display: grid;
  grid-template-columns: 1fr 1.2fr 0.9fr;
  gap: 1px; background: var(--accent-dim);
}
.col { background: var(--bg); padding: 1.1rem; display: flex; flex-direction: column; min-height: 0; }
.panel-title {
  color: var(--ink-dim); font-size: 0.65rem; letter-spacing: 0.3em;
  border-bottom: 1px solid var(--accent-dim); padding-bottom: 0.5rem; margin-bottom: 0.8rem;
}

/* ============ DIALOGUE ============ */
.col-dialogue { max-height: calc(100vh - 130px); }
.dialogue { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 0.7rem; padding-right: 0.3rem; scrollbar-width: thin; }
.msg { animation: msgIn 400ms var(--ease); max-width: 100%; }
@keyframes msgIn { from { opacity: 0; transform: translateY(8px); } }
.msg-ai { color: var(--ink); }
.msg .who { color: var(--accent); font-family: var(--font-display); font-style: italic; margin-right: 0.5rem; }
.msg-subject { color: var(--ink-dim); text-align: right; font-size: 0.8rem; }
.msg-system { color: var(--warn); font-size: 0.72rem; letter-spacing: 0.12em; text-align: center; opacity: 0.9; }
.msg-amendment { color: var(--accent); font-size: 0.75rem; border-left: 2px solid var(--accent); padding-left: 0.7rem; letter-spacing: 0.05em; }
.msg-judgment-good { color: var(--accent); }
.msg-judgment-bad { color: var(--danger); }
.speak { display: flex; gap: 0.5rem; margin-top: 0.8rem; }
.speak button { white-space: nowrap; }

/* ============ DIRECTIVE ============ */
.directive-card {
  background: var(--bg-card); border: 1px solid var(--accent-dim);
  padding: 1.3rem; display: flex; flex-direction: column; gap: 1rem;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  transition: transform 200ms var(--ease);
  will-change: transform;
}
.directive-text {
  font-family: var(--font-display); font-size: 1.25rem; font-style: italic;
  color: var(--ink); line-height: 1.5; min-height: 3em;
}
.directive-timer, .ritual-timer { height: 4px; background: var(--bg); border: 1px solid var(--ink-dim); }
.timer-fill { height: 100%; background: var(--accent); width: 100%; transition: width 200ms linear; }
.directive-area { display: flex; flex-direction: column; gap: 0.8rem; min-height: 60px; }
.directive-actions { display: flex; justify-content: flex-end; }
.btn-refuse { border-color: var(--danger); color: var(--danger); font-size: 0.7rem; }
.btn-refuse:hover { background: var(--danger); color: var(--bg); }
.sigil-row { display: flex; gap: 0.7rem; flex-wrap: wrap; justify-content: center; }
.sigil-btn { font-size: 1.6rem; width: 64px; height: 64px; padding: 0; display: grid; place-items: center; }
.big-sigil {
  font-size: 2.2rem; width: 110px; height: 110px; margin: 0 auto;
  border-radius: 50%; display: grid; place-items: center;
  user-select: none;
}
.area-note { color: var(--ink-dim); font-size: 0.72rem; text-align: center; letter-spacing: 0.1em; }
.glyph-flash {
  font-size: 3rem; text-align: center; color: var(--accent);
  font-family: var(--font-display); min-height: 4.5rem;
  animation: msgIn 200ms var(--ease);
}
.choice-stack { display: flex; flex-direction: column; gap: 0.6rem; }
.choice-stack button { text-align: left; text-transform: none; letter-spacing: 0.02em; font-size: 0.85rem; line-height: 1.4; }
.tribute-readout { text-align: center; font-size: 1.1rem; color: var(--accent); }
.forbidden-word { color: var(--danger); font-weight: bold; letter-spacing: 0.1em; }
.do-not-press { border-color: var(--warn); color: var(--warn); margin: 0 auto; }
.do-not-press:hover { background: var(--warn); color: var(--bg); }
.sigil-tell { animation: sigilBreathe 2.8s ease-in-out infinite; }
@keyframes sigilBreathe { 50% { transform: scale(1.045); opacity: 0.86; } }

/* ============ RITUAL ============ */
.ritual {
  margin-top: 1rem; border: 1px dashed var(--warn); padding: 0.9rem;
  display: flex; flex-direction: column; gap: 0.6rem; align-items: center;
  animation: msgIn 300ms var(--ease);
}
.ritual-text { color: var(--warn); font-size: 0.7rem; letter-spacing: 0.25em; }
.btn-ritual { border-color: var(--warn); color: var(--warn); }
.btn-ritual:hover { background: var(--warn); color: var(--bg); }
.ritual-timer { width: 100%; }
.ritual-timer .timer-fill { background: var(--warn); }

/* ============ STATUS ============ */
.rank-box {
  background: var(--bg-card); border: 1px solid var(--accent-dim);
  padding: 0.9rem; text-align: center; margin-bottom: 1rem;
}
.rank-label { color: var(--ink-dim); font-size: 0.6rem; letter-spacing: 0.3em; }
.rank-value {
  font-family: var(--font-display); font-size: 1.5rem; color: var(--accent);
  letter-spacing: 0.12em; margin: 0.2rem 0;
}
.standing { color: var(--ink); font-size: 0.85rem; }
.standing-label { color: var(--ink-dim); font-size: 0.65rem; letter-spacing: 0.2em; }
.knows { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.6rem; }
.knows-label { color: var(--ink-dim); font-size: 0.55rem; letter-spacing: 0.22em; white-space: nowrap; }
.knows-bar { flex: 1; height: 4px; background: var(--bg); border: 1px solid var(--accent-dim); }
.knows-fill { height: 100%; background: var(--accent); width: 0%; transition: width 800ms var(--ease); }
.knows-pct { color: var(--accent); font-size: 0.6rem; }
.metrics { display: flex; flex-direction: column; gap: 0.7rem; margin-bottom: 1.2rem; }
.metric { display: flex; flex-direction: column; gap: 0.25rem; }
.metric-head { display: flex; justify-content: space-between; font-size: 0.68rem; letter-spacing: 0.15em; }
.metric-name { color: var(--ink-dim); }
.metric-name.inverted::after { content: " ⊖"; color: var(--danger); }
.metric-num { color: var(--ink); }
.metric-bar { height: 6px; background: var(--bg-card); border: 1px solid var(--accent-dim); }
.metric-fill { height: 100%; background: var(--accent); transition: width 600ms var(--ease); }
.metric-fill.low { background: var(--danger); }
.metrics-redacted { margin-bottom: 1.2rem; color: var(--ink-dim); }
.redacted-line { letter-spacing: 0.2em; opacity: 0.4; margin-bottom: 0.4rem; }
.redacted-note { color: var(--danger); font-size: 0.6rem; letter-spacing: 0.25em; margin-top: 0.5rem; }
.codex-title { margin-top: 0.4rem; }
.codex { flex: 1; overflow-y: auto; max-height: 30vh; display: flex; flex-direction: column; gap: 0.55rem; scrollbar-width: thin; }
.codex-entry { font-size: 0.7rem; color: var(--ink-dim); border-left: 2px solid var(--accent-dim); padding-left: 0.6rem; line-height: 1.45; }
.codex-entry .codex-num { color: var(--accent); }
.codex-entry.by-subject { border-left-color: var(--warn); }
.outcomes { margin-top: 0.8rem; display: flex; justify-content: space-between; font-size: 0.65rem; color: var(--ink-dim); letter-spacing: 0.15em; }
.btn-transcript { margin-top: 0.7rem; width: 100%; font-size: 0.62rem; padding: 0.45rem; border-color: var(--ink-dim); color: var(--ink-dim); }
.btn-transcript:hover { border-color: var(--accent); background: var(--accent); color: var(--bg); }

/* ============ FOOTER ============ */
.footer {
  padding: 0.55rem 1.4rem; border-top: 1px solid var(--accent-dim);
  background: var(--bg-panel); color: var(--ink-dim);
  font-size: 0.62rem; letter-spacing: 0.25em; text-align: center;
}

/* ============ OVERLAY (ENDINGS / CEREMONIES) ============ */
.overlay {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(0, 0, 0, 0.93);
  display: grid; place-items: center;
  animation: overlayIn 800ms var(--ease);
}
@keyframes overlayIn { from { opacity: 0; } }
.overlay-inner { max-width: 620px; padding: 2rem; text-align: center; display: flex; flex-direction: column; gap: 1.4rem; align-items: center; }
.overlay-glyph { font-size: 4rem; color: var(--accent); animation: glyphPulse 3s ease-in-out infinite; }
@keyframes glyphPulse { 50% { opacity: 0.45; transform: scale(0.92); } }
.overlay-title {
  font-family: var(--font-display); font-style: italic; font-weight: normal;
  font-size: 2rem; color: var(--accent); letter-spacing: 0.08em;
}
.overlay-body { color: var(--ink); line-height: 1.8; font-size: 0.95rem; white-space: pre-line; }
.overlay-extra { width: 100%; display: flex; flex-direction: column; gap: 0.7rem; }
.overlay-btn { padding: 0.8rem 2.4rem; }

/* ============ FLASH (RULE MUTATIONS) ============ */
.flash {
  position: fixed; inset: 0; z-index: 80; pointer-events: none;
  background: var(--accent);
  animation: flashOut 700ms var(--ease) forwards;
}
@keyframes flashOut { from { opacity: 0.35; } to { opacity: 0; } }

/* ============ GLITCH (for big moments) ============ */
.glitching { animation: glitch 350ms steps(3) 2; }
@keyframes glitch {
  0% { transform: translate(0); filter: none; }
  33% { transform: translate(-3px, 1px); filter: hue-rotate(90deg); }
  66% { transform: translate(3px, -1px); filter: invert(0.8); }
  100% { transform: translate(0); filter: none; }
}

/* ============ RESPONSIVE ============ */
@media (max-width: 980px) {
  .columns { grid-template-columns: 1fr; }
  .col-dialogue { max-height: none; }
  .dialogue { max-height: 38vh; }
  .masthead { flex-wrap: wrap; gap: 0.6rem; justify-content: center; }
  .masthead-left, .masthead-right { flex: initial; }
}
@media (max-width: 600px) {
  /* 16px inputs prevent iOS Safari from auto-zooming on focus */
  input[type="text"], textarea { font-size: 16px; }
  .col { padding: 0.8rem; }
  .directive-card { padding: 1rem; }
  .directive-text { font-size: 1.05rem; }
  .overlay-inner { padding: 1.2rem; }
  .overlay-title { font-size: 1.5rem; }
  .sigil-btn { width: 56px; height: 56px; }
  .footer { letter-spacing: 0.12em; }
  .codex { max-height: 22vh; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
