:root {
    /* ── Brand palette ── */
    --alpine-night:  #1B2B4B;
    --summit-white:  #F5F5F0;
    --alpenglühen:   #E8431A;
    --glacier-teal:  #3A8A8C;
    --rock-grey:     #6B7280;

    /* ── Piste colours (game only — do NOT use for brand UI) ── */
    --piste-blue:   #4a90d9;
    --piste-red:    #e05252;
    --piste-black:  #2c2c2c;
    --piste-yellow: #f0c040;

    /* ── Semantic UI tokens ── */
    --green: #4caf50;   /* success / Rot-Grün green result */
    --bg:    var(--summit-white);
    --card:  #ffffff;
    --border: #D8D9D2;
    --text:  var(--alpine-night);
    --muted: var(--rock-grey);
    --shadow: 0 2px 10px rgba(27,43,75,0.10);
    --radius: 14px;

    /* ── Typography (Brand) ── */
    /* Headline: Frank Ruhl Libre — editorial warm serif, used for brand moments only */
    --font-headline: 'Frank Ruhl Libre', Georgia, 'Times New Roman', serif;
    /* Body / UI: Work Sans — humanist sans-serif, used for everything in the app */
    --font-body: 'Work Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  }
  * { box-sizing: border-box; margin: 0; padding: 0; }
  body {
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
  }
  /* Brand headline class — use for app title, box-style headings, marketing moments */
  .brand-headline, header h1 {
    font-family: var(--font-headline);
    font-weight: 700;
    letter-spacing: -0.01em;
  }

  /* ── HEADER ── */
  header {
    background: linear-gradient(135deg, var(--alpine-night) 0%, #2A3F6A 100%);
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  }
  header h1 { font-size: 1.2rem; font-weight: 700; letter-spacing: 0.5px; }
  header .clock { font-size: 1.4rem; font-weight: 800; font-variant-numeric: tabular-nums; }
  .header-sub { font-size: 0.75rem; opacity: 0.8; margin-top: 2px; }
  .header-player-info { text-align: right; }
  .header-player-row {
    display: flex; align-items: center; justify-content: flex-end;
    gap: 6px; margin-top: 4px; flex-wrap: wrap;
  }
  .header-player-name { font-size: 0.85rem; font-weight: 700; }
  .header-player-points {
    font-size: 0.85rem; font-weight: 800;
    background: rgba(255,255,255,0.2); border-radius: 10px;
    padding: 1px 7px;
  }
  .header-player-row .player-color-dot { width: 14px; height: 14px; }

  /* ── TABS ── */
  .tabs {
    display: flex;
    background: var(--alpine-night);
    border-bottom: 3px solid #2A3F6A;
  }
  .tab-btn {
    flex: 1; padding: 10px 6px; border: none; background: transparent;
    color: rgba(255,255,255,0.6); font-size: 0.75rem; font-weight: 600;
    cursor: pointer; text-transform: uppercase; letter-spacing: 0.5px;
    transition: all 0.2s;
  }
  .tab-btn.active { color: white; background: rgba(255,255,255,0.1); border-bottom: 3px solid var(--alpenglühen); margin-bottom: -3px; }
  .tab-btn:hover:not(.active):not(:disabled) { color: rgba(255,255,255,0.85); }
  .tab-btn:disabled { color: rgba(255,255,255,0.25); cursor: not-allowed; }

  /* ── CONTENT PANELS ── */
  .panel { display: none; padding: 16px; }
  .panel.active { display: block; }

  /* ── CARDS ── */
  .card {
    background: var(--card); border-radius: var(--radius);
    padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow);
    border: 1px solid var(--border);
  }
  .card-title {
    font-size: 0.7rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: 1px; color: var(--muted); margin-bottom: 12px;
  }

  /* ── PLAYER CARDS ── */
  .player-strip {
    display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px;
    margin-bottom: 14px;
  }
  .player-chip {
    flex-shrink: 0; padding: 8px 14px; border-radius: 50px;
    border: 2px solid var(--border); background: white;
    cursor: default; font-size: 0.85rem; font-weight: 600;
    transition: all 0.2s; white-space: nowrap;
  }
  .player-chip.active {
    border-color: var(--glacier-teal); background: var(--glacier-teal); color: white;
    box-shadow: 0 2px 8px rgba(58,138,140,0.35);
  }
  .player-chip.done {
    background: #f0f0f0; color: #9aaa9a; border-color: #c8d6c8;
    cursor: default; opacity: 0.65;
  }
  .player-chip.done .chip-done-mark { color: #4caf50; font-weight: 800; margin-right: 4px; }
  .player-chip .chip-pts { font-size: 0.7rem; font-weight: 400; opacity: 0.8; }

  /* ── LEVEL BADGE ── */
  .level-badge {
    display: inline-block; padding: 3px 10px; border-radius: 50px;
    font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px;
  }
  /* Level badges — deliberate non-piste colours to avoid semantic collision */
  .level-anfaenger      { background: #DDF0F0; color: #1F5F60; }   /* Glacier Teal tint */
  .level-fortgeschritten { background: #E8EEF7; color: #1B2B4B; }  /* Alpine Night tint */
  .level-profi          { background: #FBE8E2; color: #8C2610; }   /* Alpenglühen tint */

  /* ── DICE AREA ── */
  .dice-row {
    display: flex; flex-wrap: wrap; gap: 10px;
    justify-content: center; margin: 12px 0;
  }
  .die {
    width: 64px; height: 64px; border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.6rem; font-weight: 800; cursor: pointer;
    border: 3px solid transparent;
    transition: all 0.15s; position: relative; user-select: none;
    box-shadow: 0 3px 8px rgba(0,0,0,0.18);
    overflow: hidden; padding: 0;
  }
  .die img { width: 100%; height: 100%; object-fit: contain; border-radius: 9px; display: block; }
  .die:active { transform: scale(0.93); }
  .die.held {
    border-color: var(--alpenglühen) !important;
    box-shadow: 0 0 0 3px rgba(232,67,26,0.30), 0 3px 8px rgba(0,0,0,0.18);
  }
  .die.held::after {
    content: '★'; position: absolute; top: -8px; right: -6px;
    font-size: 0.7rem; color: var(--alpenglühen);
  }
  .die.rolling { animation: rollAnim 0.35s ease-out; }

  /* Beförderungswürfel */
  .die-transport { background: linear-gradient(135deg, #DDF0F0, #A8D4D5); color: var(--alpine-night); }
  /* Ereigniswürfel */
  .die-event { background: linear-gradient(135deg, #fff3cd, #ffe082); color: #5d4037; }
  /* Abfahrt – Anfänger (rot) */
  .die-descent-red { background: linear-gradient(135deg, #ffcdd2, #ef9a9a); color: #b71c1c; }
  /* Abfahrt – Fortgeschrittene (schwarz) */
  .die-descent-black { background: linear-gradient(135deg, #424242, #212121); color: #ffffff; }
  /* Abfahrt – Profi (gelb) */
  .die-descent-yellow { background: linear-gradient(135deg, #fff9c4, #fff176); color: #795548; }
  /* Rot/Grün */
  .die-rg-green { background: linear-gradient(135deg, #c8e6c9, #a5d6a7); color: #1b5e20; }
  .die-rg-red   { background: linear-gradient(135deg, #ffcdd2, #ef9a9a); color: #b71c1c; }

  @keyframes rollAnim {
    0%   { transform: rotate(0deg) scale(1); }
    25%  { transform: rotate(-15deg) scale(1.1); }
    50%  { transform: rotate(10deg) scale(0.95); }
    75%  { transform: rotate(-6deg) scale(1.05); }
    100% { transform: rotate(0deg) scale(1); }
  }

  /* ── BUTTONS ── */
  .btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 12px 20px; border-radius: 50px; border: 2px solid transparent; cursor: pointer;
    font-size: 0.9rem; font-weight: 700; transition: all 0.18s;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
  }
  .btn:active { transform: scale(0.96); }
  .btn-primary { background: var(--glacier-teal); color: white; }
  .btn-primary:hover { background: #2E6E70; }
  .btn-success { background: var(--green); color: white; }
  .btn-danger  { background: var(--piste-red); color: white; }
  .btn-warn    { background: var(--alpenglühen); color: white; }
  .btn-neutral { background: #E5E6E0; color: var(--text); }
  .btn:disabled { opacity: 0.4; cursor: not-allowed; }
  .btn-full { width: 100%; }

  /* ── ACTION BUTTONS (Bergauf / Bergab / Pause) ── */
  .btn-action {
    padding: 16px 20px;
    font-size: 1rem;
    border-radius: 14px;
    flex: 1;
    min-height: 56px;
    position: relative;
  }
  .btn-action.btn-action-selected {
    border: 2px solid rgba(255,255,255,0.7) !important;
    box-shadow: 0 0 0 3px rgba(0,0,0,0.18), 0 4px 12px rgba(0,0,0,0.25);
    transform: translateY(-2px);
  }
  .btn-action.btn-action-selected::after {
    content: '✓';
    position: absolute;
    top: 5px; right: 9px;
    font-size: 0.7rem;
    opacity: 0.9;
  }
  /* Unselected action buttons look muted */
  .btn-action.btn-action-unselected {
    opacity: 0.45;
    transform: none;
    box-shadow: none;
  }

  .btn-row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-top: 10px; }

  /* ── RESULT BOX ── */
  .result-box {
    border-radius: 10px; padding: 14px 16px; margin-top: 12px;
    font-size: 0.95rem; font-weight: 600; line-height: 1.5;
    border-left: 5px solid transparent;
  }
  .result-box.success { background: #e8f5e9; border-color: var(--green);        color: #2e7d32; }
  .result-box.warning { background: #FBE8E2; border-color: var(--alpenglühen); color: #8C2610; }
  .result-box.danger  { background: #ffebee; border-color: var(--piste-red);   color: #c62828; }
  .result-box.info    { background: #DDF0F0; border-color: var(--glacier-teal); color: #1F5F60; }

  /* ── ACCORDION CARDS (Extraaktivität / Ohne Befugnis) ── */
  .accordion-card {
    padding: 0;
    overflow: hidden;
  }
  .accordion-trigger {
    width: 100%; display: flex; align-items: center; justify-content: space-between;
    padding: 14px 16px; background: none; border: none; cursor: pointer;
    font-size: 0.92rem; font-weight: 700; color: var(--text);
    text-align: left;
  }
  .accordion-trigger:hover { background: rgba(0,0,0,0.03); }
  .accordion-chevron {
    font-size: 0.85rem; color: var(--muted); transition: transform 0.2s;
  }
  .accordion-body {
    padding: 0 16px 16px;
    border-top: 1px solid var(--border);
  }
  #cardExtraaktivitaet .accordion-trigger { color: var(--glacier-teal); }
  #cardOhneBefugnis    .accordion-trigger { color: var(--alpenglühen); }

  /* ── STAT ROW ── */
  .stat-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 0.9rem;
  }
  .stat-row:last-child { border-bottom: none; }
  .stat-label { color: var(--muted); }
  .stat-value { font-weight: 700; }

  /* ── SCOREBOARD ── */
  .score-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
  .score-table th {
    background: var(--alpine-night); color: white; padding: 8px 10px;
    font-weight: 600; text-align: left;
  }
  .score-table td { padding: 9px 10px; border-bottom: 1px solid var(--border); }
  .score-table tr:nth-child(even) td { background: #EEEEE9; }
  .score-table tr.current-player td { background: #DDF0F0; font-weight: 700; }

  /* ── TRANSPORT SYMBOLS ── */
  .symbol-grid {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
    margin: 10px 0;
  }
  .symbol-cell {
    background: var(--summit-white); border-radius: 8px; padding: 8px;
    text-align: center; font-size: 0.78rem; color: var(--muted); cursor: default;
  }
  .symbol-cell .sym { width: 48px; height: 48px; display: block; margin: 0 auto 4px; object-fit: contain; }

  /* ── HELD INDICATOR ── */
  .held-hint {
    font-size: 0.75rem; color: var(--muted); text-align: center; margin-top: 4px;
  }

  /* ── SETUP FORM ── */
  .form-group { margin-bottom: 14px; }
  .form-label { font-size: 0.8rem; font-weight: 600; color: var(--muted); margin-bottom: 5px; display: block; }
  .form-input {
    width: 100%; padding: 10px 12px; border: 1px solid var(--border);
    border-radius: 8px; font-size: 0.9rem; background: white; color: var(--text);
    outline: none; transition: border-color 0.2s;
  }
  .form-input:focus { border-color: var(--glacier-teal); }

  /* ── PLAYER SETUP ── */
  .player-setup-row {
    display: flex; gap: 8px; align-items: center; margin-bottom: 8px;
  }
  .player-setup-row input { flex: 1; }
  .player-color-dot {
    width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0;
    border: 2px solid rgba(0,0,0,0.15);
  }

  /* ── TURN HISTORY ── */
  .history-list { max-height: 220px; overflow-y: auto; }
  .history-item {
    padding: 8px 10px; border-bottom: 1px solid var(--border);
    font-size: 0.82rem; display: flex; gap: 8px; align-items: flex-start;
  }
  .history-item:last-child { border-bottom: none; }
  .history-time { color: var(--muted); flex-shrink: 0; font-variant-numeric: tabular-nums; }
  .history-text { line-height: 1.4; }

  /* ── RESPONSIVE ── */
  @media (min-width: 600px) {
    .panel { padding: 20px; max-width: 640px; margin: 0 auto; }
    .dice-row { gap: 14px; }
    .die { width: 72px; height: 72px; font-size: 1.8rem; overflow: hidden; }
  }

  /* ── ROLL COUNT ── */
  .roll-count-dots {
    display: flex; gap: 6px; justify-content: center; margin: 8px 0;
  }
  .roll-dot {
    width: 10px; height: 10px; border-radius: 50%;
    background: var(--border); transition: background 0.2s;
  }
  .roll-dot.used { background: var(--glacier-teal); }

  /* ── EVENT ICON ── */
  .event-icon { font-size: 2rem; text-align: center; margin-bottom: 6px; }

  /* ── SLOPE SELECTOR ── */
  .slope-row {
    margin-bottom: 12px;
  }
  .slope-label {
    display: flex; align-items: center; gap: 8px; margin-bottom: 6px;
  }
  .slope-badge {
    display: inline-block; padding: 3px 10px; border-radius: 50px;
    font-size: 0.75rem; font-weight: 700;
  }
  .slope-blue   { background: #cce5ff; color: #004085; }
  .slope-red    { background: #f8d7da; color: #721c24; }
  .slope-black  { background: #343a40; color: #fff; }
  .slope-yellow { background: #fff3cd; color: #856404; }
  .slope-pts-label { font-size: 0.75rem; color: var(--muted); }

  /* Forbidden slope label badge */
  .slope-forbidden-badge {
    display: inline-block; padding: 2px 8px; border-radius: 50px;
    font-size: 0.68rem; font-weight: 700; background: #FBE8E2; color: #8C2610;
    border: 1px solid var(--alpenglühen);
  }

  /* Forbidden slope row — muted header, amber kbox highlight */
  .slope-row.slope-forbidden .slope-badge { opacity: 0.55; }
  .slope-row.slope-forbidden .slope-pts-label { opacity: 0.55; }

  /* kbox selected on a forbidden row → Alpenglühen warning */
  .kbox.kbox-forbidden-active {
    background: var(--alpenglühen);
    border-color: #C23615;
    color: white;
    box-shadow: 0 2px 8px rgba(232,67,26,0.4);
  }

  .kreuzung-boxes {
    display: flex; gap: 6px; flex-wrap: nowrap;
  }
  .kbox {
    flex: 1; min-width: 0;
    height: 44px;
    border-radius: 10px;
    border: 2px solid var(--border);
    background: #f4f7fb;
    color: var(--text);
    font-size: 1rem; font-weight: 700;
    cursor: pointer;
    transition: all 0.15s;
    display: flex; align-items: center; justify-content: center;
  }
  .kbox:active { transform: scale(0.93); }
  .kbox.kbox-active {
    background: var(--glacier-teal);
    border-color: var(--glacier-teal);
    color: white;
    box-shadow: 0 2px 8px rgba(58,138,140,0.4);
  }
  .kbox.kbox-disabled {
    background: #f0f0f0;
    border-color: #e0e0e0;
    color: #c0c0c0;
    cursor: not-allowed;
    box-shadow: none;
  }
  .kbox.kbox-disabled:active { transform: none; }

  /* ── CROSSING COUNTER ── */
  .crossing-counter {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 4px;
    font-size: 2rem;
    font-weight: 800;
    color: var(--glacier-teal);
    margin: 0 0 14px;
    letter-spacing: -0.5px;
  }
  .crossing-counter-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--muted);
    margin-left: 2px;
  }
  .crossing-counter.counter-full {
    color: var(--green);
  }
  .crossing-counter.counter-over {
    color: var(--red);
  }

  /* ── ROT/GRÜN NEUTRAL (pre-roll state) ── */
  .die-rg-neutral { background: linear-gradient(135deg, #e0e0e0, #bdbdbd); color: #555; }

  /* ── STICKY FOOTER ── */
  .sticky-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-top: 1px solid var(--border);
    padding: 12px 16px;
    padding-bottom: 12px;
    padding-bottom: env(safe-area-inset-bottom, 12px);
    box-shadow: 0 -4px 16px rgba(0,0,0,0.10);
    z-index: 50;
  }
  /* Give the Zug panel enough bottom space so content isn't hidden under the footer */
  #tab-turn.active {
    padding-bottom: 80px;
  }

  /* ── MODAL ── */
  .modal-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.45); z-index: 100;
    align-items: center; justify-content: center; padding: 20px;
  }
  .modal-overlay.open { display: flex; }
  .modal {
    background: white; border-radius: var(--radius); padding: 22px;
    max-width: 400px; width: 100%; box-shadow: 0 10px 40px rgba(0,0,0,0.25);
  }
  .modal h2 { font-size: 1.1rem; margin-bottom: 12px; }
  .modal p { font-size: 0.9rem; color: var(--muted); line-height: 1.5; margin-bottom: 14px; }
  .modal .btn-row { justify-content: flex-end; }
