:root {
  --paper: #f4f1ea;
  --paper-deep: #e8e3d9;
  --ink: #171717;
  --muted: #716c64;
  --rule: #aaa399;
  --red: #a52323;
  --green: #315c45;
  --shadow: rgba(25, 22, 18, .18);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: #d9d4cb;
  font-family: Georgia, "Times New Roman", serif;
}
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }

.masthead {
  width: min(1180px, calc(100% - 32px));
  margin: 24px auto 0;
  padding: 26px 42px 24px;
  background: var(--paper);
  border-bottom: 3px double var(--ink);
  text-align: center;
}
.masthead-line {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 18px;
  padding-bottom: 15px;
  border-bottom: 1px solid var(--ink);
  font: 10px/1.4 "Courier New", monospace;
  letter-spacing: .17em;
}
.masthead-line span:first-child { text-align: left; }
.masthead-line span:last-child { text-align: right; }
.masthead h1 { margin: 20px 0 2px; font-size: clamp(42px, 8vw, 78px); line-height: .95; }
.masthead p { margin: 12px 0 0; font-style: italic; color: #4e4a45; }

.shell {
  display: grid;
  grid-template-columns: 245px minmax(0, 1fr);
  width: min(1180px, calc(100% - 32px));
  min-height: 670px;
  margin: 0 auto 32px;
  background: var(--paper);
  box-shadow: 0 16px 40px var(--shadow);
}
.sidebar { padding: 30px 20px; border-right: 1px solid var(--ink); background: rgba(0, 0, 0, .025); }
.identity { padding-bottom: 22px; border-bottom: 1px solid var(--rule); }
.identity small, .section-header small { display: block; font: 10px/1.5 "Courier New", monospace; letter-spacing: .14em; color: var(--red); }
.identity strong { display: block; margin-top: 8px; font-size: 18px; }
.identity span { display: block; margin-top: 3px; color: var(--muted); font-size: 13px; }
nav { display: grid; gap: 7px; margin-top: 24px; }
.nav-button { padding: 11px 12px; border: 0; border-left: 3px solid transparent; text-align: left; background: transparent; }
.nav-button:hover, .nav-button.active { border-left-color: var(--red); background: rgba(165, 35, 35, .07); }
.quota { margin-top: 32px; padding-top: 18px; border-top: 1px dashed var(--rule); font: 11px/1.7 "Courier New", monospace; color: var(--muted); }

main { min-width: 0; padding: 32px 38px 48px; }
.view { display: none; }
.view.active { display: block; }
.section-header { display: flex; justify-content: space-between; gap: 20px; align-items: end; margin-bottom: 28px; padding-bottom: 13px; border-bottom: 2px solid var(--ink); }
.section-header h2 { margin: 2px 0 0; font-size: 34px; }
.save-state { color: var(--muted); font: 11px "Courier New", monospace; }

.cards { display: grid; gap: 14px; }
.story-card { display: grid; grid-template-columns: 120px 1fr auto; gap: 18px; align-items: center; padding: 18px; border: 1px solid var(--rule); background: rgba(255,255,255,.18); }
.story-card:hover { border-color: var(--ink); }
.story-card .stamp { font: 10px/1.5 "Courier New", monospace; text-transform: uppercase; letter-spacing: .08em; color: var(--red); }
.story-card h3 { margin: 0 0 6px; font-size: 20px; }
.story-card p { margin: 0; color: var(--muted); font-size: 14px; }
.story-card button { white-space: nowrap; }
.empty { padding: 45px 20px; border: 1px dashed var(--rule); text-align: center; color: var(--muted); font-style: italic; }

.paper-form { display: grid; gap: 18px; }
label { display: grid; gap: 7px; font-size: 13px; font-weight: 700; letter-spacing: .03em; }
input, textarea, select { width: 100%; border: 1px solid var(--rule); border-radius: 0; padding: 10px 11px; color: var(--ink); background: rgba(255,255,255,.28); }
textarea { resize: vertical; line-height: 1.55; }
input:focus, textarea:focus, select:focus { outline: 2px solid rgba(165,35,35,.25); border-color: var(--red); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.form-actions { display: flex; justify-content: flex-end; gap: 12px; padding-top: 8px; }
.ink-button, .paper-button { border: 1px solid var(--ink); padding: 10px 16px; text-transform: uppercase; letter-spacing: .09em; font: 11px "Courier New", monospace; }
.ink-button { background: var(--ink); color: var(--paper); }
.paper-button { background: transparent; color: var(--ink); }
.ink-button:disabled, .paper-button:disabled { opacity: .45; cursor: not-allowed; }

.invite-form { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; align-items: end; padding: 18px; border: 1px solid var(--rule); }
.user-list { margin-top: 24px; }
.user-row { display: grid; grid-template-columns: 1.4fr 1fr 1fr auto; gap: 12px; padding: 12px 4px; border-bottom: 1px dotted var(--rule); align-items: center; }
.user-row small { color: var(--muted); }

.fatal { width: min(760px, calc(100% - 32px)); margin: 50px auto; padding: 30px; border: 2px solid var(--red); background: var(--paper); text-align: center; }
.fatal strong { font-size: 24px; }
.toast { position: fixed; right: 22px; bottom: 22px; max-width: 390px; padding: 15px 18px; color: var(--paper); background: var(--ink); box-shadow: 0 8px 24px var(--shadow); }
.toast.error { background: var(--red); }
dialog { width: min(760px, calc(100% - 30px)); max-height: 85vh; overflow: auto; border: 2px solid var(--ink); padding: 30px; color: var(--ink); background: var(--paper); box-shadow: 0 18px 60px rgba(0,0,0,.35); }
dialog::backdrop { background: rgba(20,18,15,.68); }
.dialog-close { float: right; border: 0; background: transparent; font-size: 28px; }
.process-body { white-space: pre-wrap; line-height: 1.6; }
.process-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 24px; padding-top: 18px; border-top: 1px solid var(--rule); }

@media (max-width: 760px) {
  .masthead, .shell { width: 100%; margin-top: 0; }
  .masthead { padding: 18px; }
  .masthead-line { grid-template-columns: 1fr auto; }
  .masthead-line span:last-child { display: none; }
  .shell { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--ink); }
  nav { grid-template-columns: repeat(2, 1fr); }
  main { padding: 24px 18px 38px; }
  .story-card { grid-template-columns: 1fr; }
  .form-grid, .invite-form { grid-template-columns: 1fr; }
  .user-row { grid-template-columns: 1fr 1fr; }
}
