:root {
  --bg: #ebe5d9;
  --paper: #fffdf8;
  --ink: #1d1b18;
  --muted: #777064;
  --line: #d7d0c3;
  --accent: #8f2f25;
  --soft: #f4efe4;
  --shadow: 0 24px 70px rgb(57 46 28 / 14%);
  --paper-rotate: 0deg;
  --paper-scale: 1;
  --section-drift: 0px;
  --storm-opacity: 1;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--ink); }
body { overflow-x: hidden; }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.app { min-height: 100vh; padding: 18px; }
.shell { width: min(1380px, 100%); margin: 0 auto; position: relative; }
.topbar { display: flex; gap: 12px; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brandmark { width: 34px; height: 34px; border: 1px solid var(--ink); display: grid; place-items: center; font-family: Georgia, serif; font-weight: 700; background: var(--paper); box-shadow: 3px 3px 0 var(--ink); flex: 0 0 auto; }
.brand-copy { min-width: 0; }
.brand strong { display: block; letter-spacing: .02em; }
.tagline { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.btn { border: 1px solid var(--line); background: rgb(255 255 255 / 50%); color: var(--ink); border-radius: 999px; padding: 8px 12px; min-height: 38px; transition: transform .18s ease, background .18s ease, border-color .18s ease; }
.btn:hover { transform: translateY(-1px); background: var(--paper); }
.btn.primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.danger { color: var(--accent); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }

.stage { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(280px, .55fr); gap: 14px; align-items: start; }
.paper-wrap { position: relative; perspective: 1200px; }
.paper { background: var(--paper); box-shadow: var(--shadow); min-height: 76vh; border: 1px solid rgb(70 56 36 / 12%); padding: clamp(28px, 5vw, 72px); position: relative; overflow: hidden; transform: rotate(var(--paper-rotate)) scale(var(--paper-scale)); transform-origin: 50% 10%; transition: transform 280ms ease, box-shadow 280ms ease, filter 280ms ease; }
.paper::before { content: ""; position: absolute; left: clamp(24px, 4vw, 54px); top: 0; bottom: 0; width: 1px; background: rgb(143 47 37 / 13%); }
.paper::after { content: ""; position: absolute; inset: 0; pointer-events: none; opacity: 0; background: repeating-linear-gradient(0deg, transparent 0 28px, rgb(143 47 37 / 2.5%) 28px 29px); transition: opacity 250ms ease; }
.paper-head { text-align: center; padding: 8px 4% 28px; border-bottom: 1px solid var(--line); margin-bottom: 24px; position: relative; z-index: 1; }
.paper-kicker { font: 600 11px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .16em; text-transform: uppercase; color: var(--muted); }
h1 { font: 700 clamp(26px, 4vw, 46px)/1.06 Georgia, "Times New Roman", serif; margin: 12px 0 10px; }
.authors { font: italic 14px/1.5 Georgia, serif; color: var(--muted); }
.sections { position: relative; z-index: 1; }
.section { position: relative; padding: 0 0 22px 18px; transform: translateX(var(--section-drift)); transition: opacity .18s ease, transform .18s ease; }
.section:nth-child(even) { transform: translateX(calc(var(--section-drift) * -1)); }
.section::before { content: ""; position: absolute; left: 0; top: .45em; width: 6px; height: 6px; border-radius: 50%; background: var(--line); }
.section.active::before { background: var(--accent); box-shadow: 0 0 0 6px rgb(143 47 37 / 8%); }
.section.done { opacity: .72; }
.section h2 { font: 700 15px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .06em; text-transform: uppercase; margin: 0 0 8px; }
.section p { font: 17px/1.72 Georgia, "Times New Roman", serif; margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.cursor { display: inline-block; color: var(--accent); animation: blink .9s steps(2, end) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.progress { height: 3px; background: rgb(0 0 0 / 8%); position: sticky; top: 0; z-index: 4; }
.progress span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .12s linear; }

.panel { display: grid; gap: 12px; position: sticky; top: 18px; }
.card { background: rgb(255 253 248 / 74%); backdrop-filter: blur(12px); border: 1px solid rgb(70 56 36 / 14%); border-radius: 18px; padding: 14px; }
.card h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .1em; margin: 0 0 10px; color: var(--muted); }
.status { display: grid; grid-template-columns: 1fr auto; gap: 7px; font-size: 13px; }
.status span:nth-child(even) { font-variant-numeric: tabular-nums; color: var(--muted); max-width: 16rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.range-row { display: grid; grid-template-columns: 1fr auto; gap: 7px; margin-top: 12px; align-items: center; }
.range-row label { font-size: 12px; color: var(--muted); }
input[type="range"] { grid-column: 1 / -1; width: 100%; accent-color: var(--accent); }
.privacy { font-size: 11px; line-height: 1.45; color: var(--muted); margin-top: 8px; }

.keyboard { display: grid; grid-template-columns: repeat(10, 1fr); gap: 5px; }
.key { min-width: 0; padding: 8px 2px; border: 1px solid var(--line); border-radius: 7px; text-align: center; font: 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace; background: rgb(255 255 255 / 55%); transition: .08s; user-select: none; }
.key.live { background: var(--ink); color: #fff; transform: translateY(-2px) scale(1.04); }
.feed { display: grid; gap: 6px; max-height: 150px; overflow: auto; }
.feed-item { display: flex; justify-content: space-between; gap: 12px; padding-bottom: 6px; border-bottom: 1px dashed var(--line); font: 11px/1.35 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); }

.pdf-progress { display: grid; gap: 9px; }
.pdf-progress-row { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; color: var(--muted); }
.meter { height: 7px; border-radius: 999px; overflow: hidden; background: rgb(0 0 0 / 8%); }
.meter span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .15s linear; }

.hero { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 22px; background: rgb(235 229 217 / 86%); backdrop-filter: blur(10px); transition: .3s; }
.hero.hidden { opacity: 0; pointer-events: none; visibility: hidden; }
.hero-card { width: min(720px, 100%); background: var(--paper); padding: clamp(28px, 6vw, 64px); box-shadow: var(--shadow); border: 1px solid rgb(70 56 36 / 16%); text-align: center; }
.hero .eyebrow { font: 600 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--accent); letter-spacing: .14em; text-transform: uppercase; }
.hero h2 { font: 700 clamp(38px, 7vw, 76px)/.95 Georgia, serif; margin: 18px 0 16px; }
.hero p { max-width: 560px; margin: 0 auto 24px; color: var(--muted); line-height: 1.6; }
.hero-actions { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; }
.hint { margin-top: 16px; font: 11px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); }

dialog { border: 0; border-radius: 18px; padding: 0; width: min(760px, calc(100vw - 28px)); box-shadow: 0 30px 100px rgb(0 0 0 / 28%); background: var(--paper); color: var(--ink); }
dialog::backdrop { background: rgb(20 18 14 / 42%); backdrop-filter: blur(4px); }
.dialog-body { padding: 20px; }
.dialog-head { display: flex; justify-content: space-between; gap: 12px; align-items: start; margin-bottom: 14px; }
.dialog-head h2 { font: 700 28px/1.05 Georgia, serif; margin: 0; }
.dialog-head p { margin: 6px 0 0; color: var(--muted); font-size: 13px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.text-input { width: 100%; min-height: 320px; resize: vertical; border: 1px solid var(--line); border-radius: 12px; padding: 14px; background: #fff; color: var(--ink); font: 14px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; outline: none; }
.text-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgb(143 47 37 / 9%); }
.drop { border: 1px dashed var(--line); padding: 16px; border-radius: 12px; text-align: center; color: var(--muted); font-size: 13px; margin-top: 10px; }
.drop.drag { border-color: var(--accent); background: rgb(143 47 37 / 4%); }

#storm { position: fixed; inset: 0; z-index: 12; pointer-events: none; opacity: var(--storm-opacity); }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 12px); z-index: 30; background: var(--ink); color: white; padding: 10px 14px; border-radius: 999px; font-size: 12px; opacity: 0; pointer-events: none; transition: .2s; max-width: calc(100vw - 24px); text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

body.chaos-1 { --paper-rotate: -.08deg; }
body.chaos-2 { --paper-rotate: .16deg; --section-drift: .7px; }
body.chaos-2 .paper::after { opacity: .38; }
body.chaos-3 { --paper-rotate: -.32deg; --section-drift: 1.6px; }
body.chaos-3 .paper { box-shadow: 0 30px 90px rgb(57 46 28 / 21%); }
body.chaos-3 .paper::after { opacity: .7; }
body.chaos-3 .cursor { animation-duration: .48s; }
body.chaos-4 { --paper-rotate: .55deg; --paper-scale: 1.003; --section-drift: 3px; }
body.chaos-4 .paper { box-shadow: 0 38px 120px rgb(57 46 28 / 28%); filter: contrast(1.015); }
body.chaos-4 .paper::after { opacity: 1; }
body.chaos-4 .section.active h2 { letter-spacing: .095em; }

html.cinema body { background: #12100d; }
html.cinema .app { padding: 0; }
html.cinema .shell { width: 100%; }
html.cinema .topbar, html.cinema .panel { display: none; }
html.cinema .stage { display: block; }
html.cinema .progress { position: fixed; top: 0; left: 0; right: 0; z-index: 10; background: rgb(255 255 255 / 10%); }
html.cinema .paper-wrap { min-height: 100vh; display: grid; place-items: start center; padding: clamp(16px, 4vw, 46px); }
html.cinema .paper { width: min(980px, calc(100vw - 24px)); min-height: calc(100vh - clamp(32px, 8vw, 92px)); border-radius: 2px; }
html.cinema .cinema-exit { display: block; }
.cinema-exit { display: none; position: fixed; z-index: 18; right: 14px; bottom: 14px; border-color: rgb(255 255 255 / 20%); color: #fff; background: rgb(20 18 14 / 72%); }

@media (max-width: 900px) {
  .stage { grid-template-columns: 1fr; }
  .panel { position: static; grid-template-columns: 1fr 1fr; }
  .paper { min-height: 68vh; }
  .keyboard { grid-template-columns: repeat(8, 1fr); }
}

@media (max-width: 680px) {
  .app { padding: 10px; }
  .tagline { display: none; }
  .actions .label { display: none; }
  .panel { grid-template-columns: 1fr; }
  .paper { padding: 28px 22px 42px; }
  .paper::before { left: 14px; }
  .section p { font-size: 16px; }
  .keyboard { grid-template-columns: repeat(6, 1fr); }
  .status span:nth-child(even) { max-width: 10rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
  .cursor { animation: none; }
  .btn, .key, .hero, .toast, .paper, .section { transition: none !important; }
}
