:root {
  --paper: #f5efe3;
  --paper-soft: #fbf7ef;
  --paper-card: #fffdf8;
  --ink: #211d18;
  --ink-soft: #5f574b;
  --ink-faint: #8a8172;
  --line: #ded3bf;
  --line-strong: #c9bba1;
  --accent: #9a4f2f;
  --accent-deep: #7d3d22;
  --green: #3c5a45;
  --danger: #9b2c2c;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia,
    "Times New Roman", serif;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, sans-serif;
  --shadow: 0 24px 50px -38px rgba(52, 38, 20, 0.5);
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--sans);
  background:
    radial-gradient(1100px 560px at 12% -8%, rgba(255, 255, 255, 0.8), transparent 62%),
    radial-gradient(900px 520px at 102% 2%, rgba(216, 196, 160, 0.32), transparent 66%),
    var(--paper);
}

a {
  color: inherit;
}

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

button {
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid rgba(154, 79, 47, 0.55);
  outline-offset: 2px;
}

.shell {
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding-left: 32px;
  padding-right: 32px;
}

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

/* ---------- Header ---------- */

.topbar {
  border-bottom: 1px solid rgba(201, 187, 161, 0.45);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding-top: 26px;
  padding-bottom: 26px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  font-family: var(--serif);
  font-size: 1.3rem;
  letter-spacing: 0.01em;
  text-decoration: none;
}

.brand-seal {
  position: relative;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, #b8683f, var(--accent-deep) 72%);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.25),
    0 1px 2px rgba(60, 30, 10, 0.25);
}

.brand-seal::after {
  content: "";
  position: absolute;
  inset: 7px;
  border-radius: 50%;
  border: 1px solid rgba(255, 246, 232, 0.55);
}

.topnav {
  display: flex;
  gap: 26px;
  font-size: 0.82rem;
  letter-spacing: 0.04em;
}

.topnav a {
  padding-bottom: 2px;
  color: var(--ink-soft);
  text-decoration: none;
  border-bottom: 1px solid transparent;
}

.topnav a:hover {
  color: var(--ink);
  border-color: var(--line-strong);
}

/* ---------- Page layout ---------- */

.page {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(320px, 0.9fr);
  gap: 52px;
  align-items: start;
  padding-top: 54px;
  padding-bottom: 64px;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  color: var(--accent);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.eyebrow::before {
  content: "";
  width: 26px;
  height: 1px;
  background: currentColor;
  opacity: 0.55;
}

h1 {
  margin: 14px 0 18px;
  font-family: var(--serif);
  font-size: clamp(2.4rem, 4.6vw, 3.5rem);
  font-weight: 400;
  line-height: 1.1;
  letter-spacing: -0.015em;
}

.prompt {
  min-height: 1.5em;
  margin: 0 0 16px;
  font-family: var(--serif);
  font-size: 1.02rem;
  font-style: italic;
  line-height: 1.6;
  color: var(--ink-faint);
  opacity: 0;
  transition: opacity 240ms ease;
}

.prompt.is-visible {
  opacity: 1;
}

/* ---------- Letter sheet ---------- */

.sheet {
  position: relative;
  overflow: hidden;
  background: var(--paper-card);
  border: 1px solid var(--line);
  border-radius: 3px;
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.sheet::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), #c98a5f 45%, rgba(201, 138, 95, 0.15));
  opacity: 0.75;
}

#body {
  display: block;
  width: 100%;
  min-height: 360px;
  max-height: 62vh;
  padding: 34px 30px 10px;
  border: 0;
  background: transparent;
  font-family: var(--serif);
  font-size: 1.1rem;
  line-height: 1.9;
  resize: vertical;
  outline: none;
}

#body::placeholder {
  color: #a89e8d;
  font-style: italic;
}

.sheet-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 24px 16px;
  border-top: 1px dashed rgba(201, 187, 161, 0.8);
}

.inspire {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border: 0;
  border-bottom: 1px solid var(--line-strong);
  background: none;
  color: var(--ink-soft);
  font-size: 0.8rem;
  letter-spacing: 0.05em;
}

.inspire:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.counter {
  color: var(--ink-faint);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  font-variant-numeric: tabular-nums;
}

.counter.is-near {
  color: var(--accent);
}

.counter.is-full {
  color: var(--danger);
  font-weight: 600;
}

.letter-note {
  margin: 16px 0 0;
  max-width: 46ch;
  font-size: 0.78rem;
  line-height: 1.7;
  color: var(--ink-faint);
}

/* ---------- Dispatch column ---------- */

.dispatch-col {
  display: grid;
  gap: 18px;
  position: sticky;
  top: 24px;
}

.card {
  padding: 30px;
  background: rgba(255, 253, 248, 0.86);
  border: 1px solid var(--line);
  border-radius: 3px;
  box-shadow: var(--shadow);
}

.card h2 {
  margin: 0 0 24px;
  font-family: var(--serif);
  font-size: 1.5rem;
  font-weight: 400;
}

.field {
  display: grid;
  gap: 8px;
  margin: 0 0 20px;
  padding: 0;
  border: 0;
}

.field label,
.field legend,
.custom-label {
  padding: 0;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.field input,
.copy-row input {
  width: 100%;
  padding: 12px 14px;
  background: var(--paper-card);
  border: 1px solid var(--line-strong);
  border-radius: 2px;
  font-size: 0.95rem;
  transition: border-color 160ms ease;
}

.field input:hover,
.copy-row input:hover {
  border-color: var(--ink-faint);
}

.field input:focus {
  border-color: var(--accent);
  outline: 2px solid rgba(154, 79, 47, 0.22);
  outline-offset: 1px;
}

.turnstile-field {
  margin-bottom: 18px;
}

.turnstile-label {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.turnstile-widget {
  min-height: 65px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 4px;
}

.chip {
  padding: 9px 14px;
  background: var(--paper-card);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  font-size: 0.8rem;
  letter-spacing: 0.02em;
  color: var(--ink-soft);
  transition:
    background 160ms ease,
    color 160ms ease,
    border-color 160ms ease;
}

.chip:hover {
  border-color: var(--ink);
  color: var(--ink);
}

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

.custom-label {
  margin-top: 14px;
}

.arrival {
  min-height: 1.4em;
  margin: 4px 0 0;
  padding-top: 10px;
  border-top: 1px dashed rgba(201, 187, 161, 0.8);
  font-family: var(--serif);
  font-size: 0.98rem;
  line-height: 1.5;
  color: var(--ink-soft);
}

.arrival.is-warning {
  color: var(--danger);
}

.primary {
  width: 100%;
  padding: 15px 20px;
  background: var(--ink);
  border: 1px solid var(--ink);
  border-radius: 2px;
  color: #f8f3e8;
  font-size: 0.9rem;
  letter-spacing: 0.05em;
  transition:
    background 160ms ease,
    transform 120ms ease;
}

.primary:hover:not(:disabled) {
  background: #3a332a;
}

.primary:active:not(:disabled) {
  transform: translateY(1px);
}

.primary:disabled {
  opacity: 0.6;
  cursor: progress;
}

.fine {
  margin: 14px 0 0;
  font-size: 0.76rem;
  line-height: 1.65;
  color: var(--ink-faint);
}

.form-error {
  margin: 0 0 16px;
  padding: 10px 12px;
  background: #fbf0ec;
  border: 1px solid #e5c4b6;
  border-radius: 2px;
  color: #8a3320;
  font-size: 0.82rem;
  line-height: 1.5;
}

.form-error[hidden] {
  display: none;
}

.mini-card {
  padding: 22px 26px;
  background: rgba(255, 253, 248, 0.45);
  border: 1px dashed var(--line-strong);
  border-radius: 3px;
}

.mini-card h3 {
  margin: 0 0 10px;
  font-family: var(--serif);
  font-size: 1rem;
  font-weight: 400;
}

.mini-card ol {
  margin: 0;
  padding-left: 18px;
  color: var(--ink-soft);
  font-size: 0.8rem;
  line-height: 1.7;
}

.mini-card li + li {
  margin-top: 4px;
}

/* ---------- Dialogs ---------- */

.dialog {
  max-width: 100vw;
  max-height: 100vh;
  padding: 0;
  border: 0;
  background: transparent;
}

.dialog::backdrop {
  background: rgba(28, 22, 15, 0.55);
  backdrop-filter: blur(2px);
}

.dialog-inner {
  width: min(460px, calc(100vw - 32px));
  padding: 38px;
  background: var(--paper-soft);
  border: 1px solid var(--line);
  border-radius: 4px;
  box-shadow: 0 36px 70px -28px rgba(20, 14, 8, 0.6);
}

.dialog[open] .dialog-inner {
  animation: rise 220ms ease-out;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.dialog h2 {
  margin: 12px 0 12px;
  font-family: var(--serif);
  font-size: 1.85rem;
  font-weight: 400;
  line-height: 1.2;
}

.dialog-text {
  margin: 0 0 20px;
  font-size: 0.9rem;
  line-height: 1.7;
  color: var(--ink-soft);
}

.dialog-text strong {
  color: var(--ink);
  font-weight: 600;
}

.code-input {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 1.8rem;
  letter-spacing: 0.45em;
  text-align: center;
  padding: 14px 8px 14px 20px;
}

.link-button {
  display: block;
  margin: 14px auto 0;
  padding: 6px;
  border: 0;
  background: none;
  color: var(--ink-soft);
  font-size: 0.8rem;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.link-button:hover {
  color: var(--ink);
}

.copy-row {
  display: flex;
  gap: 8px;
}

.copy-row input {
  flex: 1;
  min-width: 0;
  font-size: 0.76rem;
  color: var(--ink-soft);
}

.copy-row button {
  flex: 0 0 auto;
  padding: 0 16px;
  background: var(--paper-card);
  border: 1px solid var(--line-strong);
  border-radius: 2px;
  font-size: 0.78rem;
  letter-spacing: 0.05em;
}

.copy-row button:hover {
  border-color: var(--ink);
}

/* ---------- Manage page ---------- */

.manage-page {
  width: 100%;
  max-width: 780px;
  margin: 0 auto;
  padding: 48px 32px 88px;
}

.back-link {
  display: inline-block;
  margin-bottom: 20px;
  color: var(--ink-soft);
  font-size: 0.8rem;
  letter-spacing: 0.03em;
  text-decoration: none;
}

.back-link:hover {
  color: var(--ink);
}

.manage-card {
  padding: 40px;
  background: var(--paper-card);
  border: 1px solid var(--line);
  border-radius: 3px;
  box-shadow: var(--shadow);
}

.manage-card h1 {
  margin: 12px 0 26px;
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  overflow-wrap: anywhere;
}

.manage-card h2 {
  margin: 0 0 8px;
  font-family: var(--serif);
  font-size: 1.15rem;
  font-weight: 400;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 22px 28px;
  margin: 0 0 24px;
  padding: 22px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.meta-item {
  display: grid;
  gap: 5px;
}

.meta-item span {
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.meta-item strong {
  font-family: var(--serif);
  font-size: 1rem;
  font-weight: 400;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.pill {
  display: inline-flex;
  padding: 4px 10px;
  border: 1px solid currentColor;
  border-radius: 999px;
  font-family: var(--sans);
  font-size: 0.68rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.pill[data-status="pending"] {
  color: #7a5a1e;
  background: #fbf1d8;
  border-color: #e2c98d;
}

.pill[data-status="sent"] {
  color: #2f5b40;
  background: #eaf4ed;
  border-color: #b9d4c1;
}

.pill[data-status="failed"] {
  color: #8a2c2c;
  background: #faeaea;
  border-color: #e3b4b4;
}

.status-note {
  margin: 0 0 26px;
  font-size: 0.84rem;
  line-height: 1.65;
  color: var(--ink-soft);
}

.inline-form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  padding: 24px 0;
  border-top: 1px solid var(--line);
}

.inline-form .field {
  flex: 1 1 220px;
  margin: 0;
}

.inline-form button {
  width: auto;
  padding: 12px 22px;
}

.feedback {
  width: 100%;
  margin: 0;
  font-size: 0.82rem;
  line-height: 1.6;
  color: var(--green);
}

.feedback.is-error {
  color: var(--danger);
}

.feedback:empty {
  display: none;
}

.danger-zone {
  margin-top: 28px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
}

.danger-zone p {
  margin: 0 0 14px;
  max-width: 52ch;
  font-size: 0.84rem;
  line-height: 1.65;
  color: var(--ink-soft);
}

.danger {
  padding: 11px 20px;
  background: transparent;
  border: 1px solid #cf9a9a;
  border-radius: 2px;
  color: var(--danger);
  font-size: 0.82rem;
  letter-spacing: 0.03em;
}

.danger:hover {
  background: #fbf0ec;
  border-color: var(--danger);
}

.danger[hidden],
.danger-zone[hidden],
.inline-form[hidden],
.status-note[hidden] {
  display: none;
}

.cancel-confirm {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 4px;
}

.cancel-confirm[hidden] {
  display: none;
}

.cancel-confirm .ghost {
  padding: 11px 18px;
  background: transparent;
  border: 1px solid var(--line-strong);
  border-radius: 2px;
  font-size: 0.82rem;
}

.state-panel {
  padding: 12px 0;
  color: var(--ink-soft);
  font-size: 0.92rem;
  line-height: 1.75;
}

.state-panel h1 {
  margin-top: 8px;
  font-size: clamp(1.7rem, 3.6vw, 2.3rem);
}

.state-panel a {
  color: var(--accent);
}

.state-panel[hidden] {
  display: none;
}

/* ---------- Footer ---------- */

.site-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 24px;
  padding-top: 22px;
  padding-bottom: 34px;
  border-top: 1px solid rgba(201, 187, 161, 0.5);
  color: var(--ink-faint);
  font-size: 0.72rem;
  letter-spacing: 0.03em;
}

.site-footer p {
  margin: 0;
}

/* ---------- Responsive ---------- */

@media (max-width: 980px) {
  .page {
    grid-template-columns: minmax(0, 1fr);
    gap: 40px;
    padding-top: 40px;
  }

  .dispatch-col {
    position: static;
  }

  #body {
    min-height: 300px;
  }
}

@media (max-width: 600px) {
  .shell {
    padding-left: 20px;
    padding-right: 20px;
  }

  .topbar-inner {
    padding-top: 20px;
    padding-bottom: 20px;
  }

  .topnav {
    gap: 18px;
  }

  .card,
  .manage-card {
    padding: 24px;
  }

  .dialog-inner {
    padding: 28px 24px;
  }

  .sheet-foot {
    padding: 8px 18px 14px;
  }

  #body {
    padding: 26px 20px 8px;
    min-height: 260px;
    font-size: 1.02rem;
  }

  .meta-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 18px;
  }

  .manage-page {
    padding: 32px 20px 64px;
  }
}

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