:root {
  --bg: oklch(0.09 0.02 265);
  --surface: oklch(0.14 0.022 265);
  --surface-2: oklch(0.19 0.024 265);
  --line: oklch(0.3 0.02 265);
  --ink: oklch(0.93 0.014 90);
  --muted: oklch(0.64 0.02 265);
  --gold: oklch(0.72 0.14 90);
  --gold-ink: oklch(0.16 0.03 90);
  --laurel: oklch(0.58 0.12 130);
  --ember: oklch(0.6 0.15 30);
  --serif: "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --sans: system-ui, "Segoe UI", Roboto, sans-serif;
  --radius: 12px;
  --tap: 48px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --shadow: 0 1px 0 oklch(1 0 0 / 0.04) inset, 0 10px 30px oklch(0 0 0 / 0.35);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, oklch(0.72 0.14 90 / 0.07), transparent 60%),
    radial-gradient(ellipse 60% 40% at 90% 110%, oklch(0.58 0.12 130 / 0.05), transparent 60%);
  z-index: 0;
}

#app { position: relative; z-index: 1; min-height: 100vh; display: flex; flex-direction: column; }

a { color: var(--gold); }
a:hover { color: oklch(0.8 0.13 90); }

:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
  border-radius: 4px;
}

::selection { background: oklch(0.72 0.14 90 / 0.35); }

.desktop-only { display: none; }

/* ============ Setup (BYOK) ============ */

.setup {
  border: 0;
  padding: 0;
  background: transparent;
  max-width: 680px;
  width: 100%;
  height: 100%;
  max-height: 100%;
  margin: 0;
  color: var(--ink);
}

.setup::backdrop {
  background: oklch(0.04 0.015 265 / 0.92);
  backdrop-filter: blur(4px);
}

.setup form {
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 24px 18px;
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(24px + var(--safe-b));
}

.setup-hero { text-align: center; margin-bottom: 8px; }

.setup-hero h1 {
  font-family: var(--serif);
  font-size: clamp(2rem, 8vw, 3.2rem);
  letter-spacing: 0.18em;
  margin: 0;
  color: var(--gold);
  text-transform: uppercase;
  text-wrap: balance;
}

.setup-sub {
  margin: 4px 0 0;
  color: var(--muted);
  letter-spacing: 0.06em;
  font-size: 0.95rem;
}

.setup-cards { display: grid; gap: 14px; margin: 18px 0; }

.setup-card {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.setup-card h2 { font-size: 1.05rem; margin: 0 0 8px; color: var(--gold); }
.setup-card p { margin: 0 0 10px; color: var(--ink); }
.setup-card p:last-child { margin-bottom: 0; }

.setup-steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }

.setup-steps li { display: flex; gap: 12px; align-items: flex-start; }

.step-num {
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--gold);
  color: var(--gold-ink);
  font-weight: 700;
  display: grid;
  place-items: center;
  font-size: 0.9rem;
  margin-top: 2px;
}

.setup-steps p { margin: 0; }

code {
  background: oklch(0.09 0.02 265);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 1px 6px;
  font-size: 0.88em;
  color: var(--gold);
  word-break: break-all;
}

.setup-tip {
  font-size: 0.88rem;
  color: var(--muted);
  border-left: 2px solid var(--laurel);
  padding-left: 12px;
  margin-top: 12px;
}

.setup-label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin: 4px 0 8px;
}

input[type="password"], input[type="text"] {
  width: 100%;
  background: oklch(0.09 0.02 265);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 13px 14px;
  font-size: 16px;
  font-family: var(--sans);
  min-height: var(--tap);
}

input::placeholder { color: oklch(0.5 0.02 265); }

input:focus { border-color: var(--gold); outline: none; }

.setup-error { color: var(--ember); font-size: 0.9rem; min-height: 1.2em; margin: 8px 0 0; }

.setup-actions { margin-top: 14px; }

.setup-note {
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: 14px;
}

/* ============ Botões ============ */

.btn {
  font-family: var(--sans);
  font-size: 1rem;
  font-weight: 600;
  border-radius: 10px;
  border: 1px solid transparent;
  padding: 12px 20px;
  min-height: var(--tap);
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.btn:active { transform: translateY(1px); }

.btn-gold {
  background: var(--gold);
  color: var(--gold-ink);
}
.btn-gold:hover { background: oklch(0.78 0.13 90); }

.btn-ghost {
  background: transparent;
  color: var(--ink);
  border-color: var(--line);
}
.btn-ghost:hover { border-color: var(--gold); color: var(--gold); }

.btn-sm { padding: 8px 12px; font-size: 0.85rem; min-height: 36px; }

.btn-danger { border-color: var(--ember); color: var(--ember); }

.btn-danger:hover { background: oklch(0.6 0.15 30 / 0.12); }

.btn[disabled] { opacity: 0.5; cursor: wait; }

/* ============ Topbar ============ */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(10px + var(--safe-t)) 14px 10px;
  border-bottom: 1px solid var(--line);
  background: oklch(0.12 0.02 265 / 0.85);
  position: sticky;
  top: 0;
  z-index: 5;
  backdrop-filter: blur(6px);
  flex-wrap: wrap;
}

.brand { display: flex; flex-direction: column; line-height: 1.15; }

.brand-mark {
  font-family: var(--serif);
  letter-spacing: 0.14em;
  color: var(--gold);
  font-size: 0.85rem;
  white-space: nowrap;
}

.brand-name { color: var(--muted); font-size: 0.72rem; white-space: nowrap; }

.topbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 0.76rem;
  color: var(--muted);
  white-space: nowrap;
}

.pill-laurel { border-color: var(--laurel); color: var(--laurel); }

.modo-select { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 0.78rem; }

.modo-select select {
  background: var(--surface-2);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 0.85rem;
  min-height: 36px;
}

.chapter {
  font-family: var(--serif);
  font-style: italic;
  color: var(--ink);
  font-size: 0.9rem;
  width: 100%;
  text-align: center;
  order: 3;
}

/* ============ Layout ============ */

.layout {
  flex: 1;
  max-width: 1180px;
  width: 100%;
  margin: 0 auto;
  padding: 20px 16px calc(170px + var(--safe-b));
}

.story-col { min-width: 0; }

/* ============ História ============ */

.story {
  font-family: var(--serif);
  font-size: 1.15rem;
  line-height: 1.65;
  max-width: 68ch;
  color: var(--ink);
}

.story p { margin: 0 0 1.1em; text-wrap: pretty; }

.story .story-hook { color: var(--gold); font-style: italic; }

.story .story-player {
  font-family: var(--sans);
  font-size: 0.92rem;
  color: var(--muted);
  border-left: 2px solid var(--gold);
  padding-left: 12px;
  margin-bottom: 1.1em;
}

.story .story-player strong { color: var(--gold); font-weight: 600; }

.story .story-chapter {
  font-family: var(--sans);
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 0.6em;
}

.story .story-pc {
  color: var(--laurel);
  font-family: var(--sans);
  font-size: 0.9rem;
  border: 1px solid var(--laurel);
  border-radius: 10px;
  padding: 12px 14px;
  margin: 1.2em 0;
  background: oklch(0.58 0.12 130 / 0.08);
}

.story .story-perg {
  color: var(--gold);
  font-family: var(--sans);
  border: 1px dashed var(--gold);
  border-radius: 10px;
  padding: 14px;
  margin: 1.2em 0;
}

.story .story-perg h3 { margin: 0 0 6px; font-size: 0.95rem; }

.story .story-perg ol { margin: 0; padding-left: 20px; }

.story .story-perg li { margin-bottom: 4px; }

.story em { color: var(--gold); }

/* ============ Loading ============ */

.loading {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: 14px;
}

.loading-spin {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--line);
  border-top-color: var(--gold);
  animation: spin 0.9s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ============ Dock (input + abas) ============ */

.dock {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 6;
  background: oklch(0.11 0.02 265 / 0.95);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(8px);
  padding: 10px 14px calc(10px + var(--safe-b));
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.input-row {
  display: flex;
  gap: 10px;
}

.input-row input { flex: 1; min-width: 0; }

.suggestions {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.suggestions::-webkit-scrollbar { display: none; }

.suggestion {
  flex: none;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 0.85rem;
  padding: 10px 16px;
  min-height: 42px;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.suggestion:hover { border-color: var(--gold); color: var(--gold); }

.tabbar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.tab {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.85rem;
  font-weight: 600;
  min-height: 44px;
  padding: 8px 4px;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.tab:active { transform: translateY(1px); }

.tab[aria-pressed="true"] { border-color: var(--gold); color: var(--gold); }

/* ============ Painéis (desktop) ============ */

.side { display: none; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.panel h3 {
  margin: 0 0 10px;
  font-size: 0.8rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gold);
}

.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }

.list li { color: var(--ink); font-size: 0.92rem; line-height: 1.4; }

.list li small { display: block; color: var(--muted); font-size: 0.78rem; }

.gloss-list li { cursor: pointer; padding: 8px 6px; margin: 0 -6px; border-radius: 8px; }

.select-full {
  width: 100%;
  background: var(--surface-2);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.95rem;
  min-height: 44px;
}

.gloss-list li:hover { color: var(--gold); background: var(--surface-2); }

.quest-done { color: var(--laurel); }

.quest-active { color: var(--ink); }

/* ============ Diálogos ============ */

.gloss-dialog, .map-dialog {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  color: var(--ink);
  padding: 24px;
  max-width: 520px;
  width: calc(100% - 32px);
  box-shadow: var(--shadow);
}

.gloss-dialog::backdrop, .map-dialog::backdrop, .sheet::backdrop {
  background: oklch(0.04 0.015 265 / 0.85);
  backdrop-filter: blur(3px);
}

.gloss-close {
  position: absolute;
  top: 10px;
  right: 14px;
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 1.6rem;
  cursor: pointer;
  line-height: 1;
  min-width: 44px;
  min-height: 44px;
}

.gloss-close:hover { color: var(--gold); }

.gloss-dialog h2 { margin: 0 0 4px; color: var(--gold); font-family: var(--serif); }

.gloss-pron { color: var(--muted); font-style: italic; margin: 0 0 12px; }

.gloss-dialog p:last-child { margin-bottom: 0; }

#mapa-svg svg { width: 100%; height: auto; display: block; }

#mapa-svg text { fill: var(--muted); font-size: 11px; }

#mapa-svg .map-path { fill: none; stroke: var(--gold); stroke-width: 1.5; stroke-dasharray: 4 4; }

#mapa-svg .map-stop { fill: var(--gold); stroke: var(--bg); stroke-width: 1.5; }

/* ============ Bottom sheet (mobile) ============ */

.sheet {
  border: 0;
  padding: 0;
  margin: auto 0 0 0;
  width: 100%;
  max-width: 640px;
  max-height: 72vh;
  background: var(--surface);
  color: var(--ink);
  border-top: 1px solid var(--line);
  border-radius: 18px 18px 0 0;
  box-shadow: var(--shadow);
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px 6px;
}

.sheet-head h2 {
  margin: 0;
  font-size: 1rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--gold);
}

.sheet-head .gloss-close { position: static; }

#sheet-content { padding: 4px 18px calc(24px + var(--safe-b)); }

#sheet-content .panel { border: 0; background: transparent; padding: 8px 0; }

/* ============ Rodapé ============ */

.site-footer {
  border-top: 1px solid var(--line);
  padding: 14px 20px calc(14px + var(--safe-b));
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  position: relative;
  z-index: 1;
}

/* ============ Desktop (>= 900px) ============ */

@media (min-width: 900px) {
  .desktop-only { display: inline-flex; }

  .setup {
    height: auto;
    max-height: 90vh;
    margin: auto;
    width: min(680px, calc(100% - 32px));
    border-radius: 20px;
  }

  .setup form { border-radius: 20px; height: auto; padding: 28px; }

  .topbar { padding: 12px 20px; flex-wrap: nowrap; }
  .chapter { order: 0; width: auto; text-align: left; }

  .layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 300px;
    gap: 28px;
    padding: 28px 24px 48px;
  }

  .story { font-size: 1.12rem; }

  .side { display: flex; flex-direction: column; gap: 16px; }

  .dock {
    position: static;
    background: none;
    border: 0;
    backdrop-filter: none;
    padding: 0;
    max-width: 68ch;
    margin: 0 auto;
  }

  .suggestions { flex-wrap: wrap; overflow: visible; }

  .tabbar { display: none; }

  .site-footer { padding-bottom: 14px; }
}

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