/* Blackwood Manor — mobile-first, dark, Halloween-toned. */

:root {
  --bg: #0e0b12;
  --panel: #17121f;
  --ink: #e9e2f0;
  --muted: #8d8399;
  --accent: #d97706;
  --accent-2: #7c3aed;
  --ok: #34d399;
  --bad: #f87171;
  --line: #2a2133;
  /* Derived tokens (swapped wholesale by the light theme below). */
  --btn-ink: #1c1005;
  --link: #c4b5fd;
  --link-hover: #ddd6fe;
  --pill-ok-ink: #06281d;
  --pill-warn-ink: #2a0a0a;
  --pill-cat-bg: #1e293b;
  --pill-cat-ink: #cbd5e1;
  --alert-bg: rgba(248, 113, 113, .12);
  --alert-ink: #fca5a5;
  --alert-border: rgba(248, 113, 113, .35);
  --alert-ok-bg: rgba(52, 211, 153, .12);
  --alert-ok-ink: #34d399;
  --alert-ok-border: rgba(52, 211, 153, .35);
  --code-bg: #120d19;
  --body-ink: #e5d9f0;
  --dot-off: #4a4254;
  --preview-bg: rgba(124, 58, 237, .12);
  --panel-shadow: none;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
}

.wrap { max-width: 44rem; margin: 0 auto; padding: 1rem; }
.wrap.narrow { max-width: 26rem; }
.wrap.wide { max-width: 56rem; }

.top-actions { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }

.tabs { display: flex; gap: .25rem; flex-wrap: wrap; margin-bottom: 1rem; }
.tabs a {
  padding: .45rem .85rem; border-radius: 8px 8px 0 0;
  text-decoration: none; color: var(--muted);
  background: var(--panel); border: 1px solid var(--line); border-bottom: 0;
  font-size: .88rem;
}
.tabs a:hover { color: var(--ink); }
.tabs a.active { color: var(--ink); background: var(--panel); box-shadow: inset 0 -2px 0 var(--accent); }

/* Sub-tabs for the Players & Links section (player switcher + per-player tabs). */
.subtabs {
  display: flex; align-items: center; gap: .5rem; flex-wrap: wrap;
  margin: -0.5rem 0 .9rem; padding: .4rem .6rem;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
}
.subtabs a {
  padding: .3rem .7rem; border-radius: 7px; text-decoration: none;
  color: var(--muted); font-size: .85rem;
}
.subtabs a:hover { color: var(--ink); background: var(--bg); }
.subtabs a.active { color: var(--ink); background: var(--bg); box-shadow: inset 0 -2px 0 var(--accent-2); }
.subtabs.playertabs { border-top: 0; margin-top: -0.9rem; border-radius: 0 0 10px 10px; }
.player-switch { margin-left: auto; }
.player-switch label { margin: 0; display: inline-flex; align-items: center; gap: .35rem; }

.quick-actions { margin-bottom: 1rem; }

.btn.danger { background: transparent; color: var(--bad); border: 1px solid rgba(248,113,113,.5); }
.btn.danger:hover { background: rgba(248,113,113,.12); filter: none; }

.game-head { display: flex; align-items: flex-start; justify-content: space-between; gap: .75rem; }
.game-card h2 { margin-bottom: .15rem; }
.game-card h2 a { color: var(--ink); text-decoration: none; }
.game-card h2 a:hover { color: var(--accent); }

ul.log li { padding: .3rem 0; border-bottom: 1px dashed var(--line); font-size: .9rem; }
ul.log li:last-child { border-bottom: 0; }

.linkgrid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); margin-top: 1rem; }
.linkcard { text-align: center; }
.linkcard h2 { font-size: .98rem; }
.linkcard .qr { width: 150px; height: 150px; border-radius: 8px; background: #fff; padding: .35rem; margin: .4rem auto; display: block; }
.linktext { font-size: .78rem; }
#copy-all { margin-top: .5rem; }

ul.bin li { padding: .55rem 0; border-bottom: 1px dashed var(--line); display: flex; justify-content: space-between; gap: .5rem; align-items: baseline; }
ul.bin li:last-child { border-bottom: 0; }

.bin-heading {
  font-size: .82rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--accent); margin: .9rem 0 .35rem;
}
.bin-heading:first-of-type { margin-top: .5rem; }

/* Evidence bin items: make the whole row a clear, tappable target. */
ul.bin li.bin-item { display: block; }
.bin-link {
  display: flex; justify-content: space-between; align-items: baseline; gap: .6rem;
  text-decoration: none; color: var(--ink);
  padding: .5rem .7rem; border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg);
}
.bin-link:hover { border-color: var(--accent); }
.bin-title { font-weight: 600; }
.bin-meta { white-space: nowrap; color: var(--muted); }
.bin-inline { margin-top: .45rem; }
.bin-inline .media { margin: 0; }

.media { display: block; max-width: 100%; border-radius: 8px; margin: .6rem 0; background: #fff; }
audio.media { width: 100%; height: 44px; background: transparent; }
/* PDF viewer: dvh keeps it inside the visible viewport on mobile browsers whose
   toolbars collapse/expand (vh would overshoot and hide the bottom). */
.media-pdf { width: 100%; height: 70vh; height: 70dvh; border: 1px solid var(--line); border-radius: 8px; margin: .6rem 0; }

.msg { padding: .5rem 0; border-bottom: 1px dashed var(--line); }
.msg:last-child { border-bottom: 0; }
.msg-head { margin: 0 0 .15rem; }
.msg-body { margin: 0; color: var(--body-ink); }

.evidence-add textarea {
  width: 100%; margin-top: .3rem; padding: .6rem .7rem;
  background: var(--bg); color: var(--ink);
  border: 1px solid var(--line); border-radius: 8px; font-size: .95rem; font-family: inherit;
}
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 .75rem; }
.grid2 label { margin-top: 0; }
@media (max-width: 560px) { .grid2 { grid-template-columns: 1fr; } }

details.contact-details summary { cursor: pointer; color: var(--muted); font-size: .85rem; padding: .15rem 0; }
details.contact-details summary:hover { color: var(--ink); }
.contact-form { margin-top: .4rem; }
.contact-form input { font-size: .85rem; }

details.edit-ev summary { cursor: pointer; color: var(--muted); font-size: .82rem; }
details.edit-ev summary:hover { color: var(--ink); }
.filter-ev { margin: .5rem 0; max-width: 18rem; }
label.chk { display: flex; align-items: center; gap: .4rem; color: var(--ink); }
label.chk input { width: auto; margin: 0; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: .75rem; flex-wrap: wrap; margin: .5rem 0 1rem;
}
.topbar h1 { font-size: 1.35rem; margin: 0; }

h1, h2 { color: var(--ink); }
h2 { font-size: 1.05rem; margin: 0 0 .5rem; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1rem 1.1rem;
  margin-bottom: 1rem;
}

.pill {
  display: inline-block; font-size: .72rem; letter-spacing: .06em;
  padding: .15em .6em; border-radius: 999px; vertical-align: middle;
  background: var(--accent-2); color: #fff;
}
.pill.ai { background: #065f46; }
/* Dark text on the light status colours keeps WCAG AA contrast (white on these fails). */
.pill.ok { background: var(--ok); color: var(--pill-ok-ink); }
.pill.warn { background: var(--bad); color: var(--pill-warn-ink); }
.pill.cat { background: var(--pill-cat-bg); color: var(--pill-cat-ink); }

.objective { padding: .55rem 0; border-bottom: 1px dashed var(--line); }
.objective:last-child { border-bottom: 0; }
.obj-top { display: flex; gap: .4rem; align-items: center; }
.obj-text { margin: .25rem 0 .3rem; font-size: .95rem; }
.obj-actions, .actions { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }

.target .name-line { color: var(--accent); }
.player-progress { padding: .4rem 0; }
.player-progress > ul { margin-top: .2rem; }

.assign { border-top: 1px dashed var(--line); margin-top: .75rem; padding-top: .5rem; }
.assign h3 { font-size: .95rem; margin: 0 0 .4rem; }
.arrows li { font-size: .92rem; }

.rowform { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; margin: .55rem 0; }
.wrapform { align-items: flex-start; }
.couple { display: inline-flex; align-items: center; gap: .3rem; font-size: .82rem; color: var(--muted); }
.couple select, select { background: var(--bg); color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: .3rem .4rem; font-size: .85rem; }
input.mini { display: inline-block; width: 6rem; padding: .25rem .4rem; font-size: .82rem; }

.name-line { font-size: 1.2rem; font-weight: 600; margin: .25rem 0 .5rem; }

.muted { color: var(--muted); }
.small { font-size: .82rem; }
.break { word-break: break-all; }

.alert {
  background: var(--alert-bg); color: var(--alert-ink);
  border: 1px solid var(--alert-border);
  border-radius: 8px; padding: .6rem .8rem; font-size: .92rem;
}
.alert.ok { background: var(--alert-ok-bg); color: var(--alert-ok-ink); border-color: var(--alert-ok-border); }

a { color: var(--link); }
a:hover { color: var(--link-hover); }

ul.plain { list-style: none; padding-left: 0; margin: 0; }
ul.plain li { padding: .25rem 0; }
ul.props li { padding: .45rem 0; border-bottom: 1px dashed var(--line); }
ul.props li:last-child { border-bottom: 0; }

.prop-body {
  font-size: 1.05rem; font-style: italic; color: var(--body-ink);
  border-left: 3px solid var(--accent); padding-left: .9rem; margin: .75rem 0 .25rem;
}

label { display: block; margin: .6rem 0; font-size: .9rem; color: var(--muted); }
input {
  display: block; width: 100%; margin-top: .3rem; padding: .6rem .7rem;
  background: var(--bg); color: var(--ink);
  border: 1px solid var(--line); border-radius: 8px; font-size: 1rem;
}
input:focus { outline: 2px solid var(--accent-2); }

.btn {
  display: inline-block; cursor: pointer;
  background: var(--accent); color: var(--btn-ink); font-weight: 600;
  border: 0; border-radius: 8px; padding: .6rem 1rem; font-size: .95rem;
  text-decoration: none;
}
.btn:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.btn.ghost:hover { color: var(--ink); }
.btn.small { padding: .3rem .6rem; font-size: .82rem; }

table.players { width: 100%; border-collapse: collapse; font-size: .92rem; margin-top: .5rem; }
table.players th, table.players td { text-align: left; padding: .45rem .35rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.players th { color: var(--muted); font-weight: 500; font-size: .78rem; letter-spacing: .04em; }

.dot { display: inline-block; width: .6rem; height: .6rem; border-radius: 50%; margin-right: .3rem; }
.dot.on { background: var(--ok); }
.dot.off { background: var(--dot-off); }
/* --- Player story + motivation brief ------------------------------------ */
.brief p { margin: .5rem 0; }
.brief-h3 {
  font-size: .82rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--accent);
  margin: 1rem 0 .35rem;
}
.brief-order { margin: .25rem 0 0; padding-left: 1.25rem; }
.brief-order li { margin: .2rem 0; }
.brief-why {
  border-left: 2px solid var(--line);
  padding-left: .85rem;
  margin: .85rem 0;
}
.brief-why p { margin: .3rem 0; }
.brief-footer {
  border-top: 1px dashed var(--line);
  padding-top: .75rem;
  margin-top: 1rem;
}

/* --- Player card: targeting / objectives / why ---------------------------- */
.player-card .card-section { margin-top: 1.1rem; }
.player-card .card-section .brief-h3 { margin-top: 0; }
.player-card .card-section .objectives { margin-top: .25rem; }

/* --- GM preview banner (shown atop a player's page in preview mode) -------- */
.preview-banner {
  display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap;
  background: var(--preview-bg); border: 1px solid var(--accent-2);
  border-radius: 10px; padding: .6rem .8rem; margin: 0 0 1rem; font-size: .9rem;
}
.preview-actions { display: flex; gap: .4rem; }

/* --- Murder reveal (player) ----------------------------------------------- */
.murder-banner { border-left: 3px solid var(--bad); }
.role-brief h2 { margin-bottom: .35rem; }
.role-killer { border-left: 3px solid var(--bad); background: rgba(248, 113, 113, .05); }
.role-victim { border-left: 3px solid var(--accent-2); background: rgba(124, 58, 237, .06); }

/* --- GM per-player story summary ------------------------------------------ */
.brief-summary { border-left: 3px solid var(--accent-2); }
.brief-summary .brief-h3 { margin-top: .9rem; }
.brief-summary .brief-why {
  border-left: 3px solid var(--accent);
  padding: .5rem .8rem;
  background: rgba(217, 119, 6, .06);
  border-radius: 0 8px 8px 0;
}

/* --- Story Studio --------------------------------------------------------- */
.stack { display: grid; gap: .75rem; margin: .75rem 0; }
.stack label { display: grid; gap: .25rem; font-weight: 600; }
.stack input, .stack textarea { font: inherit; }
.brief { margin: .5rem 0; }
.code {
  background: var(--code-bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .75rem;
  overflow: auto;
  max-height: 32rem;
  font-size: .8rem;
  white-space: pre-wrap;
  word-break: break-word;
}
.draft-row { padding: .4rem 0; border-bottom: 1px dashed var(--line); }
.draft-row:last-child { border-bottom: 0; }
details summary { cursor: pointer; color: var(--accent); margin: .5rem 0; }
.anchor-block { margin: .5rem 0; padding: .5rem; border: 1px solid var(--line); border-radius: 8px; }
.anchor-row { display: flex; gap: .5rem; margin: .35rem 0; }
.anchor-row input { flex: 1; font: inherit; padding: .35rem .5rem; border: 1px solid var(--line); border-radius: 6px; background: transparent; color: inherit; }
.anchor-block .btn { margin-top: .35rem; }
.card-inner { margin-top: .75rem; padding: .5rem; border: 1px dashed var(--line); border-radius: 8px; }

/* Story Map: closeness-to-kill progress bar */
.race-bar {
  height: .5rem;
  background: var(--line);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: .25rem;
}
.race-bar > span {
  display: block;
  height: 100%;
  background: var(--ok);
}

/* ============================================================================
   Accessibility + mobile hardening (WCAG 2.1 AA oriented)
   ============================================================================ */

/* Skip link: hidden until focused, then pinned to the top-left. */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
  background: var(--accent);
  color: #1c1005;
  font-weight: 700;
  padding: .7rem 1.1rem;
  border-radius: 0 0 8px 0;
  text-decoration: none;
}
.skip-link:focus { left: 0; }

/* Visible keyboard focus on every interactive element (WCAG 2.4.7). */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible,
[tabindex]:focus-visible,
.table-scroll:focus-visible {
  outline: 3px solid #a78bfa;
  outline-offset: 2px;
  border-radius: 6px;
}

/* Media never overflows its container. */
img, video, audio, svg, canvas { max-width: 100%; height: auto; }

/* Comfortable, finger-sized controls (WCAG 2.5.5 target size). */
.btn {
  min-height: 2.75rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  line-height: 1.2;
}
.btn.small { min-height: 2.5rem; padding: .45rem .8rem; }
button { font: inherit; }
input, select, textarea { min-height: 2.75rem; font-size: 1rem; } /* 16px stops iOS zoom-on-focus */
textarea { min-height: 6rem; }
input[type="checkbox"], input[type="radio"] { min-height: 0; }

/* Wide tables scroll instead of breaking the layout — semantics preserved. */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* Respect users who ask for less motion. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- Phones ---------- */
@media (max-width: 640px) {
  body { font-size: 1.0625rem; } /* 17px base */
  .wrap { padding: 1rem .9rem calc(1.75rem + env(safe-area-inset-bottom)); }
  .card { padding: 1rem; border-radius: 14px; }
  h2 { font-size: 1.15rem; }
  .name-line { font-size: 1.3rem; }

  /* Header stacks so the title and actions don't fight for width. */
  .topbar { flex-direction: column; align-items: stretch; gap: .5rem; }
  .topbar h1 { font-size: 1.35rem; }
  .topbar .top-actions, .topbar .btn { width: 100%; }
  .topbar .top-actions .btn { flex: 1; }

  /* Tab bars scroll horizontally instead of wrapping into a ragged block. */
  .tabs, .subtabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }
  .tabs a, .subtabs a { white-space: nowrap; flex: 0 0 auto; }
  .player-switch { margin-left: 0; }
  .player-switch label { width: 100%; }
  .player-switch select { width: 100%; }

  /* Primary actions go full-width for easy tapping. */
  .stack .btn,
  form > .btn,
  .obj-actions .btn,
  .bin-inline .btn { width: 100%; }

  /* Evidence rows: roomier and easier to hit. */
  .bin-link { padding: .8rem .85rem; }
  .bin-meta { white-space: normal; }

  table.players { font-size: .9rem; }
  table.players th, table.players td { padding: .55rem .4rem; }

  /* Long words/links must not force horizontal scroll. */
  .break, .linktext a, code { overflow-wrap: anywhere; }
}

/* ============================================================================
   Light theme — follows the OS by default, overridable with the toggle.
   ============================================================================ */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #faf7f2;
    --panel: #ffffff;
    --ink: #1b1424;
    --muted: #57506a;
    --accent: #b45309;
    --accent-2: #6d28d9;
    --ok: #047857;
    --bad: #b91c1c;
    --line: #e6e0ec;
    --btn-ink: #ffffff;
    --link: #6d28d9;
    --link-hover: #4c1d95;
    --pill-ok-ink: #ffffff;
    --pill-warn-ink: #ffffff;
    --pill-cat-bg: #e2e8f0;
    --pill-cat-ink: #1e293b;
    --alert-bg: #fee2e2;
    --alert-ink: #991b1b;
    --alert-border: #fca5a5;
    --alert-ok-bg: #d1fae5;
    --alert-ok-ink: #065f46;
    --alert-ok-border: #6ee7b7;
    --code-bg: #f3eef8;
    --body-ink: #2b2433;
    --dot-off: #c8c0d2;
    --preview-bg: rgba(109, 40, 217, .08);
    --panel-shadow: 0 1px 2px rgba(20, 10, 40, .06);
  }
}
:root[data-theme="light"] {
  --bg: #faf7f2;
  --panel: #ffffff;
  --ink: #1b1424;
  --muted: #57506a;
  --accent: #b45309;
  --accent-2: #6d28d9;
  --ok: #047857;
  --bad: #b91c1c;
  --line: #e6e0ec;
  --btn-ink: #ffffff;
  --link: #6d28d9;
  --link-hover: #4c1d95;
  --pill-ok-ink: #ffffff;
  --pill-warn-ink: #ffffff;
  --pill-cat-bg: #e2e8f0;
  --pill-cat-ink: #1e293b;
  --alert-bg: #fee2e2;
  --alert-ink: #991b1b;
  --alert-border: #fca5a5;
  --alert-ok-bg: #d1fae5;
  --alert-ok-ink: #065f46;
  --alert-ok-border: #6ee7b7;
  --code-bg: #f3eef8;
  --body-ink: #2b2433;
  --dot-off: #c8c0d2;
  --preview-bg: rgba(109, 40, 217, .08);
  --panel-shadow: 0 1px 2px rgba(20, 10, 40, .06);
}
/* In light mode give panels a subtle lift so white cards read against the page. */
:root[data-theme="light"] .card,
:root[data-theme="light"] .subtabs,
:root[data-theme="light"] .tabs a { box-shadow: var(--panel-shadow); }
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) .card,
  :root:not([data-theme="dark"]) .subtabs,
  :root:not([data-theme="dark"]) .tabs a { box-shadow: var(--panel-shadow); }
}

/* ---------- Theme toggle (floating, thumb-reachable) ---------- */
.theme-toggle {
  position: fixed;
  right: .8rem;
  bottom: calc(.8rem + env(safe-area-inset-bottom));
  z-index: 60;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: .5rem .95rem;
  font: inherit;
  font-size: .85rem;
  min-height: 2.5rem;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .3);
}
.theme-toggle:hover { border-color: var(--accent); }

/* Phone: let the PDF use most of the visible height. */
@media (max-width: 640px) {
  .media-pdf { height: 76vh; height: 76dvh; }
}
