:root {
  --night: #14110e;
  --night-edge: #1c1712;
  --paper: #f3ead9;
  --paper-ruled: #e3d3ac;
  --paper-edge: #d9c79a;
  --ink: #241b14;
  --ink-soft: #6b5945;
  --oxblood: #7a2e2e;
  --oxblood-deep: #4f1e1e;
  --oxblood-bright: #a53f3f;
  --gold: #b8935b;
  --gold-bright: #dcb87c;
  --rail-bg: #1e1a15;
  --rail-bg-raised: #262019;
  --rail-text: #e9dfc9;
  --rail-text-soft: #a8998661;
  --rail-text-soft-solid: #a89986;
  --font-display: "Fraunces", "Iowan Old Style", serif;
  --font-body: "Be Vietnam Pro", "Helvetica Neue", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--night);
}

.night {
  min-height: 100vh;
  width: 100%;
  padding: clamp(20px, 5vw, 64px) clamp(16px, 4vw, 48px);
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at 50% -10%, #2a2117 0%, transparent 60%),
    var(--night);
}

.page-shell {
  width: 100%;
  max-width: 1180px;
}

.book {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(280px, 1fr);
  border-radius: 14px;
  overflow: hidden;
  box-shadow:
    0 40px 90px -30px rgba(0, 0, 0, 0.65),
    0 0 0 1px rgba(184, 147, 91, 0.15);
}

/* ---------- PAPER PANEL ---------- */

.page {
  background:
    repeating-linear-gradient(
      to bottom,
      transparent 0,
      transparent 38px,
      var(--paper-ruled) 39px
    ),
    var(--paper);
  padding: clamp(28px, 4vw, 56px);
  position: relative;
}

.page::before {
  content: "";
  position: absolute;
  inset: 0;
  border-right: 1px solid var(--paper-edge);
  pointer-events: none;
}

.kicker {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--oxblood);
  margin: 0 0 18px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.kicker::before {
  content: "";
  width: 22px;
  height: 1px;
  background: var(--gold);
}

.page h1 {
  font-family: var(--font-display);
  font-optical-sizing: auto;
  font-weight: 500;
  font-size: clamp(28px, 3.6vw, 42px);
  line-height: 1.12;
  letter-spacing: -0.01em;
  margin: 0 0 16px;
  color: var(--ink);
}

.lede {
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink-soft);
  max-width: 46ch;
  margin: 0 0 28px;
}

.field-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 8px;
}

.field-label-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.field-label-row .field-label {
  margin-bottom: 0;
}

.upload-btn {
  flex-shrink: 0;
  font-family: var(--font-body);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--oxblood);
  background: transparent;
  border: 1px solid var(--oxblood);
  border-radius: 999px;
  padding: 6px 14px;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}

.upload-btn:hover {
  background: var(--oxblood);
  color: #f5ece0;
}

.upload-btn.loading {
  opacity: 0.6;
  pointer-events: none;
}

textarea.manuscript {
  width: 100%;
  resize: vertical;
  min-height: 260px;
  background: transparent;
  border: none;
  border-top: 1px solid var(--paper-edge);
  border-bottom: 1px solid var(--paper-edge);
  padding: 16px 0;
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 39px;
  color: var(--ink);
}

textarea.manuscript::placeholder {
  color: #a5937a;
  font-style: italic;
}

textarea.manuscript:focus-visible {
  outline: none;
  border-top-color: var(--oxblood);
  border-bottom-color: var(--oxblood);
}

.char-count {
  text-align: right;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-soft);
  margin-top: 8px;
}

.error-box {
  margin-top: 18px;
  padding: 12px 16px;
  background: rgba(122, 46, 46, 0.09);
  border: 1px solid rgba(122, 46, 46, 0.35);
  border-radius: 8px;
  color: var(--oxblood-deep);
  font-size: 13.5px;
  line-height: 1.5;
}

/* ribbon dock: audio result, styled like a hanging bookmark ribbon */

.ribbon-dock {
  margin-top: 26px;
  background: var(--oxblood);
  border-radius: 6px 6px 4px 4px;
  padding: 14px 16px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  position: relative;
  box-shadow: 0 10px 24px -12px rgba(122, 46, 46, 0.7);
}

.ribbon-tail {
  position: absolute;
  bottom: -9px;
  left: 22px;
  width: 20px;
  height: 12px;
  background: var(--oxblood-deep);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
}

.ribbon-dock audio {
  flex: 1;
  min-width: 0;
  height: 34px;
}

.seal {
  flex-shrink: 0;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  background: radial-gradient(circle at 35% 30%, var(--gold-bright), var(--gold) 65%, #8a6a3c 100%);
  box-shadow: inset 0 -3px 6px rgba(0, 0, 0, 0.25), 0 2px 6px rgba(0, 0, 0, 0.35);
  color: #2b1c0d;
  font-family: var(--font-display);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-align: center;
  transition: transform 0.15s ease;
}

.seal:hover {
  transform: scale(1.06);
}

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

/* ---------- CONTROL RAIL ---------- */

.rail {
  background: var(--rail-bg);
  padding: clamp(26px, 3.6vw, 40px) clamp(22px, 3vw, 32px);
  display: flex;
  flex-direction: column;
  gap: 22px;
  border-left: 1px solid rgba(184, 147, 91, 0.18);
}

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

.rail-label {
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--rail-text-soft-solid);
}

.rail-label-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.rail-value {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--gold-bright);
}

.preview-link {
  font-family: var(--font-body);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--gold-bright);
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0;
  transition: opacity 0.12s ease;
}

.preview-link:hover:not(:disabled) {
  opacity: 0.8;
}

.preview-link:disabled {
  cursor: progress;
  opacity: 0.5;
}

.preview-audio {
  width: 100%;
  height: 32px;
  margin-top: 8px;
}

.optional {
  text-transform: none;
  font-weight: 400;
  letter-spacing: 0;
  color: var(--rail-text-soft-solid);
  opacity: 0.75;
}

.rail-select,
.rail-textarea {
  font-family: var(--font-body);
  font-size: 13.5px;
  color: var(--rail-text);
  background: var(--rail-bg-raised);
  border: 1px solid rgba(184, 147, 91, 0.25);
  border-radius: 7px;
  padding: 10px 12px;
}

.rail-select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--gold) 50%),
    linear-gradient(135deg, var(--gold) 50%, transparent 50%);
  background-position: calc(100% - 18px) center, calc(100% - 13px) center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  cursor: pointer;
}

.rail-textarea {
  resize: vertical;
  min-height: 64px;
  line-height: 1.5;
}

.vibe-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 2px;
}

.vibe-chip {
  font-family: var(--font-body);
  font-size: 11.5px;
  font-weight: 500;
  color: var(--rail-text-soft-solid);
  background: transparent;
  border: 1px solid rgba(184, 147, 91, 0.35);
  border-radius: 999px;
  padding: 5px 12px;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}

.vibe-chip:hover {
  border-color: var(--gold);
  color: var(--rail-text);
}

.vibe-chip.active {
  background: var(--gold);
  border-color: var(--gold);
  color: #2b1c0d;
}

.vibe-chip:focus-visible {
  outline: 2px solid var(--gold-bright);
  outline-offset: 2px;
}

.rail-select:focus-visible,
.rail-textarea:focus-visible {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(184, 147, 91, 0.2);
}

.rail-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 3px;
  border-radius: 2px;
  background: linear-gradient(to right, var(--gold) 0%, var(--gold) 20%, rgba(184, 147, 91, 0.25) 20%);
  margin: 8px 0 4px;
}

.rail-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--gold-bright);
  border: 2px solid var(--rail-bg);
  box-shadow: 0 0 0 1px var(--gold);
  cursor: pointer;
}

.rail-slider::-moz-range-thumb {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--gold-bright);
  border: 2px solid var(--rail-bg);
  box-shadow: 0 0 0 1px var(--gold);
  cursor: pointer;
}

.rail-slider:focus-visible {
  outline: 2px solid var(--gold-bright);
  outline-offset: 4px;
}

#instructionsGroup {
  transition: opacity 0.15s ease;
}

#instructionsGroup.disabled {
  opacity: 0.4;
  pointer-events: none;
}

/* ---------- GENERATE BUTTON (signature) ---------- */

.generate-btn {
  margin-top: 6px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  height: 52px;
  border: none;
  border-radius: 8px;
  background: linear-gradient(180deg, var(--oxblood-bright), var(--oxblood));
  color: #f5ece0;
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 500;
  letter-spacing: 0.01em;
  cursor: pointer;
  box-shadow: 0 8px 20px -8px rgba(122, 46, 46, 0.8);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.generate-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 10px 24px -8px rgba(122, 46, 46, 0.9);
}

.generate-btn:active:not(:disabled) {
  transform: translateY(0);
}

.generate-btn:focus-visible {
  outline: 2px solid var(--gold-bright);
  outline-offset: 3px;
}

.generate-btn:disabled {
  cursor: progress;
  opacity: 0.85;
}

.generate-btn .stamp {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--gold-bright);
  box-shadow: inset 0 -2px 3px rgba(0, 0, 0, 0.3);
  flex-shrink: 0;
  display: none;
}

.generate-btn.loading .stamp {
  display: block;
  animation: stamp-press 0.9s ease-in-out infinite;
}

@keyframes stamp-press {
  0%, 100% { transform: scale(1) translateY(0); }
  40% { transform: scale(0.8) translateY(1px); }
  55% { transform: scale(1.05) translateY(-1px); }
}

/* ---------- LOGIN PAGE ---------- */

.login-night {
  align-items: center;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background:
    repeating-linear-gradient(
      to bottom,
      transparent 0,
      transparent 38px,
      var(--paper-ruled) 39px
    ),
    var(--paper);
  border-radius: 14px;
  padding: clamp(28px, 5vw, 44px);
  box-shadow:
    0 40px 90px -30px rgba(0, 0, 0, 0.65),
    0 0 0 1px rgba(184, 147, 91, 0.15);
  display: flex;
  flex-direction: column;
}

.login-title {
  font-family: var(--font-display);
  font-optical-sizing: auto;
  font-weight: 500;
  font-size: clamp(24px, 3vw, 30px);
  margin: 0 0 10px;
  color: var(--ink);
}

.login-card .lede {
  margin-bottom: 24px;
}

.login-input {
  width: 100%;
  font-family: var(--font-body);
  font-size: 14.5px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.35);
  border: 1px solid var(--paper-edge);
  border-radius: 7px;
  padding: 10px 12px;
  margin-bottom: 16px;
}

.login-input:focus-visible {
  outline: none;
  border-color: var(--oxblood);
  box-shadow: 0 0 0 3px rgba(122, 46, 46, 0.15);
}

.login-submit {
  margin-top: 8px;
}

.login-card .error-box {
  margin-top: 0;
  margin-bottom: 16px;
}

/* ---------- TOP BAR (logout) ---------- */

.top-bar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 12px;
}

.logout-link {
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--rail-text-soft-solid);
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 4px 0;
}

.logout-link:hover {
  color: var(--gold-bright);
}

/* ---------- RESPONSIVE ---------- */

@media (max-width: 860px) {
  .book {
    grid-template-columns: 1fr;
  }

  .page::before {
    border-right: none;
    border-bottom: 1px solid var(--paper-edge);
  }
}

@media (prefers-reduced-motion: reduce) {
  .generate-btn.loading .stamp {
    animation: none;
  }
  .seal,
  .generate-btn {
    transition: none;
  }
}
