/* Telltoll styles. Dark theme by default with a light alternative. Desktop shows the villagers around
   a circle; phones and tablets show them as a list with the circle diagram underneath. */

:root,
[data-theme="dark"] {
  --bg: #0f131d;
  --bg-accent: radial-gradient(circle at 50% 22%, #1d253b 0%, #0f131d 68%);
  --surface: #161c2a;
  --surface-card: rgba(22, 28, 42, 0.95);
  --surface-hub: rgba(18, 24, 38, 0.95);
  --surface-2: #1e2638;
  --surface-hover: #252f46;
  --border: rgba(212, 168, 83, 0.22);
  --border-strong: rgba(212, 168, 83, 0.5);
  --text: #efe9dc;
  --muted: #9ca7bc;
  --brass: #d4a853;
  --brass-soft: rgba(212, 168, 83, 0.14);
  --good: #52b788;
  --good-bg: rgba(82, 183, 136, 0.16);
  --evil: #e05a5a;
  --evil-bg: rgba(224, 90, 90, 0.18);
  --corrupted: #a78bfa;
  --corrupted-bg: rgba(167, 139, 250, 0.19);
  --team: #60a5fa;
  --draft: #f59e0b;
  --shadow: 0 10px 28px rgba(0, 0, 0, 0.36);
}

/* Subtle weekday atmospheric glow (dark theme) */
[data-theme="dark"] body[data-tier="mon"] {
  --bg-accent: radial-gradient(circle at 50% 22%, rgba(212, 168, 83, 0.11) 0%, #0f131d 66%);
}
[data-theme="dark"] body[data-tier="mid"] {
  --bg-accent: radial-gradient(circle at 50% 22%, rgba(96, 130, 210, 0.14) 0%, #0f131d 66%);
}
[data-theme="dark"] body[data-tier="late"] {
  --bg-accent: radial-gradient(circle at 50% 22%, rgba(200, 72, 72, 0.13) 0%, #0f131d 66%);
}
[data-theme="dark"] body[data-tier="sun"] {
  --bg-accent: radial-gradient(circle at 50% 22%, rgba(145, 108, 224, 0.16) 0%, #0f131d 66%);
}
[data-theme="dark"] body[data-tier="trial"] {
  --bg-accent: radial-gradient(circle at 50% 22%, rgba(212, 168, 83, 0.17) 0%, #10111c 66%);
}

[data-theme="light"] {
  --bg: #f5f0e4;
  --bg-accent: radial-gradient(circle at 50% 20%, #fdfaf3 0%, #efe7d6 70%);
  --surface: #fffdf8;
  --surface-card: rgba(255, 253, 248, 0.96);
  --surface-hub: rgba(255, 252, 245, 0.96);
  --surface-2: #f1eadb;
  --surface-hover: #e7dcc7;
  --border: rgba(120, 90, 38, 0.24);
  --border-strong: rgba(120, 90, 38, 0.52);
  --text: #1f1c17;
  --muted: #625a4c;
  --brass: #966619;
  --brass-soft: rgba(150, 102, 25, 0.12);
  --good: #257a52;
  --good-bg: rgba(37, 122, 82, 0.14);
  --evil: #bf3636;
  --evil-bg: rgba(191, 54, 54, 0.14);
  --corrupted: #6b45c2;
  --corrupted-bg: rgba(107, 69, 194, 0.14);
  --team: #2563eb;
  --draft: #b45309;
  --shadow: 0 8px 22px rgba(50, 38, 18, 0.09);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  background-image: var(--bg-accent);
  background-attachment: fixed;
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.4;
  min-height: 100%;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brass); }

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

button:focus-visible,
a:focus-visible,
.seat-node:focus-visible,
.seat-card:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 2px;
}

.ico {
  display: inline-block;
  vertical-align: -2px;
  flex-shrink: 0;
}

.role-with-ico {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

/* Header */
.topbar {
  max-width: 980px;
  margin: 0 auto;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
  color: var(--text);
}

.brand img {
  width: 28px;
  height: 28px;
  display: block;
}

.brand-title {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.05;
}

.brand-meta {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
}

/* 7-day Weekly Bell Row */
.week-bells {
  display: flex;
  align-items: center;
  gap: 4px;
}

.week-bell {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 3px 6px;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  min-width: 28px;
  color: var(--muted);
  transition: border-color 100ms ease, color 100ms ease, background 100ms ease;
}

.week-bell:hover:not(:disabled) {
  border-color: var(--brass);
  color: var(--text);
}

.week-bell:disabled {
  opacity: 0.35;
  cursor: default;
}

.week-bell-day {
  font-size: 0.64rem;
  font-weight: 700;
  line-height: 1;
}

.week-bell.is-today {
  border-color: var(--border-strong);
}

.week-bell.is-viewing {
  box-shadow: 0 0 0 1.5px var(--brass);
}

.week-bell.bell-gold {
  background: var(--brass-soft);
  border-color: var(--brass);
  color: var(--brass);
}

.week-bell.bell-silver {
  background: var(--good-bg);
  border-color: var(--good);
  color: var(--good);
}

.week-bell.bell-missed {
  background: var(--evil-bg);
  border-color: var(--evil);
  color: var(--evil);
}

.week-bells-lg .week-bell {
  min-width: 44px;
  padding: 6px 8px;
}

.week-bells-lg .week-bell-day {
  font-size: 0.74rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}

.icon-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 5px 9px;
  font-size: 0.8rem;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 120ms ease, border-color 120ms ease;
}

.icon-btn.icon-only {
  padding: 5px 8px;
}

.icon-btn:hover {
  background: var(--surface-hover);
  border-color: var(--border-strong);
}

.icon-btn-accent {
  border-color: var(--border-strong);
  color: var(--brass);
  background: var(--brass-soft);
  font-weight: 600;
}

.trial-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

.trial-card {
  width: 100%;
  text-align: left;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.trial-card:hover { border-color: var(--brass); }
.trial-card.is-won { border-color: var(--good); }
.trial-card.is-current { box-shadow: 0 0 0 1.5px var(--brass); }
.trial-card-title { font-weight: 700; display: block; font-size: 0.92rem; }
.trial-card-sub { font-size: 0.78rem; color: var(--muted); }
.trial-card-badge { font-size: 0.78rem; font-weight: 700; color: var(--brass); white-space: nowrap; }

/* Main container */
.app-shell {
  max-width: 980px;
  margin: 0 auto;
  padding: 8px 16px 28px;
}

/* Always-visible Roster & Rule Strip */
.roster-strip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 6px;
}

.roster-pills {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.77rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
}

.pill-good { color: var(--good); background: var(--good-bg); border-color: transparent; }
.pill-evil { color: var(--evil); background: var(--evil-bg); border-color: transparent; }
.pill-corrupted { color: var(--corrupted); background: var(--corrupted-bg); border-color: transparent; }
.pill-rule { color: var(--brass); background: var(--brass-soft); border-color: var(--border); }

.script-toggle {
  background: var(--brass-soft);
  border: 1px solid var(--border-strong);
  color: var(--brass);
  font-weight: 600;
  font-size: 0.79rem;
  padding: 4px 10px;
  border-radius: 7px;
}

.script-toggle:hover {
  background: var(--surface-hover);
}

/* Collapsible Full Script & Rules Panel */
.script-panel {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 10px;
}

.script-panel[hidden] { display: none; }

.script-rules-box {
  background: var(--surface-2);
  border-radius: 8px;
  padding: 9px 12px;
  margin-bottom: 10px;
}

.script-rules-box h3,
.script-section-title {
  margin: 0 0 6px;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--brass);
}

.script-rules-list {
  margin: 0;
  padding-left: 18px;
  font-size: 0.85rem;
}

.script-rules-list li { margin: 2px 0; }

.script-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.script-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.81rem;
}

.script-card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 4px;
}

.script-card strong { font-size: 0.86rem; }
.script-card .muted-sm { font-size: 0.74rem; color: var(--muted); }
.script-card p { margin: 2px 0; color: var(--muted); }
.script-card p span { color: var(--text); font-weight: 600; }
.script-card.card-evil { border-left: 3px solid var(--evil); }
.script-card.card-corrupted { border-left: 3px solid var(--corrupted); }

/* =========================================================
   CENTER-STAGE TOWN CIRCLE (Desktop > 860px, above-the-fold fit)
   ========================================================= */
.town-stage-wrap {
  margin: 2px auto 8px;
}

.town-stage {
  position: relative;
  width: 100%;
  max-width: 920px;
  aspect-ratio: 920 / 630;
  margin: 0 auto;
}

.town-svg-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
}

.town-svg {
  width: 100%;
  height: 100%;
  display: block;
}

.mobile-clockface-wrap { display: none; }

.parish-ring {
  fill: none;
  stroke: var(--border-strong);
  stroke-width: 1.7;
  stroke-dasharray: 5 5;
}

.parish-ring-inner {
  fill: none;
  stroke: var(--border);
  stroke-width: 1;
}

.ring-highlight {
  fill: none;
  stroke-width: 3.2;
  opacity: 0.88;
}

.relation-arc {
  fill: none;
  stroke-width: 2.8;
  stroke-linecap: round;
  opacity: 0.92;
}

.relation-arc.arc-dashed {
  stroke-dasharray: 6 5;
  stroke-width: 2.2;
  opacity: 0.78;
}

.hexer-tether {
  fill: none;
  stroke: var(--corrupted);
  stroke-width: 3;
  stroke-dasharray: 6 4;
  opacity: 0.95;
}

.arc-evil { stroke: var(--evil); }
.arc-corrupted { stroke: var(--corrupted); }
.arc-team { stroke: var(--team); }
.arc-farther { stroke: var(--muted); }
.arc-ring,
.arc-proof { stroke: var(--brass); }

.arc-pill-label {
  font-size: 10.5px;
  font-weight: 800;
  text-anchor: middle;
  paint-order: stroke;
  stroke: var(--bg);
  stroke-width: 4px;
  stroke-linejoin: round;
}

.label-evil { fill: var(--evil); }
.label-farther { fill: var(--muted); }
.label-corrupted { fill: var(--corrupted); }

.stage-anchor {
  fill: var(--surface-2);
  stroke: var(--border-strong);
  stroke-width: 1.4;
}

.stage-anchor.is-active {
  fill: var(--brass);
  stroke: var(--brass);
}

/* Center Role Explainer Hub right inside the town circle */
.town-center-hub {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: clamp(236px, 29.5%, 272px);
  max-height: min(276px, 44%);
  overflow-y: auto;
  z-index: 4;
  background: var(--surface-hub);
  border: 1.5px solid var(--border-strong);
  border-radius: 16px;
  padding: 9px 11px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
  text-align: center;
}

.hub-eyebrow {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--brass);
  margin: 0 0 2px;
}

.hub-title {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.06rem;
  line-height: 1.18;
}

.hub-quote {
  margin: 6px 0;
  font-size: 0.81rem;
  color: var(--text);
  font-weight: 600;
  padding: 5px 7px;
  background: var(--surface-2);
  border-radius: 7px;
  border: 1px solid var(--border);
}

.hub-inverted {
  margin: 0 0 6px;
  font-size: 0.74rem;
  color: var(--draft);
  font-style: italic;
  text-align: left;
  padding: 4px 7px;
  background: rgba(245, 158, 11, 0.1);
  border-radius: 6px;
}

.hub-proof-text {
  margin: 7px 0;
  font-size: 0.82rem;
  line-height: 1.38;
  color: var(--text);
}

.hub-role-block {
  text-align: left;
  font-size: 0.74rem;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.hub-role-block strong { color: var(--text); }
.hub-role-block .hub-true strong { color: var(--good); }
.hub-role-block .hub-lie strong { color: var(--evil); }

.hub-rules-list {
  text-align: left;
  margin: 7px 0 5px;
  padding-left: 16px;
  font-size: 0.76rem;
  color: var(--muted);
}

.hub-rules-list li { margin: 2px 0; }
.hub-rules-list strong { color: var(--text); }

.hub-foot {
  margin-top: 7px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  flex-wrap: wrap;
}

.hub-unpin {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 7px;
  font-size: 0.71rem;
  color: var(--muted);
}

.hub-unpin:hover { border-color: var(--brass); color: var(--text); }

.hub-targets-note {
  font-size: 0.71rem;
  color: var(--brass);
  font-weight: 600;
}

/* Villager Seat Cards positioned around the Town Circle */
.town-seats {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}

.seat-card {
  position: absolute;
  left: var(--x);
  top: var(--y);
  transform: translate(-50%, -50%);
  width: clamp(154px, 19%, 174px);
  pointer-events: auto;
  background: var(--surface-card);
  border: 1.5px solid var(--border);
  border-radius: 11px;
  padding: 6px 8px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: border-color 120ms ease, background 120ms ease, opacity 130ms ease, box-shadow 120ms ease;
}

.seat-card.is-dimmed {
  opacity: 0.44;
}

.seat-card:hover,
.seat-card.is-active {
  opacity: 1;
  border-color: var(--brass);
  background: var(--surface-2);
  box-shadow: 0 0 0 2px rgba(212, 168, 83, 0.28), var(--shadow);
  z-index: 6;
}

.seat-card.is-target {
  opacity: 1;
  border-color: var(--evil);
  box-shadow: 0 0 0 2px rgba(224, 90, 90, 0.28), var(--shadow);
}

.seat-card.is-target.target-corrupted {
  border-color: var(--corrupted);
  box-shadow: 0 0 0 2px rgba(167, 139, 250, 0.34), var(--shadow);
}

.seat-card.is-target.target-team {
  border-color: var(--team);
  box-shadow: 0 0 0 2px rgba(96, 165, 250, 0.34), var(--shadow);
}

.seat-card.is-proof-lit {
  opacity: 1;
  border-color: var(--brass);
  box-shadow: 0 0 0 2.5px rgba(212, 168, 83, 0.4), var(--shadow);
  z-index: 5;
}

.seat-card.is-draft {
  outline: 2px dashed var(--draft);
  outline-offset: 2px;
}

.seat-card.mark-good { border-top: 3px solid var(--good); }
.seat-card.mark-evil { border-top: 3px solid var(--evil); }
.seat-card.mark-corrupted { border-top: 3px solid var(--corrupted); }

.seat-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  margin-bottom: 2px;
}

.seat-card-who {
  display: flex;
  align-items: baseline;
  gap: 3px;
  min-width: 0;
}

.seat-idx { font-size: 0.7rem; font-weight: 700; color: var(--muted); }
.villager-name { font-weight: 700; font-size: 0.84rem; }

.role-pill {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 6px;
  font-size: 0.68rem;
  color: var(--brass);
  font-weight: 700;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.role-pill:hover { border-color: var(--brass); }

.clue-text {
  margin: 0;
  font-size: 0.75rem;
  line-height: 1.28;
  color: var(--text);
}

.clue-inverted {
  margin: 3px 0 0;
  font-size: 0.69rem;
  line-height: 1.22;
  color: var(--draft);
  font-style: italic;
}

.seat-card-foot {
  margin-top: 5px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
}

.seat-mark-lbl { font-size: 0.68rem; font-weight: 700; color: var(--muted); }
.seat-mark-lbl.lbl-good { color: var(--good); }
.seat-mark-lbl.lbl-evil { color: var(--evil); }
.seat-mark-lbl.lbl-corrupted { color: var(--corrupted); }

.seat-reveal-tags {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.truth-tag,
.identity-tag {
  font-size: 0.67rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 999px;
}

.truth-true { color: var(--good); background: var(--good-bg); }
.truth-false { color: var(--evil); background: var(--evil-bg); }
.id-evil { color: var(--evil); background: var(--evil-bg); }
.id-corrupted { color: var(--corrupted); background: var(--corrupted-bg); }
.id-good { color: var(--good); background: var(--good-bg); }

/* Mark buttons */
.mark-controls {
  display: flex;
  gap: 3px;
  flex-shrink: 0;
}

.mark-btn {
  width: 24px;
  height: 22px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 100ms ease, border-color 100ms ease, color 100ms ease;
}

.mark-btn:hover { border-color: var(--border-strong); color: var(--text); }
.mark-btn.btn-good.is-on { background: var(--good-bg); border-color: var(--good); color: var(--good); }
.mark-btn.btn-evil.is-on { background: var(--evil-bg); border-color: var(--evil); color: var(--evil); }
.mark-btn.btn-corrupted.is-on { background: var(--corrupted-bg); border-color: var(--corrupted); color: var(--corrupted); }

/* Phone-only pieces (see the compact breakpoints below); desktop uses the center hub and text buttons */
.seat-card-details,
.ring-wrap-note,
.topbar-actions .btn-ico,
.show-phone {
  display: none;
}

.clock-legend {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 4px;
  font-size: 0.74rem;
  color: var(--muted);
}

.leg-ico { margin-right: 3px; vertical-align: middle; }
.leg-good { color: var(--good); }
.leg-evil { color: var(--evil); }
.leg-corrupted { color: var(--corrupted); }
.legend-tip { color: var(--brass); }

/* Centered Controls, Sandbox, History, Hints, Results beneath the circle */
.below-stage {
  max-width: 820px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Accusation controls stay pinned to the bottom of the screen while the circle is in view, so
   "Toll the bell" is reachable on short laptop screens and phones alike. */
.action-dock {
  position: sticky;
  bottom: 8px;
  z-index: 20;
  max-width: 820px;
  margin: 0 auto 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.action-dock .action-bar {
  box-shadow: var(--shadow);
}

.sandbox-banner {
  background: rgba(245, 158, 11, 0.14);
  border: 1.5px dashed var(--draft);
  border-radius: 10px;
  padding: 7px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 0.84rem;
}

.sandbox-banner[hidden] { display: none; }
.sandbox-actions { display: flex; gap: 6px; }

.action-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 9px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.action-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

.action-status {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 0.84rem;
}

.target-counters {
  display: flex;
  gap: 10px;
  font-weight: 700;
}

.counter-ok { color: var(--good); }
.rings-left { color: var(--muted); font-size: 0.8rem; }

.action-buttons {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}

.action-notice {
  font-size: 0.82rem;
  color: var(--brass);
  font-weight: 600;
}

.btn {
  border-radius: 8px;
  padding: 8px 14px;
  font-weight: 700;
  font-size: 0.86rem;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn-sm {
  padding: 6px 10px;
  font-size: 0.8rem;
}

.btn:hover:not(:disabled) {
  border-color: var(--border-strong);
  background: var(--surface-hover);
}

.btn-primary {
  background: var(--brass);
  border-color: var(--brass);
  color: #15120c;
}

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.07);
  background: var(--brass);
}

.btn.is-sandbox-active {
  border-color: var(--draft);
  color: var(--draft);
  background: rgba(245, 158, 11, 0.14);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Bell submit animations */
@keyframes bellToll {
  0% { transform: rotate(0deg) scale(1); }
  20% { transform: rotate(-14deg) scale(1.06); }
  45% { transform: rotate(12deg) scale(1.06); }
  70% { transform: rotate(-7deg); }
  100% { transform: rotate(0deg) scale(1); }
}

@keyframes bellClunk {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  65% { transform: translateX(5px); }
}

.btn.is-tolling .ico-bell {
  animation: bellToll 520ms ease;
}

.btn.is-clunk {
  animation: bellClunk 260ms ease;
}

.history-box,
.hints-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 0.84rem;
}

.history-box h3,
.hints-box h3 {
  margin: 0 0 5px;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.history-list,
.hints-list {
  margin: 0;
  padding-left: 18px;
}

.history-list li,
.hints-list li {
  margin: 3px 0;
}

.attempt-score { color: var(--brass); font-weight: 700; }

/* Result Panel & Interactive Visual Proof */
.result-panel {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 11px;
}

.result-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  flex-wrap: wrap;
}

.result-title {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.25rem;
}

.result-sub {
  margin: 3px 0 0;
  font-size: 0.86rem;
  color: var(--muted);
}

.save-warning {
  margin: 0;
  padding: 7px 11px;
  border-radius: 8px;
  border: 1px solid var(--draft);
  background: rgba(245, 158, 11, 0.14);
  color: var(--text);
  font-size: 0.83rem;
  line-height: 1.38;
}

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

.stat-box {
  background: var(--surface-2);
  border-radius: 8px;
  padding: 7px 6px;
  text-align: center;
}

.stat-val { display: block; font-size: 1.15rem; font-weight: 800; color: var(--brass); }
.stat-lbl { font-size: 0.73rem; color: var(--muted); }

.proof-details {
  background: var(--surface-2);
  border-radius: 10px;
  padding: 10px 12px;
}

.proof-details summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--brass);
  font-size: 0.88rem;
}

.proof-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.proof-hint-note {
  font-size: 0.77rem;
  margin-left: auto;
}

.proof-list {
  margin: 8px 0 0;
  padding-left: 20px;
}

.proof-list li { margin: 5px 0; }

.proof-step-btn {
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 0.84rem;
  line-height: 1.38;
  transition: border-color 110ms ease, background 110ms ease;
}

.proof-step-btn:hover {
  border-color: var(--brass);
}

.proof-step-btn.is-active {
  border-color: var(--brass);
  background: var(--brass-soft);
  box-shadow: 0 0 0 1.5px var(--brass);
}

.result-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.countdown {
  margin-left: auto;
  font-size: 0.82rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.toast { font-size: 0.82rem; color: var(--good); font-weight: 600; }

.archive-banner {
  background: var(--brass-soft);
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  padding: 6px 12px;
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 0.84rem;
}

.midnight-banner {
  background: var(--good-bg);
  border: 1px solid var(--good);
  border-radius: 9px;
  padding: 6px 12px;
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 0.84rem;
}

.load-error-banner {
  background: var(--evil-bg);
  border: 1px solid var(--evil);
  border-radius: 9px;
  padding: 8px 12px;
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 0.84rem;
}

/* Mobile SVG clockface node styles */
.clockface-svg {
  width: 100%;
  height: auto;
  display: block;
  user-select: none;
}

.target-halo {
  fill: none;
  stroke-width: 2;
  stroke-dasharray: 4 3;
}

.center-title { fill: var(--brass); font-family: Georgia, "Times New Roman", serif; font-size: 18px; font-weight: 700; text-anchor: middle; }
.center-name { fill: var(--text); font-size: 14px; font-weight: 700; text-anchor: middle; }
.center-role { fill: var(--brass); font-size: 12px; font-weight: 600; text-anchor: middle; }

.seat-node { cursor: pointer; transition: opacity 130ms ease; }
.seat-node.is-dimmed { opacity: 0.42; }
.seat-disc { fill: var(--surface-2); stroke: var(--border-strong); stroke-width: 1.8; }
.seat-node:hover .seat-disc,
.seat-node.is-active .seat-disc { stroke: var(--brass); stroke-width: 2.8; }
.seat-node.is-draft .seat-disc { stroke-dasharray: 4 3; }
.seat-node.seat-good .seat-disc { fill: var(--good-bg); stroke: var(--good); }
.seat-node.seat-evil .seat-disc { fill: var(--evil-bg); stroke: var(--evil); }
.seat-node.seat-corrupted .seat-disc { fill: var(--corrupted-bg); stroke: var(--corrupted); }
.seat-num { fill: var(--muted); font-size: 9px; font-weight: 700; text-anchor: middle; }
.seat-name { fill: var(--text); font-size: 11.5px; font-weight: 700; text-anchor: middle; }
.seat-role-mini { fill: var(--muted); font-size: 8.5px; text-anchor: middle; }
.seat-badge { fill: var(--text); font-size: 8.5px; font-weight: 800; letter-spacing: 0.05em; text-anchor: middle; }
.seat-node.seat-good .seat-badge { fill: var(--good); }
.seat-node.seat-evil .seat-badge { fill: var(--evil); }
.seat-node.seat-corrupted .seat-badge { fill: var(--corrupted); }

/* Modals (Tutorial, Archive, Stats) */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(6, 8, 14, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}

.modal-backdrop[hidden] { display: none; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  max-width: 540px;
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  padding: 18px 20px;
  box-shadow: var(--shadow);
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.modal-head h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.25rem;
}

.close-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 10px;
  font-weight: 700;
}

.tutorial-demo {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  margin: 10px 0;
  font-size: 0.86rem;
}

.tutorial-tabs {
  display: flex;
  gap: 6px;
}

.tutorial-tab {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 5px 10px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
}

.tutorial-tab.is-active {
  border-color: var(--brass);
  background: var(--brass-soft);
  color: var(--brass);
}

.tutorial-seats {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 8px 0;
}

.tutorial-seat-btn {
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 0.84rem;
}

.tutorial-seat-btn:hover:not(:disabled) { border-color: var(--brass); }
.tutorial-seat-btn:disabled { opacity: 0.6; cursor: default; }
.tutorial-seat-btn.is-correct { border-color: var(--good); background: var(--good-bg); }
.tutorial-seat-btn.is-wrong { border-color: var(--evil); background: var(--evil-bg); }

.archive-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(115px, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.archive-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  text-align: left;
  font-size: 0.82rem;
}

.archive-item:hover { border-color: var(--brass); }
.archive-item.is-won { border-color: var(--good); }
.archive-item.is-lost { border-color: var(--evil); }
.archive-item.is-current { box-shadow: 0 0 0 2px var(--brass); }
.archive-num { font-weight: 800; display: block; }
.archive-status { margin-left: 4px; font-weight: 600; }
.archive-meta { font-size: 0.74rem; color: var(--muted); }

/* Footer & About page */
.site-footer {
  max-width: 980px;
  margin: 18px auto 0;
  padding: 12px 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 0.8rem;
  color: var(--muted);
  align-items: center;
}

.footer-links {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

/* Ko-fi "Buy me a coffee" link: a plain link styled as a small pill (no third-party widget or tracking) */
.kofi-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--brass-soft);
  color: var(--brass);
  font-weight: 700;
  font-size: 0.8rem;
  text-decoration: none;
  white-space: nowrap;
}

.kofi-link:hover { background: var(--surface-hover); }

.support-line {
  margin: 0;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 0.86rem;
  color: var(--muted);
}

.page-narrow { max-width: 720px; margin: 32px auto; padding: 0 18px 48px; }
.page-narrow h1 { font-family: Georgia, "Times New Roman", serif; margin-top: 4px; }
.page-narrow h2 { margin-top: 26px; font-size: 1.1rem; color: var(--brass); }
.eyebrow { text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.78rem; color: var(--brass); font-weight: 700; margin: 0; }
.muted { color: var(--muted); }
.ad-slot { min-height: 0; margin-top: 14px; }

/* =========================================================
   MOBILE / COMPACT BREAKPOINT (<= 900px)
   ========================================================= */
@media (max-width: 900px) {
  .topbar {
    flex-wrap: wrap;
  }

  .topbar .week-bells {
    order: 3;
    width: 100%;
    justify-content: center;
    padding-top: 4px;
  }

  /* Statements first: the seat list leads, the circle diagram follows as a map */
  .town-stage {
    position: static;
    min-width: 0;
    max-width: none;
    aspect-ratio: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
  }

  .town-svg-layer { display: none; }

  /* Role details live inside the tapped card instead */
  .town-center-hub { display: none; }

  .mobile-clockface-wrap {
    display: block;
    width: 100%;
    max-width: 300px;
    margin: 4px auto 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 8px;
  }

  .town-seats {
    position: static;
    display: flex;
    flex-direction: column;
    gap: 5px;
    pointer-events: auto;
  }

  /* Compact card: name, role and mark buttons on one row, the statement beneath */
  .seat-card {
    position: static;
    transform: none;
    width: 100%;
    padding: 5px 10px 7px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "head foot"
      "clue clue"
      "inv inv"
      "details details";
    column-gap: 8px;
    align-items: center;
  }

  .seat-card-head {
    grid-area: head;
    justify-content: flex-start;
    gap: 8px;
    margin: 0;
    min-width: 0;
  }

  .seat-card-foot { grid-area: foot; margin: 0; }
  .seat-mark-lbl { display: none; }
  .villager-name { font-size: 0.9rem; }
  .role-pill { font-size: 0.7rem; }

  .seat-card.is-dimmed { opacity: 0.62; }
  .seat-card.mark-good { border-top: 1.5px solid var(--border); border-left: 4px solid var(--good); }
  .seat-card.mark-evil { border-top: 1.5px solid var(--border); border-left: 4px solid var(--evil); }
  .seat-card.mark-corrupted { border-top: 1.5px solid var(--border); border-left: 4px solid var(--corrupted); }

  .clue-text { grid-area: clue; font-size: 0.88rem; line-height: 1.3; margin-top: 1px; }
  .clue-inverted { grid-area: inv; font-size: 0.78rem; }
  .mark-btn { width: 34px; height: 28px; }

  .seat-card-details {
    display: block;
    grid-area: details;
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px dashed var(--border);
    font-size: 0.78rem;
    line-height: 1.35;
    color: var(--muted);
  }

  .seat-card-details p { margin: 0 0 3px; }
  .seat-card-details strong { color: var(--text); }
  .seat-card-details .details-checks { margin: 0; color: var(--brass); font-weight: 600; }

  .ring-wrap-note {
    display: block;
    margin: 0;
    text-align: center;
    font-size: 0.76rem;
    color: var(--muted);
  }

  .legend-tip { display: none; }
}

/* =========================================================
   PHONE BREAKPOINT (<= 640px): icon topbar, short roster, one-row controls
   ========================================================= */
@media (max-width: 640px) {
  .hide-phone { display: none; }
  .show-phone { display: inline; }

  .topbar { flex-wrap: nowrap; gap: 8px; }
  .brand-title { font-size: 1.12rem; }
  .topbar .week-bells { display: none; } /* also shown in the Stats dialog */
  .brand,
  .brand > span { min-width: 0; }
  .brand-meta { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  .topbar-actions { flex-wrap: nowrap; gap: 4px; flex-shrink: 0; }
  .topbar-actions .icon-btn { width: 32px; height: 32px; padding: 0; }
  .topbar-actions .btn-ico { display: inline-flex; }
  .topbar-actions .btn-label {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
  }

  .town-stage-wrap { margin: 0 auto 6px; }
  .town-seats { gap: 3px; }
  .seat-card { padding: 4px 9px 5px; }
  .clue-text { line-height: 1.27; }
  .mark-btn { width: 32px; height: 26px; }

  .roster-strip { padding: 5px 8px; gap: 6px; flex-wrap: nowrap; margin-bottom: 4px; }
  .roster-pills { gap: 4px; }
  .pill { font-size: 0.72rem; padding: 2px 7px; }
  .pill-good { display: none; } /* everyone not listed is an ordinary villager; saves a roster row */
  .script-toggle { padding: 3px 8px; font-size: 0.74rem; white-space: nowrap; flex-shrink: 0; }

  .action-bar { padding: 6px 9px; gap: 3px; }
  .action-row { gap: 5px; }
  .action-status { width: 100%; justify-content: space-between; gap: 8px; font-size: 0.78rem; }
  .target-counters { gap: 8px; }
  .action-buttons { width: 100%; flex-wrap: nowrap; gap: 4px; }
  .action-buttons .btn { white-space: nowrap; }
  .action-buttons .btn-sm { padding: 6px 8px; font-size: 0.76rem; }
  .action-buttons .btn-sm .ico { display: none; }
  .action-buttons .btn-primary { margin-left: auto; padding: 7px 11px; font-size: 0.82rem; white-space: nowrap; }
}

/* Narrow phones (360-380px wide): keep the roster and the controls on one row each */
@media (max-width: 380px) {
  .pill .ico { display: none; }
  .pill { padding: 2px 6px; }
  .action-buttons { gap: 3px; }
  .action-buttons .btn-sm { padding: 6px 6px; }
  .action-buttons .btn-primary .ico { display: none; }
}

@media (max-width: 440px) {
  .topbar { padding: 6px 12px; }
  .app-shell { padding: 6px 12px 28px; }
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .proof-hint-note { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  .btn.is-tolling .ico-bell,
  .btn.is-clunk {
    transition: none !important;
    animation: none !important;
  }
}
