:root {
  --ink: #0d0f12;
  --ink-2: #14171c;
  --ink-3: #1b1f26;
  --line: #2a303a;
  --text: #e8e4da;
  --muted: #9aa1ad;
  --accent: #d8a657;
  --accent-soft: rgba(216, 166, 87, 0.14);
  --danger: #e07a6a;
  --radius: 14px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(1200px 600px at 15% -10%, #1d232c 0%, transparent 60%),
    radial-gradient(900px 500px at 100% 0%, #241d16 0%, transparent 55%),
    var(--ink);
  color: var(--text);
  font-family: var(--sans);
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--line);
  background: rgba(13, 15, 18, 0.7);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.wordmark {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-family: var(--serif);
  font-size: 1.25rem;
  letter-spacing: 0.02em;
}

.mark {
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border-radius: 8px;
  background: var(--accent-soft);
  border: 1px solid rgba(216, 166, 87, 0.4);
  color: var(--accent);
  font-weight: 700;
}

.status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.status .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}

.status[data-state="ready"] .dot { background: #6fbf8b; }
.status[data-state="nokey"] .dot { background: var(--danger); }
.status[data-state="busy"] .dot { background: var(--accent); animation: pulse 1s infinite; }

@keyframes pulse { 50% { opacity: 0.35; } }

.layout {
  flex: 1;
  width: min(1200px, 100%);
  margin: 0 auto;
  padding: 1.5rem;
  display: grid;
  grid-template-columns: minmax(300px, 380px) minmax(0, 1fr);
  gap: 1.25rem;
  align-items: start;
}

.panel {
  background: linear-gradient(180deg, var(--ink-2), var(--ink-3));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.seed h1 {
  font-family: var(--serif);
  font-size: 1.5rem;
  margin: 0 0 0.25rem;
  font-weight: 600;
}

.hint {
  margin: 0 0 1.25rem;
  color: var(--muted);
  font-size: 0.9rem;
}

label {
  display: block;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0 0 0.4rem;
}

.optional {
  text-transform: none;
  letter-spacing: 0;
  opacity: 0.6;
}

textarea, input, select {
  width: 100%;
  background: var(--ink);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.7rem 0.8rem;
  font: inherit;
  font-size: 0.95rem;
  margin-bottom: 1rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

textarea { resize: vertical; min-height: 7rem; font-family: var(--serif); font-size: 1rem; }

textarea:focus, input:focus, select:focus {
  outline: none;
  border-color: rgba(216, 166, 87, 0.6);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.field { min-width: 0; }

.actions { display: flex; gap: 0.6rem; flex-wrap: wrap; }

button {
  font: inherit;
  font-size: 0.9rem;
  border-radius: 10px;
  padding: 0.65rem 1rem;
  cursor: pointer;
  border: 1px solid transparent;
  transition: transform 0.08s ease, background 0.15s ease, border-color 0.15s ease;
}

button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: 0.45; cursor: not-allowed; }

.primary {
  background: var(--accent);
  color: #1a1206;
  font-weight: 600;
}

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

.ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--line);
}

.ghost:hover:not(:disabled) { border-color: #3a424f; background: rgba(255, 255, 255, 0.03); }

.manuscript { display: flex; flex-direction: column; min-height: 60vh; }

.manuscript-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid var(--line);
  padding-bottom: 0.75rem;
  margin-bottom: 1rem;
}

.manuscript-head h2 {
  font-family: var(--serif);
  font-size: 1.15rem;
  font-weight: 600;
  margin: 0;
}

.meta { font-size: 0.78rem; color: var(--muted); }

.story {
  flex: 1;
  font-family: var(--serif);
  font-size: 1.08rem;
  line-height: 1.75;
  max-width: 68ch;
}

.story p { margin: 0 0 1.1rem; }
.story p:first-child::first-letter {
  font-size: 3.1rem;
  float: left;
  line-height: 0.85;
  padding: 0.1rem 0.5rem 0 0;
  color: var(--accent);
}

.story .empty { color: var(--muted); font-style: italic; }
.story .empty::first-letter { font-size: inherit; float: none; color: inherit; padding: 0; }

.story .pending { color: var(--muted); font-style: italic; }

.error {
  border: 1px solid rgba(224, 122, 106, 0.45);
  background: rgba(224, 122, 106, 0.1);
  color: #f0b3a8;
  border-radius: 10px;
  padding: 0.7rem 0.85rem;
  font-size: 0.9rem;
  margin-bottom: 1rem;
}

.actions.sticky {
  position: sticky;
  bottom: 0;
  padding-top: 1rem;
  margin-top: 1rem;
  background: linear-gradient(180deg, transparent, var(--ink-3) 35%);
}

.footer {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.78rem;
}

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; padding: 1rem; }
  .manuscript { min-height: 50vh; }
  .row { grid-template-columns: 1fr; gap: 0; }
}
