/* ============================================================
   Otherside Dreams — editorial theme (dark "ink" default + light "paper" override)
   Self-contained: system fonts only, no external assets.
   ============================================================ */

:root {
  /* dark (ink) — the default for anyone without a saved choice */
  --bg: #111220;
  --bg-2: #0e0f1a;
  --surface: #1a1c2b;
  --surface-2: #232538;
  --border: #2b2d3f;
  --text: #ece7da;
  --muted: #9a9cb5;
  --accent: #9a8cf0;
  --accent-2: #b6a9ff;
  --marker: #d9b06a;
  --danger: #e46c6c;
  --ok: #6fce9a;
  color-scheme: dark;

  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, ui-serif, serif;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  --radius: 10px;
  --space: 16px;
  --maxw: 960px;
  --maxw-prose: 720px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  font-size: 16px;
}

/* explicit light choice (toggle / persisted); data-theme="dark" just matches :root */
:root[data-theme="light"] {
  --bg: #f7f2e8;
  --bg-2: #efe8d8;
  --surface: #fffdf8;
  --surface-2: #f2ece0;
  --border: #e4dccb;
  --text: #2b2a26;
  --muted: #6f6a5f;
  --accent: #5b4fb0;
  --accent-2: #4a3f96;
  --marker: #9c7526;
  --danger: #a23b3b;
  --ok: #3f8f63;
  --shadow: 0 8px 30px rgba(20, 18, 40, 0.10);
  color-scheme: light;
}

* { box-sizing: border-box; }

/* Author display rules (e.g. .btn's inline-block) override the browser's
   built-in [hidden]{display:none}; restore the attribute's meaning globally. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, .brand { font-family: var(--serif); font-weight: 600; }
h1 { font-size: 2.1rem; line-height: 1.15; margin: 0 0 0.4em; letter-spacing: 0.01em; }
h2 { font-size: 1.4rem; margin: 1.5em 0 0.5em; }
h3 { font-size: 1.15rem; margin: 0 0 0.3em; }
.muted { color: var(--muted); }
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--surface-2); padding: 2px 8px; border-radius: 6px;
  font-size: 0.95em; word-break: break-all;
}

/* ---- header ---- */
.site-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space); padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-size: 1.35rem; color: var(--text); letter-spacing: 0.01em; }
.site-header nav { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.site-header nav a {
  font-family: var(--sans); color: var(--muted);
  padding: 8px 12px; border-radius: 999px; font-size: 0.95rem;
}
.site-header nav a:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.theme-toggle {
  font-family: var(--sans); font-size: 1.1rem; line-height: 1;
  background: transparent; border: 1px solid var(--border); color: var(--muted);
  width: 38px; height: 38px; border-radius: 999px; cursor: pointer; margin-left: 4px;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.theme-toggle:hover { color: var(--text); border-color: var(--accent); }

/* ---- layout ---- */
.container { max-width: var(--maxw); margin: 0 auto; padding: 40px 22px 96px; }
.page-title { margin-bottom: 0.1em; }
.page-intro { margin: 0 0 1.6em; max-width: var(--maxw-prose); font-size: 1.02rem; }
.page-title.centered, .page-intro.centered { max-width: var(--maxw-prose); margin-left: auto; margin-right: auto; }

/* ---- buttons ---- */
.btn {
  font-family: var(--sans);
  display: inline-block; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
  padding: 10px 18px; border-radius: var(--radius); font-size: 1rem; cursor: pointer;
  transition: transform 0.05s ease, background 0.15s ease, border-color 0.15s ease;
}
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn.danger:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); }

/* ---- hero / landing ---- */
.hero { text-align: center; max-width: var(--maxw-prose); margin: 24px auto 8px; padding: 32px 0 8px; }
.hero h1 { font-size: 2.8rem; }
.hero .tagline { font-family: var(--serif); font-style: italic; font-size: 1.35rem; color: var(--muted); margin: 0.2em 0 1em; }
.lede { font-family: var(--serif); font-size: 1.12rem; line-height: 1.7; text-align: left; }
.doors {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px; max-width: var(--maxw-prose); margin: 28px auto 0;
}
.door {
  display: block; color: var(--text);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
  transition: transform 0.1s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.door:hover { transform: translateY(-3px); border-color: var(--accent); box-shadow: var(--shadow); text-decoration: none; }
.door h2 { margin: 0 0 0.3em; font-size: 1.2rem; }
.door p { margin: 0; color: var(--muted); font-family: var(--sans); font-size: 0.95rem; }

/* ---- door emblems (the veil triptych: meet your dream-self, visit another's, let one go) ---- */
.door-emblem { display: block; width: 100%; max-width: 150px; height: auto; margin: 0 auto 12px; }
.door-emblem .fig { fill: var(--text); }
.door-emblem .ghost { fill: var(--accent); fill-opacity: 0.45; }
.door-emblem .veil { stroke: var(--marker); }
.door-emblem .veil.faint { opacity: 0.3; }
.door-emblem .star { fill: var(--marker); }
.door-emblem .star.fading { opacity: 0.7; }
.door-emblem .star.dim { opacity: 0.45; }

/* ---- cards / feed ---- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; margin-top: 22px; }
.dream-card { color: var(--text); display: block; transition: transform 0.1s ease, border-color 0.15s ease, box-shadow 0.15s ease; }
.dream-card:hover { transform: translateY(-3px); border-color: var(--accent); box-shadow: var(--shadow); text-decoration: none; }
.dream-card h3 { color: var(--text); }
.terms { max-width: var(--maxw-prose); margin: 0 auto; }
.dream-card:hover h3 { text-decoration: underline; text-decoration-color: var(--accent); text-underline-offset: 3px; }
.card-meta {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 6px 0 10px;
  color: var(--muted); font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase;
}
.snippet { font-family: var(--serif); color: var(--muted); margin: 0; line-height: 1.6; }
.badge {
  display: inline-block; background: var(--surface-2); border: 1px solid var(--border);
  color: var(--muted); padding: 2px 9px; border-radius: 999px;
  font-size: 0.68rem; letter-spacing: 0.06em; text-transform: uppercase;
}
.badge.prophetic { border-color: var(--marker); color: var(--marker); }
.badge.spoke { border-color: var(--accent); color: var(--accent); }

.feed-controls { margin: 8px 0 4px; max-width: var(--maxw-prose); }
.filters { margin-top: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 4px 14px; }
.filters summary { cursor: pointer; padding: 8px 0; color: var(--muted); font-family: var(--sans); }
.filter-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; margin: 8px 0 12px; }
.filter-grid label { margin: 4px 0; font-size: 0.85rem; color: var(--muted); }
#feed-empty { margin-top: 24px; }

/* ---- forms ---- */
label { display: block; margin: 14px 0; color: var(--text); }
input[type="text"], input[type="date"], input[type="search"], input[type="email"], select, textarea {
  width: 100%; margin-top: 6px; padding: 11px 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); font-size: 1rem; font-family: var(--sans);
}
textarea { font-family: var(--serif); resize: vertical; line-height: 1.6; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
fieldset.yesno {
  border: 1px solid var(--border); border-radius: var(--radius); margin: 14px 0; padding: 10px 14px;
  display: flex; flex-wrap: wrap; gap: 16px; align-items: center;
}
fieldset.yesno legend { color: var(--muted); padding: 0 6px; }
fieldset.yesno label { display: inline-flex; align-items: center; gap: 6px; margin: 0; }
fieldset.yesno.levels { flex-direction: column; align-items: flex-start; gap: 8px; }
.chk-group { display: flex; flex-wrap: wrap; gap: 12px; margin: 8px 0; }
.chk { display: inline-flex; align-items: center; gap: 6px; margin: 0; color: var(--muted); }
.chk input { width: auto; margin: 0; }

/* ---- subscribe ---- */
.subscribe { max-width: var(--maxw-prose); margin: 40px auto 0; text-align: center; }
.subscribe-form { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; align-items: center; margin-top: 10px; }
.subscribe-form input[type="email"] { flex: 1 1 260px; margin: 0; width: auto; }

.contact { max-width: var(--maxw-prose); margin: 0 auto; }

/* ---- wizard ---- */
.wizard { max-width: var(--maxw-prose); margin: 0 auto; }
.wizard .dream-input { font-size: 1.2rem; line-height: 1.7; }
.wizard-progress { margin-bottom: 24px; }
#step-label { font-family: var(--sans); color: var(--muted); font-size: 0.78rem; letter-spacing: 0.1em; text-transform: uppercase; }
.progress-bar { height: 3px; background: var(--surface-2); border-radius: 999px; margin-top: 8px; overflow: hidden; }
#progress-fill { height: 100%; width: 11%; background: var(--accent); transition: width 0.25s ease; }
.frontispiece { text-align: center; padding: 24px 0; }
.frontispiece h2 { font-size: 1.9rem; }
.frontispiece .rules { text-align: left; max-width: 46ch; margin: 16px auto 0; }
.rules { color: var(--muted); }
.rules li { margin: 10px 0; }
.scene-row, .entity-row { position: relative; margin: 12px 0; }
.remove-row { position: absolute; top: 10px; right: 10px; background: transparent; border: none; color: var(--danger); font-size: 1.3rem; line-height: 1; cursor: pointer; }
.wizard-nav { display: flex; justify-content: space-between; margin-top: 28px; }
.site-footer {
  max-width: var(--maxw); margin: 48px auto 0; padding: 18px 24px 28px;
  border-top: 1px solid var(--border);
  text-align: center; color: var(--muted); font-size: 0.9rem;
}
.site-footer a { color: var(--muted); text-decoration: underline; }
.site-footer a:hover { color: var(--text); }
#add-scene, #add-entity { margin-top: 8px; }
.confirmation { text-align: center; margin: 24px auto 0; max-width: var(--maxw-prose); }
.confirmation code { display: inline-block; margin: 10px 0; font-size: 1.05rem; }
.confirmation .actions { margin-top: 20px; }
.actions { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; margin-top: 24px; }

.error { color: var(--danger); margin-top: 12px; }
.message { margin-top: 16px; padding: 12px 14px; border-radius: var(--radius); }
.message.ok { background: color-mix(in srgb, var(--ok) 12%, transparent); border: 1px solid var(--ok); color: var(--ok); }
.message.error { background: color-mix(in srgb, var(--danger) 12%, transparent); border: 1px solid var(--danger); color: var(--danger); }
.dream-manage-list { list-style: none; padding: 0; margin: 8px 0 0; }
.dream-manage-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 10px 0; }

/* ---- dream detail (article) ---- */
.dream-detail { max-width: var(--maxw-prose); }
.dream-title { font-size: 2.4rem; margin-bottom: 0.15em; }
.byline {
  font-family: var(--sans); color: var(--muted); font-size: 0.75rem;
  letter-spacing: 0.09em; text-transform: uppercase; margin: 0 0 1.6em;
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
}
.byline span + span::before { content: "·"; margin-right: 10px; color: var(--border); }
.dream-text {
  font-family: var(--serif); font-size: 1.15rem; line-height: 1.75;
  white-space: pre-wrap; overflow-wrap: break-word; margin: 0 0 1.8em;
}
.dream-text::first-letter {
  float: left; font-size: 3.3em; line-height: 0.82; padding: 0.06em 0.1em 0 0;
  font-family: var(--serif); color: var(--accent);
}
.meta-table { width: 100%; border-collapse: collapse; margin: 8px 0 4px; }
.meta-table th, .meta-table td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.meta-table th { font-family: var(--sans); color: var(--muted); font-weight: 600; width: 55%; font-size: 0.9rem; }
.scene-list, .entity-list { list-style: none; padding: 0; }
.scene-list li, .entity-list li { padding: 12px 0; border-bottom: 1px solid var(--border); }
.flag-list { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 4px; }
.flag-list li { background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 4px 12px; color: var(--text); font-size: 0.9rem; }
.spoken { font-family: var(--serif); color: var(--marker); font-style: italic; margin-top: 6px; }
.back { margin-top: 32px; }

hr { border: none; border-top: 1px solid var(--border); margin: 32px 0; }

/* ---- motion / responsive ---- */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
@media (max-width: 560px) {
  .site-header { flex-direction: column; gap: 10px; }
  .hero h1 { font-size: 2.2rem; }
  .dream-title { font-size: 1.9rem; }
  .meta-table th { width: auto; }
}

/* keyboard focus parity for interactive non-form elements */
.btn:focus-visible, .door:focus-visible, .theme-toggle:focus-visible,
.dream-card:focus-visible, .site-header nav a:focus-visible,
.filters summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
