:root {
  color-scheme: dark;
  --bg: #050706;
  --phosphor: #d9e4d8;
  --phosphor-strong: #eff6ee;
  --glimmer: #b8c9b9;
  --line: #536159;
  --piece: rgba(205, 225, 207, .11);
  --piece-border: rgba(212, 231, 214, .35);
  --recent: rgba(224, 242, 225, .22);
  --ease-soft: cubic-bezier(.2,.72,.2,1);
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100svh;
  overflow-x: hidden;
  color: var(--phosphor);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  letter-spacing: .015em;
}

body::before,
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 99;
}

body::before {
  background: repeating-linear-gradient(to bottom, rgba(255,255,255,.018) 0, rgba(255,255,255,.018) 1px, transparent 1px, transparent 4px);
  opacity: .28;
}

body::after {
  background: radial-gradient(circle at 50% 42%, transparent 0 38%, rgba(0,0,0,.42) 100%);
}

button,
input { font: inherit; }
button { color: inherit; }

.drift-shell {
  width: min(1120px, calc(100% - 36px));
  min-height: 100svh;
  margin: 0 auto;
  display: grid;
  place-items: center;
  position: relative;
  z-index: 1;
  transition: grid-template-columns 900ms var(--ease-soft), gap 900ms var(--ease-soft);
}

.story-panel {
  width: min(760px, 100%);
  padding: max(7vh, 48px) 0 max(8vh, 54px);
  transition: width 900ms var(--ease-soft);
}

.brand {
  font-size: 10px;
  letter-spacing: .34em;
  color: rgba(217,228,216,.28);
  margin: 0 48px 28px;
  user-select: none;
}

.story-stage {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 42px;
  align-items: center;
  gap: 6px;
}

.story-viewport {
  min-height: 290px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  position: relative;
  opacity: 1;
  transform: translateX(0);
  transition: opacity 240ms ease, transform 420ms var(--ease-soft);
}

.story-viewport.page-leave-left { opacity: 0; transform: translateX(-14px); }
.story-viewport.page-leave-right { opacity: 0; transform: translateX(14px); }
.story-viewport.page-enter-left { animation: storyEnterLeft 500ms var(--ease-soft) both; }
.story-viewport.page-enter-right { animation: storyEnterRight 500ms var(--ease-soft) both; }

.story-memory {
  min-height: 15px;
  margin-bottom: 12px;
  color: rgba(217,228,216,.2);
  font-size: 8px;
  letter-spacing: .16em;
  opacity: 0;
  transition: opacity 700ms var(--ease-soft);
}
.has-story-history .story-memory { opacity: 1; }

.story-nav {
  width: 38px;
  min-height: 74px;
  border: 0;
  background: transparent;
  color: rgba(217,228,216,.32);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 34px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transform: scale(.94);
  transition: opacity 800ms var(--ease-soft), color 220ms ease, transform 300ms ease;
}
.has-story-history .story-nav { opacity: .72; }
.story-nav:disabled { opacity: .09 !important; cursor: default; }
.story-nav:not(:disabled):hover,
.story-nav:not(:disabled):focus-visible {
  color: rgba(239,246,238,.85);
  transform: scale(1.08);
  outline: none;
}

.transcript { display: block; }

.passage,
.response {
  font-size: clamp(17px, 2.15vw, 23px);
  line-height: 1.72;
  text-wrap: pretty;
}

.passage p,
.response p { margin: 0 0 1em; }
.passage p:last-child,
.response p:last-child { margin-bottom: 0; }

.glimmer {
  color: var(--glimmer);
  text-decoration: underline dotted rgba(184,201,185,.28);
  text-underline-offset: .22em;
  text-decoration-thickness: 1px;
  cursor: pointer;
  transition: color 350ms ease, text-shadow 350ms ease, text-decoration-color 350ms ease, opacity 350ms ease;
}

.glimmer.exposed-in-prose {
  animation: glimmerBreathe 4.2s ease-in-out infinite;
}

.glimmer:hover,
.glimmer:focus-visible {
  color: var(--phosphor-strong);
  text-decoration-color: rgba(239,246,238,.5);
  outline: none;
}

.glimmer.learned-in-prose {
  color: var(--phosphor-strong);
  text-decoration-color: transparent;
  text-shadow: 0 0 12px rgba(215,235,217,.16);
  animation: none;
}

.turn {
  animation: turnIn 420ms var(--ease-soft) both;
}

.player-line {
  margin: 0 0 14px;
  color: rgba(217,228,216,.58);
  font-size: 13px;
  line-height: 1.6;
}

.player-line::before {
  content: "> ";
  color: rgba(217,228,216,.35);
}

.command-line {
  margin: 30px 48px 0;
  min-height: 44px;
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 10px;
  color: var(--phosphor-strong);
}

.prompt-mark {
  color: rgba(217,228,216,.45);
  font-size: 18px;
}

.input-wrap {
  position: relative;
  min-width: 0;
}

#commandInput {
  width: 100%;
  border: 0;
  outline: 0;
  padding: 10px 0;
  background: transparent;
  color: var(--phosphor-strong);
  font-size: clamp(16px, 2vw, 21px);
  line-height: 1.4;
  caret-color: var(--phosphor-strong);
}

.idle-cursor {
  position: absolute;
  left: 1px;
  top: 50%;
  width: .68em;
  height: 1.15em;
  transform: translateY(-50%);
  background: rgba(239,246,238,.78);
  animation: blink 1.05s steps(1, end) infinite;
  pointer-events: none;
}

.input-wrap:focus-within .idle-cursor,
.input-wrap:has(input:not(:placeholder-shown)) .idle-cursor { opacity: 0; }

.status-line {
  min-height: 18px;
  margin: 8px 48px 0;
  color: rgba(217,228,216,.34);
  font-size: 10px;
  letter-spacing: .08em;
  text-transform: uppercase;
  transition: opacity 420ms ease;
}

.mind-panel {
  width: min(350px, 100%);
  opacity: 0;
  transform: translateX(26px) scale(.985);
  pointer-events: none;
  transition: opacity 1150ms var(--ease-soft), transform 1150ms var(--ease-soft);
}

.drift-shell.awake {
  grid-template-columns: minmax(0, 1fr) 350px;
  gap: clamp(28px, 6vw, 84px);
  place-items: center stretch;
}

.drift-shell.awake .story-panel { width: 100%; }
.drift-shell.awake .mind-panel {
  opacity: 1;
  transform: translateX(0) scale(1);
  pointer-events: auto;
}

.head-button {
  width: 100%;
  border: 0;
  background: transparent;
  padding: 0;
  cursor: pointer;
}
.head-button:focus-visible { outline: 1px solid rgba(217,228,216,.18); outline-offset: 8px; border-radius: 42%; }

.head-wrap {
  position: relative;
  width: min(330px, 100%);
  aspect-ratio: 260 / 340;
  margin: 0 auto;
}

.head-engraving {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.head-outline,
.etch,
.face-detail {
  fill: none;
  stroke: rgba(205,221,207,.24);
  vector-effect: non-scaling-stroke;
}
.head-outline { stroke-width: 1.2; }
.etch {
  stroke-width: .65;
  stroke-dasharray: 1.4 2.2;
  opacity: .55;
}
.face-detail {
  stroke-width: .8;
  opacity: .68;
}

.cognition-grid-wrap,
.action-grid-wrap { position: absolute; }

.cognition-grid-wrap {
  left: 19%;
  top: 16%;
  width: 47%;
}

.action-grid-wrap {
  left: 24%;
  bottom: 16%;
  width: 34%;
}

.grid-label {
  margin-bottom: 5px;
  font-size: 8px;
  letter-spacing: .16em;
  color: rgba(217,228,216,.29);
}

.cognition-grid,
.action-grid {
  display: grid;
  gap: 4px;
  grid-auto-flow: dense;
}

.cognition-grid {
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 32px);
  min-height: 140px;
  background: linear-gradient(rgba(217,228,216,.045) 1px, transparent 1px), linear-gradient(90deg, rgba(217,228,216,.045) 1px, transparent 1px);
  background-size: calc(25% + 1px) 36px;
  border: 1px solid rgba(217,228,216,.08);
}

.action-grid {
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(2, 30px);
  min-height: 64px;
  background: linear-gradient(rgba(217,228,216,.045) 1px, transparent 1px), linear-gradient(90deg, rgba(217,228,216,.045) 1px, transparent 1px);
  background-size: calc(50% + 2px) 34px;
  border: 1px solid rgba(217,228,216,.08);
}

.thought-piece,
.action-piece {
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--piece-border);
  background: var(--piece);
  display: grid;
  place-items: center;
  padding: 3px 4px;
  text-align: center;
  overflow: hidden;
  color: rgba(239,246,238,.9);
  font-size: 8px;
  letter-spacing: .06em;
  line-height: 1.05;
  text-transform: uppercase;
  animation: pieceIn 600ms var(--ease-soft) both;
  cursor: pointer;
}

.thought-piece:hover,
.action-piece:hover,
.thought-piece:focus-visible,
.action-piece:focus-visible {
  outline: none;
  border-color: rgba(239,246,238,.55);
  background: rgba(205,225,207,.16);
}

.thought-piece.span-2 { grid-column: span 2; }
.thought-piece.recent,
.action-piece.recent {
  background: var(--recent);
  box-shadow: 0 0 20px rgba(220,238,222,.08);
}

.empty-action { border: 1px solid rgba(217,228,216,.07); }

.mind-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 0 18px;
}

.lexicon-toggle,
.restart {
  border: 0;
  background: transparent;
  padding: 7px 0;
  cursor: pointer;
  color: rgba(217,228,216,.33);
  font-size: 9px;
  letter-spacing: .12em;
  transition: color 240ms ease, opacity 700ms var(--ease-soft);
}

.lexicon-toggle[hidden] { display: block; visibility: hidden; opacity: 0; pointer-events: none; }
.lexicon-toggle:not([hidden]) { visibility: visible; opacity: 1; }

.lexicon-toggle:hover,
.restart:hover,
.lexicon-toggle:focus-visible,
.restart:focus-visible {
  color: rgba(217,228,216,.8);
  outline: none;
}

.drift-dialog {
  padding: 0;
  border: 1px solid rgba(217,228,216,.16);
  border-radius: 14px;
  background: rgba(7,10,8,.96);
  color: var(--phosphor);
  box-shadow: 0 34px 110px rgba(0,0,0,.66);
  opacity: 0;
  transform: translateY(8px) scale(.987);
  transition: opacity 280ms ease, transform 380ms var(--ease-soft), display 380ms allow-discrete, overlay 380ms allow-discrete;
}
.drift-dialog[open] { opacity: 1; transform: translateY(0) scale(1); }
@starting-style { .drift-dialog[open] { opacity: 0; transform: translateY(10px) scale(.985); } }
.drift-dialog::backdrop {
  background: rgba(0,0,0,.68);
  backdrop-filter: blur(3px);
  opacity: 0;
  transition: opacity 320ms ease, display 320ms allow-discrete, overlay 320ms allow-discrete;
}
.drift-dialog[open]::backdrop { opacity: 1; }
@starting-style { .drift-dialog[open]::backdrop { opacity: 0; } }

.term-dialog { width: min(520px, calc(100% - 28px)); }
.dialog-card { position: relative; padding: 30px; }
.dialog-close {
  position: absolute;
  top: 10px;
  right: 14px;
  border: 0;
  background: transparent;
  color: rgba(217,228,216,.42);
  font-size: 24px;
  cursor: pointer;
}
.dialog-close:hover,
.dialog-close:focus-visible { color: var(--phosphor-strong); outline: none; }
.dialog-kicker,
.entry-kind {
  margin: 0 0 9px;
  color: rgba(217,228,216,.38);
  font-size: 8px;
  letter-spacing: .16em;
  text-transform: uppercase;
}
.drift-dialog h2,
.drift-dialog h3 { font-weight: 500; letter-spacing: -.025em; }
.drift-dialog h2 { margin: 0 0 18px; font-size: 28px; }
.drift-dialog h3 { margin: 0 0 14px; font-size: 22px; }
.dialog-copy,
.lexicon-article {
  color: rgba(217,228,216,.76);
  font-size: 13px;
  line-height: 1.7;
}
.dialog-copy p,
.lexicon-article p { margin: 0 0 1em; }

.lexicon-dialog {
  width: min(880px, calc(100% - 28px));
  max-height: min(720px, calc(100svh - 30px));
}
.lexicon-shell { min-height: 500px; display: flex; flex-direction: column; }
.lexicon-heading {
  position: relative;
  padding: 28px 34px 20px;
  border-bottom: 1px solid rgba(83,97,89,.26);
}
.lexicon-heading h2 { margin-bottom: 6px; }
.lexicon-heading > div > p:last-child { margin: 0; color: rgba(217,228,216,.42); font-size: 10px; }
.lexicon-layout {
  min-height: 410px;
  display: grid;
  grid-template-columns: 210px 1fr;
  overflow: hidden;
}
.lexicon-index {
  padding: 18px;
  border-right: 1px solid rgba(83,97,89,.26);
  display: grid;
  align-content: start;
  gap: 5px;
  overflow: auto;
}
.lexicon-index button {
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: rgba(217,228,216,.42);
  padding: 9px 10px;
  text-align: left;
  font-size: 10px;
  cursor: pointer;
  transition: color 180ms ease, background 180ms ease;
}
.lexicon-index button:hover,
.lexicon-index button:focus-visible,
.lexicon-index button.active {
  outline: none;
  color: var(--phosphor-strong);
  background: rgba(205,225,207,.06);
}
.lexicon-article { padding: 28px 34px; overflow: auto; }
.lexicon-empty { color: rgba(217,228,216,.35); }

.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;
}

@keyframes blink {
  0%, 45% { opacity: .8; }
  46%, 100% { opacity: 0; }
}
@keyframes glimmerBreathe {
  0%, 100% { opacity: .72; }
  50% { opacity: 1; }
}
@keyframes turnIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes pieceIn {
  from { opacity: 0; transform: scale(.9); }
  to { opacity: 1; transform: scale(1); }
}
@keyframes storyEnterLeft {
  from { opacity: 0; transform: translateX(-14px); }
  to { opacity: 1; transform: translateX(0); }
}
@keyframes storyEnterRight {
  from { opacity: 0; transform: translateX(14px); }
  to { opacity: 1; transform: translateX(0); }
}

@media (max-width: 860px) {
  .drift-shell,
  .drift-shell.awake {
    width: min(720px, calc(100% - 28px));
    display: block;
  }

  .story-panel {
    min-height: 100svh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: max(48px, 8vh) 0;
  }

  .drift-shell.awake .story-panel {
    min-height: auto;
    padding-bottom: 24px;
  }

  .mind-panel {
    margin: 0 auto 70px;
    transform: translateY(18px) scale(.985);
  }
  .drift-shell.awake .mind-panel { transform: translateY(0) scale(1); }
}

@media (max-width: 520px) {
  .drift-shell,
  .drift-shell.awake { width: calc(100% - 16px); }
  .story-panel { padding-top: max(44px, calc(env(safe-area-inset-top) + 24px)); }
  .brand { margin: 0 34px 22px; }
  .story-stage { grid-template-columns: 30px minmax(0,1fr) 30px; gap: 2px; }
  .story-nav { width: 28px; font-size: 27px; }
  .story-viewport { min-height: 300px; }
  .passage,
  .response {
    font-size: 16px;
    line-height: 1.68;
  }
  .turn { padding-top: 0; }
  .command-line { margin: 24px 34px 0; }
  .status-line { margin: 8px 34px 0; }
  #commandInput { font-size: 16px; }
  .mind-panel { width: min(310px, 94vw); }
  .lexicon-layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .lexicon-index {
    display: flex;
    gap: 4px;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid rgba(83,97,89,.26);
    padding: 12px;
  }
  .lexicon-index button { white-space: nowrap; }
  .lexicon-article { padding: 22px; }
  .lexicon-shell { min-height: 0; }
}

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