:root {
  --bg: #0d0c0b;
  --panel: #151311;
  --panel-2: #1c1916;
  --line: #2c2723;
  --text: #d9d1c5;
  --muted: #8b8177;
  --faint: #5c544d;
  --accent: #a33a32;      /* blood */
  --gold: #c39d5e;
  --hp: #b8433a;
  --mana: #4f7fd1;
  --stamina: #6a9c4f;
  --spirit: #c9b25a;
  --rift: #8a5cd6;
  --friendly: #6a9c4f;
  --neutral: #c39d5e;
  --hostile: #c4473d;
  --unknown: #8b8177;
  --success: #7fae5f;
  --fail: #c4473d;

  --serif: "Cormorant Garamond", Georgia, serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", Consolas, monospace;

  --left-w: 300px;
  --right-w: 320px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--sans);
}
button { font: inherit; color: inherit; }

/* ---------- Layout ---------- */
.app {
  display: grid;
  grid-template-columns: var(--left-w) minmax(0, 1fr) var(--right-w);
  height: 100vh;
  height: 100dvh;
}
.panel { min-height: 0; min-width: 0; display: flex; flex-direction: column; }
.panel-left  { border-right: 1px solid var(--line); background: var(--panel); }
.panel-right { border-left: 1px solid var(--line); background: var(--panel); }
.panel-center { background: var(--bg); }

.section-title {
  font-family: var(--serif);
  font-size: 17px;
  font-weight: 600;
  color: var(--gold);
  letter-spacing: .02em;
}
.muted { color: var(--muted); font-family: var(--sans); font-size: 12px; font-weight: 400; }
.hint { color: var(--faint); font-size: 12px; margin: 8px 0 0; }

/* ---------- Left: tabs ---------- */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  flex-shrink: 0;
}
.tab {
  flex: 1;
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  padding: 12px 6px 10px;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.is-active { color: var(--gold); border-bottom-color: var(--gold); }
.tab-body { overflow-y: auto; padding: 14px 16px 24px; flex: 1; }

.sheet-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 2px; }
.sheet-name { font-family: var(--serif); font-size: 26px; font-weight: 700; line-height: 1.1; }
.sheet-level { font-family: var(--mono); color: var(--gold); font-size: 13px; }
.sheet-sub { color: var(--muted); font-size: 12px; margin-bottom: 14px; }

.bar { margin: 6px 0; }
.bar-label { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.bar-label b { color: var(--text); font-family: var(--mono); font-weight: 400; }
.bar-track { height: 6px; background: var(--panel-2); border-radius: 3px; overflow: hidden; margin-top: 3px; }
.bar-fill { height: 100%; border-radius: 3px; }

.block { margin-top: 18px; }
.block h3 {
  margin: 0 0 8px;
  font-family: var(--serif);
  font-size: 16px;
  font-weight: 600;
  color: var(--gold);
  border-bottom: 1px solid var(--line);
  padding-bottom: 4px;
}
.attr-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.attr { background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; text-align: center; padding: 6px 0; }
.attr small { display: block; color: var(--muted); font-size: 11px; letter-spacing: .08em; }
.attr span { font-family: var(--mono); font-size: 16px; }

.rows { list-style: none; margin: 0; padding: 0; }
.rows li { display: flex; justify-content: space-between; gap: 8px; padding: 5px 0; border-bottom: 1px dashed var(--line); font-size: 13px; }
.rows li:last-child { border-bottom: 0; }
.rows .r { color: var(--muted); font-family: var(--mono); font-size: 12px; white-space: nowrap; }
.tree-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }

.essence-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.ess { background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; text-align: center; padding: 6px 0; }
.ess small { display: block; font-size: 11px; color: var(--muted); }
.ess span { font-family: var(--mono); font-size: 15px; }

.journal-group h4 { margin: 14px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.entry { background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 9px 11px; margin-bottom: 8px; }
.entry-title { font-weight: 600; font-size: 13px; }
.entry-body { color: var(--muted); font-size: 12.5px; margin-top: 3px; }
.entry-lead { color: var(--gold); font-size: 12px; margin-top: 5px; }
.entry.is-done { opacity: .75; }

/* ---------- Center: log ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  flex-shrink: 0;
}
.topbar-info { flex: 1; display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.clock { font-family: var(--serif); font-size: 18px; font-weight: 600; }
.where { color: var(--muted); font-size: 12.5px; }
.where .lvl { color: var(--gold); font-family: var(--mono); }
.drawer-btn { display: none; background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; width: 34px; height: 34px; cursor: pointer; }

.log {
  flex: 1;
  overflow-y: auto;
  padding: 20px clamp(16px, 4vw, 48px) 28px;
  scroll-behavior: smooth;
}
.log > * { max-width: 760px; margin-left: auto; margin-right: auto; }

.narr { font-family: var(--serif); font-size: 19px; line-height: 1.55; margin: 0 auto 16px; }
.narr p { margin: 0 0 10px; }
.speech { color: var(--gold); }

.player {
  margin: 18px auto 12px;
  padding: 8px 12px;
  border-left: 2px solid var(--accent);
  color: var(--text);
  background: linear-gradient(90deg, rgba(163,58,50,.10), transparent 70%);
  font-size: 14px;
}
.player .who { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .1em; display: block; }
.tag { color: var(--gold); font-weight: 600; }

.roll {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 8px auto;
  padding: 8px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
}
.die {
  flex-shrink: 0;
  width: 38px; height: 38px;
  display: grid; place-items: center;
  font-family: var(--mono); font-weight: 600; font-size: 15px;
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
  background: var(--panel-2);
  border: 0;
  outline: 1px solid var(--line);
}
.roll.ok .die { background: rgba(127,174,95,.18); color: var(--success); }
.roll.bad .die { background: rgba(196,71,61,.18); color: var(--fail); }
.roll-main { flex: 1; min-width: 0; }
.roll-title { font-weight: 600; }
.roll-math { color: var(--muted); font-family: var(--mono); font-size: 12px; }
.roll-result { font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; }
.roll.ok .roll-result { color: var(--success); }
.roll.bad .roll-result { color: var(--fail); }

.system {
  margin: 16px auto;
  padding: 14px 16px;
  border: 1px solid rgba(138,92,214,.45);
  border-radius: 8px;
  background: radial-gradient(120% 140% at 0% 0%, rgba(138,92,214,.16), transparent 60%), var(--panel);
  box-shadow: 0 0 24px rgba(138,92,214,.12);
}
.system .sys-title { font-family: var(--serif); font-size: 20px; font-weight: 700; color: #cdb8f2; }
.system .sys-body { color: var(--text); font-size: 13px; margin-top: 4px; }
.system ul { margin: 8px 0 0; padding-left: 18px; color: var(--muted); font-size: 13px; }

.time {
  display: flex; align-items: center; gap: 10px;
  margin: 18px auto; color: var(--faint); font-size: 12px; text-transform: uppercase; letter-spacing: .12em;
}
.time::before, .time::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.thinking { color: var(--faint); font-style: italic; font-size: 13px; margin: 6px auto; }

/* ---------- Composer ---------- */
.composer {
  position: relative;
  display: flex;
  gap: 10px;
  padding: 12px clamp(16px, 4vw, 48px) 16px;
  border-top: 1px solid var(--line);
  background: var(--panel);
  flex-shrink: 0;
}
.composer textarea {
  flex: 1;
  resize: none;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  font: 14px/1.4 var(--sans);
}
.composer textarea:focus { outline: none; border-color: var(--gold); }
.send {
  background: var(--accent);
  border: 0;
  border-radius: 8px;
  padding: 0 20px;
  font-weight: 600;
  cursor: pointer;
}
.send:hover { filter: brightness(1.15); }

.tag-menu {
  position: absolute;
  left: clamp(16px, 4vw, 48px);
  bottom: calc(100% - 4px);
  width: min(360px, calc(100% - 32px));
  max-height: 260px;
  overflow-y: auto;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
  padding: 4px;
  z-index: 5;
}
.tag-opt { display: flex; justify-content: space-between; gap: 10px; padding: 7px 10px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.tag-opt small { color: var(--muted); font-family: var(--mono); }
.tag-opt.is-active, .tag-opt:hover { background: rgba(195,157,94,.14); }

/* ---------- Right: map + NPCs ---------- */
.map-wrap { padding: 12px 14px; border-bottom: 1px solid var(--line); flex-shrink: 0; }
.map-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.seg { display: flex; background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 2px; }
.seg-btn { background: none; border: 0; padding: 3px 10px; border-radius: 4px; font-size: 12px; color: var(--muted); cursor: pointer; }
.seg-btn.is-active { background: var(--bg); color: var(--gold); }

.minimap {
  width: 100%;
  aspect-ratio: 1;
  display: block;
  background: #11100e;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.map-foot { color: var(--muted); font-size: 12px; margin-top: 6px; display: flex; justify-content: space-between; }

.npc-dot { cursor: pointer; transition: r .15s; }
.npc-ring { fill: none; stroke-width: 1.5; opacity: 0; pointer-events: none; }
.npc-g.is-selected .npc-ring { opacity: 1; animation: pulse 1.4s ease-out infinite; }
.npc-g.is-selected .npc-label { opacity: 1; }
.npc-label { font: 600 7px var(--sans); fill: var(--text); opacity: 0; pointer-events: none; paint-order: stroke; stroke: #11100e; stroke-width: 2.5px; }
@keyframes pulse {
  0%   { r: 4; opacity: 1; }
  100% { r: 11; opacity: 0; }
}
.you-dot { fill: #fff; }
.map-text { font: 600 6.5px var(--sans); fill: var(--faint); letter-spacing: .06em; text-transform: uppercase; }

.npc-wrap { padding: 12px 14px; overflow-y: auto; flex: 1; }
.npc-list { list-style: none; margin: 8px 0 0; padding: 0; }
.npc {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid transparent;
}
.npc:hover { background: var(--panel-2); }
.npc.is-selected { background: var(--panel-2); border-color: var(--gold); }
.npc-swatch { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.npc-main { flex: 1; min-width: 0; }
.npc-name { font-weight: 600; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.npc-sub { color: var(--muted); font-size: 12px; }
.npc-threat { font-size: 11px; font-family: var(--mono); color: var(--muted); white-space: nowrap; }
.npc-threat.t-beyond { color: var(--hostile); }
.npc-threat.t-danger { color: #d98a3a; }
.npc-threat.t-even { color: var(--neutral); }
.npc-threat.t-beneath { color: var(--friendly); }
.npc-detail { color: var(--muted); font-size: 12px; padding: 4px 10px 10px 30px; }

/* ---------- Responsive: side panels become drawers ---------- */
@media (max-width: 1180px) {
  :root { --left-w: 260px; --right-w: 280px; }
}
@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .topbar-info { flex-direction: column; gap: 0; min-width: 0; }
  .clock { font-size: 16px; }
  .drawer-btn { display: grid; place-items: center; }
  .panel-left, .panel-right {
    position: fixed;
    top: 0; bottom: 0;
    width: min(340px, 88vw);
    z-index: 20;
    transition: transform .2s ease;
  }
  .panel-left  { left: 0;  transform: translateX(-100%); }
  .panel-right { right: 0; transform: translateX(100%); }
  .app.show-left  .panel-left  { transform: none; }
  .app.show-right .panel-right { transform: none; }
  .scrim { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 10; display: none; }
  .app.show-left .scrim, .app.show-right .scrim { display: block; }
  .topbar { padding: 10px 16px; }
  .narr { font-size: 17.5px; }
}

/* ===================================================================
   Live game additions (M2)
   =================================================================== */

/* ---------- Simple pages: login, setup, create ---------- */
.page {
  min-height: 100%;
  display: flex;
  justify-content: center;
  padding: 48px 16px;
  background: radial-gradient(120% 80% at 50% 0%, rgba(138,92,214,.10), transparent 60%), var(--bg);
}
.card {
  width: 100%;
  max-width: 440px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 28px 24px;
  align-self: flex-start;
}
.card.wide { max-width: 760px; }
.card h1 { font-family: var(--serif); font-size: 32px; margin: 0 0 4px; color: var(--text); text-wrap: balance; }
.card .lede { color: var(--muted); margin: 0 0 20px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 12px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.field input, .field textarea {
  background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 12px; font: 15px/1.4 var(--sans);
}
.field input:focus, .field textarea:focus { outline: none; border-color: var(--gold); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--accent); color: var(--text); border: 0; border-radius: 8px;
  padding: 11px 20px; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:hover { filter: brightness(1.15); }
.btn:disabled { opacity: .45; cursor: not-allowed; filter: none; }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--muted); }
.btn.small { padding: 4px 10px; font-size: 12px; font-weight: 500; border-radius: 6px; }
.alert { background: rgba(196,71,61,.12); border: 1px solid rgba(196,71,61,.45); color: #f0c3be; border-radius: 8px; padding: 10px 12px; margin-bottom: 14px; }

/* Character creation */
.create-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
@media (max-width: 720px) { .create-grid { grid-template-columns: 1fr; } }
.create-grid h2 { font-family: var(--serif); color: var(--gold); font-size: 20px; margin: 0 0 10px; }
.paths { display: grid; gap: 8px; }
.path-opt { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.path-opt:has(input:checked) { border-color: var(--gold); background: rgba(195,157,94,.08); }
.path-opt input { margin-top: 4px; accent-color: var(--gold); }
.path-opt b { display: block; }
.path-opt small { color: var(--muted); }
.pb-row { display: grid; grid-template-columns: 52px 32px 40px 32px 1fr; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.pb-row:last-child { border-bottom: 0; }
.pb-name { font-weight: 600; letter-spacing: .06em; }
.pb-val { text-align: center; font-family: var(--mono); font-size: 17px; font-variant-numeric: tabular-nums; }
.pb-mod { color: var(--muted); font-family: var(--mono); font-size: 12px; }
.pb-btn { width: 32px; height: 32px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel-2); color: var(--text); cursor: pointer; font-size: 16px; }
.pb-btn:disabled { opacity: .35; cursor: not-allowed; }
.pb-left { margin: 10px 0 0; color: var(--muted); }
.pb-left b { color: var(--gold); font-family: var(--mono); }

/* ---------- Game screen additions ---------- */
.note { color: var(--muted); font-size: 13px; margin: 4px auto 8px; padding-left: 12px; border-left: 2px solid var(--line); }
.narr .plain { margin: 0 0 10px; }

.activity { margin: 10px auto; padding: 12px 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; font-size: 13px; }
.activity .a-title { font-weight: 600; }
.activity .a-sum { color: var(--muted); margin: 2px 0 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.chip { width: 26px; height: 26px; display: grid; place-items: center; font: 600 11px var(--mono); border-radius: 5px; background: var(--panel-2); color: var(--faint); }
.chip.ok { color: var(--success); background: rgba(127,174,95,.14); }
.chip.crit { color: var(--gold); background: rgba(195,157,94,.22); }
.activity ul { margin: 0; padding-left: 18px; color: var(--text); }
.activity .a-skill { color: var(--gold); margin-top: 6px; font-size: 12px; }

.combat-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px;
  padding: 8px clamp(16px, 4vw, 48px);
  background: rgba(163,58,50,.12); border-top: 1px solid rgba(163,58,50,.45);
  font-size: 13px; flex-shrink: 0;
}
.combat-bar b { color: #f0c3be; letter-spacing: .08em; text-transform: uppercase; font-size: 11px; }
.combat-foe { display: flex; align-items: center; gap: 8px; }
.combat-foe .bar-track { width: 120px; margin: 0; }

.ess-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.ess-table td { padding: 6px 4px; border-bottom: 1px dashed var(--line); vertical-align: middle; }
.ess-table .k { font-family: var(--mono); color: var(--muted); }
.grade { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.grade.dense { color: var(--gold); }
.grade.common { color: var(--text); }
.grade.weak { color: var(--muted); }
.grade.thin { color: var(--mana); }
.grade.worthless { color: var(--faint); }
.tainted { color: var(--hostile); font-size: 11px; font-weight: 600; }
.row-actions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.attr .raise { display: block; margin-top: 4px; font-size: 10px; color: var(--muted); background: none; border: 1px solid var(--line); border-radius: 4px; cursor: pointer; padding: 1px 4px; }
.attr .raise:hover { color: var(--gold); border-color: var(--gold); }
.muted-note { color: var(--muted); font-size: 12px; margin: 6px 0 0; }
.sheet-actions { display: flex; justify-content: flex-end; margin-top: 18px; }
.composer.busy textarea { opacity: .6; }
.combat-bar[hidden] { display: none; }
