:root {
  color-scheme: dark;
  font-family: system-ui, sans-serif;
  font-synthesis: none;
  color: #E5DED1;
  background: #111517;
  --ground: #111517;
  --surface: #1A2123;
  --panel: #202729;
  --hover: #2C373B;
  --paper: #E5DED1;
  --muted: #B2B8B7;
  --glass: #A7BFC6;
  --brick: #CF897E;
  --line: #414C50;
  --ink: #212628;
  --serif: Georgia, "Times New Roman", serif;
  --mono: ui-monospace, "SF Mono", monospace;
  --type-title: clamp(2rem, 1.78rem + 1.12vw, 2.7rem);
  --type-dialog-title: clamp(1.5rem, 1.38rem + .65vw, 1.9rem);
  --type-section: clamp(1.3rem, 1.22rem + .32vw, 1.5rem);
  --type-body: clamp(1.125rem, 1.08rem + .19vw, 1.25rem);
  --type-ui: clamp(.9375rem, .92rem + .14vw, 1.025rem);
  --type-small: clamp(.8125rem, .79rem + .15vw, .9rem);
  --type-meta: clamp(.75rem, .73rem + .12vw, .825rem);
}

* { box-sizing: border-box; }
html { scroll-padding-top: 73px; }
body { margin: 0; min-height: 100vh; font-size: var(--type-ui); }
body:has(dialog[open]) { overflow: hidden; }
[hidden] { display: none !important; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
button { border: 0; font: inherit; cursor: pointer; }
:where(button, summary):focus-visible {
  outline: 2px solid var(--glass);
  outline-offset: 3px;
}

.masthead {
  position: sticky;
  z-index: 2;
  top: 0;
  background: var(--ground);
  border-bottom: 1px solid #2B3437;
}
.masthead-inner {
  max-width: 1100px;
  min-height: 59px;
  margin: 0 auto;
  padding: 0 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.brand { display: flex; min-width: 0; align-items: center; gap: 9px; }
.masthead-actions { display: flex; flex: none; align-items: center; gap: 4px; }
.brand-avatar { display: block; flex: none; border-radius: 50%; }
.wordmark { color: var(--paper); font-size: var(--type-ui); font-weight: 690; line-height: 1.25; }
.dossier-trigger, .dialog-close {
  display: inline-flex;
  align-items: center;
  flex: none;
  gap: 8px;
  min-height: 44px;
  padding: 8px 11px;
  border-radius: 6px;
  background: transparent;
  color: var(--paper);
  font-size: var(--type-ui);
  font-weight: 640;
}
.dossier-trigger:hover, .dialog-close:hover { color: var(--glass); background: var(--panel); }
.unread { width: 6px; height: 6px; border-radius: 50%; background: var(--brick); }

.layout {
  max-width: 882px;
  margin: 0 auto;
  padding: 36px 28px 64px;
}
.story {
  display: grid;
  grid-template-areas: "head" "visual" "body";
  grid-template-columns: minmax(0, 1fr);
}
.scene-head { grid-area: head; }
.scene-visual { grid-area: visual; }
.scene-body { grid-area: body; min-width: 0; }
.story.intro {
  grid-template-areas: "visual head" "visual body";
  grid-template-columns: minmax(168px, 248px) minmax(0, 1fr);
  grid-template-rows: auto auto;
  align-items: center;
  column-gap: clamp(26px, 5vw, 64px);
  padding-top: 22px;
}
.intro .scene-head { align-self: end; }
.intro .scene-body { align-self: start; }

.eyebrow, .clock {
  margin: 0;
  color: var(--glass);
  font: 640 var(--type-meta)/1.45 var(--mono);
  letter-spacing: .075em;
  text-transform: uppercase;
}
.story-meta { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 21px; }
.scene-meta-actions { display: flex; align-items: center; gap: 9px; }
.clock { color: var(--muted); font-size: var(--type-small); font-variant-numeric: tabular-nums; }
h1 {
  margin: 10px 0 18px;
  font: 400 var(--type-title)/1.13 var(--serif);
  letter-spacing: -.02em;
  text-wrap: balance;
  overflow-wrap: break-word;
}
h1:focus { outline: none; }
.scene-visual { margin: 0 0 19px; min-width: 0; }
.scene-visual img {
  display: block;
  width: 100%;
  aspect-ratio: 2.55;
  object-fit: cover;
  border-radius: 8px;
  background: var(--surface);
}
.scene-visual figcaption {
  margin-top: 7px;
  color: var(--muted);
  font: var(--type-meta)/1.45 var(--mono);
}
.intro .scene-visual { margin: 0; }
.intro .scene-visual img { aspect-ratio: 2 / 3; }
.scene-text {
  max-width: 62ch;
  font-size: var(--type-body);
  line-height: 1.62;
  overflow-wrap: break-word;
}
.scene-text p { margin: 0 0 .65em; }
.scene-text p:last-child { margin-bottom: 0; }
.scene-text .dialogue { padding-inline-start: 13px; color: #E2EBE9; }

.scene-documents {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(218px, 100%), 1fr));
  gap: 10px;
  margin-top: 19px;
}
.document {
  min-width: 0;
  margin: 0;
  padding: 12px 14px;
  border-radius: 4px;
  background: var(--paper);
  color: var(--ink);
  font: var(--type-small)/1.5 var(--mono);
  overflow-wrap: anywhere;
}
.document figcaption { font-weight: 700; }
.document-stamp { margin: 4px 0 8px; padding-bottom: 7px; border-bottom: 1px dashed #747573; color: #424B4E; }
.document dl { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: 3px 9px; margin: 0; }
.document dd { margin: 0; text-align: right; }

.notice { margin-top: 19px; color: var(--glass); font-size: var(--type-small); line-height: 1.55; }
.notice p { margin: 0; }
.notice > p + p { margin-top: 4px; }
.notice .badge-grid { margin-top: 8px; }
.decision { margin-top: 25px; }
.decision h2 { margin-bottom: 8px; color: var(--muted); }
.choices { display: grid; gap: 7px; }
.choice-jump { display: none; }
.choice {
  min-height: 46px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 4px 14px;
  padding: 11px 14px;
  border-radius: 7px;
  background: var(--panel);
  color: var(--paper);
  text-align: left;
  font-size: var(--type-ui);
  font-weight: 590;
  line-height: 1.42;
}
.choice > * { min-width: 0; overflow-wrap: anywhere; }
.choice:hover { background: var(--hover); }
.intro .choice { background: var(--glass); color: var(--ink); }
.intro .choice:hover { background: #C0D2D6; }
.choice small { color: var(--muted); font: var(--type-meta)/1.45 var(--mono); }

dialog {
  width: min(440px, calc(100% - 28px));
  padding: 23px;
  border: 0;
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 18px 80px #0008;
  color: var(--paper);
}
dialog::backdrop { background: #090D0EDB; }
dialog h2 { margin: 0; font: var(--type-dialog-title)/1.17 var(--serif); text-wrap: balance; overflow-wrap: break-word; }
dialog p { color: var(--muted); line-height: 1.55; }
dialog form { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; }
#restart-dialog button {
  min-height: 44px;
  padding: 8px 12px;
  border-radius: 6px;
  background: var(--panel);
  color: var(--paper);
}
#restart-dialog button:hover { background: var(--hover); }
#restart-dialog button.confirm { background: var(--glass); color: var(--ink); }

.dossier {
  width: min(746px, calc(100% - 28px));
  max-height: calc(100dvh - 28px);
  padding: 0;
  overflow: hidden;
}
.dossier[open] { display: flex; flex-direction: column; }
.dossier-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 19px 23px 12px;
}
.dossier-header .eyebrow { margin-bottom: 4px; }
.dossier-header > div { min-width: 0; }
.dossier-header h2 { color: var(--paper); }
.dossier-content { overflow: auto; overscroll-behavior: contain; padding: 8px 23px 18px; }
.dossier-rules { margin-bottom: 8px; }
.shift-summary { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 13px; margin-bottom: 10px; }
.shift-summary > div { display: grid; gap: 3px; }
.shift-summary strong { font: var(--type-section)/1.2 var(--mono); }
.shift-summary span { color: var(--muted); font-size: var(--type-small); line-height: 1.45; }
.shift-track {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: 4px;
  margin: 3px 0 1px;
  padding: 0;
  list-style: none;
}
.shift-track li { height: 4px; border-radius: 2px; background: var(--line); }
.shift-track .done { background: var(--glass); }
.shift-track .current { background: #6F878E; }
.refusals { grid-column: 1 / -1; margin: 0; color: var(--muted); font: var(--type-meta)/1.5 var(--mono); }
.refusals.warning, .choice .warning { color: var(--brick); }
.badge-section { margin: 14px 0; }
.badge-section > header { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.badge-section h3 { margin: 0; font: var(--type-section)/1.2 var(--serif); }
.badge-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; list-style: none; padding: 0; margin: 0; }
.badge {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  align-items: start;
  gap: 9px;
  min-width: 0;
  padding: 9px;
  border-radius: 7px;
  background: var(--panel);
  color: var(--paper);
}
.badge.locked { background: var(--ground); }
.badge-emblem { display: grid; place-items: center; width: 52px; aspect-ratio: 1; color: var(--muted); font: var(--type-section)/1 var(--mono); }
.badge-emblem img { display: block; width: 100%; height: auto; border-radius: 6px; }
.badge.locked img { filter: grayscale(.85); opacity: .65; }
.badge-state { display: block; margin-bottom: 2px; color: var(--glass); font: var(--type-meta)/1.4 var(--mono); text-transform: uppercase; }
.badge.locked .badge-state { color: var(--muted); }
.badge strong { display: block; font-size: var(--type-ui); line-height: 1.35; }
.badge p { margin: 4px 0 0; color: var(--muted); font-size: var(--type-small); line-height: 1.5; }
.badge progress { display: block; width: 100%; height: 7px; margin-top: 5px; accent-color: var(--glass); }
.unlocked-badges { grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr)); }
details { border-radius: 7px; background: var(--panel); }
summary { min-height: 44px; padding: 11px 12px; cursor: pointer; font-size: var(--type-ui); line-height: 1.55; }
summary span { float: right; color: var(--glass); font-variant-numeric: tabular-nums; }
.records { margin: 0; padding: 0 12px 11px; list-style: none; font-size: var(--type-small); }
.records li + li { margin-top: 11px; }
.records p { margin: 3px 0 0; color: var(--muted); line-height: 1.5; }
.records .record-source { color: var(--glass); font: var(--type-meta)/1.5 var(--mono); }
.dossier-actions { display: flex; flex-wrap: wrap; gap: 0 16px; margin-top: 8px; }
.dossier-actions button {
  min-height: 44px;
  padding: 5px 0;
  background: none;
  color: var(--glass);
  font-size: var(--type-small);
  text-align: left;
}
.dossier-actions button:hover { text-decoration: underline; }
.storage-status { margin: 5px 0 0; color: var(--muted); font-size: var(--type-meta); line-height: 1.5; }

@media (max-width: 620px) {
  .layout { padding: 16px 16px 38px; }
  .masthead-inner { min-height: 53px; padding: 0 16px; }
  body:has(.story.intro) { min-height: 100dvh; }
  .layout:has(.story.intro) { max-width: none; padding: 0; }
  .story.intro {
    position: relative;
    isolation: isolate;
    grid-template: "body" 1fr / minmax(0, 1fr);
    min-height: 100dvh;
    padding: 0;
  }
  .intro .scene-head, .intro .scene-text, .intro .scene-visual figcaption, .intro .decision h2 {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
  .intro .scene-visual {
    position: absolute;
    inset: 0;
    grid-area: auto;
    overflow: hidden;
    background: #0C1011;
  }
  .intro .scene-visual::before, .intro .scene-visual::after { position: absolute; content: ""; }
  .intro .scene-visual::before {
    inset: -18px;
    background: url("assets/cover-mirror.png") center bottom / cover;
    filter: blur(20px);
    opacity: .65;
  }
  .intro .scene-visual img {
    position: relative;
    width: 100%;
    height: auto;
    max-height: 100%;
    object-fit: contain;
    object-position: center top;
    border-radius: 0;
    background: transparent;
    mask-image: linear-gradient(#000 0 76%, transparent);
  }
  .intro .scene-visual::after {
    inset: 0;
    background: linear-gradient(transparent 53%, #0C101166 76%, #0C1011 100%);
  }
  .intro .scene-body {
    z-index: 1;
    align-self: end;
    justify-self: center;
    width: min(100%, 420px);
    padding: 16px 18px max(18px, calc(env(safe-area-inset-bottom) + 14px));
  }
  .intro .decision { margin: 0; }
  .intro .choice { justify-content: center; min-height: 50px; }
  .story-meta { min-height: 44px; gap: 6px; }
  .scene-head h1 { margin-block: 7px 13px; }
  .scene-visual { margin-block-end: 13px; }
  .scene-visual img { aspect-ratio: 2.12; }
  .scene-visual figcaption { margin-top: 5px; }
  .decision { margin-top: 19px; }
  .choice-jump {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    min-height: 44px;
    padding: 7px 9px;
    border-radius: 7px;
    background: var(--panel);
    color: var(--glass);
    font-size: var(--type-small);
    font-weight: 650;
  }
  .choice-jump:hover { background: var(--hover); }
}
@media (max-width: 470px) {
  .masthead-inner { gap: 5px; padding-inline: 14px; }
  .brand-avatar { width: 30px; height: 30px; }
  .dossier-trigger { padding-inline: 8px; }
  .scene-documents, .badge-grid { grid-template-columns: minmax(0, 1fr); }
  .dossier-header, .dossier-content { padding-inline: 14px; }
}
@media (max-width: 410px) {
  .masthead:has(#header-choice-jump:not([hidden])) .wordmark { display: none; }
}
