:root {
  color-scheme: dark;
  --bg: #070711;
  --bg-2: #10101f;
  --ink: #f7ecd0;
  --muted: #b9a98a;
  --soft: rgba(247, 236, 208, 0.72);
  --card: rgba(19, 18, 34, 0.78);
  --card-2: rgba(30, 26, 48, 0.72);
  --line: rgba(255, 218, 151, 0.18);
  --gold: #f3c86a;
  --ember: #ff8c4b;
  --aqua: #88f4ff;
  --violet: #b38cff;
  --danger: #ff7777;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.42);
  --radius: 28px;
  --max: 1180px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 20% 10%, rgba(179, 140, 255, 0.22), transparent 28rem),
    radial-gradient(circle at 84% 18%, rgba(136, 244, 255, 0.13), transparent 24rem),
    radial-gradient(circle at 50% 100%, rgba(255, 140, 75, 0.12), transparent 34rem),
    linear-gradient(140deg, #05050c, #111021 46%, #06060f);
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255,255,255,0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.02) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: radial-gradient(circle at center, black, transparent 80%);
  z-index: -2;
}

.stars {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 11% 22%, rgba(255,255,255,.9) 0 1px, transparent 2px),
    radial-gradient(circle at 47% 18%, rgba(255,255,255,.7) 0 1px, transparent 2px),
    radial-gradient(circle at 83% 35%, rgba(255,255,255,.55) 0 1px, transparent 2px),
    radial-gradient(circle at 22% 74%, rgba(255,255,255,.5) 0 1px, transparent 2px),
    radial-gradient(circle at 66% 82%, rgba(255,255,255,.65) 0 1px, transparent 2px);
  opacity: .52;
  z-index: -1;
}

a { color: inherit; text-decoration: none; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .52; }

.skip-link {
  position: fixed;
  left: 1rem;
  top: -4rem;
  z-index: 20;
  background: var(--gold);
  color: #14100a;
  padding: .7rem 1rem;
  border-radius: 999px;
}
.skip-link:focus { top: 1rem; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 12;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  width: min(var(--max), calc(100% - 2rem));
  margin: 0 auto;
  padding: .85rem 0;
  backdrop-filter: blur(18px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: .75rem;
  min-width: max-content;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 2.6rem;
  height: 2.6rem;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--gold);
  background: radial-gradient(circle, rgba(243, 200, 106, .2), rgba(136, 244, 255, .08) 46%, transparent 70%);
  box-shadow: 0 0 26px rgba(243, 200, 106, .22);
}
.brand strong { display: block; letter-spacing: .02em; }
.brand small { display: block; color: var(--muted); font-size: .78rem; }

.header-nav {
  display: flex;
  justify-content: center;
  gap: .3rem;
  padding: .28rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(9, 8, 18, .48);
}
.header-nav a {
  padding: .55rem .8rem;
  border-radius: 999px;
  color: var(--soft);
  font-size: .92rem;
}
.header-nav a:hover { background: rgba(255,255,255,.07); color: var(--ink); }
.header-actions { display: flex; align-items: center; gap: .5rem; }

.solid-button, .ghost-button, .chip-button {
  border: 1px solid var(--line);
  border-radius: 999px;
  min-height: 2.4rem;
  padding: .62rem .95rem;
  color: var(--ink);
  background: rgba(255,255,255,.06);
  box-shadow: none;
  transition: transform .18s ease, border-color .18s ease, background .18s ease;
}
.solid-button {
  border-color: rgba(243, 200, 106, .42);
  color: #1b1206;
  background: linear-gradient(135deg, #ffe7a5, #f3c86a 42%, #ff9d62);
  font-weight: 800;
  box-shadow: 0 10px 28px rgba(243, 200, 106, .18);
}
.ghost-button:hover, .chip-button:hover, .solid-button:hover { transform: translateY(-1px); }
.ghost-button:hover, .chip-button:hover { border-color: rgba(243, 200, 106, .38); background: rgba(255,255,255,.1); }
.large { min-height: 3rem; padding-inline: 1.25rem; }
.small { min-height: 2rem; padding: .45rem .72rem; font-size: .88rem; }

main { position: relative; z-index: 1; }
.hero-shell {
  display: grid;
  grid-template-columns: minmax(0, .86fr) minmax(330px, 1.14fr);
  gap: clamp(1.2rem, 3vw, 3rem);
  align-items: center;
  width: min(var(--max), calc(100% - 2rem));
  min-height: calc(100vh - 5rem);
  margin: 0 auto;
  padding: clamp(1.2rem, 4vw, 4rem) 0 2rem;
}

.hero-copy { max-width: 640px; }
.eyebrow {
  margin: 0 0 .7rem;
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: .16em;
  font-size: .76rem;
  font-weight: 900;
}
h1, h2, h3 { margin: 0; line-height: .98; letter-spacing: -.045em; }
h1 { font-size: clamp(3.05rem, 8vw, 7.4rem); max-width: 8ch; }
h2 { font-size: clamp(2rem, 5vw, 4.1rem); }
h3 { font-size: 1.32rem; line-height: 1.05; }
.hero-lede {
  margin: 1.25rem 0 1.5rem;
  max-width: 62ch;
  color: var(--soft);
  font-size: clamp(1.05rem, 2vw, 1.28rem);
  line-height: 1.65;
}
.hero-actions, .mini-actions, .form-actions, .sheet-actions, .card-actions { display: flex; flex-wrap: wrap; gap: .7rem; align-items: center; }

.globe-card {
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(255, 218, 151, .2);
  border-radius: calc(var(--radius) + 10px);
  background:
    linear-gradient(180deg, rgba(255,255,255,.08), rgba(255,255,255,.02)),
    radial-gradient(circle at 50% 45%, rgba(136,244,255,.14), transparent 34%),
    rgba(8, 8, 20, .78);
  box-shadow: var(--shadow), inset 0 0 0 1px rgba(255,255,255,.04);
}
.globe-toolbar {
  position: absolute;
  left: 1rem;
  right: 1rem;
  top: 1rem;
  z-index: 4;
  display: flex;
  align-items: center;
  gap: .55rem;
  flex-wrap: wrap;
}
.search-wrap { flex: 1 1 220px; }
.search-wrap input, .command-palette input {
  width: 100%;
  min-height: 2.65rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 1rem;
  color: var(--ink);
  outline: none;
  background: rgba(3, 3, 10, .68);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.025);
}
.search-wrap input:focus, .command-palette input:focus { border-color: rgba(136,244,255,.55); box-shadow: 0 0 0 4px rgba(136,244,255,.08); }
.globe-stage {
  position: relative;
  min-height: clamp(440px, 72vw, 680px);
  display: grid;
  place-items: center;
}
#mythGlobe { width: min(100%, 680px); height: auto; touch-action: none; filter: drop-shadow(0 42px 90px rgba(0,0,0,.7)); }
.globe-hint {
  position: absolute;
  left: 50%;
  bottom: 4.8rem;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 2rem);
  padding: .55rem .8rem;
  color: var(--soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(0,0,0,.34);
  backdrop-filter: blur(12px);
  font-size: .88rem;
}
.filter-strip {
  position: absolute;
  left: 1rem;
  right: 1rem;
  bottom: 1rem;
  z-index: 4;
  display: flex;
  gap: .45rem;
  overflow-x: auto;
  padding-bottom: .2rem;
  scrollbar-width: thin;
}
.filter-chip {
  white-space: nowrap;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: .48rem .72rem;
  color: var(--soft);
  background: rgba(0,0,0,.28);
}
.filter-chip.active { color: #1b1206; background: var(--gold); border-color: var(--gold); font-weight: 800; }

.compact-rail, .panel-board, .story-browser, .draft-shell {
  width: min(var(--max), calc(100% - 2rem));
  margin: 0 auto;
}
.compact-rail {
  display: grid;
  grid-template-columns: repeat(6, minmax(150px, 1fr));
  gap: .8rem;
  padding: 1.25rem 0;
  overflow-x: auto;
}
.rail-card {
  min-width: 150px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 1rem;
  color: var(--ink);
  background: rgba(255,255,255,.045);
}
.rail-card span { display: inline-grid; place-items: center; width: 2rem; height: 2rem; margin-bottom: .8rem; color: var(--gold); border: 1px solid var(--line); border-radius: 50%; }
.rail-card strong, .rail-card small { display: block; }
.rail-card small { margin-top: .35rem; color: var(--muted); line-height: 1.35; }
.rail-card.active { background: linear-gradient(180deg, rgba(243, 200, 106, .18), rgba(136, 244, 255, .06)); border-color: rgba(243, 200, 106, .42); }

.panel-board {
  min-height: 280px;
  margin-top: .8rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(135deg, rgba(255,255,255,.08), rgba(255,255,255,.025));
  box-shadow: var(--shadow);
  overflow: hidden;
}
.info-panel { display: none; padding: clamp(1.2rem, 4vw, 2.2rem); }
.info-panel.active { display: block; }
.info-panel p { max-width: 74ch; color: var(--soft); line-height: 1.7; font-size: 1.06rem; }
.profile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: .8rem;
  margin-top: 1rem;
}
.profile-tile {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 1rem;
  background: rgba(0,0,0,.22);
}
.profile-tile strong { display: block; font-size: 1.4rem; }
.profile-tile span { color: var(--muted); font-size: .9rem; }

.story-browser, .draft-shell { padding: clamp(2.8rem, 8vw, 5.5rem) 0; }
.section-heading { display: grid; gap: .6rem; margin-bottom: 1.2rem; }
.section-heading p:not(.eyebrow) { max-width: 65ch; margin: 0; color: var(--soft); line-height: 1.6; }
.story-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: .85rem;
}
.story-card {
  display: flex;
  flex-direction: column;
  min-height: 270px;
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 1rem;
  background: linear-gradient(180deg, rgba(255,255,255,.07), rgba(255,255,255,.025));
  box-shadow: 0 14px 38px rgba(0,0,0,.18);
}
.story-card-top { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-bottom: .9rem; }
.category-pill, .distance-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: .32rem .55rem;
  color: var(--gold);
  border: 1px solid rgba(243, 200, 106, .25);
  background: rgba(243, 200, 106, .08);
  font-size: .78rem;
  white-space: nowrap;
}
.distance-pill { color: var(--aqua); border-color: rgba(136,244,255,.22); background: rgba(136,244,255,.07); }
.story-card p { color: var(--soft); line-height: 1.55; flex: 1; }
.card-tags, .sheet-tags { display: flex; flex-wrap: wrap; gap: .4rem; margin: .6rem 0 .9rem; }
.tag { border: 1px solid var(--line); color: var(--muted); border-radius: 999px; padding: .28rem .48rem; font-size: .78rem; }

.draft-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .85rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: clamp(1rem, 3vw, 1.5rem);
  background: rgba(255,255,255,.045);
  box-shadow: var(--shadow);
}
.draft-form label, .auth-form label {
  display: grid;
  gap: .4rem;
  color: var(--muted);
  font-weight: 750;
}
.draft-form input, .draft-form textarea, .draft-form select, .auth-form input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: .8rem .9rem;
  color: var(--ink);
  background: rgba(5, 5, 13, .72);
  outline: none;
}
.draft-form textarea { resize: vertical; }
.draft-form label:nth-last-of-type(2), .draft-form label:nth-last-of-type(1), .form-actions, .form-note { grid-column: 1 / -1; }
.form-note { margin: 0; color: var(--muted); line-height: 1.5; }

.story-sheet {
  position: fixed;
  right: max(1rem, env(safe-area-inset-right));
  bottom: max(1rem, calc(var(--safe-bottom) + 1rem));
  z-index: 10;
  width: min(430px, calc(100vw - 2rem));
  border: 1px solid rgba(255, 218, 151, .25);
  border-radius: 30px;
  padding: 1.2rem;
  background: rgba(12, 11, 25, .86);
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
  transform: translateY(calc(100% + 2rem));
  transition: transform .28s ease;
}
.story-sheet.open { transform: translateY(0); }
.sheet-close, .dialog-close {
  position: absolute;
  top: .8rem;
  right: .8rem;
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--ink);
  background: rgba(255,255,255,.06);
}
.story-sheet h2 { padding-right: 2rem; font-size: 2rem; }
.story-sheet p:not(.eyebrow) { color: var(--soft); line-height: 1.55; }

.story-dialog, .auth-dialog, .command-palette {
  width: min(820px, calc(100vw - 2rem));
  max-height: min(84vh, 900px);
  border: 1px solid var(--line);
  border-radius: 30px;
  color: var(--ink);
  background: rgba(12, 11, 25, .94);
  box-shadow: var(--shadow);
  backdrop-filter: blur(24px);
  padding: clamp(1.1rem, 4vw, 2rem);
  overflow: auto;
}
.story-dialog::backdrop, .auth-dialog::backdrop, .command-palette::backdrop { background: rgba(0,0,0,.7); backdrop-filter: blur(5px); }
.story-detail-header { display: grid; gap: .7rem; padding-right: 2rem; }
.story-detail-meta { color: var(--gold); font-size: .88rem; letter-spacing: .08em; text-transform: uppercase; }
.story-detail-body { margin-top: 1.4rem; color: var(--soft); line-height: 1.86; font-size: 1.08rem; }
.story-detail-actions { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: 1rem; }
.source-notes {
  margin-top: 1.2rem;
  border-left: 3px solid rgba(243, 200, 106, .46);
  padding-left: .9rem;
  color: var(--muted);
}
.auth-form { display: grid; gap: .9rem; margin-top: 1rem; }
.auth-choice { display: flex; flex-wrap: wrap; gap: 1rem; color: var(--soft); }
.hidden { display: none !important; }

.command-palette { width: min(720px, calc(100vw - 2rem)); }
.command-results { display: grid; gap: .55rem; margin-top: 1rem; }
.command-result {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: .8rem;
  background: rgba(255,255,255,.045);
  text-align: left;
  color: var(--ink);
}
.command-result small { display: block; color: var(--muted); margin-top: .2rem; }

.reader-bar {
  position: fixed;
  left: 50%;
  bottom: max(.75rem, calc(var(--safe-bottom) + .75rem));
  transform: translateX(-50%);
  z-index: 14;
  display: flex;
  align-items: center;
  gap: .4rem;
  width: min(680px, calc(100vw - 1rem));
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: .45rem;
  background: rgba(8,8,18,.9);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}
.reader-bar span { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; color: var(--soft); padding-inline: .7rem; }
.reader-bar button { border: 1px solid var(--line); border-radius: 999px; padding: .45rem .65rem; color: var(--ink); background: rgba(255,255,255,.06); }

.toast {
  position: fixed;
  left: 50%;
  bottom: max(5rem, calc(var(--safe-bottom) + 5rem));
  transform: translateX(-50%);
  z-index: 30;
  width: max-content;
  max-width: calc(100vw - 2rem);
  padding: .75rem 1rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink);
  background: rgba(12, 11, 25, .92);
  box-shadow: var(--shadow);
}

@media (max-width: 920px) {
  .hero-shell { grid-template-columns: 1fr; min-height: 0; }
  .hero-copy { padding-top: 1rem; }
  h1 { max-width: 11ch; }
  .header-nav { display: none; }
  .compact-rail { grid-template-columns: repeat(6, 170px); }
  .story-sheet {
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    border-radius: 28px 28px 0 0;
    padding-bottom: calc(1.2rem + var(--safe-bottom));
  }
}

@media (max-width: 640px) {
  .site-header { width: min(100% - 1rem, var(--max)); }
  .brand small { display: none; }
  .header-actions .ghost-button { display: none; }
  .hero-shell, .compact-rail, .panel-board, .story-browser, .draft-shell { width: min(100% - 1rem, var(--max)); }
  .globe-toolbar { position: relative; left: auto; right: auto; top: auto; padding: .8rem .8rem 0; }
  .globe-stage { min-height: 390px; }
  .globe-hint { bottom: 4.5rem; font-size: .78rem; }
  .filter-strip { left: .8rem; right: .8rem; bottom: .8rem; }
  .draft-form { grid-template-columns: 1fr; }
  .reader-bar { border-radius: 20px; flex-wrap: wrap; }
  .reader-bar span { flex-basis: 100%; padding-top: .35rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; scroll-behavior: auto !important; transition-duration: .001ms !important; }
}
