@font-face {
  font-family: "OldTimeyMono";
  src: url("OldTimeyMono-0.11.0.ttf") format("truetype");
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

:root {
  /* Vintage parlor tabletop & yellowing rulebook paper palette */
  --table-wood: #261a12;
  --table-wood-dark: #18100b;
  --paper-light: #f4e8ca;
  --paper-mid: #ebd9b0;
  --paper-aged: #dec691;
  --card-stock: #faf2de;
  --card-edge: #e9d7b0;
  --ink-dark: #22170e;
  --ink-muted: #584330;
  --ink-rule: rgba(44, 30, 18, 0.34);
  --vintage-crimson: #9b2024;
  --vintage-blue: #224866;
  --vintage-teal: #1d594e;
  --vintage-ochre: #9a6212;
  --vintage-gold: #c48e2a;

  /* Subtle yellowing paper fiber grain (SVG fractalNoise) */
  --paper-grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='p'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.045' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0.2'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23p)' opacity='0.11'/%3E%3C/svg%3E");

  /* Classic Cluedo drawn tile flooring (alternating tan & dark brown) */
  --sq-light: #dab07a;
  --sq-light-edge: #c99a60;
  --sq-dark: #744725;
  --sq-dark-edge: #5d3619;
  --tile-grout: #2a180c;
  --coord-light: #4a2d16;
  --coord-dark: #edd2a8;

  /* Selection highlights: distinct colors for empty space vs piece space */
  --sel-empty-fill: rgba(245, 194, 66, 0.42);
  --sel-empty-border: #ffd166;
  --sel-piece-fill: rgba(56, 189, 248, 0.38);
  --sel-piece-border: #38bdf8;

  /* Investigated states */
  --inv-empty-overlay: rgba(88, 94, 108, 0.72);
  --inv-murder-overlay: rgba(214, 38, 46, 0.58);

  --board-size: min(76vw, 60vh, 520px);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: Georgia, "Times New Roman", Times, serif;
  background-color: var(--table-wood);
  background-image:
    radial-gradient(circle at 50% 24%, rgba(235, 192, 118, 0.14), transparent 58%),
    repeating-linear-gradient(
      90deg,
      rgba(255, 224, 178, 0.015) 0px,
      rgba(255, 224, 178, 0.015) 3px,
      rgba(0, 0, 0, 0.04) 3px,
      rgba(0, 0, 0, 0.04) 7px
    ),
    radial-gradient(ellipse at center, var(--table-wood) 0%, var(--table-wood-dark) 100%);
  color: var(--ink-dark);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 16px 16px 28px;
}

.app-shell {
  width: 100%;
  max-width: 780px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 13px;
}

/* Header — Vintage Board Game Rulebook Masthead Page */
.top-bar {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  background-color: var(--paper-mid);
  background-image:
    var(--paper-grain),
    radial-gradient(ellipse at center, var(--paper-light) 35%, var(--paper-aged) 100%);
  border: 1.5px solid var(--ink-dark);
  border-radius: 1px;
  padding: 12px 18px;
  box-shadow:
    inset 0 0 0 4px var(--paper-light),
    inset 0 0 0 5px rgba(44, 30, 18, 0.45),
    0 5px 14px rgba(0, 0, 0, 0.48);
}

.brand-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-icon {
  font-size: 1.6rem;
  color: var(--vintage-crimson);
  line-height: 1;
}

.top-bar h1 {
  font-family: "OldTimeyMono", Georgia, serif;
  font-size: 1.38rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--ink-dark);
  text-transform: uppercase;
}

.case-subtitle {
  font-family: Georgia, "Times New Roman", serif;
  font-style: italic;
  font-size: 0.85rem;
  color: var(--ink-muted);
  margin-top: 2px;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.seed-form {
  display: flex;
  align-items: center;
  gap: 6px;
}

.seed-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: "OldTimeyMono", "Courier New", monospace;
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--ink-dark);
  text-transform: uppercase;
}

.seed-input {
  width: 108px;
  background: #fbf4e2;
  color: var(--ink-dark);
  border: 1.5px solid var(--ink-dark);
  border-radius: 1px;
  padding: 4px 8px;
  font-size: 0.86rem;
  font-family: "OldTimeyMono", "Courier New", monospace;
  letter-spacing: 0.05em;
  outline: none;
  box-shadow: inset 1px 1px 3px rgba(44, 30, 18, 0.2);
}

.seed-input:focus {
  border-color: var(--vintage-crimson);
  background: #fffaf0;
}

/* Header small paper card buttons */
.icon-btn {
  font-family: "OldTimeyMono", Georgia, serif;
  background-color: var(--card-stock);
  background-image: linear-gradient(180deg, #fcf6e6 0%, var(--card-edge) 100%);
  color: var(--ink-dark);
  border: 1.5px solid var(--ink-dark);
  border-radius: 2px;
  padding: 5px 11px;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  cursor: pointer;
  box-shadow:
    inset 0 0 0 2px #fcf6e6,
    inset 0 0 0 3px rgba(44, 30, 18, 0.35),
    0 2px 0 #2b1e12,
    0 3px 6px rgba(0, 0, 0, 0.28);
  transition: transform 0.08s ease, box-shadow 0.08s ease, filter 0.12s ease;
}

.icon-btn:hover {
  filter: brightness(1.03);
  transform: translateY(-1px);
  box-shadow:
    inset 0 0 0 2px #fcf6e6,
    inset 0 0 0 3px rgba(44, 30, 18, 0.5),
    0 3px 0 #2b1e12,
    0 4px 8px rgba(0, 0, 0, 0.32);
}

.icon-btn:active {
  transform: translateY(1px);
  box-shadow:
    inset 0 0 0 2px #fcf6e6,
    inset 0 0 0 3px rgba(44, 30, 18, 0.5),
    0 1px 0 #2b1e12;
}

.icon-btn-accent {
  background-image: linear-gradient(180deg, #f8e5b4 0%, #e4c070 100%);
  color: var(--vintage-crimson);
  box-shadow:
    inset 0 0 0 2px #f8e5b4,
    inset 0 0 0 3.2px var(--vintage-crimson),
    0 2px 0 #2b1e12,
    0 3px 6px rgba(0, 0, 0, 0.3);
}

.icon-btn-accent:hover {
  box-shadow:
    inset 0 0 0 2px #f8e5b4,
    inset 0 0 0 3.2px var(--vintage-crimson),
    0 3px 0 #2b1e12,
    0 4px 8px rgba(0, 0, 0, 0.34);
}

/* Vintage segmented cardstock toggle for switching puzzle generators */
.gen-toggle {
  display: inline-flex;
  border: 1.5px solid var(--ink-dark);
  border-radius: 2px;
  overflow: hidden;
  background: var(--paper-aged);
  box-shadow:
    0 2px 0 #2b1e12,
    0 3px 6px rgba(0, 0, 0, 0.25);
}

.gen-toggle-btn {
  font-family: "OldTimeyMono", Georgia, serif;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  padding: 5px 9px;
  border: none;
  border-right: 1px solid rgba(44, 30, 18, 0.45);
  background: linear-gradient(180deg, #efe2c0 0%, #dfca9b 100%);
  color: var(--ink-muted);
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}

.gen-toggle-btn:last-child {
  border-right: none;
}

.gen-toggle-btn:hover:not(.is-active) {
  color: var(--ink-dark);
  background: linear-gradient(180deg, #f6ebd0 0%, #e7d5aa 100%);
}

.gen-toggle-btn.is-active {
  background: linear-gradient(180deg, #3a2718 0%, #24170e 100%);
  color: #f6e7c1;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.5);
}

/* Daily mode case counter badge */
.daily-case-badge {
  font-family: "OldTimeyMono", "Courier New", monospace;
  font-size: 0.86rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--vintage-crimson);
  background: #fbf4e2;
  border: 1.5px solid var(--ink-dark);
  border-radius: 2px;
  padding: 5px 11px;
  box-shadow:
    inset 0 0 0 2px #fbf4e2,
    inset 0 0 0 3px rgba(155, 32, 36, 0.45);
}

/* Turns remaining banner above the board — Yellowing Rulebook Sheet */
.turns-strip {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background-color: var(--paper-mid);
  background-image:
    var(--paper-grain),
    radial-gradient(ellipse at center, var(--paper-light) 35%, var(--paper-aged) 100%);
  border: 1.5px solid var(--ink-dark);
  border-radius: 1px;
  padding: 9px 16px;
  text-align: center;
  box-shadow:
    inset 0 0 0 4px var(--paper-light),
    inset 0 0 0 5px rgba(44, 30, 18, 0.4),
    0 5px 14px rgba(0, 0, 0, 0.45);
}

.turns-prompt {
  font-family: Georgia, "Times New Roman", serif;
  font-style: italic;
  font-size: 0.92rem;
  color: var(--ink-muted);
}

.turns-counter {
  font-family: "OldTimeyMono", "Courier New", monospace;
  font-size: 1.08rem;
  font-weight: 700;
  color: var(--ink-dark);
  letter-spacing: 0.02em;
}

.turns-counter strong {
  font-size: 1.24rem;
  color: var(--vintage-teal);
}

.turns-strip.is-low .turns-counter strong,
.turns-strip.is-critical .turns-counter strong {
  color: var(--vintage-crimson);
}

.turns-strip.is-critical {
  background-image:
    var(--paper-grain),
    radial-gradient(ellipse at center, #faecd8 30%, #e5bfa6 100%);
}

.stamp.stamp-cold {
  border-color: var(--vintage-blue);
  color: var(--vintage-blue);
  background: rgba(34, 72, 102, 0.07);
}

/* Main Stage */
.stage {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

/* Classic Cluedo board: black paper-wrapped outer border + vintage printed margin */
.board-frame {
  position: relative;
  padding: 20px;
  background:
    radial-gradient(circle at 50% 50%, rgba(74, 86, 68, 0.55) 0%, rgba(44, 52, 43, 0.85) 68%, rgba(28, 33, 29, 0.98) 100%),
    repeating-linear-gradient(
      45deg,
      rgba(255, 255, 255, 0.015) 0px,
      rgba(255, 255, 255, 0.015) 2px,
      rgba(0, 0, 0, 0.025) 2px,
      rgba(0, 0, 0, 0.025) 4px
    ),
    #2b332b;
  border: 10px solid #151517;
  border-radius: 3px;
  box-shadow:
    0 20px 44px rgba(0, 0, 0, 0.72),
    0 0 0 1px rgba(255, 255, 255, 0.09),
    inset 0 0 0 1.5px #0c0d0c,
    inset 0 0 18px rgba(0, 0, 0, 0.45);
}

/* Subtle vintage 4-panel folding-board crease */
.board-frame::before,
.board-frame::after {
  content: "";
  position: absolute;
  pointer-events: none;
  z-index: 12;
}

.board-frame::before {
  left: 0;
  right: 0;
  top: 50%;
  height: 2px;
  margin-top: -1px;
  background: linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0.34),
    rgba(255, 255, 255, 0.08)
  );
}

.board-frame::after {
  top: 0;
  bottom: 0;
  left: 50%;
  width: 2px;
  margin-left: -1px;
  background: linear-gradient(
    to right,
    rgba(0, 0, 0, 0.34),
    rgba(255, 255, 255, 0.08)
  );
}

.board-wrapper {
  position: relative;
  width: var(--board-size);
  height: var(--board-size);
  /* Classic Cluedo red-brick architectural wall trim framing the tiled floor */
  box-shadow:
    0 0 0 2px #1e120a,
    0 0 0 6px #b3493b,
    0 0 0 8px #1a1009,
    0 6px 16px rgba(0, 0, 0, 0.5);
}

.chessboard {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border-radius: 0;
  overflow: hidden;
  user-select: none;
  background: var(--tile-grout);
}

/* Painterly drawn tile flooring squares (alternating tan & dark brown) */
.square {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: none;
  padding: 0;
  background-color: var(--sq-light);
  background-image:
    /* Soft organic gouache/paper grain (fractalNoise) */
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.065' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0.25'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)' opacity='0.14'/%3E%3C/svg%3E"),
    /* Per-tile varied hand-painted watercolor pigment washes */
    radial-gradient(ellipse at var(--tile-wash-x, 30%) var(--tile-wash-y, 30%), rgba(255, 244, 218, 0.28) 0%, transparent 65%),
    radial-gradient(ellipse at var(--tile-shade-x, 70%) var(--tile-shade-y, 70%), rgba(132, 78, 32, 0.18) 0%, transparent 68%),
    linear-gradient(var(--tile-grad-angle, 150deg), #e2bc8a 0%, var(--sq-light) 52%, var(--sq-light-edge) 100%);
  background-size: 180px 180px, 100% 100%, 100% 100%, 100% 100%;
  background-position: var(--tile-noise-x, 0px) var(--tile-noise-y, 0px), center, center, center;
  box-shadow:
    inset 0 0 0 1px var(--tile-grout),
    inset 0 0 7px rgba(78, 44, 18, var(--tile-vignette, 0.22));
  filter: brightness(var(--tile-tone, 1));
  transition: filter 0.12s ease;
  outline: none;
}

.square.dark {
  background-color: var(--sq-dark);
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.065' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0.25'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)' opacity='0.17'/%3E%3C/svg%3E"),
    radial-gradient(ellipse at var(--tile-wash-x, 30%) var(--tile-wash-y, 30%), rgba(224, 168, 112, 0.15) 0%, transparent 64%),
    radial-gradient(ellipse at var(--tile-shade-x, 70%) var(--tile-shade-y, 70%), rgba(22, 10, 3, 0.28) 0%, transparent 68%),
    linear-gradient(var(--tile-grad-angle, 150deg), #80512c 0%, var(--sq-dark) 52%, var(--sq-dark-edge) 100%);
  background-size: 180px 180px, 100% 100%, 100% 100%, 100% 100%;
  background-position: var(--tile-noise-x, 42px) var(--tile-noise-y, 28px), center, center, center;
  box-shadow:
    inset 0 0 0 1px #1f1108,
    inset 0 0 8px rgba(18, 8, 3, var(--tile-vignette, 0.34));
}

.square:hover {
  filter: brightness(calc(var(--tile-tone, 1) * 1.07));
}

/* Algebraic coordinates */
.coord-rank,
.coord-file {
  position: absolute;
  font-family: "OldTimeyMono", "Courier New", monospace;
  font-size: 0.68rem;
  font-weight: 700;
  pointer-events: none;
  z-index: 2;
  opacity: 0.88;
}

.coord-rank {
  top: 2px;
  left: 3px;
}

.coord-file {
  bottom: 1px;
  right: 3px;
}

.square.light .coord-rank,
.square.light .coord-file {
  color: var(--coord-light);
}

.square.dark .coord-rank,
.square.dark .coord-file {
  color: var(--coord-dark);
}

/* Persistent state layers */
.square-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
}

/* Investigated (wrong) or cleared by a witness's LoS -> grey color from then on out */
.square.investigated-empty .square-overlay,
.square.witness-cleared .square-overlay {
  background: var(--inv-empty-overlay);
}

/* Ruled-out suspect piece after wrong crack attempt -> grey square + grey piece + small grey X */
.square.cleared-piece .square-overlay {
  background: var(--inv-empty-overlay);
}

.square.cleared-piece .piece-wrap {
  filter: grayscale(100%) brightness(0.75);
  opacity: 0.78;
}

.square.cleared-piece.selected-piece .piece-wrap {
  filter:
    grayscale(100%)
    brightness(0.85)
    drop-shadow(0 0 2px #38bdf8)
    drop-shadow(0 0 5px rgba(56, 189, 248, 0.85));
}

.cleared-x {
  position: absolute;
  z-index: 8;
  pointer-events: none;
  font-size: 1.55rem;
  font-weight: 900;
  line-height: 1;
  color: #aeb5c2;
  text-shadow:
    0 0 4px rgba(17, 19, 24, 0.95),
    0 1px 2px rgba(0, 0, 0, 0.9);
}

/* Investigated (murder location!) -> red color from then on out */
.square.investigated-murder .square-overlay {
  background: var(--inv-murder-overlay);
}

/* Selection highlight: EMPTY SPACE (amber/gold fill + border) */
.square.selected-empty::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--sel-empty-fill);
  box-shadow: inset 0 0 0 3.5px var(--sel-empty-border);
  pointer-events: none;
  z-index: 4;
}

/* Selection highlight: PIECE SPACE (different color: cyan/blue fill + border) */
.square.selected-piece::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--sel-piece-fill);
  box-shadow: inset 0 0 0 3.5px var(--sel-piece-border);
  pointer-events: none;
  z-index: 4;
}

/* Piece container & outline highlight */
.piece-wrap {
  position: relative;
  width: 84%;
  height: 84%;
  z-index: 5;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.14s ease, filter 0.14s ease;
}

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

/* Piece outline highlight when selected */
.square.selected-piece .piece-wrap {
  transform: scale(1.07);
  filter:
    drop-shadow(0 0 2px #38bdf8)
    drop-shadow(0 0 4px #7dd3fc)
    drop-shadow(0 0 7px rgba(56, 189, 248, 0.9));
}

/* Subtle questioned badge on witnesses who have already been questioned */
.questioned-dot {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent-gold);
  border: 1.5px solid #16181f;
  z-index: 7;
  pointer-events: none;
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.5);
}

.questioned-dot.dot-hostile {
  background: #ef233c;
  box-shadow: 0 0 6px rgba(239, 35, 60, 0.75);
}

/* Circle markers: Here!, Investigated Murder Location, and Accuse! */
.marker-ring {
  position: absolute;
  inset: 6%;
  border-radius: 50%;
  pointer-events: none;
  z-index: 6;
}

/* Circle around empty space from "Here!" */
.marker-ring.here-ring {
  border: 3.5px solid #f59e0b;
  box-shadow: 0 0 10px rgba(245, 158, 11, 0.65), inset 0 0 6px rgba(245, 158, 11, 0.3);
}

/* Circle around murder location when discovered by "Investigate" */
.marker-ring.murder-ring {
  border: 4px solid #ff3b3b;
  box-shadow: 0 0 12px rgba(255, 59, 59, 0.8), inset 0 0 8px rgba(255, 59, 59, 0.4);
}

/* Red circle around piece and space from "Accuse!" */
.marker-ring.accuse-ring {
  border: 4px solid #ef233c;
  box-shadow: 0 0 12px rgba(239, 35, 60, 0.85), inset 0 0 6px rgba(239, 35, 60, 0.35);
}

/* Revealed victim Black King when case is closed */
.victim-king {
  opacity: 0.95;
  transform: rotate(-18deg);
  filter: drop-shadow(0 2px 6px rgba(239, 35, 60, 0.8));
}

/* Red herring icon revealed on decoy potential mate squares after solving */
.red-herring-wrap {
  position: relative;
  width: 74%;
  height: 74%;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  filter: drop-shadow(0 2px 5px rgba(0, 0, 0, 0.55));
  animation: herring-pop 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}

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

@keyframes herring-pop {
  from {
    opacity: 0;
    transform: scale(0.6) rotate(-12deg);
  }
  to {
    opacity: 1;
    transform: scale(1) rotate(0deg);
  }
}

/* Overlapping witness question marks */
.clue-marks {
  position: relative;
  z-index: 3;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 1px;
  padding: 2px 4px;
  max-width: 90%;
  pointer-events: none;
}

.clue-q {
  font-weight: 900;
  font-size: 0.95rem;
  line-height: 1;
  color: #161820;
  text-shadow: 0 0 4px rgba(255, 240, 195, 0.95), 0 1px 0 rgba(255, 255, 255, 0.7);
}

.square.investigated-empty .clue-q {
  color: #e2e6ef;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.85);
}

.clue-marks.density-medium .clue-q {
  font-size: 0.82rem;
}

.clue-marks.density-high .clue-q {
  font-size: 0.7rem;
}

/* Action dock beneath the board — Yellowing Rulebook Page Sheet */
.action-dock {
  width: 100%;
  max-width: 560px;
  background-color: var(--paper-mid);
  background-image:
    var(--paper-grain),
    radial-gradient(ellipse at center, var(--paper-light) 35%, var(--paper-aged) 100%);
  border: 1.5px solid var(--ink-dark);
  border-radius: 1px;
  padding: 14px 20px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  min-height: 98px;
  box-shadow:
    inset 0 0 0 4px var(--paper-light),
    inset 0 0 0 5px rgba(44, 30, 18, 0.42),
    0 6px 16px rgba(0, 0, 0, 0.48);
}

.selection-banner {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 0.94rem;
  color: var(--ink-muted);
  text-align: center;
}

.selection-banner strong {
  font-family: "OldTimeyMono", Georgia, serif;
  color: var(--ink-dark);
}

.action-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
}

.crack-row {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 12px;
  padding-top: 10px;
  border-top: 1px dashed rgba(44, 30, 18, 0.38);
}

.crack-row[hidden],
.crack-row [hidden] {
  display: none;
}

/* Bottom rotating detective tip */
.tip-bar {
  width: 100%;
  max-width: 560px;
  text-align: center;
  font-family: Georgia, "Times New Roman", serif;
  font-style: italic;
  font-size: 0.84rem;
  line-height: 1.4;
  color: #dfd0b0;
  padding: 2px 10px 4px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.75);
}

/* Vintage Board Game Paper Card Buttons */
.btn {
  font-family: "OldTimeyMono", Georgia, serif;
  background-color: var(--card-stock);
  background-image:
    var(--paper-grain),
    linear-gradient(180deg, #fcf6e6 0%, var(--card-edge) 100%);
  color: var(--ink-dark);
  border: 1.5px solid var(--ink-dark);
  border-radius: 3px;
  padding: 10px 18px;
  font-size: 0.96rem;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  box-shadow:
    inset 0 0 0 3px #faf2de,
    inset 0 0 0 4.5px var(--card-accent, var(--ink-dark)),
    0 3px 0 #2b1e12,
    0 5px 10px rgba(0, 0, 0, 0.3);
  transition: transform 0.08s ease, box-shadow 0.08s ease, filter 0.12s ease, opacity 0.15s ease;
}

.btn:hover:not(:disabled) {
  filter: brightness(1.03);
  transform: translateY(-2px);
  box-shadow:
    inset 0 0 0 3px #faf2de,
    inset 0 0 0 4.5px var(--card-accent, var(--ink-dark)),
    0 5px 0 #2b1e12,
    0 7px 14px rgba(0, 0, 0, 0.34);
}

.btn:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow:
    inset 0 0 0 3px #faf2de,
    inset 0 0 0 4.5px var(--card-accent, var(--ink-dark)),
    0 1px 0 #2b1e12;
}

.btn:disabled {
  opacity: 0.46;
  filter: grayscale(40%);
  cursor: not-allowed;
  box-shadow:
    inset 0 0 0 3px #efe6cf,
    inset 0 0 0 4.5px rgba(44, 30, 18, 0.35),
    0 1px 0 #2b1e12;
}

.btn-investigate {
  --card-accent: var(--vintage-blue);
  color: var(--vintage-blue);
}

.btn-here {
  --card-accent: var(--vintage-ochre);
  color: #7c4c0b;
}

.btn-question {
  --card-accent: var(--vintage-teal);
  color: var(--vintage-teal);
}

.btn-accuse {
  --card-accent: var(--vintage-crimson);
  color: var(--vintage-crimson);
  background-image:
    var(--paper-grain),
    linear-gradient(180deg, #fdf0ea 0%, #f1d3c7 100%);
}

.btn-crack {
  --card-accent: var(--vintage-crimson);
  background-image:
    var(--paper-grain),
    linear-gradient(180deg, #f7e1a0 0%, #dfba66 100%);
  color: #6b1417;
  padding: 12px 24px;
  font-size: 1.04rem;
  box-shadow:
    inset 0 0 0 3px #f6df9d,
    inset 0 0 0 5px var(--vintage-crimson),
    0 3px 0 #2b1e12,
    0 6px 14px rgba(0, 0, 0, 0.38);
}

.btn-crack:hover:not(:disabled) {
  box-shadow:
    inset 0 0 0 3px #f6df9d,
    inset 0 0 0 5px var(--vintage-crimson),
    0 5px 0 #2b1e12,
    0 8px 16px rgba(0, 0, 0, 0.42);
}

.btn-primary {
  --card-accent: var(--vintage-crimson);
  background-image:
    var(--paper-grain),
    linear-gradient(180deg, #f8e5b4 0%, #e4c070 100%);
  color: var(--ink-dark);
}

.btn-secondary {
  --card-accent: #5e4b38;
  color: var(--ink-dark);
}

/* Brief text popup toast — Vintage printed paper slip */
.toast-popup {
  position: fixed;
  top: 22px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  pointer-events: none;
  animation: toast-in 0.2s ease-out;
}

.toast-popup[hidden] {
  display: none;
}

.toast-content {
  font-family: "OldTimeyMono", "Courier New", monospace;
  background-color: var(--paper-light);
  background-image:
    var(--paper-grain),
    linear-gradient(180deg, #f8eed4 0%, #e7d4a8 100%);
  color: var(--ink-dark);
  border: 2px solid var(--ink-dark);
  border-radius: 2px;
  padding: 12px 24px;
  font-size: 1.1rem;
  font-weight: 700;
  box-shadow:
    inset 0 0 0 3px #f8eed4,
    inset 0 0 0 4.5px rgba(44, 30, 18, 0.45),
    0 10px 26px rgba(0, 0, 0, 0.58);
  text-align: center;
  max-width: 90vw;
}

.toast-popup.toast-danger .toast-content {
  color: var(--vintage-crimson);
  box-shadow:
    inset 0 0 0 3px #f8eed4,
    inset 0 0 0 4.5px var(--vintage-crimson),
    0 10px 26px rgba(0, 0, 0, 0.58);
}

.toast-popup.toast-clue .toast-content {
  color: var(--vintage-teal);
  box-shadow:
    inset 0 0 0 3px #f8eed4,
    inset 0 0 0 4.5px var(--vintage-teal),
    0 10px 26px rgba(0, 0, 0, 0.58);
}

.toast-popup.toast-neutral .toast-content {
  color: var(--ink-muted);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, -10px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

/* Witness speech bubble positioned upper-right above the questioned piece */
.speech-bubble {
  position: absolute;
  z-index: 60;
  pointer-events: none;
  font-family: "OldTimeyMono", "Courier New", monospace;
  background: #fdfaf3;
  color: #181a20;
  border: 2.5px solid #181a20;
  border-radius: 16px;
  padding: 11px 18px;
  font-size: 1.14rem;
  font-weight: 700;
  line-height: 1.25;
  white-space: nowrap;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.56);
  transform-origin: bottom left;
  animation: bubble-pop 0.18s cubic-bezier(0.22, 1, 0.36, 1);
}

.speech-bubble[hidden] {
  display: none;
}

.speech-bubble-sub {
  position: absolute;
  top: calc(100% + 16px);
  left: 0;
  font-family: "OldTimeyMono", "Courier New", monospace;
  font-size: 1.12rem;
  font-style: normal;
  font-weight: 700;
  color: #ffe29a;
  white-space: nowrap;
  text-shadow:
    0 2px 5px rgba(0, 0, 0, 0.98),
    0 0 12px rgba(0, 0, 0, 0.95),
    -1.2px -1.2px 0 #140808,
    1.2px -1.2px 0 #140808,
    -1.2px 1.2px 0 #140808,
    1.2px 1.2px 0 #140808;
}

.speech-bubble.bubble-flip .speech-bubble-sub {
  left: auto;
  right: 0;
  text-align: right;
}

/* Outer border of the bottom-left speech tail pointing down-left toward the piece */
.speech-bubble::before {
  content: "";
  position: absolute;
  bottom: -15px;
  left: 12px;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 15px 16px 0 0;
  border-color: #181a20 transparent transparent transparent;
  transform: skewX(-24deg);
}

/* Inner fill of the speech tail */
.speech-bubble::after {
  content: "";
  position: absolute;
  bottom: -11px;
  left: 14px;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 12px 12px 0 0;
  border-color: #fdfaf3 transparent transparent transparent;
  transform: skewX(-24deg);
}

.speech-bubble.bubble-clue {
  background: #fff9e6;
  border-color: #d99b26;
}

.speech-bubble.bubble-clue::before {
  border-color: #d99b26 transparent transparent transparent;
}

.speech-bubble.bubble-clue::after {
  border-color: #fff9e6 transparent transparent transparent;
}

.speech-bubble.bubble-hostile {
  background: #fff1f2;
  border-color: #d62828;
  color: #590d14;
}

.speech-bubble.bubble-hostile::before {
  border-color: #d62828 transparent transparent transparent;
}

.speech-bubble.bubble-hostile::after {
  border-color: #fff1f2 transparent transparent transparent;
}

/* Flipped bubble for right half of the board: sits upper-left with tail on bottom-right */
.speech-bubble.bubble-flip {
  transform-origin: bottom right;
  animation: bubble-pop-right 0.18s cubic-bezier(0.22, 1, 0.36, 1);
}

.speech-bubble.bubble-flip::before {
  left: auto;
  right: 12px;
  border-width: 15px 0 0 16px;
  transform: skewX(24deg);
}

.speech-bubble.bubble-flip::after {
  left: auto;
  right: 14px;
  border-width: 12px 0 0 12px;
  transform: skewX(24deg);
}

@keyframes bubble-pop {
  from {
    opacity: 0;
    transform: scale(0.78) translate(-4px, 6px);
  }
  to {
    opacity: 1;
    transform: scale(1) translate(0, 0);
  }
}

@keyframes bubble-pop-right {
  from {
    opacity: 0;
    transform: scale(0.78) translate(4px, 6px);
  }
  to {
    opacity: 1;
    transform: scale(1) translate(0, 0);
  }
}

/* Center-of-board text-only popup (e.g. "Something's not right....") */
.board-banner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 70;
  pointer-events: none;
  font-family: "OldTimeyMono", "Courier New", monospace;
  font-size: clamp(1.7rem, 4.8vw, 2.5rem);
  font-weight: 700;
  color: #ff4d4d;
  text-align: center;
  width: 92%;
  line-height: 1.2;
  letter-spacing: 0.02em;
  text-shadow:
    0 2px 6px rgba(0, 0, 0, 0.98),
    0 0 18px rgba(0, 0, 0, 0.95),
    -1.5px -1.5px 0 #140808,
    1.5px -1.5px 0 #140808,
    -1.5px 1.5px 0 #140808,
    1.5px 1.5px 0 #140808;
  animation: banner-pop 0.22s ease-out;
}

.board-banner[hidden] {
  display: none;
}

.board-banner.banner-neutral {
  color: #f4ebd4;
}

.board-banner-sub {
  margin-top: 8px;
  font-size: clamp(1.1rem, 3vw, 1.5rem);
  color: #ffe29a;
  line-height: 1.25;
}

@keyframes banner-pop {
  from {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.86);
  }
  to {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}

/* Modals — Vintage Rulebook Pages & Case File Dossier */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(14, 9, 5, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 200;
}

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

.modal-card {
  width: 100%;
  max-width: 490px;
  background-color: var(--paper-mid);
  background-image:
    var(--paper-grain),
    radial-gradient(ellipse at center, var(--paper-light) 30%, var(--paper-aged) 100%);
  color: var(--ink-dark);
  border: 2px solid var(--ink-dark);
  border-radius: 2px;
  padding: 26px 28px;
  box-shadow:
    inset 0 0 0 5px var(--paper-light),
    inset 0 0 0 6.5px rgba(44, 30, 18, 0.5),
    0 24px 60px rgba(0, 0, 0, 0.72);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-card h2 {
  font-family: "OldTimeyMono", Georgia, serif;
  font-size: 1.35rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-dark);
  border-bottom: 1.5px double rgba(44, 30, 18, 0.5);
  padding-bottom: 6px;
  text-align: center;
}

.victory-card {
  text-align: center;
  align-items: center;
  font-family: "OldTimeyMono", "Courier New", monospace;
}

.stamp {
  display: inline-block;
  border: 3px double var(--vintage-crimson);
  color: var(--vintage-crimson);
  font-family: "OldTimeyMono", "Courier New", monospace;
  font-weight: 900;
  font-size: 1rem;
  letter-spacing: 0.16em;
  padding: 5px 14px;
  border-radius: 2px;
  transform: rotate(-3deg);
  background: rgba(155, 32, 36, 0.05);
}

.victory-difficulty {
  font-family: "OldTimeyMono", "Courier New", monospace;
  font-size: 0.92rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.victory-difficulty strong {
  color: var(--ink-dark);
}

.victory-detail {
  font-size: 0.96rem;
  color: var(--ink-dark);
  line-height: 1.5;
}

.victory-scores {
  width: 100%;
  background: rgba(252, 245, 227, 0.75);
  border: 1.5px solid var(--ink-dark);
  border-radius: 1px;
  padding: 12px 16px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  font-size: 0.88rem;
}

.victory-score-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.victory-score-item span {
  color: var(--ink-muted);
  font-size: 0.76rem;
}

.victory-score-item strong {
  font-size: 1.2rem;
  color: var(--ink-dark);
}

.victory-score-item.total strong {
  color: var(--vintage-crimson);
}

.victory-score-item.total-span {
  grid-column: 1 / -1;
  padding-top: 8px;
  border-top: 1px dashed rgba(44, 30, 18, 0.45);
}

.victory-score-item.victory-score-single {
  grid-column: 1 / -1;
  align-items: center;
  text-align: center;
  gap: 4px;
  padding: 4px 0;
}

.victory-score-item.victory-score-single span {
  font-size: 0.96rem;
  color: var(--ink-dark);
}

.victory-score-item.victory-score-single strong {
  font-size: 1.9rem;
  line-height: 1.1;
}

/* Vintage printed score-distribution histogram inside Case Closed! modal */
.victory-histogram {
  width: 100%;
  background-color: rgba(252, 245, 227, 0.82);
  background-image:
    linear-gradient(to right, rgba(44, 30, 18, 0.06) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(44, 30, 18, 0.06) 1px, transparent 1px);
  background-size: 16px 16px;
  border: 1.5px solid var(--ink-dark);
  border-radius: 1px;
  padding: 10px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.hist-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 0.74rem;
  color: var(--ink-muted);
  border-bottom: 1px dashed rgba(44, 30, 18, 0.35);
  padding-bottom: 4px;
}

.hist-title {
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-dark);
}

.hist-percentile {
  font-weight: 700;
  color: var(--vintage-crimson);
}

.hist-bars {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 92px;
  padding-top: 18px;
  border-bottom: 1.5px solid var(--ink-dark);
}

.hist-col {
  flex: 1 1 0;
  min-width: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  position: relative;
}

.hist-you-tag {
  position: absolute;
  top: -16px;
  font-size: 0.62rem;
  font-weight: 900;
  letter-spacing: 0.04em;
  color: var(--vintage-crimson);
  white-space: nowrap;
}

.hist-bar {
  width: 100%;
  min-height: 2px;
  background: linear-gradient(180deg, #8b6a47 0%, #5b4128 100%);
  border: 1px solid var(--ink-dark);
  border-bottom: none;
  transition: height 0.25s ease;
}

.hist-col.is-player .hist-bar {
  background: linear-gradient(180deg, #c93338 0%, var(--vintage-crimson) 100%);
  box-shadow: 0 0 6px rgba(155, 32, 36, 0.45);
}

.hist-labels {
  display: flex;
  gap: 4px;
}

.hist-label {
  flex: 1 1 0;
  min-width: 0;
  text-align: center;
  font-size: 0.66rem;
  color: var(--ink-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hist-label.is-player {
  font-weight: 900;
  color: var(--vintage-crimson);
}

.hist-caption {
  font-size: 0.68rem;
  color: var(--ink-muted);
  text-align: center;
}

/* Final Score modal & 0..20+ histogram */
.final-score-card {
  max-width: 560px;
}

.final-greeting {
  border-bottom: none !important;
  padding-bottom: 0 !important;
  font-size: 1.45rem !important;
  text-transform: none !important;
}

.detective-rank-line {
  font-family: "OldTimeyMono", "Courier New", monospace;
  font-size: 1.05rem;
  color: var(--ink-muted);
}

.detective-rank-line strong {
  color: var(--vintage-crimson);
  font-size: 1.15rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.final-case-breakdown {
  grid-template-columns: repeat(3, 1fr);
}

.final-histogram .hist-bars {
  gap: 2px;
}

.final-histogram .hist-labels {
  gap: 2px;
}

.final-histogram .hist-label {
  font-size: 0.56rem;
}

.final-histogram .hist-you-tag {
  font-size: 0.54rem;
}

.share-feedback {
  font-family: "OldTimeyMono", "Courier New", monospace;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--vintage-teal);
  background: rgba(29, 89, 78, 0.1);
  border: 1px dashed var(--vintage-teal);
  border-radius: 2px;
  padding: 5px 12px;
  text-align: center;
}

.share-feedback.is-error {
  color: var(--vintage-crimson);
  background: rgba(155, 32, 36, 0.08);
  border-color: var(--vintage-crimson);
}

.share-feedback[hidden] {
  display: none;
}

/* Welcome & Tutorial Story Dialog Modals */
.welcome-card {
  text-align: center;
  align-items: center;
}

.welcome-card h2 {
  border-bottom: none;
  padding-bottom: 0;
  text-transform: none;
  font-size: 1.24rem;
  line-height: 1.35;
}

.tutorial-dialog-card {
  max-width: 460px;
}

.tutorial-dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1.5px double rgba(44, 30, 18, 0.45);
  padding-bottom: 6px;
}

.tutorial-dialog-speaker {
  font-family: "OldTimeyMono", "Courier New", monospace;
  font-size: 0.9rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--vintage-crimson);
}

.tutorial-exit-link {
  font-family: "OldTimeyMono", "Courier New", monospace;
  font-size: 0.76rem;
  color: var(--ink-muted);
  background: transparent;
  border: none;
  text-decoration: underline;
  cursor: pointer;
}

.tutorial-exit-link:hover {
  color: var(--ink-dark);
}

.tutorial-dialog-text {
  font-family: "OldTimeyMono", Georgia, serif;
  font-size: 1.06rem;
  line-height: 1.5;
  color: var(--ink-dark);
  text-align: center;
  padding: 6px 4px;
}

/* Floating Tutorial Arrow & Word Bubble */
.tutorial-pointer {
  position: fixed;
  z-index: 165;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: min(290px, 86vw);
  transition: left 0.16s ease, top 0.16s ease;
}

.tutorial-pointer[hidden] {
  display: none;
}

.tutorial-pointer.is-below {
  flex-direction: column-reverse;
}

.tutorial-bubble {
  font-family: "OldTimeyMono", "Courier New", monospace;
  font-size: 0.96rem;
  font-weight: 700;
  line-height: 1.32;
  color: var(--ink-dark);
  background: #fff9e6;
  border: 2.5px solid var(--vintage-crimson);
  border-radius: 12px;
  padding: 9px 14px;
  text-align: center;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.55);
}

.tutorial-arrow {
  position: relative;
  font-size: 1.65rem;
  line-height: 1;
  color: #e63946;
  text-shadow:
    0 2px 5px rgba(0, 0, 0, 0.85),
    -1px -1px 0 #1f0a0c,
    1px -1px 0 #1f0a0c,
    -1px 1px 0 #1f0a0c,
    1px 1px 0 #1f0a0c;
  animation: tutorial-bounce 0.85s ease-in-out infinite;
}

.tutorial-pointer.is-below .tutorial-arrow {
  animation: tutorial-bounce-up 0.85s ease-in-out infinite;
}

@keyframes tutorial-bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(5px); }
}

@keyframes tutorial-bounce-up {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

.rules-list {
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 0.9rem;
  line-height: 1.48;
  color: var(--ink-muted);
}

.rules-list strong {
  color: var(--ink-dark);
}

.rules-list code {
  font-family: "OldTimeyMono", "Courier New", monospace;
  background: rgba(44, 30, 18, 0.09);
  padding: 0 4px;
  color: var(--ink-dark);
}

.rules-list ul {
  margin-top: 4px;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 4px;
}

@media (max-width: 540px) {
  :root {
    --board-size: min(92vw, 56vh, 420px);
  }
  .hide-on-mobile {
    display: none;
  }
  .score-strip {
    grid-template-columns: repeat(2, 1fr);
    padding: 4px;
  }
  .stat-pill {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    padding: 5px 10px;
    gap: 6px;
    border-right: none;
    border-bottom: 1px solid var(--ink-rule);
  }
  .stat-pill:nth-child(odd) {
    border-right: 1px solid var(--ink-rule);
  }
  .stat-pill:nth-last-child(-n + 2) {
    border-bottom: none;
  }
  .stat-label {
    font-size: 0.68rem;
    text-align: left;
  }
  .stat-value {
    font-size: 1.05rem;
  }
  .action-dock {
    min-height: 118px;
    justify-content: center;
    padding: 10px 12px;
    gap: 8px;
  }
  .selection-banner.is-selection-status {
    display: none;
  }
  .action-buttons {
    width: 100%;
    flex-wrap: nowrap;
    gap: 8px;
  }
  .crack-row {
    width: 100%;
    flex-wrap: nowrap;
    gap: 8px;
    padding-top: 8px;
  }
  .action-dock .btn {
    flex: 1 1 0;
    padding: 8px 10px;
    font-size: 0.84rem;
    white-space: nowrap;
  }
  .action-dock .btn-crack {
    padding: 8px 12px;
    font-size: 0.9rem;
  }
  .speech-bubble {
    font-size: 0.98rem;
    padding: 9px 13px;
    white-space: normal;
    max-width: 58vw;
  }
  .speech-bubble-sub {
    font-size: 0.98rem;
    white-space: normal;
    width: max-content;
    max-width: 58vw;
  }
}
