/* ============================================================================
 * styles.css — Bramblemere Reaches hex map
 * Aesthetic: aged cartographer's field journal. Ink, parchment, foxing.
 * Touch-first: large tap targets, bottom-sheet detail panel on mobile.
 * ============================================================================ */

:root {
  --ink:        #2b2118;
  --ink-soft:   #5a4a39;
  --parch:      #ece3cf;
  --parch-deep: #ddd0b1;
  --parch-edge: #c9b78f;
  --accent:     #7c3b2e;   /* oxblood */
  --accent-2:   #3d5a45;   /* moss */
  --gold:       #9c7a35;
  --risk:       #8a2f23;

  /* terrain tints */
  --t-marsh:      #5e6b4a;
  --t-ruins:      #8a7d6b;
  --t-settlement: #9c7a35;
  --t-forest:     #3d5a45;
  --t-water:      #4a6b78;
  --t-unknown:    #b7a884;

  --font-display: 'Cormorant Garamond', 'Hoefler Text', Georgia, serif;
  --font-body:    'Spectral', Georgia, 'Times New Roman', serif;
  /* Was a script font (Caveat); replaced with the readable serif everywhere.
     Kept as a variable so existing rules still resolve to something sensible. */
  --font-hand:    'Spectral', Georgia, 'Times New Roman', serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; height: 100%;
  font-family: var(--font-body);
  font-size: 18px;            /* larger, more readable base */
  color: var(--ink);
  background: var(--parch);
  overscroll-behavior: none;
}

/* Parchment texture via layered gradients (no image dependency) */
body {
  background-color: var(--parch);
  background-image:
    radial-gradient(ellipse at 20% 15%, rgba(156,122,53,0.10), transparent 55%),
    radial-gradient(ellipse at 85% 80%, rgba(124,59,46,0.08), transparent 50%),
    radial-gradient(circle at 50% 50%, rgba(0,0,0,0.02), transparent 70%);
}

/* ---- App frame --------------------------------------------------------- */

#app { display: flex; flex-direction: column; height: 100dvh; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: .75rem;
  padding: .7rem 1rem;
  border-bottom: 2px solid var(--parch-edge);
  background: linear-gradient(180deg, var(--parch-deep), var(--parch));
  box-shadow: 0 2px 8px rgba(0,0,0,.08);
  z-index: 5;
}
.topbar-titles { display: flex; align-items: baseline; gap: .75rem; min-width: 0; }
.topbar-about {
  flex: 0 0 auto;
  font-family: var(--font-display); font-weight: 600; font-size: 1.05rem;
  text-decoration: none; color: var(--ink);
  border: 1.5px solid var(--parch-edge); border-radius: 8px;
  padding: .4rem .9rem; background: var(--parch);
}
.topbar-about:hover, .topbar-about:active { background: var(--parch-deep); }
.topbar .brand {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.5rem;
  letter-spacing: .02em;
  color: var(--ink);
  margin: 0;
}
.topbar .sub {
  font-family: var(--font-hand);
  font-size: 1.05rem;
  color: var(--accent);
  margin: 0;
}

/* ---- Map --------------------------------------------------------------- */

.map-wrap { position: relative; flex: 1; overflow: hidden; }

#hexmap {
  width: 100%; height: 100%;
  display: block;
  touch-action: none;            /* we handle all gestures ourselves */
  cursor: grab;
  background:
    radial-gradient(circle at 30% 30%, #efe7d4, #e2d7bd 70%, #d3c39e 100%);
}
#hexmap:active { cursor: grabbing; }

#map-status {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-family: var(--font-display); font-size: 1.2rem; color: var(--ink-soft);
  padding: 1.5rem;
}
.load-error {
  max-width: 420px; text-align: center;
  background: var(--parch); border: 1.5px solid var(--accent);
  border-radius: 12px; padding: 1.5rem 1.4rem;
  box-shadow: 0 4px 16px rgba(0,0,0,.15);
}
.load-error strong { font-size: 1.3rem; color: var(--accent); display: block; margin-bottom: .5rem; }
.load-error p { font-size: 1rem; font-family: var(--font-body); margin: .4rem 0; line-height: 1.45; }
.load-error code { font-size: .9em; }

/* Hexes */
.hex polygon {
  fill: var(--parch-deep);
  stroke: var(--ink-soft);
  stroke-width: 1.5;
  transition: fill .15s ease, stroke .15s ease;
}
/* Empty lattice — now tappable groups (tap to create) */
.empty-cell {
  fill: rgba(199,183,143,.18);
  stroke: rgba(90,74,57,.32);
  stroke-width: 1;
  stroke-dasharray: 3 3;
  transition: fill .12s ease;
}
.hex--empty { cursor: pointer; }
.hex--empty .empty-plus {
  font-family: var(--font-display);
  font-size: 22px; font-weight: 600;
  fill: var(--accent);
  opacity: 0;
  transition: opacity .12s ease;
  pointer-events: none; user-select: none;
}
.hex--empty:hover .empty-cell,
.hex--empty:active .empty-cell { fill: rgba(156,122,53,.22); stroke: var(--accent); }
.hex--empty:hover .empty-plus,
.hex--empty:active .empty-plus { opacity: .7; }
.hex--filled { cursor: pointer; }
.hex--filled polygon { fill: var(--parch-deep); }

/* Zoom-based decluttering */
.hex.hide-coord .hex-coord { display: none; }
.hex.hide-label .hex-label { display: none; }

.hex--filled[data-terrain="marsh"]      polygon { fill: color-mix(in srgb, var(--t-marsh) 38%, var(--parch-deep)); }
.hex--filled[data-terrain="ruins"]      polygon { fill: color-mix(in srgb, var(--t-ruins) 42%, var(--parch-deep)); }
.hex--filled[data-terrain="settlement"] polygon { fill: color-mix(in srgb, var(--t-settlement) 40%, var(--parch-deep)); }
.hex--filled[data-terrain="forest"]     polygon { fill: color-mix(in srgb, var(--t-forest) 40%, var(--parch-deep)); }
.hex--filled[data-terrain="water"]      polygon { fill: color-mix(in srgb, var(--t-water) 42%, var(--parch-deep)); }
.hex--filled[data-terrain="cave"]       polygon { fill: color-mix(in srgb, #3a3340 46%, var(--parch-deep)); }
.hex--filled[data-terrain="mountain"]   polygon { fill: color-mix(in srgb, #6b6258 42%, var(--parch-deep)); }

/* Distortion rings — the Bible's "single biggest lever", shown at a glance.
   Drawn as an inset outline; kept subtle so it reads over images cleanly. */
.dist-ring { fill: none; stroke-width: 2.5; pointer-events: none; opacity: .9; }
.dist-ring-low  { stroke: #4a7c59; stroke-dasharray: none; }      /* spared / green */
.dist-ring-mid  { stroke: #9c7a35; stroke-dasharray: 6 4; }       /* gold, dashed */
.dist-ring-high { stroke: #8a2f23; stroke-dasharray: 2 3; }       /* oxblood, urgent */

/* Base hex border: thin and neutral; the image (if any) sits on top. */
.hex--filled polygon { stroke: var(--ink-soft); stroke-width: 1; }

/* Sanctuary — the anchor hex. Let the green distortion ring carry the colour;
   keep the base border thin so the two don't fight at the edge. */
.hex--anchor polygon { stroke: var(--accent); stroke-width: 2; }
.hex--anchor .hex-icon { font-size: 20px; }

.hex--filled { cursor: pointer; }

.hex--filled:hover polygon,
.hex--filled:active polygon {
  fill: color-mix(in srgb, var(--gold) 30%, var(--parch-deep));
  stroke: var(--accent);
  stroke-width: 2.5;
}

.hex-coord { font-size: 7px; fill: rgba(90,74,57,.55); font-family: var(--font-body); user-select: none; pointer-events: none; }
.hex-label { font-size: 15px; fill: var(--ink); font-family: var(--font-display); font-weight: 700; user-select: none; pointer-events: none; paint-order: stroke; }
.hex-label-bg {
  fill: rgba(236,227,207,.72);
  stroke: rgba(255,255,255,.5); stroke-width: .5;
  filter: url(#labelblur);
  pointer-events: none;
}
.hex-icon  { font-size: 22px; user-select: none; pointer-events: none; }

/* Zoom controls */
.map-controls {
  position: absolute; right: .8rem; bottom: .8rem;
  display: flex; flex-direction: column; gap: .4rem; z-index: 4;
}
.map-controls button {
  width: 48px; height: 48px;        /* generous touch target */
  border: 1.5px solid var(--parch-edge);
  background: var(--parch);
  color: var(--ink);
  font-family: var(--font-display); font-size: 1.4rem; font-weight: 600;
  border-radius: 10px;
  box-shadow: 0 2px 6px rgba(0,0,0,.18);
  cursor: pointer;
  display: grid; place-items: center;
  transition: transform .08s ease, background .15s ease;
}
.map-controls button:active { transform: scale(.92); background: var(--parch-deep); }

/* ---- Views (map vs hex page) ------------------------------------------- */
.view[hidden] { display: none !important; }
#hexpage {
  position: fixed; inset: 0; z-index: 9;
  background: var(--parch);
  background-image:
    radial-gradient(ellipse at 20% 15%, rgba(156,122,53,.10), transparent 55%),
    radial-gradient(ellipse at 85% 80%, rgba(124,59,46,.08), transparent 50%);
  display: flex; flex-direction: column;
  height: 100dvh;
}

/* page header — centred title with the back button floated top-left */
.hp-top {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: .15rem; text-align: center;
  padding: .9rem 1rem .8rem;
  min-height: 4.2rem;
  border-bottom: 2px solid var(--parch-edge);
  background: linear-gradient(180deg, var(--parch-deep), var(--parch));
}
.hp-top[data-distortion="high"] { border-bottom-color: var(--risk); }
.hp-top[data-distortion="low"]  { border-bottom-color: #4a7c59; }
.hp-back {
  position: absolute; left: .8rem; top: .8rem;
  font-family: var(--font-display); font-weight: 600; font-size: 1rem;
  background: var(--parch); border: 1.5px solid var(--parch-edge); border-radius: 8px;
  color: var(--ink); padding: .4rem .75rem; cursor: pointer; z-index: 2;
}
.hp-back:active, .hp-back:hover { background: var(--parch-deep); }
.hp-titlewrap { min-width: 0; max-width: 100%; padding: 0 3.2rem; }
.hp-eyebrow {
  font-family: var(--font-body); font-size: 1rem; font-weight: 500;
  letter-spacing: .03em; color: var(--accent); text-transform: capitalize;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.hp-title {
  font-family: var(--font-display); font-weight: 700; font-size: 2rem;
  margin: 0; line-height: 1.08; color: var(--ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* tab bar — horizontal scroll on narrow screens, with a right-edge fade
   so it's clear there are more tabs off-screen. */
.hp-tabwrap { position: relative; border-bottom: 1.5px solid var(--parch-edge); }
.hp-tabwrap::after {
  content: ''; position: absolute; top: 0; right: 0; bottom: 0; width: 2.5rem;
  pointer-events: none;
  background: linear-gradient(90deg, transparent, var(--parch) 80%);
}
.hp-tabs {
  display: flex; gap: .3rem; overflow-x: auto; -webkit-overflow-scrolling: touch;
  padding: .5rem .8rem 0; scrollbar-width: none;
}
.hp-tabs::-webkit-scrollbar { display: none; }
.hp-tab {
  flex: 0 0 auto;
  font-family: var(--font-display); font-weight: 600; font-size: 1.1rem;
  background: none; border: none; color: var(--ink-soft);
  padding: .5rem .7rem; border-radius: 8px; cursor: pointer;
  white-space: nowrap; position: relative;
  display: flex; align-items: center; gap: .35rem;
}
.hp-tab.active { color: var(--accent); background: rgba(124,59,46,.1); }
.hp-tab.active::after {
  content: ''; position: absolute; left: .7rem; right: .7rem; bottom: 0;
  height: 2.5px; background: var(--accent); border-radius: 2px;
}
.hp-tabcount {
  font-family: var(--font-body); font-size: .72rem; font-weight: 700;
  background: var(--parch-edge); color: var(--ink); border-radius: 10px;
  padding: 0 .4rem; min-width: 1.1rem; text-align: center;
}
.hp-tab.active .hp-tabcount { background: var(--accent); color: var(--parch); }

/* page body */
.hp-body {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 1.2rem 1.5rem 3rem; max-width: 860px; width: 100%; margin: 0 auto;
}
.hp-tagline { font-style: italic; color: var(--ink-soft); font-size: 1.25rem; margin: .4rem 0 1rem; text-align: center; line-height: 1.4; }
.hp-empty { text-align: center; padding: 3rem 1rem; }

/* lists with tappable rows (NPCs, organisations) */
.hp-list { list-style: none; margin: 0; padding: 0; }
.hp-list-item, .hp-res-item {
  display: flex; align-items: center; gap: .8rem;
  padding: .9rem .9rem; margin-bottom: .55rem;
  background: rgba(255,255,255,.4); border: 1.5px solid var(--parch-edge);
  border-radius: 10px; cursor: pointer;
  transition: border-color .12s, background .12s;
}
.hp-list-item:active { background: var(--parch-deep); border-color: var(--accent); }
.hp-list-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .2rem; }
.hp-list-main strong { font-family: var(--font-display); font-size: 1.15rem; }
.hp-list-summary { color: var(--ink-soft); font-size: .96rem; line-height: 1.4; }
.hp-chevron { color: var(--accent); font-size: 1.5rem; flex: 0 0 auto; }

/* subtab header (within a list item's detail) */
.hp-subhead { display: flex; align-items: center; gap: .7rem; margin-bottom: .6rem; }
.hp-subback {
  font-family: var(--font-display); font-weight: 600; font-size: .92rem;
  background: none; border: 1.5px solid var(--parch-edge); border-radius: 8px;
  color: var(--accent-2); padding: .35rem .7rem; cursor: pointer; flex: 0 0 auto;
}
.hp-subhead h2 { font-family: var(--font-display); font-size: 1.5rem; margin: 0; }

/* stat block */
.statblock {
  background: rgba(156,122,53,.08);
  border: 1px solid var(--parch-edge); border-left: 3px solid var(--accent);
  border-radius: 0 10px 10px 0; padding: .8rem 1rem; margin: 1rem 0;
}
.sb-head { font-style: italic; color: var(--ink-soft); margin-bottom: .4rem; }
.sb-line { display: flex; flex-wrap: wrap; gap: 1rem; margin-bottom: .5rem; font-size: .95rem; }
.sb-stats {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: .3rem;
  text-align: center; margin: .5rem 0; border-block: 1px solid var(--parch-edge); padding: .4rem 0;
}
.sb-stats > div { display: flex; flex-direction: column; }
.sb-ab { font-family: var(--font-display); font-weight: 700; color: var(--accent); font-size: .85rem; }
.sb-val { font-size: .82rem; }
.sb-skills { font-size: .92rem; margin: .4rem 0; }
.sb-traits p { font-size: .92rem; line-height: 1.45; margin: .35rem 0; }
.sb-cr { margin: .4rem 0 0; }
@media (max-width: 420px) { .sb-stats { grid-template-columns: repeat(3, 1fr); row-gap: .5rem; } }

/* resources */
.res-type {
  flex: 0 0 auto; font-family: var(--font-hand); font-size: .95rem;
  padding: .15rem .6rem; border-radius: 14px; align-self: flex-start;
}
.res-shop    { background: rgba(156,122,53,.18); color: #6b5320; }
.res-gather  { background: rgba(74,124,89,.18); color: #2f5d3a; }
.res-service { background: rgba(124,59,46,.14); color: var(--accent); }
.hp-res-item { cursor: default; }

/* encounter rows that have detail */
.roll-table tr.has-detail { cursor: pointer; }
.roll-table tr.has-detail:active td { background: var(--parch-deep); }

.hex-detail-head { padding-bottom: .4rem; border-bottom: 1px dashed var(--parch-edge); margin-bottom: 1rem; }
.hex-eyebrow {
  font-family: var(--font-hand); font-size: 1.05rem; color: var(--accent);
  text-transform: capitalize;
}
.hex-detail-head h2 {
  font-family: var(--font-display); font-weight: 700;
  font-size: 2rem; margin: .1rem 0 .2rem; line-height: 1.05;
}
.tagline { font-style: italic; color: var(--ink-soft); margin: 0; }

/* Distortion badge in the detail header */
.dist-badge {
  display: inline-block; margin-top: .6rem;
  font-family: var(--font-hand); font-size: 1rem;
  padding: .15rem .7rem; border-radius: 20px;
  border: 1.5px solid;
}
.dist-low  { color: #2f5d3a; border-color: #4a7c59; background: rgba(74,124,89,.12); }
.dist-mid  { color: #6b5320; border-color: #9c7a35; background: rgba(156,122,53,.14); }
.dist-high { color: #7c241a; border-color: #8a2f23; background: rgba(138,47,35,.12); }

/* Distinctive lines for the Bible's signature fields */
.rule-line {
  font-weight: 500; background: rgba(156,122,53,.12);
  border-left: 3px solid var(--gold); padding: .55rem .8rem; border-radius: 0 8px 8px 0;
}
.edge-line { font-style: italic; color: var(--ink-soft); }
.detail-list .rumour { font-style: italic; color: var(--accent-2); }

.hex-section { margin: 1.6rem 0; }
.hex-section h3 {
  font-family: var(--font-display); font-size: 1.5rem; font-weight: 600;
  color: var(--accent-2); margin: 0 0 .5rem; text-align: center;
  border-bottom: 1px solid var(--parch-edge); padding-bottom: .3rem;
}
.hex-section p { margin: .3rem 0; line-height: 1.6; font-size: 1.08rem; }

.detail-list { list-style: none; margin: 0; padding: 0; }
.detail-list li { padding: .65rem 0; border-bottom: 1px dotted var(--parch-edge); line-height: 1.5; font-size: 1.05rem; }
.detail-list li:last-child { border-bottom: none; }
.detail-list .muted { color: var(--ink-soft); font-size: .94em; }
.detail-list .cr {
  font-family: var(--font-hand); color: var(--accent); font-size: 1em;
  background: rgba(124,59,46,.1); padding: 0 .4rem; border-radius: 4px;
}
.detail-list .risk { color: var(--risk); }
.muted { color: var(--ink-soft); }
code { font-family: ui-monospace, monospace; background: rgba(0,0,0,.06); padding: 0 .3rem; border-radius: 3px; }

/* Roll tables */
.roll-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.roll-btn {
  font-family: var(--font-display); font-weight: 600; font-size: .95rem;
  background: var(--accent); color: var(--parch);
  border: none; border-radius: 8px; padding: .5rem .9rem;
  cursor: pointer; box-shadow: 0 2px 5px rgba(0,0,0,.2);
  transition: transform .08s ease, background .15s;
  white-space: nowrap;
}
.roll-btn:active { transform: scale(.94); background: #5e2c22; }
.roll-result {
  margin: .5rem 0; padding: .6rem .8rem; border-radius: 8px;
  background: rgba(156,122,53,.14); border-left: 3px solid var(--gold);
  font-style: italic; line-height: 1.4;
}
.roll-result .rolled {
  font-style: normal; font-family: var(--font-hand);
  color: var(--accent); font-size: 1.15em; margin-right: .4rem;
}
.roll-table table { width: 100%; border-collapse: collapse; margin-top: .5rem; font-size: .94rem; }
.roll-table th { text-align: left; font-family: var(--font-display); color: var(--ink-soft); border-bottom: 1.5px solid var(--parch-edge); padding: .35rem .4rem; }
.roll-table td { padding: .4rem .4rem; border-bottom: 1px dotted var(--parch-edge); vertical-align: top; line-height: 1.4; }
.roll-table td:first-child { width: 3.2rem; font-family: var(--font-hand); color: var(--accent); font-size: 1.05em; }
.roll-table tr.hit td { background: rgba(156,122,53,.22); }
.roll-table tr.hit td:first-child { font-weight: 700; }

.empty-hex { text-align: center; padding: 3rem 1rem; }
.empty-hex p:first-child { font-family: var(--font-display); font-size: 1.4rem; }
.loading { text-align: center; color: var(--ink-soft); padding: 2rem; }

/* ---- Undiscovered (empty) hex view ------------------------------------- */
.undiscovered { text-align: center; padding: 3.5rem 1.5rem; }
.undiscovered-mark {
  width: 84px; height: 84px; margin: 0 auto 1.2rem;
  display: grid; place-items: center;
  font-family: var(--font-display); font-size: 3rem; font-weight: 600;
  color: var(--parch-edge);
  border: 2px dashed var(--parch-edge); border-radius: 50%;
}
.undiscovered h2 {
  font-family: var(--font-display); font-weight: 700; font-size: 2rem;
  color: var(--ink-soft); margin: 0 0 .4rem;
}
.undiscovered .coord-chip { margin-top: 1.4rem; font-family: var(--font-body); font-size: 1.05rem; color: var(--accent); }
.undiscovered p { font-size: 1.1rem; line-height: 1.55; max-width: 30rem; margin: .6rem auto; }

/* Exploring hex page */
.undiscovered.exploring .undiscovered-mark { color: var(--gold); border-color: var(--gold); border-style: solid; }
.undiscovered.exploring h2 { color: var(--accent); }
.ig-cta {
  display: inline-block; margin-top: 1.6rem;
  font-family: var(--font-display); font-weight: 700; font-size: 1.2rem;
  background: var(--accent); color: var(--parch);
  padding: .8rem 1.6rem; border-radius: 10px; text-decoration: none;
  box-shadow: 0 3px 8px rgba(0,0,0,.22);
}
.ig-cta:hover { background: #5e2c22; }

/* loading state while a hex detail file is fetched */
.hp-loading {
  display: grid; place-items: center; height: 60vh;
  font-family: var(--font-display); font-size: 1.4rem; color: var(--ink-soft);
}

/* Map cue: exploring hexes pulse a soft gold dashed ring so they read as
   "open but not yet charted." */
.hex--exploring polygon { stroke: var(--gold); stroke-width: 2.5; stroke-dasharray: 8 5; }


/* ---- Responsive tuning ------------------------------------------------- */
/* Narrow phones: scale text down so nothing crowds the screen edges. */
@media (max-width: 420px) {
  html, body { font-size: 16px; }
  .hp-title { font-size: 1.65rem; }
  .hp-eyebrow { font-size: .9rem; }
  .hp-titlewrap { padding: 0 2.8rem; }
  .hp-tab { font-size: 1rem; padding: .5rem .55rem; }
  .hex-section h3 { font-size: 1.3rem; }
  .hp-tagline { font-size: 1.1rem; }
  .hp-body { padding: 1rem 1rem 3rem; }
  .statblock { font-size: .92rem; }
}
/* Map topbar: keep the title tidy and stack the subtitle on narrow screens. */
@media (max-width: 560px) {
  .topbar { padding: .55rem 1rem; }
  .topbar-titles { flex-direction: column; align-items: flex-start; gap: .05rem; }
  .topbar .brand { font-size: 1.35rem; }
  .topbar .sub { font-size: .92rem; }
  .topbar-about { font-size: .95rem; padding: .35rem .75rem; }
}
