:root {
  --paper: #E9DFC7;
  --paper-hi: #F2EADA;
  --paper-deep: #DCCFB2;
  --ink: #221C15;
  --ink-soft: #3A3126;
  --ink-line: rgba(34, 28, 21, 0.38);
  --sepia: #A9885C;
  --ochre: #C9A063;
  --rust: #8C5433;
  --teal-deep: #3F5B58;
  --teal-mid: #6E8A82;
  --danger: #A3402F;
  --lamp: #F2C879;

  --fs-body: 17px;
  --fs-lead: 19px;
  --fs-h3: 22px;
  --fs-h2: 26px;
  --fs-h1: clamp(30px, 8vw, 38px);
  --fs-caption: 16px;

  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-6: 24px;
  --sp-8: 32px;

  --tap-min: 44px;
  --tap-primary: 56px;
  --tap-gap: 10px;

  --r-1: 2px;
  --r-2: 4px;
  --r-3: 8px;

  --t-fast: 120ms;
  --t-base: 180ms;
  --ease: cubic-bezier(0.2, 0.7, 0.3, 1);

  --font-title: "Neucha", "Georgia", serif;
  --font-body: "PT Serif", "Georgia", serif;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  max-width: 100%;
  overflow-x: clip;
}

html {
  background: var(--paper);
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100dvh;
  font-family: var(--font-body);
  font-size: var(--fs-body);
  line-height: 1.45;
  color: var(--ink);
  background-color: var(--paper);
  background-image: url("assets/art/ui/paper-tile-512.webp");
  background-size: 512px 512px;
  background-repeat: repeat;
  -webkit-font-smoothing: antialiased;
}

[hidden] {
  display: none !important;
}

img {
  max-width: 100%;
}

p,
ul,
ol,
figure {
  margin: 0;
}

button {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 2px;
}

.app {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  min-height: 100dvh;
  width: 100%;
  padding:
    max(10px, var(--safe-top))
    max(14px, var(--safe-right))
    max(18px, var(--safe-bottom))
    max(14px, var(--safe-left));
}

.app-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  min-height: var(--tap-min);
}

.app-bar__day {
  font-family: var(--font-title);
  font-size: 22px;
  line-height: 1.1;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink);
  white-space: nowrap;
}

.app-bar__tools {
  display: flex;
  gap: var(--sp-1);
}

.tool {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: var(--tap-min);
  padding: 6px 10px;
  border: 1px solid var(--ink-line);
  border-radius: var(--r-2);
  background: var(--paper-hi);
  font-family: var(--font-body);
  font-size: var(--fs-caption);
  line-height: 1.1;
  color: var(--ink);
  cursor: pointer;
}

.tool img {
  width: 22px;
  height: 22px;
  flex: none;
}

.resources {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  padding: 0;
  list-style: none;
}

.resource {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  min-height: 46px;
  padding: 6px 8px;
  border: 1px solid var(--ink-line);
  border-radius: var(--r-2);
  background: var(--paper-hi);
}

.resource__icon {
  width: 24px;
  height: 24px;
  flex: none;
}

.resource__body {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.05;
}

.resource__value {
  font-family: var(--font-title);
  font-size: 21px;
  font-variant-numeric: tabular-nums;
}

.resource__label {
  font-size: 16px;
  line-height: 1.15;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.resource.is-low {
  border-color: var(--rust);
}

.resource.is-low .resource__value {
  color: var(--rust);
}

.resource.is-empty {
  opacity: 0.55;
}

.resource.is-empty .resource__value {
  text-decoration: line-through;
}

.resource.is-changed {
  border-color: var(--ink);
}

.resource__slash {
  position: absolute;
  left: 4px;
  top: 50%;
  width: 24px;
  height: 24px;
  transform: translateY(-50%);
  opacity: 0.85;
}

.scene {
  position: relative;
  width: 100%;
  height: clamp(184px, 32dvh, 360px);
  flex: none;
  overflow: hidden;
  border: 1px solid var(--ink-line);
  border-radius: var(--r-1);
  background: var(--paper-deep);
}

.scene__image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 42%;
}

.scene--logo .scene__image {
  object-fit: contain;
  padding: var(--sp-6);
}

.app[data-screen="summary"],
.app[data-screen="part"],
.app[data-screen="ending"],
.app[data-screen="turn"] {
  gap: 0;
  padding: 0;
}

.app[data-screen="summary"] .app-bar,
.app[data-screen="part"] .app-bar,
.app[data-screen="ending"] .app-bar,
.app[data-screen="turn"] .app-bar,
.app[data-screen="summary"] .resources,
.app[data-screen="part"] .resources,
.app[data-screen="ending"] .resources,
.app[data-screen="turn"] .resources,
.app[data-screen="summary"] .scene,
.app[data-screen="part"] .scene,
.app[data-screen="ending"] .scene,
.app[data-screen="turn"] .scene {
  display: none;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  min-width: 0;
  padding-bottom: var(--sp-2);
}

.panel__body {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  min-width: 0;
}

.panel.is-busy {
  cursor: progress;
}

.panel.is-busy .actions,
.panel.is-busy .mechanic {
  opacity: 0.6;
  pointer-events: none;
}

.panel__text {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  font-size: var(--fs-lead);
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.panel__text p {
  max-width: 34ch;
}

.dialog {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-left: 3px solid var(--ink-line);
  background: var(--paper-hi);
  border-radius: var(--r-1);
}

.dialog__line {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.dialog__who {
  font-size: 16px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.dialog__text {
  font-size: var(--fs-body);
  font-style: italic;
  line-height: 1.45;
}

.note {
  padding: var(--sp-2) var(--sp-3);
  border: 1px dashed var(--ink-line);
  border-radius: var(--r-1);
  font-size: var(--fs-caption);
  color: var(--ink-soft);
}

.actions {
  display: flex;
  flex-direction: column;
  gap: var(--tap-gap);
}

.actions[hidden] {
  display: none;
}

.page {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.page[hidden] {
  display: none;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
}

.pager[hidden] {
  display: none;
}

.pager__count {
  font-size: var(--fs-caption);
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

.pager__next {
  width: auto;
  min-width: 148px;
  min-height: 48px;
  padding: 10px 18px;
  font-size: var(--fs-body);
}

.task {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  padding: var(--sp-3);
  border: 1px solid var(--ink-line);
  border-radius: var(--r-2);
  background: var(--paper-hi);
}

.task__speaker {
  font-family: var(--font-display);
  font-size: var(--fs-body);
  font-weight: 700;
}

.task__frame {
  margin: 0;
  padding-left: var(--sp-3);
  border-left: 3px solid var(--sepia);
  font-size: var(--fs-body);
  font-style: italic;
  line-height: 1.5;
}

.task__label {
  margin-top: var(--sp-1);
  font-size: var(--fs-caption);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.task__legend,
.task__steps {
  margin: 0;
  padding-left: 22px;
  font-size: var(--fs-caption);
  line-height: 1.45;
}

.task__legend li,
.task__steps li {
  margin-bottom: var(--sp-1);
}

.task__step-name {
  display: block;
  font-size: var(--fs-caption);
}

.task__step-known {
  display: block;
  color: var(--ink-soft);
}

.task__cost {
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-1);
  background: var(--paper-deep);
  font-size: var(--fs-caption);
  line-height: 1.4;
}

.task__how {
  margin-top: var(--sp-1);
  border-top: 1px dashed var(--ink-line);
}

.task__how-summary {
  min-height: var(--tap-min);
  display: flex;
  align-items: center;
  font-size: var(--fs-caption);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-soft);
  cursor: pointer;
}

.task__how[open] .task__how-summary {
  color: var(--ink);
}

.task__how[open] .task__how-summary::after {
  content: "свернуть";
  margin-left: auto;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
}

.task__how:not([open]) .task__how-summary::after {
  content: "развернуть";
  margin-left: auto;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
}

.task__how .task__label:first-of-type {
  margin-top: 0;
}

.act-result {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  padding: var(--sp-3);
  border: 1px solid var(--ink);
  border-radius: var(--r-2);
  background: var(--paper-hi);
}

.act-result__verdict {
  font-size: var(--fs-body);
  line-height: 1.45;
}

.act-result__line {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: var(--sp-2);
  align-items: baseline;
}

.act-result__who {
  font-size: var(--fs-caption);
  font-weight: 700;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.act-result__text,
.act-result__heard,
.act-result__tape {
  font-size: var(--fs-caption);
  line-height: 1.45;
}

.act-result__heard,
.act-result__tape {
  color: var(--ink-soft);
}

.mask {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  min-height: 64px;
  padding: var(--sp-3);
  border: 1px solid var(--ink-line);
  border-radius: var(--r-2);
  background: var(--paper-hi);
  font-family: var(--font-body);
  text-align: left;
  color: var(--ink);
  cursor: pointer;
}

.mask.is-picked {
  border: 2px solid var(--ink);
  background: var(--paper);
}

.mask__name {
  font-size: var(--fs-body);
  font-weight: 700;
}

.mask__manner,
.mask__hear {
  font-size: var(--fs-caption);
  line-height: 1.4;
}

.mask__hear {
  color: var(--ink-soft);
}

.toggle {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px var(--sp-3);
  width: 100%;
  min-height: 64px;
  padding: var(--sp-3);
  border: 1px solid var(--ink-line);
  border-radius: var(--r-2);
  background: var(--paper-hi);
  font-family: var(--font-body);
  text-align: left;
  color: var(--ink);
  cursor: pointer;
}

.toggle.is-on {
  border: 2px solid var(--ink);
  background: var(--paper);
}

.toggle__label {
  font-size: var(--fs-body);
  font-weight: 700;
}

.toggle__state {
  grid-column: 1 / -1;
  font-size: var(--fs-caption);
  line-height: 1.4;
  color: var(--ink-soft);
}

.power__budget,
.power__tape {
  font-size: var(--fs-caption);
  line-height: 1.45;
}

.power__budget.is-over {
  color: var(--danger);
  font-weight: 700;
}

.power__zero,
.power__warn {
  margin: 0;
  padding: 8px 10px;
  border-left: 3px solid var(--sepia);
  background: var(--paper);
  font-size: var(--fs-caption);
  line-height: 1.35;
  color: var(--ink-soft);
}

.power__warn {
  border-left-color: var(--rust);
  color: var(--ink);
}

.mechanic__hint--cost {
  border-left-color: var(--rust);
  background: var(--paper-deep);
  font-size: var(--fs-caption);
}

.mechanic__hint--free {
  border-left-color: var(--sepia);
  background: var(--paper);
  font-size: var(--fs-caption);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  width: 100%;
  min-height: var(--tap-primary);
  padding: 12px 18px;
  border: 1px solid var(--ink);
  border-radius: var(--r-2);
  background: var(--paper-hi);
  font-family: var(--font-body);
  font-size: 18px;
  font-weight: 700;
  line-height: 1.25;
  text-align: center;
  color: var(--ink);
  cursor: pointer;
}

.btn--primary {
  background: var(--ink);
  color: var(--paper-hi);
}

.btn--small {
  width: auto;
  min-height: var(--tap-min);
  padding: 8px 14px;
  font-size: var(--fs-caption);
}

.btn--ghost {
  width: auto;
  border-color: var(--ink-line);
  background: transparent;
  font-weight: 400;
}

.btn[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn img {
  width: 20px;
  height: 20px;
  flex: none;
}

.choice {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  min-height: 64px;
  padding: 12px 16px;
  border: 1px solid var(--ink-line);
  border-radius: var(--r-2);
  background: var(--paper-hi);
  text-align: left;
  cursor: pointer;
}

.choice__label {
  font-size: 18px;
  font-weight: 600;
  line-height: 1.3;
}

.choice__meta {
  font-size: var(--fs-caption);
  color: var(--ink-soft);
}

.failure {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  padding: var(--sp-3);
  border: 1px solid var(--danger);
  border-radius: var(--r-2);
  background: var(--paper-hi);
}

.failure__text {
  font-size: var(--fs-caption);
  color: var(--danger);
}

.mechanic {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  padding: var(--sp-4);
  border: 1px solid var(--ink-line);
  border-radius: var(--r-2);
  background: var(--paper-hi);
}

.mechanic__head {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stamp {
  font-family: var(--font-title);
  font-size: 14px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.mechanic__prompt {
  font-size: var(--fs-lead);
  font-weight: 700;
  line-height: 1.35;
  max-width: 30ch;
}

.mechanic__question {
  font-size: var(--fs-caption);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.docs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.doc {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 104px;
  padding: 10px 10px 8px;
  border: 1px solid var(--ink-line);
  background-color: var(--paper);
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent 21px,
    rgba(34, 28, 21, 0.16) 21px,
    rgba(34, 28, 21, 0.16) 22px
  );
  border-radius: var(--r-1);
}

.doc__title {
  font-size: var(--fs-caption);
  font-weight: 700;
  line-height: 1.2;
}

.doc__note {
  font-size: 14px;
  line-height: 1.25;
  color: var(--ink-soft);
}

.methods {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.method {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  min-height: 56px;
  padding: 10px 12px;
  border: 1px solid var(--ink-line);
  border-radius: var(--r-2);
  background: var(--paper);
  text-align: left;
  font-size: var(--fs-body);
  line-height: 1.35;
  cursor: pointer;
}

.method[aria-pressed="true"] {
  border-color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--ink);
}

.method__num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  flex: none;
  border: 1px solid var(--ink-line);
  border-radius: 50%;
  font-family: var(--font-title);
  font-size: 17px;
  line-height: 1;
}

.mechanic__hint {
  font-size: 14px;
  line-height: 1.4;
  color: var(--ink-soft);
}

.attempts {
  align-self: flex-start;
  margin: 0;
  font-family: var(--font-title);
  font-size: 15px;
  letter-spacing: 0.04em;
  line-height: 1.35;
  color: var(--rust);
}

.attempts--spent {
  align-self: flex-start;
  margin: 0;
  font-size: var(--fs-caption);
  line-height: 1.35;
  color: var(--ink-soft);
}

.rev-table {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--ink-line);
  border-radius: var(--r-2);
  background: var(--paper);
}

.rev-head {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) minmax(0, 1fr);
  gap: 6px;
  padding: 8px;
  border-bottom: 1px solid var(--ink-line);
  background: var(--paper-deep);
  font-size: 12px;
  line-height: 1.2;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.rev-head__day {
  font-weight: 700;
}

.rev-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) minmax(0, 1fr);
  gap: 6px;
  align-items: center;
  width: 100%;
  min-height: 44px;
  padding: 8px;
  border: 0;
  border-bottom: 1px solid var(--ink-line);
  background: transparent;
  text-align: left;
  font-family: var(--font-body);
  font-size: 17px;
  cursor: pointer;
}

.rev-row:last-child {
  border-bottom: 0;
}

.rev-row[aria-pressed="true"],
.rev-row.is-picked {
  background: var(--paper-hi);
  box-shadow: inset 3px 0 0 var(--rust);
}

.rev-row__day {
  font-family: var(--font-title);
  font-size: 18px;
  font-weight: 700;
}

.rev-row__num {
  font-variant-numeric: tabular-nums;
}

.rev-row__note {
  grid-column: 1 / -1;
  padding-left: 2px;
  font-size: 13px;
  line-height: 1.25;
  color: var(--ink-soft);
}

.rev-count,
.mix-count {
  margin: 0;
  font-size: 14px;
  line-height: 1.35;
  color: var(--ink-soft);
}

.units {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0 2px;
  border-top: 1px dashed var(--ink-line);
}

.units__label {
  max-width: 16ch;
  font-size: 15px;
  line-height: 1.25;
}

.units__row {
  display: flex;
  flex: none;
  align-items: center;
  gap: 8px;
}

.units__step {
  width: 44px;
  height: 44px;
  min-width: 44px;
  border: 1px solid var(--ink-line);
  border-radius: 50%;
  background: var(--paper);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.units__step:disabled {
  opacity: 0.35;
  cursor: default;
}

.units__value {
  min-width: 44px;
  text-align: center;
  font-family: var(--font-title);
  font-size: 24px;
  font-variant-numeric: tabular-nums;
}

.widget-note {
  margin: 0;
  padding: 8px 10px;
  border-left: 3px solid var(--rust);
  background: var(--paper);
  font-size: 14px;
  line-height: 1.35;
}

.widget-note[hidden] {
  display: none;
}

.other {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 4px;
  border-top: 1px solid var(--ink-line);
}

.other__sep {
  margin: 8px 0 0;
  font-family: var(--font-title);
  font-size: 18px;
  text-align: center;
  color: var(--ink-soft);
}

.other__choice {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 56px;
  padding: 12px 14px;
  border: 1px solid var(--ink-line);
  border-radius: var(--r-2);
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 17px;
  line-height: 1.3;
  text-align: left;
  cursor: pointer;
}

.other__choice:active {
  background: var(--paper-deep);
}

.confirm {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--ink);
  border-radius: var(--r-2);
  background: var(--paper-hi);
}

.confirm[hidden] {
  display: none;
}

.confirm__text {
  margin: 0;
  font-size: 16px;
  line-height: 1.35;
}

.confirm__row {
  display: flex;
  gap: 10px;
}

.confirm__row .btn {
  flex: 1;
  min-height: 44px;
}

.confirm__no {
  background: transparent;
}

.presets {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.preset {
  min-height: 48px;
  align-items: center;
}

.preset__label {
  line-height: 1.3;
}

.frags {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.frag__legend {
  margin: 0;
  padding: 8px 10px;
  border-left: 3px solid var(--sepia);
  background: var(--paper);
  font-size: 14px;
  line-height: 1.35;
  color: var(--ink-soft);
}

.frag {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--ink-line);
  border-radius: var(--r-2);
  background: var(--paper);
  text-align: left;
  cursor: pointer;
}

.frag[aria-pressed="true"] {
  border-color: var(--ink);
  background: var(--paper-hi);
  box-shadow: inset 0 0 0 1px var(--ink);
}

.frag__label {
  font-family: var(--font-title);
  font-size: 15px;
  letter-spacing: 0.03em;
  color: var(--ink-soft);
}

.frag__layers {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.frag__layer {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.frag__layer[hidden] {
  display: none;
}

.frag__name {
  flex: none;
  width: 58px;
  font-size: 12px;
  line-height: 1.2;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.frag__chars {
  display: flex;
  gap: 1px;
  min-width: 0;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 15px;
  line-height: 1.2;
  white-space: nowrap;
}

.frag__char {
  display: inline-block;
  width: 1ch;
  text-align: center;
}

.frag__char.is-mark {
  border-radius: 1px;
  background: var(--ink);
  color: var(--paper);
  box-shadow: 0 0 0 1px var(--rust);
}

.radio {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  padding: var(--sp-3);
  border: 1px solid var(--ink-line);
  border-radius: var(--r-2);
  background: var(--paper);
}

.radio__row {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.radio__play {
  width: auto;
  min-width: var(--tap-min);
  flex: none;
  padding: 8px 12px;
  font-size: var(--fs-caption);
}

.radio__state {
  font-size: 14px;
  color: var(--ink-soft);
  line-height: 1.2;
}

.wave {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 54px;
  overflow: hidden;
}

.wave__bar {
  flex: 1 1 2px;
  min-width: 2px;
  background: var(--ink-soft);
  border-radius: 1px;
  opacity: 0.55;
}

.wave.is-live .wave__bar {
  animation: wave-pulse 820ms ease-in-out infinite alternate;
}

@keyframes wave-pulse {
  from {
    transform: scaleY(0.55);
    opacity: 0.45;
  }
  to {
    transform: scaleY(1);
    opacity: 0.85;
  }
}

.hints {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 0;
  margin: 0;
  list-style: none;
}

.hints li {
  padding: 6px 10px;
  border-left: 2px solid var(--sepia);
  font-size: var(--fs-caption);
  color: var(--ink-soft);
}

.hint-btn {
  align-self: flex-start;
  min-height: var(--tap-min);
  padding: 8px 12px;
  border: 1px solid var(--ink-line);
  border-radius: var(--r-2);
  background: transparent;
  font-size: var(--fs-caption);
  cursor: pointer;
}

.submit {
  margin-top: var(--sp-1);
}

.result {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  min-height: 100dvh;
  padding: max(30px, calc(var(--safe-top) + 18px)) var(--sp-5, 20px)
    max(30px, calc(var(--safe-bottom) + 18px));
  background: url("assets/art/ui/paper-frame-9x16.webp") center / 100% 100% no-repeat;
  overflow-wrap: anywhere;
}

.result__title {
  font-family: var(--font-title);
  font-size: var(--fs-h2);
  line-height: 1.15;
  font-weight: 400;
}

.result__lead {
  font-size: var(--fs-body);
  line-height: 1.45;
}

.echoes {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 0;
  list-style: none;
}

.echoes li {
  padding-left: 14px;
  position: relative;
  font-size: var(--fs-body);
  line-height: 1.4;
}

.echoes li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.62em;
  width: 6px;
  height: 6px;
  background: var(--ink-line);
}

.delta {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.delta__title {
  font-size: var(--fs-caption);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.delta__row {
  display: grid;
  grid-template-columns: 24px 1fr auto auto;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  font-size: var(--fs-body);
}

.delta__row img {
  width: 24px;
  height: 24px;
}

.delta__value {
  font-family: var(--font-title);
  font-size: 20px;
  font-variant-numeric: tabular-nums;
}

.delta__now {
  font-size: 14px;
  color: var(--ink-soft);
  min-width: 38px;
  text-align: right;
}

.delta__empty {
  font-size: var(--fs-caption);
  color: var(--ink-soft);
}

.part {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  min-height: 100dvh;
  padding: max(30px, calc(var(--safe-top) + 18px)) var(--sp-6)
    max(30px, calc(var(--safe-bottom) + 18px));
  background: url("assets/art/ui/paper-frame-9x16.webp") center / 100% 100% no-repeat;
}

.part__mark {
  width: 84px;
  height: 84px;
  object-fit: contain;
}

.part__title {
  font-family: var(--font-title);
  font-size: var(--fs-h1);
  line-height: 1.05;
  font-weight: 400;
}

.part__text {
  max-width: 30ch;
  font-size: var(--fs-lead);
  line-height: 1.45;
}

.turn {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  min-height: 100dvh;
  padding: max(30px, calc(var(--safe-top) + 18px)) var(--sp-6)
    max(30px, calc(var(--safe-bottom) + 18px));
  background: url("assets/art/ui/paper-frame-9x16.webp") center / 100% 100% no-repeat;
}

.turn__title {
  font-family: var(--font-title);
  font-size: var(--fs-h1);
  line-height: 1.05;
  font-weight: 400;
}

.turn__day {
  margin: 0;
  font-size: var(--fs-lead);
  letter-spacing: 0.04em;
  color: var(--rust);
}

.turn__text {
  max-width: 30ch;
  font-size: var(--fs-lead);
  line-height: 1.45;
}

.ending {
  display: flex;
  flex-direction: column;
  gap: 0;
  min-height: 100dvh;
  background: url("assets/art/ui/paper-frame-9x16.webp") center / 100% 100% no-repeat;
}

.ending__figure {
  position: relative;
  width: 100%;
  max-height: 46dvh;
  overflow: hidden;
  border-bottom: 1px solid var(--ink-line);
}

.ending__art {
  display: block;
  width: 100%;
  height: 100%;
  max-height: 46dvh;
  object-fit: cover;
  object-position: center 42%;
}

.ending__sheet {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  padding: var(--sp-6) var(--sp-6) max(30px, calc(var(--safe-bottom) + 18px));
  overflow-wrap: anywhere;
}

.ending__title {
  font-family: var(--font-title);
  font-size: var(--fs-h1);
  line-height: 1.05;
  font-weight: 400;
}

.ending__lead {
  max-width: 34ch;
  font-size: var(--fs-body);
  line-height: 1.5;
}

.ending__score {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: var(--sp-3) 0 var(--sp-2);
  border-top: 1px solid var(--ink-line);
  border-bottom: 1px solid var(--ink-line);
}

.ending__score-label {
  font-size: var(--fs-caption);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.ending__score-value {
  font-family: var(--font-title);
  font-size: clamp(64px, 20vw, 104px);
  line-height: 0.9;
  font-weight: 400;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.ending__score-line {
  max-width: 32ch;
  font-size: var(--fs-lead);
  line-height: 1.35;
}

.ending__best {
  font-size: var(--fs-caption);
  line-height: 1.35;
  color: var(--ink-soft);
}

.ending__behind {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: var(--sp-3);
  border: 1px solid var(--ink-line);
  background: var(--paper-hi);
}

.ending__behind-title {
  font-size: var(--fs-caption);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.ending__behind-text {
  font-size: var(--fs-body);
  line-height: 1.45;
}

.triage {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.triage__title {
  font-family: var(--font-title);
  font-size: var(--fs-h3);
  line-height: 1.15;
}

.triage__rule {
  padding: var(--sp-3);
  border-left: 3px solid var(--rust);
  background: var(--paper-hi);
  font-size: var(--fs-lead);
  line-height: 1.4;
}

.patients {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--sp-3);
}

.patient {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: var(--sp-3);
  border: 1px solid var(--ink-line);
  background: var(--paper-hi);
}

.patient__name {
  font-family: var(--font-title);
  font-size: var(--fs-h3);
  line-height: 1.1;
  font-weight: 400;
}

.patient__text {
  font-size: var(--fs-body);
  line-height: 1.4;
}

.patient__lines {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0;
  list-style: none;
  font-size: var(--fs-caption);
  color: var(--ink-soft);
}

.patient__source {
  font-weight: 700;
}

.triage__choices {
  display: flex;
  flex-direction: column;
  gap: var(--tap-gap);
}

.scheme {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.scheme__legend {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: var(--sp-2) var(--sp-3);
  border-left: 3px solid var(--sepia);
  background: var(--paper);
  font-size: 14px;
  line-height: 1.4;
  color: var(--ink-soft);
}

.scheme__legend p {
  margin: 0;
}

.zone {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  min-height: var(--tap-primary);
  padding: var(--sp-3);
  text-align: left;
  border: 1px solid var(--ink-line);
  border-radius: var(--r-1);
  background: var(--paper-hi);
}

.zone.is-picked {
  border-color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--ink);
}

.zone__name {
  font-family: var(--font-title);
  font-size: var(--fs-h3);
  line-height: 1.15;
}

.zone__rows {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.zone__row {
  display: grid;
  grid-template-columns: minmax(84px, 1fr) 1.6fr;
  gap: 8px;
  font-size: 15px;
}

.zone__source {
  color: var(--ink-soft);
}

.zone__value {
  line-height: 1.35;
}

.choice.is-waiting {
  opacity: 0.6;
}

.sheet {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  background-color: var(--paper);
  background-image: url("assets/art/ui/paper-tile-512.webp");
  background-size: 512px 512px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.sheet__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding:
    max(12px, var(--safe-top))
    max(16px, var(--safe-right))
    8px
    max(16px, var(--safe-left));
  border-bottom: 1px solid var(--ink-line);
}

.sheet__title {
  font-family: var(--font-title);
  font-size: var(--fs-h3);
  font-weight: 400;
}

.sheet__body {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  padding:
    16px
    max(16px, var(--safe-right))
    max(24px, var(--safe-bottom))
    max(16px, var(--safe-left));
}

.menu-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding-bottom: var(--sp-3);
  border-bottom: 1px solid var(--ink-line);
}

.menu-row__text {
  min-width: 0;
}

.menu-row__title {
  font-size: var(--fs-lead);
}

.menu-row__hint {
  font-size: var(--fs-caption);
  line-height: 1.35;
  color: var(--ink-soft);
}

.switch {
  min-width: 92px;
  min-height: var(--tap-min);
  padding: 8px 12px;
  flex: none;
  border: 1px solid var(--ink);
  border-radius: var(--r-2);
  background: var(--paper-hi);
  font-size: var(--fs-caption);
  cursor: pointer;
}

.switch[aria-pressed="true"] {
  background: var(--ink);
  color: var(--paper-hi);
}

.menu-restart {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.menu-row__hint[hidden] {
  display: none;
}

.menu-meta {
  margin-top: auto;
  padding-top: var(--sp-6);
  font-size: 14px;
  color: var(--ink-soft);
}

.boot {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-3);
  padding: var(--sp-6);
  background-color: var(--paper);
  background-image: url("assets/art/ui/paper-tile-512.webp");
  background-size: 512px 512px;
  text-align: center;
}

.boot__mark {
  width: 88px;
  height: 88px;
  object-fit: contain;
  opacity: 0.85;
}

.boot__text {
  font-family: var(--font-title);
  font-size: var(--fs-h3);
  color: var(--ink-soft);
}

.boot .btn {
  width: auto;
  min-width: 180px;
}

.namegate {
  position: fixed;
  inset: 0;
  z-index: 45;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow-y: auto;
  padding:
    max(20px, env(safe-area-inset-top))
    max(14px, env(safe-area-inset-right))
    max(20px, env(safe-area-inset-bottom))
    max(14px, env(safe-area-inset-left));
  background:
    linear-gradient(rgba(233, 223, 199, 0.86), rgba(233, 223, 199, 0.86)),
    url("../assets/art/ui/paper-tile-512.webp") repeat;
}

.namegate__card {
  width: min(100%, 360px);
  padding: 24px 20px 20px;
  border: 1px solid var(--ink-line);
  border-radius: var(--r-2);
  background: var(--paper-hi);
}

.namegate__stamp {
  margin: 0 0 18px;
  font-size: 14px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.namegate__title {
  margin: 0;
  font-family: var(--font-title);
  font-size: clamp(30px, 8vw, 38px);
  line-height: 1.04;
  font-weight: 400;
}

.namegate__lead {
  margin: 10px 0 22px;
  font-size: 17px;
  line-height: 1.3;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.namegate__label {
  display: block;
  margin-bottom: 6px;
  font-size: 16px;
  color: var(--ink-soft);
}

.namegate__input {
  width: 100%;
  min-height: 56px;
  padding: 10px 12px;
  border: 1px solid var(--ink);
  border-radius: var(--r-2);
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-size: 18px;
}

.namegate__input:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 2px;
}

.namegate__hint {
  margin: 8px 0 0;
  font-size: 16px;
  line-height: 1.25;
  color: var(--ink-soft);
}

.namegate__error {
  margin: 8px 0 0;
  font-size: 16px;
  line-height: 1.25;
  color: var(--rust);
}

.namegate__next {
  width: 100%;
  margin-top: 18px;
}

.intro {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: var(--ink);
  opacity: 1;
  transition: opacity 220ms linear;
}

.intro.is-done {
  opacity: 0;
  pointer-events: none;
}

.intro__frame {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 220ms linear;
}

.intro__frame.is-active {
  opacity: 1;
}

.intro__img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 42%;
  transform: scale(1);
  transition: transform 1400ms linear;
}

.intro__frame.is-zoom .intro__img {
  transform: scale(1.015);
}

.intro__skip {
  position: absolute;
  right: max(16px, var(--safe-right));
  bottom: max(16px, var(--safe-bottom));
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: var(--tap-min);
  padding: 8px 14px;
  border: 1px solid rgba(233, 223, 199, 0.7);
  border-radius: var(--r-2);
  background: rgba(34, 28, 21, 0.72);
  color: var(--paper-hi);
  font-size: var(--fs-caption);
  cursor: pointer;
}

.intro__skip-icon {
  flex: none;
  width: 18px;
  height: 18px;
}

.intro__skip span {
  line-height: 1.1;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(18px, calc(var(--safe-bottom) + 12px));
  z-index: 60;
  width: min(92vw, 420px);
  transform: translateX(-50%);
  padding: 10px 14px;
  border: 1px solid var(--ink);
  border-radius: var(--r-2);
  background: var(--paper-hi);
  box-shadow: 0 4px 0 rgba(34, 28, 21, 0.18);
  font-size: var(--fs-caption);
  line-height: 1.35;
  text-align: center;
}

.noscript {
  padding: var(--sp-6);
  font-size: var(--fs-lead);
}

@media (max-width: 360px) {
  :root {
    --fs-body: 16px;
    --fs-lead: 18px;
  }

  .resources {
    gap: 4px;
  }

  .resource {
    gap: 3px;
    padding: 4px;
    min-height: 44px;
  }

  .resource__icon {
    width: 18px;
    height: 18px;
  }

  .resource__value {
    font-size: 19px;
  }

  .resource__label {
    font-size: 16px;
    letter-spacing: -0.01em;
  }

  .resource__slash {
    left: 3px;
    width: 18px;
    height: 18px;
  }

  .doc__note {
    font-size: 13px;
  }

  .frag__name {
    width: 48px;
    font-size: 11px;
  }

  .frag__chars {
    font-size: 14px;
  }

  .rev-head,
  .rev-row {
    grid-template-columns: 30px minmax(0, 1fr) minmax(0, 1fr);
    gap: 5px;
  }
}

@media (max-height: 660px) {
  .scene {
    height: 168px;
  }

  .app {
    gap: 8px;
  }
}

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

  .intro__frame.is-zoom .intro__img {
    transform: none;
  }

  .wave.is-live .wave__bar {
    animation: none;
  }
}
