/* ============================================================
   WikiTrail — Styles
   Mobile-first, optimised for iPhone Safari
   ============================================================ */

/* ── Reset & base ─────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Several elements below also set `display: flex`, which has the same
   specificity as the UA stylesheet's `[hidden] { display: none }` — author
   rules win ties, so without this override a hidden flex element stays
   visible. */
[hidden] {
  display: none !important;
}

:root {
  --navy:       #16213e;
  --navy-dk:    #0f1829;
  --teal:       #4fd1c5;
  --orange:     #f6ad55;
  --bg:         #ffffff;
  --surface:    #f8f8f8;
  --border:     #e0e0e0;
  --text:       #1a1a1a;
  --text-muted: #6b6b6b;
  --red:        #c0392b;
  --green:      #27ae60;
  --radius:     12px;
  --radius-sm:  8px;
  --shadow:     0 2px 8px rgba(0,0,0,.10);
  --font:       -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html {
  font-family: var(--font);
  font-size: 16px;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 480px;
  margin: 0 auto;
  padding-bottom: env(safe-area-inset-bottom, 16px);
}

/* ── Header & tabs ────────────────────────────────────────── */
.sticky-top {
  position: sticky;
  top: 0;
  z-index: 10;
}

header {
  background: var(--navy);
  padding: 14px 20px 12px;
  text-align: center;
  border-bottom: 2px solid var(--navy-dk);
}

header h1 {
  color: #fff;
  font-size: 1.3rem;
  font-weight: 700;
}

.tabs {
  display: flex;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.tab {
  flex: 1;
  padding: 10px 0;
  background: none;
  border: none;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 3px solid transparent;
}

.tab.active {
  color: var(--navy);
  border-bottom-color: var(--teal);
}

/* ── Panels ───────────────────────────────────────────────── */
.panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* ── Game banner ──────────────────────────────────────────── */
.game-banner {
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.banner-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 0.95rem;
}

.banner-article {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.banner-article:first-child {
  flex: 1;
  text-align: right;
}

.banner-target-btn {
  flex: 1;
  color: var(--navy);
  background: none;
  border: none;
  font: inherit;
  font-weight: 600;
  text-align: left;
  text-decoration: underline dotted;
  text-decoration-color: var(--orange);
  text-underline-offset: 3px;
  cursor: pointer;
}

.banner-arrow {
  color: var(--text-muted);
}

.banner-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 4px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.banner-meta-left,
.banner-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.icon-btn {
  background: none;
  border: none;
  font-size: 1rem;
  line-height: 1;
  color: var(--text);
  padding: 4px 8px;
}

.btn-text {
  background: none;
  border: none;
  color: var(--red);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 4px 6px;
}

.icon-btn:disabled,
.btn-text:disabled,
.banner-target-btn:disabled {
  opacity: 0.35;
}

/* ── Path trail ───────────────────────────────────────────── */
.path-trail {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  overflow-x: auto;
  white-space: nowrap;
  font-size: 0.8rem;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

.trail-step {
  flex: 0 0 auto;
}

.trail-arrow {
  flex: 0 0 auto;
}

/* ── Empty state & loading ───────────────────────────────── */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 40px 28px;
  text-align: center;
  color: var(--text-muted);
}

.loading {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}

/* ── Article area ─────────────────────────────────────────── */
.article-area {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.back-peek {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.95rem;
  padding: 0 40px;
  text-align: center;
}

.back-peek-arrow {
  font-size: 1.3rem;
  color: var(--navy);
}

.article-wrap {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.article-wrap.preview-mode {
  outline: 4px solid var(--orange);
  outline-offset: -4px;
}

.preview-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  background: #fff3e0;
  color: #8a5a1f;
  font-size: 0.82rem;
  border-bottom: 1px solid var(--orange);
}

.article-host {
  width: 100%;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

#edge-swipe-zone {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 22px;
  z-index: 3;
  touch-action: pan-y;
}

/* ── Toast ────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--navy);
  color: #fff;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  box-shadow: var(--shadow);
  z-index: 50;
}

/* ── Buttons ──────────────────────────────────────────────── */
.btn-primary, .btn-secondary {
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 20px;
  font-size: 0.95rem;
  font-weight: 600;
}

.btn-primary {
  background: var(--navy);
  color: #fff;
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

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

/* ── History panel ────────────────────────────────────────── */
.stats-summary {
  display: flex;
  justify-content: space-around;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stat-value {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--navy);
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.hubs {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.hubs-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.hubs ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.9rem;
}

.hub-count {
  color: var(--text-muted);
  font-size: 0.8rem;
}

.history-list {
  flex: 1;
  padding: 8px 16px;
}

.empty-note {
  color: var(--text-muted);
  text-align: center;
  padding: 24px 0;
}

.history-item {
  border-bottom: 1px solid var(--border);
  padding: 10px 0;
}

.history-item summary {
  display: flex;
  flex-direction: column;
  gap: 2px;
  cursor: pointer;
  list-style: none;
}

.history-item summary::-webkit-details-marker {
  display: none;
}

.history-route {
  font-weight: 600;
  font-size: 0.9rem;
}

.history-outcome {
  font-size: 0.82rem;
}

.history-outcome.won {
  color: var(--green);
}

.history-outcome.gave_up {
  color: var(--text-muted);
}

.history-when {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.history-detail {
  margin-top: 8px;
  padding-left: 8px;
  border-left: 2px solid var(--border);
  font-size: 0.85rem;
  color: var(--text-muted);
}

.path-step {
  padding: 2px 0;
}

.path-step .via {
  font-style: italic;
}

.data-actions {
  display: flex;
  gap: 8px;
  padding: 16px;
  flex-wrap: wrap;
}

/* ── Result modal ─────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}


.modal {
  background: #fff;
  border-radius: var(--radius);
  padding: 24px;
  max-width: 400px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}

.modal h2 {
  margin-bottom: 8px;
}

.modal p {
  color: var(--text-muted);
  margin-bottom: 16px;
}

.result-path {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin-bottom: 20px;
  font-size: 0.88rem;
  max-height: 200px;
  overflow-y: auto;
}

.modal-actions {
  display: flex;
  gap: 10px;
}

.modal-actions button {
  flex: 1;
}

/* ── Table of contents drawer ────────────────────────────── */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 199;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
}

.drawer-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: 82%;
  max-width: 320px;
  background: #fff;
  z-index: 200;
  box-shadow: var(--shadow);
  transform: translateX(-100%);
  transition: transform .25s ease;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top, 0);
}

.drawer.open {
  transform: translateX(0);
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.drawer-header h2 {
  font-size: 1.05rem;
}

.toc-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.toc-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 9px 16px;
  font-size: 0.9rem;
  color: var(--text);
}

.toc-item.level-3 {
  padding-left: 32px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.toc-empty {
  padding: 16px;
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ── Explore panel ────────────────────────────────────────── */
.explore-toolbar {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}

.explore-toolbar button {
  flex: 1;
}

.explore-frame {
  flex: 1;
  min-height: 0;
  width: 100%;
  border: none;
  display: block;
}
