:root {
    --bg: #f5f2eb;
    --surface: #fffef9;
    --surface2: #f0ece0;
    --ink: #1a1812;
    --ink2: #5a5448;
    --ink3: #9a9080;
    --gold: #b8860b;
    --gold-light: #f5e9c8;
    --gold-border: #d4aa50;
    --blue: #2a5298;
    --blue-light: #e8eef8;
    --green: #2d6a4f;
    --green-light: #e8f4ee;
    --red: #8b2020;
    --red-light: #f8e8e8;
    --amber: #92580a;
    --amber-light: #fdf0d8;
    --radius: 6px;
    --radius-lg: 10px;
  }

  * { box-sizing: border-box; margin: 0; padding: 0; }

  body {
    font-family: 'DM Sans', sans-serif;
    background: var(--bg);
    color: var(--ink);
    min-height: 100vh;
    padding: 0;
  }

  .page {
    max-width: 900px;
    margin: 0 auto;
    padding: 2rem 1.5rem 4rem;
  }

  /* ── Header ── */
  .masthead {
    text-align: center;
    padding: 2.5rem 0 2rem;
    border-bottom: 1px solid var(--gold-border);
    margin-bottom: 2.5rem;
  }
  .masthead h1 {
    font-family: 'Playfair Display', serif;
    font-size: clamp(2rem, 5vw, 3.2rem);
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--ink);
  }
  .masthead .tagline {
    font-size: 14px;
    color: var(--ink3);
    margin-top: 6px;
    font-weight: 300;
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }
  .ornament { color: var(--gold-border); margin: 0 10px; }

  /* ── Selector screen ── */
  #screen-select { }
  .selector-intro {
    text-align: center;
    margin-bottom: 2rem;
  }
  .selector-intro p {
    font-size: 15px;
    color: var(--ink2);
    max-width: 480px;
    margin: 0 auto;
    line-height: 1.7;
  }

  .size-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    gap: 12px;
    margin-bottom: 2.5rem;
  }
  .size-card {
    background: var(--surface);
    border: 1px solid var(--gold-border);
    border-radius: var(--radius-lg);
    padding: 1.25rem 0.75rem;
    text-align: center;
    cursor: pointer;
    transition: background 0.15s, transform 0.12s, box-shadow 0.15s;
    position: relative;
  }
  .size-card:hover:not(.disabled) {
    background: var(--gold-light);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(184,134,11,0.15);
  }
  .size-card.disabled {
    opacity: 0.38;
    cursor: not-allowed;
    border-style: dashed;
  }
  .size-card .num {
    font-family: 'Playfair Display', serif;
    font-size: 2.2rem;
    font-weight: 600;
    color: var(--gold);
    line-height: 1;
  }
  .size-card .lbl {
    font-size: 12px;
    color: var(--ink3);
    margin-top: 4px;
    font-weight: 300;
    letter-spacing: 0.05em;
  }
  .size-card .count-badge {
    position: absolute;
    top: 8px; right: 8px;
    font-size: 10px;
    background: var(--gold-light);
    color: var(--gold);
    border: 1px solid var(--gold-border);
    border-radius: 999px;
    padding: 1px 7px;
    font-weight: 500;
  }

  .chain-list-wrap {
    display: none;
  }
  .chain-list-wrap.visible { display: block; }
  .chain-list-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
  }
  .chain-list-header h3 {
    font-family: 'Playfair Display', serif;
    font-size: 1.1rem;
    font-weight: 600;
  }
  .btn-back {
    font-size: 13px;
    color: var(--ink3);
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 0;
    display: flex;
    align-items: center;
    gap: 4px;
  }
  .btn-back:hover { color: var(--ink); }

  .chain-item {
    background: var(--surface);
    border: 1px solid rgba(184,134,11,0.25);
    border-radius: var(--radius-lg);
    padding: 1rem 1.25rem;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s;
  }
  .chain-item:hover { background: var(--gold-light); border-color: var(--gold-border); }
  .chain-item-preview {
    font-size: 14px;
    color: var(--ink2);
    font-weight: 300;
  }
  .chain-item-preview strong { color: var(--ink); font-weight: 500; }
  .chain-item-arrow { color: var(--ink3); font-size: 18px; }

  /* ── Game screen ── */
  #screen-game { display: none; }
  #screen-game.visible { display: block; }

  .game-topbar {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    gap: 1rem;
  }
  .game-meta { }
  .game-meta .chain-size-lbl {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--ink3);
    font-weight: 400;
  }
  .game-meta .chain-size-val {
    font-family: 'Playfair Display', serif;
    font-size: 1.1rem;
    color: var(--ink);
  }

  .scoreboard {
    text-align: right;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
  }
  .score-big {
    font-family: 'Playfair Display', serif;
    font-size: 2.4rem;
    font-weight: 600;
    color: var(--ink);
    line-height: 1;
  }
  .score-big.animating { color: var(--red); }
  .score-lbl { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink3); }
  .perfect-score { font-size: 11px; color: var(--ink3); }
  .penalty-ticker {
    font-size: 12px;
    color: var(--red);
    min-height: 16px;
    font-weight: 500;
  }

  .prog-wrap {
    height: 2px;
    background: var(--surface2);
    border-radius: 999px;
    margin-bottom: 2rem;
  }
  .prog-bar {
    height: 2px;
    background: var(--gold);
    border-radius: 999px;
    width: 0%;
    transition: width 0.5s ease;
  }

  /* ── Chain layout ── */
  .chain-container {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 8px 4px;
    margin-bottom: 2rem;
  }

  .person-unit {
    display: flex;
    align-items: flex-start;
    gap: 4px;
  }

  .name-slot {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
  }


  .token {
    font-size: 14px;
    font-weight: 500;
    padding: 8px 14px;
    border-radius: var(--radius);
    border: 1px solid;
    white-space: nowrap;
    line-height: 1.3;
    font-family: 'DM Sans', sans-serif;
  }
  .token-given {
    background: #d8d4c8;
    border-color: rgba(90,84,72,0.4);
    color: var(--ink);
  }
  .token-revealed {
    background: #fde9b0;
    border-color: rgba(146,88,10,0.5);
    color: var(--amber);
  }

  .blank-slot {
    display: flex;
    flex-direction: column;
    gap: 4px;
    align-items: center;
  }
  .blank-inp {
    font-size: 14px;
    font-family: 'DM Sans', sans-serif;
    font-weight: 500;
    color: var(--ink);
    background: #ffffff;
    border: 1px solid rgba(90,84,72,0.35);
    border-radius: var(--radius);
    padding: 7px 10px;
    width: 115px;
    outline: none;
    transition: border-color 0.15s, background 0.2s;
  }
  .blank-inp:focus {
    border-color: var(--gold-border);
    box-shadow: 0 0 0 3px rgba(184,134,11,0.12);
  }
  .blank-inp.correct {
    background: #a8d5b0;
    border-color: #5a9e6e;
    color: #1a3d24;
  }
  .blank-inp.wrong {
    background: #f0a8a8;
    border-color: #c05050;
    color: #5a1a1a;
  }
  .blank-inp.partial {
    background: #fef9c3;
    border-color: #d4b800;
    color: #5a4a00;
  }
  .blank-inp:disabled { cursor: default; }

  .hint-controls {
    display: flex;
    gap: 3px;
  }
  .h-btn {
    font-size: 10px;
    font-family: 'DM Sans', sans-serif;
    padding: 3px 8px;
    border-radius: 999px;
    border: 1px solid rgba(90,84,72,0.25);
    background: var(--surface);
    color: var(--ink3);
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.12s, color 0.12s;
    font-weight: 400;
  }
  .h-btn:hover:not(:disabled) { background: var(--surface2); color: var(--ink2); }
  .h-btn:disabled, .h-btn.used { opacity: 0.3; cursor: default; }
  .h-btn.reveal-btn {
    border-color: rgba(146,88,10,0.3);
    color: var(--amber);
  }
  .h-btn.reveal-btn:hover:not(:disabled) { background: var(--amber-light); }
  
  .h-btn.letter-btn {
    border-color: rgba(146,88,10,0.3);
    color: var(--amber);
  }
  .h-btn.letter-btn:hover:not(:disabled) { background: var(--amber-light); }

  .chain-arrow {
    color: var(--ink3);
    font-size: 16px;
    align-self: flex-start;
    padding-top: 10px;
    flex-shrink: 0;
  }

  .arrow-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    flex-shrink: 0;
    align-self: flex-start;
  }

  .occ-label {
    font-size: 9px;
    color: var(--ink3);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 400;
    white-space: nowrap;
    line-height: 1.2;
    padding-top: 4px;
  }



  /* ── Message area ── */
  .msg-panel {
    border-radius: var(--radius-lg);
    padding: 12px 16px;
    font-size: 13px;
    line-height: 1.6;
    margin-bottom: 1.25rem;
    border: 1px solid;
    min-height: 46px;
    transition: background 0.2s, border-color 0.2s;
  }
  .msg-panel.neutral { background: var(--surface); border-color: rgba(90,84,72,0.2); color: var(--ink2); }
  .msg-panel.info    { background: var(--blue-light); border-color: rgba(42,82,152,0.25); color: var(--blue); }
  .msg-panel.success { background: var(--green-light); border-color: rgba(45,106,79,0.35); color: var(--green); font-weight: 500; }
  .msg-panel.warning { background: var(--amber-light); border-color: rgba(146,88,10,0.3); color: var(--amber); }

  /* ── Action buttons ── */
  .action-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
  }
  .btn {
    font-family: 'DM Sans', sans-serif;
    font-size: 13px;
    font-weight: 500;
    padding: 8px 20px;
    border-radius: var(--radius);
    border: 1px solid;
    cursor: pointer;
    transition: background 0.12s, transform 0.1s;
    letter-spacing: 0.01em;
  }
  .btn:active { transform: scale(0.98); }
  .btn-primary {
    background: var(--gold-light);
    border-color: var(--gold-border);
    color: var(--gold);
  }
  .btn-primary:hover { background: #ebd98a; }
  .btn-secondary {
    background: var(--surface);
    border-color: rgba(90,84,72,0.3);
    color: var(--ink2);
  }
  .btn-secondary:hover { background: var(--surface2); }
  .btn-new-game {
    background: var(--surface2);
    border-color: rgba(90,84,72,0.3);
    color: var(--ink2);
    font-size: 12px;
    padding: 6px 14px;
  }
  .btn-new-game:hover { background: var(--gold-light); border-color: var(--gold-border); color: var(--gold); }

  /* ── Scoring key ── */
  .scoring-key {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    padding: 10px 14px;
    background: var(--surface);
    border: 1px solid rgba(90,84,72,0.15);
    border-radius: var(--radius);
    margin-bottom: 1.5rem;
  }
  .sk-item {
    font-size: 12px;
    color: var(--ink3);
    display: flex;
    align-items: center;
    gap: 5px;
  }
  .sk-item strong { color: var(--ink2); font-weight: 500; }

  /* ── Legend ── */
  .legend-row {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
  }
  .leg {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: var(--ink3);
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }
  .leg-sw {
    width: 24px;
    height: 14px;
    border-radius: 3px;
    border: 1px solid;
    flex-shrink: 0;
  }

  @media (max-width: 600px) {
    .chain-container { gap: 6px 3px; }
    .blank-inp { width: 95px; font-size: 13px; }
    .token { font-size: 13px; padding: 7px 10px; }
    .score-big { font-size: 1.8rem; }
  }
  
  .footer {
  text-align: center;
  font-size: 12px;
  color: var(--ink3);
  padding: 1.5rem 0 2rem;
  border-top: 1px solid var(--gold-border);
  margin-top: 2rem;
  }