  :root {
    --felt-dark: #0f3d28;
    --felt-mid: #17573a;
    --felt-light: #20704b;
    --wood-dark: #4a2810;
    --wood-mid: #6e3d1a;
    --wood-light: #965728;
    --gold: #f4c430;
    --gold-dim: #c99a18;
    --cream: #fcf8ee;
    --card-border: #d8d0c0;
    --red-suit: #c82333;
    --black-suit: #1e2226;
    --text-light: #f8f5ec;
    --shadow-card: 0 4px 10px rgba(0,0,0,0.45);
    --shadow-lg: 0 10px 28px rgba(0,0,0,0.6);
  }

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


  body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: radial-gradient(circle at 50% 45%, var(--felt-light) 0%, var(--felt-mid) 55%, var(--felt-dark) 100%);
    color: var(--text-light);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
  }

  /* Header Bar */
  header {
    background: linear-gradient(180deg, #2b1608 0%, var(--wood-dark) 100%);
    border-bottom: 3px solid var(--gold-dim);
    padding: 10px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 3px 12px rgba(0,0,0,0.5);
    z-index: 20;
    flex-wrap: wrap;
    gap: 10px;
  }

  .brand {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
  }

  .k-infinity-logo {
    background: linear-gradient(135deg, #f4c430 0%, #eab308 100%);
    color: #231105;
    font-family: Georgia, 'Times New Roman', serif;
    font-weight: 900;
    font-size: 1.15rem;
    padding: 4px 12px;
    border-radius: 8px;
    letter-spacing: 0.5px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.45), inset 0 1px 1px rgba(255,255,255,0.6);
    border: 1.5px solid #fff3b0;
  }

  .brand h1 {
    font-family: Georgia, serif;
    font-size: 1.35rem;
    color: var(--gold);
    letter-spacing: 0.5px;
    text-shadow: 1px 2px 3px rgba(0,0,0,0.7);
  }

  .brand span.badge {
    background: rgba(244, 196, 48, 0.18);
    border: 1px solid var(--gold-dim);
    color: var(--gold);
    font-size: 0.72rem;
    padding: 2px 8px;
    border-radius: 12px;
    font-weight: 600;
    text-transform: uppercase;
  }

  .controls {
    display: flex;
    gap: 10px;
    align-items: center;
  }

  button.btn {
    background: linear-gradient(180deg, #f7d358 0%, var(--gold) 100%);
    color: #2b1608;
    border: none;
    padding: 7px 14px;
    border-radius: 6px;
    font-weight: 700;
    font-size: 0.85rem;
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0,0,0,0.4);
    transition: transform 0.1s, filter 0.15s;
  }

  button.btn:hover:not(:disabled) {
    filter: brightness(1.08);
    transform: translateY(-1px);
  }

  button.btn:active:not(:disabled) {
    transform: translateY(1px);
  }

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

  button.btn-secondary {
    background: rgba(255,255,255,0.12);
    color: var(--text-light);
    border: 1px solid rgba(255,255,255,0.25);
  }

  button.btn-secondary:hover:not(:disabled) {
    background: rgba(255,255,255,0.2);
  }

  button.btn-secondary.active-tab {
    background: rgba(244, 196, 48, 0.26);
    border-color: var(--gold);
    color: var(--gold);
  }

  /* Main Game Layout */
  .game-container {
    flex: 1;
    display: grid;
    grid-template-rows: auto 1fr auto;
    max-width: 1180px;
    width: 100%;
    margin: 0 auto;
    padding: 12px 16px;
    gap: 10px;
  }

  .inst-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
    gap: 14px;
  }

  .inst-card {
    background: rgba(0, 0, 0, 0.34);
    border: 1.5px solid rgba(255, 255, 255, 0.14);
    border-radius: 14px;
    padding: 18px;
    box-shadow: 0 4px 14px rgba(0,0,0,0.35);
    display: flex;
    flex-direction: column;
    gap: 10px;
  }

  .inst-card h3 {
    color: var(--gold);
    font-family: Georgia, serif;
    font-size: 1.15rem;
    border-bottom: 1px solid rgba(244, 196, 48, 0.3);
    padding-bottom: 6px;
  }

  .inst-card p, .inst-card li {
    font-size: 0.88rem;
    line-height: 1.5;
    color: #e6f2ec;
  }

  .inst-card ul, .inst-card ol {
    padding-left: 20px;
    display: flex;
    flex-direction: column;
    gap: 6px;
  }

  .example-hand-strip {
    background: rgba(255,255,255,0.08);
    border-radius: 10px;
    padding: 10px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 4px;
  }

  .mini-pill-tag {
    background: rgba(244, 196, 48, 0.22);
    border: 1px solid var(--gold-dim);
    color: #fde68a;
    font-size: 0.78rem;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 6px;
  }

  /* Wooden Cribbage Board */
  .crib-board-wrapper {
    background: linear-gradient(180deg, var(--wood-light) 0%, var(--wood-mid) 50%, var(--wood-dark) 100%);
    border: 3px solid #301706;
    border-radius: 14px;
    padding: 10px 16px;
    box-shadow: var(--shadow-lg), inset 0 1px 2px rgba(255,255,255,0.25);
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .crib-board-wrapper.peg-target-mode {
    border-color: #38bdf8;
    box-shadow: 0 0 22px rgba(56, 189, 248, 0.7), var(--shadow-lg);
  }

  .board-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.82rem;
    color: #f3dfc1;
    flex-wrap: wrap;
    gap: 8px;
  }

  .score-pills {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
  }

  .score-pill {
    display: flex;
    align-items: center;
    gap: 7px;
    background: rgba(0,0,0,0.35);
    padding: 4px 10px;
    border-radius: 20px;
    border: 1px solid rgba(255,255,255,0.12);
  }

  .peg-dot {
    width: 11px;
    height: 11px;
    border-radius: 50%;
    box-shadow: inset 0 -2px 2px rgba(0,0,0,0.5), 0 0 4px rgba(255,255,255,0.4);
  }

  .peg-player { background: #38bdf8; }
  .peg-ai1 { background: #fb7185; }
  .peg-ai2 { background: #a3e635; }

  .board-track-svg {
    width: 100%;
    height: 82px;
    background: #3b1e0a;
    border-radius: 8px;
    border: 1px solid #241004;
    box-shadow: inset 0 2px 6px rgba(0,0,0,0.7);
  }

  .board-track-svg.clickable-board {
    cursor: crosshair;
  }

  /* Table Play Area */
  .table-area {
    display: grid;
    grid-template-columns: 1fr 2fr 1fr;
    gap: 12px;
    align-items: center;
    min-height: 350px;
  }

  .opponent-zone {
    background: rgba(0, 0, 0, 0.22);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    min-height: 180px;
    justify-content: center;
    transition: border-color 0.25s, box-shadow 0.25s;
  }

  .opponent-zone.active-turn {
    border-color: var(--gold);
    box-shadow: 0 0 15px rgba(244, 196, 48, 0.3);
  }

  .opponent-zone.hidden {
    visibility: hidden;
  }

  .player-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 600;
    font-size: 0.9rem;
    background: rgba(0,0,0,0.4);
    padding: 4px 12px;
    border-radius: 14px;
  }

  .dealer-chip {
    background: var(--gold);
    color: #2b1608;
    font-size: 0.68rem;
    font-weight: 800;
    padding: 1px 6px;
    border-radius: 8px;
    text-transform: uppercase;
  }

  .speech-bubble {
    background: var(--cream);
    color: #222;
    font-size: 0.78rem;
    padding: 5px 10px;
    border-radius: 10px;
    max-width: 200px;
    text-align: center;
    box-shadow: 0 3px 8px rgba(0,0,0,0.35);
    min-height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-style: italic;
  }

  /* Center Felt Zone */
  .center-zone {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    background: rgba(0,0,0,0.18);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 16px;
    padding: 14px;
  }

  .status-banner {
    background: rgba(0, 0, 0, 0.55);
    border: 1px solid var(--gold-dim);
    color: var(--gold);
    padding: 7px 16px;
    border-radius: 20px;
    font-weight: 600;
    font-size: 0.92rem;
    text-align: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  }

  .deck-and-crib {
    display: flex;
    gap: 28px;
    align-items: center;
    justify-content: center;
  }

  .pile-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
  }

  .pile-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: #cde3d6;
    font-weight: 600;
  }

  .pegging-arena {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    width: 100%;
    background: rgba(0,0,0,0.25);
    border-radius: 12px;
    padding: 10px;
    min-height: 135px;
  }

  .pegging-header {
    display: flex;
    justify-content: space-between;
    width: 100%;
    padding: 0 8px;
    font-size: 0.85rem;
  }

  .running-count {
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--gold);
  }

  .played-cards-row {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: center;
    min-height: 92px;
    align-items: center;
  }

  /* Interactive Peg Placement Banner */
  .peg-challenge-bar {
    background: linear-gradient(90deg, rgba(14, 116, 144, 0.92), rgba(3, 105, 161, 0.92));
    border: 2px solid #38bdf8;
    border-radius: 12px;
    padding: 10px 16px;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    box-shadow: 0 6px 20px rgba(0,0,0,0.5);
  }

  .peg-challenge-bar.hidden {
    display: none;
  }

  .peg-challenge-controls {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
  }

  .peg-num-input {
    width: 78px;
    padding: 6px 10px;
    border-radius: 6px;
    border: 2px solid #f4c430;
    font-size: 1rem;
    font-weight: 800;
    text-align: center;
    background: #fcf8ee;
    color: #1e2226;
  }

  /* Playing Cards */
  .card {
    width: 64px;
    height: 92px;
    background: var(--cream);
    border: 1.5px solid var(--card-border);
    border-radius: 7px;
    box-shadow: var(--shadow-card);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 4px 6px;
    position: relative;
    transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease;
    cursor: default;
  }

  .card.red { color: var(--red-suit); }
  .card.black { color: var(--black-suit); }

  .card.playable {
    cursor: pointer;
  }

  .card.playable:hover {
    transform: translateY(-8px);
    box-shadow: 0 8px 16px rgba(0,0,0,0.55);
    border-color: var(--gold);
  }

  .card.selected {
    transform: translateY(-14px);
    border: 2.5px solid var(--gold);
    box-shadow: 0 0 14px rgba(244, 196, 48, 0.75);
  }

  .card.disabled-play {
    opacity: 0.5;
    cursor: not-allowed;
  }

  .card.mini {
    width: 48px;
    height: 68px;
    padding: 3px 4px;
    font-size: 0.8rem;
  }

  .card-corner {
    display: flex;
    flex-direction: column;
    align-items: center;
    line-height: 1;
    font-weight: 800;
    font-size: 0.92rem;
    width: 16px;
  }

  .card-corner.bottom {
    align-self: flex-end;
    transform: rotate(180deg);
  }

  .card-center-suit {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.65rem;
    opacity: 0.9;
  }

  .card.mini .card-center-suit {
    font-size: 1.2rem;
  }

  .card-back {
    background: repeating-linear-gradient(
      45deg,
      #8b1e24,
      #8b1e24 6px,
      #a82830 6px,
      #a82830 12px
    );
    border: 2.5px solid #f8f5ec;
  }

  .card-placeholder {
    width: 64px;
    height: 92px;
    border: 2px dashed rgba(255,255,255,0.22);
    border-radius: 7px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    color: rgba(255,255,255,0.4);
    text-align: center;
  }

  .hand-row {
    display: flex;
    gap: 8px;
    justify-content: center;
    flex-wrap: wrap;
  }

  /* Player Bottom Zone */
  .player-zone {
    background: rgba(0, 0, 0, 0.3);
    border: 1.5px solid rgba(255, 255, 255, 0.15);
    border-radius: 14px;
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    transition: border-color 0.25s;
  }

  .player-zone.active-turn {
    border-color: var(--gold);
    box-shadow: 0 0 18px rgba(244, 196, 48, 0.32);
  }

  .player-controls-row {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
  }

  .kid-helper-box {
    background: rgba(56, 189, 248, 0.16);
    border: 1px solid rgba(56, 189, 248, 0.45);
    color: #e0f2fe;
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 0.82rem;
    max-width: 650px;
    text-align: center;
  }

  /* Floating Point Popups */
  .points-toast {
    position: fixed;
    top: 46%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(20, 12, 4, 0.94);
    border: 2px solid var(--gold);
    color: var(--gold);
    padding: 10px 20px;
    border-radius: 12px;
    font-weight: 800;
    font-size: 1.15rem;
    z-index: 60;
    pointer-events: none;
    box-shadow: 0 8px 24px rgba(0,0,0,0.65);
    animation: popFade 1.8s forwards;
  }

  @keyframes popFade {
    0% { opacity: 0; transform: translate(-50%, -35%) scale(0.85); }
    15% { opacity: 1; transform: translate(-50%, -50%) scale(1.05); }
    80% { opacity: 1; transform: translate(-50%, -55%) scale(1); }
    100% { opacity: 0; transform: translate(-50%, -70%) scale(0.95); }
  }

  /* Modals */
  .modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.78);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 16px;
  }

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

  .modal-card {
    background: linear-gradient(180deg, #1b4d36 0%, #103323 100%);
    border: 2px solid var(--gold);
    border-radius: 16px;
    max-width: 600px;
    width: 100%;
    padding: 22px;
    box-shadow: var(--shadow-lg);
    color: var(--text-light);
    max-height: 92vh;
    overflow-y: auto;
  }

  .modal-card h2 {
    font-family: Georgia, serif;
    color: var(--gold);
    margin-bottom: 10px;
    font-size: 1.45rem;
    text-align: center;
  }

  .setup-group {
    margin-bottom: 16px;
  }

  .setup-group label {
    display: block;
    font-weight: 700;
    margin-bottom: 6px;
    color: #e2ede7;
    font-size: 0.9rem;
  }

  .option-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 8px;
  }

  .option-btn {
    background: rgba(0,0,0,0.32);
    border: 1.5px solid rgba(255,255,255,0.2);
    color: var(--text-light);
    padding: 10px;
    border-radius: 10px;
    cursor: pointer;
    text-align: left;
    transition: all 0.15s;
  }

  .option-btn:hover {
    border-color: var(--gold-dim);
  }

  .option-btn.active {
    background: rgba(244, 196, 48, 0.22);
    border-color: var(--gold);
    box-shadow: 0 0 10px rgba(244, 196, 48, 0.25);
  }

  .option-btn strong {
    display: block;
    color: var(--gold);
    font-size: 0.92rem;
    margin-bottom: 2px;
  }

  .option-btn span {
    font-size: 0.76rem;
    color: #cde3d6;
    display: block;
    line-height: 1.25;
  }

  /* Interactive Counting Quiz Box inside Showdown */
  .count-quiz-box {
    background: rgba(0, 0, 0, 0.35);
    border: 1.5px solid var(--gold);
    border-radius: 12px;
    padding: 14px;
    margin: 12px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
  }

  .quiz-cards-display {
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
  }

  .quiz-input-row {
    display: flex;
    gap: 10px;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
  }

  .quiz-feedback {
    font-size: 0.88rem;
    text-align: center;
    padding: 8px 12px;
    border-radius: 8px;
    width: 100%;
  }

  .quiz-feedback.success {
    background: rgba(34, 197, 94, 0.2);
    border: 1px solid #4ade80;
    color: #dcfce7;
  }

  .quiz-feedback.retry {
    background: rgba(251, 191, 36, 0.2);
    border: 1px solid #fbbf24;
    color: #fef3c7;
  }

  .quiz-feedback.revealed {
    background: rgba(56, 189, 248, 0.2);
    border: 1px solid #38bdf8;
    color: #e0f2fe;
  }

  /* Showdown Breakdown Table */
  .breakdown-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 10px 0 14px;
  }

  .breakdown-item {
    background: rgba(0,0,0,0.3);
    border-radius: 10px;
    padding: 10px 12px;
    border: 1px solid rgba(255,255,255,0.12);
  }

  .breakdown-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    font-weight: 700;
  }

  .breakdown-cards {
    display: flex;
    gap: 5px;
    margin-bottom: 8px;
    align-items: center;
  }

  .breakdown-reasons {
    font-size: 0.8rem;
    color: #d8ece0;
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }

  .breakdown-reasons li {
    background: rgba(255,255,255,0.1);
    padding: 2px 8px;
    border-radius: 6px;
  }

  /* Event Log Ticker */
  .log-bar {
    font-size: 0.78rem;
    color: #b7d4c4;
    text-align: center;
    background: rgba(0,0,0,0.28);
    padding: 5px 10px;
    border-radius: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  @media (max-width: 820px) {
    .table-area {
      grid-template-columns: 1fr;
    }
    .opponent-zone.hidden {
      display: none;
    }
    .opponent-zone {
      min-height: auto;
      padding: 8px;
    }
  }
  .hidden { display: none !important; }
  :focus-visible { outline: 3px solid var(--gold); outline-offset: 4px; }
  h2[tabindex="-1"]:focus { outline: none; }
  .game-container > *, .table-area > * { min-width: 0; }
  .center-zone > * { max-width: 100%; }
  .log-bar { width: 100%; }
  input { accent-color: var(--gold); }
  body.modal-open, body.tutorial-open { overflow: hidden; }

  /* A short introduction, with the full rules one disclosure away. */
  .rules-dialog {
    margin: auto;
    width: min(760px, calc(100% - 32px));
    max-height: calc(100dvh - 32px);
    border: 0;
    border-radius: 16px;
    background: #153e2d;
    color: var(--text-light);
    box-shadow: var(--shadow-lg);
    overflow-y: auto;
    scrollbar-color: #9cae92 #153e2d;
  }
  .rules-dialog::backdrop { background: rgba(5, 16, 11, 0.82); }
  .rules-heading { padding: 24px 32px 16px; position: relative; }
  .rules-heading h2 {
    font: 700 clamp(1.6rem, 4vw, 1.9rem)/1.15 Georgia, serif;
    color: var(--gold);
    margin: 0 44px 10px 0;
  }
  .rules-heading p { max-width: 58ch; color: #d7e5db; line-height: 1.55; }
  .rules-close {
    position: absolute; top: 18px; right: 18px;
    width: 44px; height: 44px; border: 1px solid #789283;
    border-radius: 50%; background: transparent; color: var(--cream);
    font-size: 1.5rem; cursor: pointer;
  }
  .rules-close:hover { background: #28513c; }
  .rules-body { padding: 0 32px 24px; }
  .rules-dialog p, .rules-dialog li, .rules-dialog strong { user-select: text; }
  .rules-dialog ::selection { background: var(--gold); color: #231105; }
  .quick-steps { list-style: none; counter-reset: steps; }
  .quick-steps li {
    counter-increment: steps; position: relative;
    padding: 12px 0 12px 48px; border-top: 1px solid #496251;
  }
  .quick-steps li::before {
    content: counter(steps); position: absolute; left: 0; top: 14px;
    width: 30px; height: 30px; display: grid; place-items: center;
    border: 1px solid #a8b596; border-radius: 50%; color: var(--gold); font-weight: 700;
  }
  .quick-steps h3 { font-size: 1rem; margin-bottom: 5px; }
  .quick-steps p { font-size: 0.92rem; line-height: 1.5; color: #d7e5db; }
  .fifteen-example {
    display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
    padding: 16px 20px; margin: 4px 0 16px;
    border-radius: 12px; background: var(--cream); color: #243b2d;
  }
  .example-cards { display: flex; align-items: center; gap: 8px; }
  .example-card {
    width: 40px; height: 54px; display: grid; place-items: center;
    border: 1px solid #b5b7a8; border-radius: 5px; background: white;
    font: 700 1.15rem Georgia, serif;
  }
  .example-card.red { color: var(--red-suit); }
  .fifteen-example p { font-size: 0.85rem; line-height: 1.5; }
  .fifteen-example strong { display: block; font-size: 1rem; }
  .card-value-note { font-size: 0.84rem; line-height: 1.5; color: #d7e5db; }
  .rules-details { margin-top: 20px; border-top: 1px solid #496251; }
  .rules-details summary {
    padding: 16px 0; color: var(--gold); font-weight: 700; cursor: pointer;
    min-height: 48px;
  }
  .rules-details .inst-grid { grid-template-columns: 1fr; gap: 0; }
  .rules-details .inst-card {
    border: 0; border-radius: 0; background: none; box-shadow: none;
    padding: 12px 0 18px;
  }
  .rules-footer {
    position: sticky; bottom: 0; display: flex; align-items: center;
    justify-content: space-between; gap: 16px; padding: 16px 32px;
    background: #103323; border-top: 1px solid #496251;
  }
  .rules-footer p { font-size: 0.8rem; color: #d7e5db; line-height: 1.4; max-width: 30ch; }
  .rules-footer button.btn { min-height: 46px; padding: 12px 20px; flex-shrink: 0; }
  .setup-intro { text-align: center; color: #d7e5db; line-height: 1.5; margin-bottom: 20px; font-size: 0.9rem; }
  .setup-help { display: grid; gap: 12px; padding-top: 4px; }
  .setup-help label { display: flex; gap: 10px; align-items: flex-start; font-size: 0.86rem; line-height: 1.45; cursor: pointer; }
  .setup-help input { margin-top: 4px; flex-shrink: 0; }
  .setup-help strong { display: block; }
  .setup-actions { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; margin-top: 22px; }
  .setup-actions .btn { min-height: 44px; }
  .setup-actions { position: sticky; bottom: -22px; background: #103323; padding: 12px 0; }
  .option-btn { min-height: 60px; }
  .option-btn.active { box-shadow: none; }
  @media (max-width: 520px) {
    header { padding: 12px; }
    .controls { width: 100%; gap: 8px; }
    .controls .btn { flex: 1; min-height: 44px; padding: 8px; }
    .brand h1 { font-size: 1.15rem; }
    .rules-dialog { width: calc(100% - 16px); max-height: calc(100dvh - 16px); }
    .rules-heading { padding: 24px 20px 16px; }
    .rules-body { padding: 0 20px 16px; }
    .rules-footer { padding: 12px 20px; flex-wrap: wrap; gap: 10px; }
    .rules-footer p { max-width: none; }
    .rules-footer .btn { width: 100%; }
    .fifteen-example { gap: 12px; padding: 14px; }
    .modal-backdrop { padding: 8px; }
    .modal-card { padding: 20px 16px; max-height: calc(100dvh - 16px); }
    #difficultyOptions { grid-template-columns: 1fr; }
    .setup-actions .btn { flex: 1; }
    .setup-actions { bottom: -20px; }
  }
  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
  }


  /* Highlighted help uses the real cards, inputs, and game buttons. */
  .rules-footer { flex-wrap: wrap; }
  .rules-footer p { flex: 1 1 180px; }
  .tutorial-shade { position: fixed; z-index: 2000; background: rgba(4, 15, 10, .78); touch-action: none; }
  .tutorial-spotlight { position: fixed; z-index: 2001; pointer-events: none; border: 3px solid var(--gold); border-radius: 10px; }
  .tutorial-target { outline: 3px solid var(--gold) !important; outline-offset: 3px; }
  .tutorial-popover { position: fixed; z-index: 2002; background: #153e2d; color: #f6f1e5; border-radius: 12px; padding: 20px; box-shadow: 0 12px 32px rgba(0, 0, 0, .4); overflow-y: auto; overscroll-behavior: contain; }
  .tutorial-popover h2 { font: 700 1.15rem/1.3 Georgia, serif; color: var(--gold); margin-bottom: 10px; }
  .tutorial-popover p { font-size: .9375rem; line-height: 1.6; }
  .tutorial-navigation { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 20px; }
  .tutorial-navigation .btn { width: 48px; min-height: 44px; padding: 0; font-size: 1.75rem; line-height: 1; }
  .tutorial-navigation span { font-size: .875rem; color: #d7e5db; font-variant-numeric: tabular-nums; }
  .tutorial-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 16px; }
  .tutorial-footer span { font-size: .75rem; color: #d7e5db; }
  .tutorial-footer .btn { min-height: 44px; padding: 8px 12px; }

  /* Scoring drawer: the edge tab stays visible when the panel slides away. */
  .controls { flex-wrap: wrap; }
  .game-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; width: 100%; max-width: 1180px; margin: 0 auto; padding: 12px 16px; align-items: start; }
  .game-layout > .game-container { min-width: 0; padding: 0; }
  .score-drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(340px, calc(100vw - 56px)); z-index: 80; transform: translateX(100%); transition: transform 220ms cubic-bezier(.22, 1, .36, 1); }
  .score-drawer.is-open { transform: translateX(0); }
  .score-drawer-tab { position: absolute; left: -44px; top: calc(50% - 36px); width: 44px; height: 72px; display: grid; place-items: center; border: 0; border-radius: 10px 0 0 10px; background: var(--gold); color: #231105; cursor: pointer; }
  .score-drawer-tab:hover { background: #ffdc64; }
  .score-drawer-tab svg { transition: transform 220ms cubic-bezier(.22, 1, .36, 1); }
  .score-drawer.is-open .score-drawer-tab svg { transform: rotate(180deg); }
  .score-reference { display: flex; flex-direction: column; height: 100%; min-width: 0; background: #103323; padding: 24px 20px 12px; box-shadow: -8px 0 24px rgba(0, 0, 0, .25); }
  .score-reference-heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
  .score-reference-heading h2 { font: 700 1.25rem/1.3 Georgia, serif; color: var(--gold); }
  .score-reference-intro, .score-reference-note { color: #d7e5db; font-size: .8125rem; line-height: 1.55; }
  .score-reference-intro { margin-bottom: 16px; }
  .score-reference-scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding-right: 6px; scrollbar-color: #9cae92 #103323; }
  .score-reference-table { width: 100%; border-collapse: collapse; font-size: .875rem; }
  .score-reference-table caption { text-align: left; font-weight: 700; color: var(--gold); padding: 12px 0; }
  .score-reference-table thead th { color: #bdcec3; font-size: .75rem; font-weight: 400; padding-bottom: 8px; }
  .score-reference-table th { text-align: left; font-weight: 600; }
  .score-reference-table tbody th, .score-reference-table td { border-top: 1px solid #496251; padding: 12px 0; vertical-align: top; }
  .score-reference-table td, .score-reference-table thead th:last-child { text-align: right; white-space: nowrap; padding-left: 12px; }
  .score-reference-table td { color: var(--gold); font-weight: 700; font-variant-numeric: tabular-nums; }
  .score-example { display: block; margin-top: 6px; font-size: .8125rem; font-weight: 400; }
  .score-cards { display: inline-flex; flex-wrap: wrap; gap: 4px; vertical-align: middle; }
  .score-card { display: inline-grid; place-items: center; min-width: 28px; min-height: 36px; padding: 3px; border-radius: 4px; background: var(--cream); color: var(--black-suit); font-family: Georgia, serif; font-weight: 700; }
  .score-card.red { color: var(--red-suit); }
  .score-reference-table small { display: block; margin-top: 6px; color: #d7e5db; font-size: .75rem; font-weight: 400; line-height: 1.5; }
  .score-reference-note { margin: 8px 0 20px; }

  /* Hand Counting and its reference share one dialog and keyboard boundary. */
  #showdownModal.counting-reference-open { padding-right: 400px; }
  #showdownModal > .score-drawer { z-index: 1; }
  @media (max-width: 900px) {
    #showdownModal.counting-reference-open { display: grid; grid-template-rows: minmax(0, 3fr) minmax(0, 2fr); align-items: stretch; justify-items: center; gap: 12px; padding: 12px 52px 12px 12px; }
    #showdownModal.counting-reference-open > .modal-card { max-height: 100%; min-height: 0; }
    #showdownModal.counting-reference-open > .score-drawer { position: relative; inset: auto; width: 100%; max-width: 600px; min-height: 0; height: 100%; transform: none; transition: none; }
    #showdownModal.counting-reference-open .score-reference { border-radius: 12px; padding: 12px; }
    #showdownModal.counting-reference-open .score-reference-heading { margin-bottom: 8px; }
    #showdownModal.counting-reference-open .score-reference-intro { display: none; }
    #showdownModal.counting-reference-open .score-drawer-tab { position: fixed; right: 0; left: auto; top: calc(50% - 36px); }
  }

  /* Count one scoring combination at a time, using the cards already on the table. */
  .count-with-me { display: block; margin: 12px auto 8px; min-height: 44px; }
  .counting-tip { color: #d7e5db; text-align: center; font-size: .8125rem; line-height: 1.5; margin-bottom: 16px; }
  .quiz-cards-display.counting-guided { position: sticky; top: 0; z-index: 2; background: #153e2d; padding-block: 12px; }
  .counting-guided .card { opacity: .45; }
  .counting-guided .card.counting-match { opacity: 1; outline: 3px solid var(--gold); outline-offset: 3px; }
  .count-guide { border-block: 1px solid #789283; padding: 20px 0; margin: 16px 0 24px; }
  .count-guide h3 { color: var(--gold); font-size: 1.1rem; margin-bottom: 10px; }
  .count-guide p { color: #e1ece5; font-size: .9375rem; line-height: 1.55; }
  .count-guide .count-guide-equation { font-size: 1.35rem; font-weight: 700; color: var(--gold); margin: 16px 0 8px; font-variant-numeric: tabular-nums; }
  .count-guide .count-guide-board { font-size: .8125rem; color: #d7e5db; }
  .count-guide-controls { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 20px; }
  .count-guide-controls .btn { min-height: 44px; flex: 1; }
  .count-guide-close { margin-top: 12px; min-height: 44px; }
