/* ============================================================
   Qwixx – Global Styles
   ============================================================ */

:root {
    --red-bg:    #D32F2F;
    --red-cell:  #FFCDD2;
    --red-text:  #B71C1C;

    --yellow-bg:   #F9A825;
    --yellow-cell: #FFF9C4;
    --yellow-text: #F57F17;

    --green-bg:   #388E3C;
    --green-cell: #C8E6C9;
    --green-text: #1B5E20;

    --blue-bg:   #1565C0;
    --blue-cell: #BBDEFB;
    --blue-text: #0D47A1;

    --white-die-bg: #FFFFFF;
    --white-die-dot: #333333;

    --bg: #F0F4F8;
    --card-bg: #FFFFFF;
    --card-shadow: 0 2px 12px rgba(0,0,0,0.10);
    --border-radius: 10px;
    --font: 'Segoe UI', system-ui, sans-serif;

    --btn-primary: #1976D2;
    --btn-primary-hover: #1565C0;
    --btn-secondary: #546E7A;
    --btn-secondary-hover: #37474F;
    --btn-success: #388E3C;
    --btn-success-hover: #2E7D32;
    --btn-danger: #C62828;
    --btn-danger-hover: #B71C1C;
}

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

html, body {
    font-family: var(--font);
    background: var(--bg);
    color: #212121;
    min-height: 100vh;
    font-size: 15px;
}

/* ============================================================
   Utility
   ============================================================ */

.hidden { display: none !important; }

.card {
    background: var(--card-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--card-shadow);
    padding: 20px;
}

/* ============================================================
   Buttons
   ============================================================ */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 18px;
    border: none;
    border-radius: 6px;
    font-family: var(--font);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s, transform 0.1s;
    white-space: nowrap;
}

.btn:active { transform: scale(0.97); }

.btn-primary   { background: var(--btn-primary);   color: #fff; }
.btn-primary:hover { background: var(--btn-primary-hover); }

.btn-secondary { background: var(--btn-secondary); color: #fff; }
.btn-secondary:hover { background: var(--btn-secondary-hover); }

.btn-success   { background: var(--btn-success);   color: #fff; }
.btn-success:hover { background: var(--btn-success-hover); }

.btn-danger    { background: var(--btn-danger);    color: #fff; }
.btn-danger:hover { background: var(--btn-danger-hover); }

.btn-ghost {
    background: transparent;
    color: #555;
    border: 1px solid #ccc;
}
.btn-ghost:hover { background: #f5f5f5; }

/* Button in dark game header */
.btn-header-home {
    background: rgba(255,255,255,0.12);
    color: #fff;
    border: 1px solid rgba(255,255,255,0.35);
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: background 0.15s;
}
.btn-header-home:hover { background: rgba(255,255,255,0.22); }

.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-large { padding: 12px 28px; font-size: 16px; }

.btn-roll {
    width: 100%;
    justify-content: center;
    font-size: 18px;
    padding: 14px;
    animation: pulseBtn 1.8s ease-in-out infinite;
}

@keyframes pulseBtn {
    0%, 100% { box-shadow: 0 0 0 0 rgba(25,118,210,0.4); }
    50%       { box-shadow: 0 0 0 8px rgba(25,118,210,0); }
}

/* ============================================================
   Alerts
   ============================================================ */

.alert {
    padding: 12px 18px;
    border-radius: 6px;
    margin-bottom: 16px;
    font-size: 14px;
}
.alert-error { background: #FFCDD2; color: #B71C1C; border-left: 4px solid #D32F2F; }
.alert-info  { background: #BBDEFB; color: #0D47A1; border-left: 4px solid #1565C0; }

/* ============================================================
   INDEX PAGE
   ============================================================ */

.index-page {
    display: flex;
    justify-content: center;
    padding: 30px 16px 60px;
}

.index-container {
    width: 100%;
    max-width: 680px;
}

.index-header {
    text-align: center;
    margin-bottom: 28px;
}

.logo-dice-row {
    display: flex;
    justify-content: center;
    gap: 10px;
    font-size: 36px;
    margin-bottom: 8px;
}

.logo-die {
    display: inline-block;
}
.logo-die.red-die    { color: var(--red-bg); }
.logo-die.yellow-die { color: var(--yellow-bg); }
.logo-die.green-die  { color: var(--green-bg); }
.logo-die.blue-die   { color: var(--blue-bg); }

.game-title {
    font-size: 54px;
    font-weight: 800;
    letter-spacing: -2px;
    background: linear-gradient(135deg, #D32F2F, #F9A825, #388E3C, #1565C0);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    line-height: 1.1;
}

.game-subtitle {
    color: #666;
    font-size: 15px;
    margin-top: 4px;
}

.setup-card { margin-bottom: 20px; }

.setup-card h2 {
    font-size: 20px;
    margin-bottom: 18px;
    color: #333;
}

.player-count-section { margin-bottom: 20px; }

.player-count-section > label {
    display: block;
    font-weight: 600;
    margin-bottom: 8px;
    color: #444;
}

.player-count-buttons {
    display: flex;
    gap: 10px;
}

.btn-count {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 2px solid #ccc;
    background: #fff;
    font-size: 18px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s;
    color: #555;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-count:hover { border-color: var(--btn-primary); color: var(--btn-primary); }
.btn-count.active { background: var(--btn-primary); border-color: var(--btn-primary); color: #fff; }

.player-names-section { margin-bottom: 22px; }

.player-name-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
}

.player-name-row label {
    min-width: 90px;
    font-weight: 600;
    color: #444;
    font-size: 14px;
}

.name-input {
    flex: 1;
    padding: 9px 12px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 15px;
    font-family: var(--font);
    transition: border-color 0.15s;
    outline: none;
}
.name-input:focus { border-color: var(--btn-primary); box-shadow: 0 0 0 3px rgba(25,118,210,0.15); }

.form-actions { text-align: center; margin-top: 6px; }

.btn-icon { font-size: 16px; }

.index-links {
    text-align: center;
    margin: 16px 0;
}

.link-highscores {
    color: var(--btn-primary);
    text-decoration: none;
    font-size: 15px;
    font-weight: 600;
}
.link-highscores:hover { text-decoration: underline; }

.rules-card { margin-top: 10px; }
.rules-card h2 { font-size: 18px; margin-bottom: 16px; color: #333; }

.rules-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

@media (max-width: 500px) {
    .rules-grid { grid-template-columns: 1fr; }
}

.rule-item {
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

.rule-icon {
    font-size: 24px;
    flex-shrink: 0;
    margin-top: 2px;
}

.rule-item strong { display: block; font-size: 14px; margin-bottom: 3px; color: #333; }
.rule-item p { font-size: 13px; color: #666; line-height: 1.4; }

/* ============================================================
   GAME PAGE LAYOUT
   ============================================================ */

.game-page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    padding: 0;
}

.game-layout {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Header */
.game-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #1a1a2e;
    color: #fff;
    padding: 10px 20px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.game-header-title {
    font-size: 24px;
    font-weight: 800;
    letter-spacing: -1px;
    background: linear-gradient(90deg, #ff6b6b, #ffd93d, #6bcb77, #4d96ff);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

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

.turn-counter {
    font-size: 13px;
    color: #aaa;
    background: #2a2a3e;
    padding: 4px 10px;
    border-radius: 12px;
}

/* Phase Banner */
.phase-banner {
    background: #263238;
    color: #ECEFF1;
    text-align: center;
    padding: 8px 20px;
    font-size: 14px;
    font-weight: 500;
    border-bottom: 1px solid #37474F;
}

/* Active Player Banner */
.active-player-banner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: linear-gradient(135deg, #1565C0, #0D47A1);
    color: #fff;
    padding: 10px 20px;
    border-bottom: 3px solid #FFD600;
}

.apb-label {
    font-size: 13px;
    font-weight: 500;
    opacity: 0.85;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.apb-name {
    font-size: 22px;
    font-weight: 800;
    letter-spacing: -0.5px;
}

.apb-hint {
    font-size: 12px;
    opacity: 0.75;
    background: rgba(255,255,255,0.15);
    padding: 2px 8px;
    border-radius: 20px;
}

/* No valid moves notice */
.no-moves-notice {
    background: #FFF3E0;
    border: 2px solid #FF9800;
    border-radius: 8px;
    padding: 10px 12px;
    text-align: center;
    font-weight: 700;
    color: #E65100;
    font-size: 13px;
    animation: noMovesPulse 1.2s ease-in-out infinite;
}

@keyframes noMovesPulse {
    0%, 100% { border-color: #FF9800; }
    50%       { border-color: #E65100; box-shadow: 0 0 0 3px rgba(230,81,0,0.2); }
}

/* Main area */
.game-main {
    display: flex;
    flex: 1;
    gap: 0;
    padding: 16px;
    gap: 16px;
    min-height: 0;
}

/* ============================================================
   DICE PANEL (left sidebar)
   ============================================================ */

.dice-panel {
    width: 220px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.dice-section {
    background: var(--card-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--card-shadow);
    padding: 14px;
}

.dice-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #888;
    margin-bottom: 8px;
    margin-top: 8px;
}
.dice-label:first-child { margin-top: 0; }

.dice-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 4px;
}

.die-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
}

.die-label-small {
    font-size: 10px;
    color: #999;
    font-weight: 600;
    text-transform: uppercase;
}

/* ============================================================
   DIE FACE
   ============================================================ */

.die {
    width: 52px;
    height: 52px;
    border-radius: 10px;
    border: 2px solid rgba(0,0,0,0.2);
    display: grid;
    grid-template-areas:
        "tl . tr"
        ". ml ."
        "bl . br";
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: 1fr 1fr 1fr;
    padding: 7px;
    gap: 2px;
    position: relative;
    transition: transform 0.2s, opacity 0.2s;
    cursor: default;
    background: #fff;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}

.die-white { background: #FFFFFF; }
.die-white .dot { background: #222; }

.die-red    { background: var(--red-bg);    }
.die-red .dot { background: #fff; }

.die-yellow { background: var(--yellow-bg); }
.die-yellow .dot { background: #7B4500; }

.die-green  { background: var(--green-bg);  }
.die-green .dot { background: #fff; }

.die-blue   { background: var(--blue-bg);   }
.die-blue .dot { background: #fff; }

.die.locked {
    opacity: 0.3;
    filter: grayscale(1);
}

.die.rolling {
    animation: rollDie 0.5s ease-in-out;
}

@keyframes rollDie {
    0%   { transform: rotate(0deg) scale(1); }
    25%  { transform: rotate(-15deg) scale(0.9); }
    50%  { transform: rotate(15deg) scale(1.1); }
    75%  { transform: rotate(-8deg) scale(0.95); }
    100% { transform: rotate(0deg) scale(1); }
}

/* Dot positions inside die */
.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    align-self: center;
    justify-self: center;
}

.dot-tl  { grid-area: tl; }
.dot-tr  { grid-area: tr; }
.dot-ml  { grid-column: 1; grid-row: 2; }
.dot-mc  { grid-column: 2; grid-row: 2; }
.dot-mr  { grid-column: 3; grid-row: 2; }
.dot-bl  { grid-area: bl; }
.dot-br  { grid-area: br; }

/* Zero-value die shows a dash */
.die.die-zero::after {
    content: '–';
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: #bbb;
}

/* ============================================================
   CONTROLS
   ============================================================ */

.controls-section {
    background: var(--card-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--card-shadow);
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.action1-info {
    background: #E3F2FD;
    border-radius: 8px;
    padding: 10px 12px;
    text-align: center;
}

.white-sum-display {
    font-size: 14px;
    color: #555;
}

/* Prominent skip button when no moves available */
.btn-no-moves-skip {
    background: #E65100 !important;
    color: #fff !important;
    font-weight: 700;
    animation: pulseBtn 1.2s ease-in-out infinite;
}

/* Auto-advance countdown bar */
.auto-advance-notice {
    background: #E8F5E9;
    border: 2px solid #388E3C;
    border-radius: 8px;
    padding: 10px 12px;
    text-align: center;
}
#autoAdvanceText {
    display: block;
    font-weight: 700;
    font-size: 13px;
    color: #1B5E20;
    margin-bottom: 6px;
}
.auto-advance-bar {
    height: 4px;
    background: #C8E6C9;
    border-radius: 2px;
    overflow: hidden;
}
.auto-advance-fill {
    height: 100%;
    background: #388E3C;
    border-radius: 2px;
    width: 100%;
    transform-origin: left;
    animation: shrinkBar 2s linear forwards;
}
@keyframes shrinkBar {
    from { transform: scaleX(1); }
    to   { transform: scaleX(0); }
}

.white-sum-value {
    font-size: 26px;
    font-weight: 800;
    color: #1565C0;
}

.action1-current {
    font-size: 13px;
    color: #444;
}

.action2-section { }

.action2-title {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #666;
    margin-bottom: 8px;
}

.action2-combos {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 10px;
    max-height: 220px;
    overflow-y: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.action2-combos::-webkit-scrollbar { display: none; }

.action2-combo-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
    border: 2px solid transparent;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    transition: all 0.15s;
    text-align: left;
    width: 100%;
}

.action2-combo-btn.combo-red    { background: var(--red-cell);    color: var(--red-text);    border-color: var(--red-bg); }
.action2-combo-btn.combo-yellow { background: var(--yellow-cell); color: var(--yellow-text); border-color: var(--yellow-bg); }
.action2-combo-btn.combo-green  { background: var(--green-cell);  color: var(--green-text);  border-color: var(--green-bg); }
.action2-combo-btn.combo-blue   { background: var(--blue-cell);   color: var(--blue-text);   border-color: var(--blue-bg); }

.action2-combo-btn:hover {
    filter: brightness(0.95);
    transform: translateX(2px);
}

/* ============================================================
   SCORE REFERENCE
   ============================================================ */

.score-reference {
    padding: 10px 12px;
    font-size: 11px;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.score-reference::-webkit-scrollbar { display: none; }

.score-ref-title {
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #888;
    margin-bottom: 8px;
}

.score-ref-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11px;
}

.score-ref-table th,
.score-ref-table td {
    padding: 3px 4px;
    text-align: center;
    border: 1px solid #e0e0e0;
}

.score-ref-table th {
    background: #F5F5F5;
    font-weight: 700;
    color: #555;
}

.score-ref-table td {
    color: #333;
}

/* ============================================================
   SHEETS PANEL (right)
   ============================================================ */

.sheets-panel {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Player tabs */
.player-tabs {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.player-tab {
    padding: 8px 16px;
    border: 2px solid #ccc;
    border-radius: 8px 8px 0 0;
    background: #f5f5f5;
    cursor: pointer;
    font-family: var(--font);
    font-size: 14px;
    font-weight: 600;
    color: #555;
    transition: all 0.15s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.player-tab:hover { background: #e8e8e8; border-color: #aaa; }

.player-tab.active {
    background: var(--card-bg);
    border-color: var(--btn-primary);
    color: var(--btn-primary);
    border-bottom-color: var(--card-bg);
    margin-bottom: -2px;
    z-index: 1;
}

.player-tab.active-player-tab {
    border-color: #F9A825;
    color: #7B4500;
}

.player-tab.action1-tab {
    border-color: #388E3C;
    color: #1B5E20;
    animation: tabPulse 1s ease-in-out infinite;
}

@keyframes tabPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(56,142,60,0.4); }
    50%       { box-shadow: 0 0 0 6px rgba(56,142,60,0); }
}

/* Tab glow when player becomes next active */
.player-tab.tab-incoming {
    animation: tabGlow 1.8s ease-out forwards;
    border-color: #F9A825 !important;
}

@keyframes tabGlow {
    0%   { box-shadow: 0 0 0 0 rgba(249,168,37,0); background: #f5f5f5; }
    15%  { box-shadow: 0 0 16px 6px rgba(249,168,37,0.8); background: #FFF8E1; }
    40%  { box-shadow: 0 0 24px 10px rgba(249,168,37,0.6); background: #FFF3CD; }
    70%  { box-shadow: 0 0 12px 4px rgba(249,168,37,0.3); background: #FFF8E1; }
    100% { box-shadow: 0 0 0 0 rgba(249,168,37,0); background: #f5f5f5; }
}

.tab-score {
    font-size: 11px;
    font-weight: 500;
    color: #888;
}
.player-tab.active .tab-score { color: #777; }

/* ============================================================
   SCORE SHEET
   ============================================================ */

.score-sheet {
    background: var(--card-bg);
    border-radius: 0 var(--border-radius) var(--border-radius) var(--border-radius);
    box-shadow: var(--card-shadow);
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.score-sheet.hidden { display: none !important; }

/* Score row */
.score-row {
    display: flex;
    align-items: center;
    gap: 6px;
    border-radius: 8px;
    padding: 6px 8px;
    position: relative;
    overflow: hidden;
}

.score-row-red    { background: var(--red-bg); }
.score-row-yellow { background: var(--yellow-bg); }
.score-row-green  { background: var(--green-bg); }
.score-row-blue   { background: var(--blue-bg); }

.row-label {
    color: rgba(255,255,255,0.9);
    font-weight: 800;
    font-size: 13px;
    min-width: 36px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.cells-container {
    display: flex;
    gap: 4px;
    flex-wrap: nowrap;
    flex: 1;
    overflow-x: auto;
}

/* Individual cell */
.cell {
    width: 46px;
    height: 46px;
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
    flex-shrink: 0;
    transition: transform 0.12s, filter 0.12s, box-shadow 0.12s;
    border: 2px solid transparent;
    user-select: none;
}

.score-row-red    .cell { background: var(--red-cell);    color: var(--red-text); }
.score-row-yellow .cell { background: var(--yellow-cell); color: var(--yellow-text); }
.score-row-green  .cell { background: var(--green-cell);  color: var(--green-text); }
.score-row-blue   .cell { background: var(--blue-cell);   color: var(--blue-text); }

.cell:hover { transform: scale(1.08); box-shadow: 0 2px 8px rgba(0,0,0,0.25); }

.cell.valid-move {
    border-color: rgba(255,255,255,0.8);
    animation: cellPulse 1.4s ease-in-out infinite;
    cursor: pointer;
}

@keyframes cellPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255,255,255,0.5); }
    50%       { box-shadow: 0 0 0 5px rgba(255,255,255,0); }
}

.cell.crossed {
    opacity: 0.7;
    cursor: default;
    transform: none !important;
}

.cell.crossed .cell-number { display: none; }
.cell.crossed .cell-cross { display: block !important; }

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

.cell.cell-last {
    border: 2px solid rgba(255,255,255,0.5);
}

.cell-number {
    font-size: 14px;
    font-weight: 800;
    line-height: 1;
}

.cell-cross {
    font-size: 18px;
    font-weight: 900;
    line-height: 1;
}

.lock-icon {
    font-size: 8px;
    position: absolute;
    bottom: 2px;
    right: 3px;
    opacity: 0.6;
}

.row-score-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 36px;
    background: rgba(0,0,0,0.12);
    border-radius: 6px;
    padding: 4px 6px;
}

.row-score-label {
    font-size: 9px;
    color: rgba(255,255,255,0.75);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.row-score-value {
    font-size: 16px;
    font-weight: 800;
    color: #fff;
}

.row-locked-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    color: #fff;
    font-weight: 900;
    font-size: 16px;
    letter-spacing: 0.15em;
    text-shadow: 0 1px 3px rgba(0,0,0,0.5);
}
.row-locked-overlay.hidden { display: none !important; }

/* Penalties */
.penalties-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 0;
    border-top: 1px solid #eee;
    margin-top: 4px;
}

.penalties-label {
    font-size: 13px;
    color: #555;
    font-weight: 600;
    min-width: 130px;
}

.penalty-boxes {
    display: flex;
    gap: 8px;
}

.penalty-box {
    width: 36px;
    height: 36px;
    border: 2px solid #D32F2F;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #FFF5F5;
}

.penalty-cross {
    color: #D32F2F;
    font-size: 20px;
    font-weight: 900;
}

.penalty-total {
    margin-left: auto;
    font-size: 15px;
    font-weight: 700;
    color: #D32F2F;
    min-width: 36px;
    text-align: right;
}

/* Total score */
.total-score-row {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    padding: 8px 0 2px;
    border-top: 2px solid #eee;
}

.total-score-label {
    font-size: 15px;
    font-weight: 700;
    color: #333;
}

.total-score-value {
    font-size: 28px;
    font-weight: 900;
    color: #1565C0;
    min-width: 60px;
    text-align: right;
}

/* ============================================================
   GAME OVER MODAL
   ============================================================ */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.65);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 20px;
}

.modal-box {
    background: #fff;
    border-radius: 16px;
    padding: 32px;
    max-width: 500px;
    width: 100%;
    box-shadow: 0 8px 40px rgba(0,0,0,0.35);
    text-align: center;
}

.modal-title {
    font-size: 28px;
    font-weight: 900;
    margin-bottom: 12px;
    color: #1565C0;
}

.modal-winner {
    font-size: 20px;
    font-weight: 700;
    color: #333;
    margin-bottom: 20px;
}

.final-scores {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 24px;
    text-align: left;
}

.final-score-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-radius: 8px;
    background: #F5F5F5;
    font-size: 15px;
}

.final-score-row.is-winner {
    background: #E3F2FD;
    border: 2px solid #1565C0;
    font-weight: 700;
}

.final-player-name { color: #333; }
.final-player-score { font-size: 20px; font-weight: 900; color: #1565C0; }

.modal-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
}

/* ============================================================
   TOAST
   ============================================================ */

.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: #263238;
    color: #fff;
    padding: 10px 22px;
    border-radius: 24px;
    font-size: 14px;
    font-weight: 600;
    z-index: 300;
    box-shadow: 0 4px 16px rgba(0,0,0,0.3);
    transition: opacity 0.3s;
}

.toast.toast-error { background: #C62828; }
.toast.toast-success { background: #2E7D32; }

/* ============================================================
   HIGHSCORES PAGE
   ============================================================ */

.highscores-page {
    padding: 30px 16px 60px;
}

.hs-container {
    max-width: 800px;
    margin: 0 auto;
}

.hs-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 24px;
}

.hs-header h1 {
    font-size: 28px;
    font-weight: 800;
    color: #333;
}

.hs-empty {
    text-align: center;
    padding: 40px;
    color: #666;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.hs-list {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin-bottom: 24px;
}

.hs-entry {
    display: flex;
    gap: 16px;
    align-items: flex-start;
    padding: 16px 20px;
}

.hs-rank {
    font-size: 24px;
    font-weight: 900;
    color: #ccc;
    min-width: 36px;
    text-align: center;
}

.hs-entry:nth-child(1) .hs-rank { color: #F9A825; }
.hs-entry:nth-child(2) .hs-rank { color: #90A4AE; }
.hs-entry:nth-child(3) .hs-rank { color: #A1887F; }

.hs-meta {
    min-width: 150px;
}

.hs-date {
    font-size: 12px;
    color: #888;
    margin-bottom: 4px;
}

.hs-winner {
    font-size: 15px;
    color: #333;
    margin-bottom: 3px;
}

.hs-turns {
    font-size: 12px;
    color: #aaa;
}

.hs-players {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.hs-player {
    background: #F9F9F9;
    border-radius: 6px;
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.hs-player.hs-player-winner {
    background: #E3F2FD;
    border: 1px solid #90CAF9;
}

.hs-player-name {
    font-weight: 700;
    font-size: 14px;
    color: #333;
    min-width: 90px;
}

.winner-crown { font-size: 14px; margin-right: 3px; }

.hs-player-scores {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
    font-size: 12px;
    color: #666;
}

.hs-color-score {
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 600;
    font-size: 11px;
}
.hs-red    { background: var(--red-cell);    color: var(--red-text); }
.hs-yellow { background: var(--yellow-cell); color: var(--yellow-text); }
.hs-green  { background: var(--green-cell);  color: var(--green-text); }
.hs-blue   { background: var(--blue-cell);   color: var(--blue-text); }

.hs-penalties { color: #D32F2F; font-weight: 600; }
.hs-total-score { font-size: 14px; color: #1565C0; }

.hs-footer { text-align: center; margin-top: 10px; }

/* ============================================================
   RESPONSIVE
   ============================================================ */

@media (max-width: 768px) {
    .game-main {
        flex-direction: column;
        padding: 10px;
        gap: 10px;
    }

    .dice-panel {
        width: 100%;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 10px;
    }

    .dice-section { flex: 1; min-width: 200px; }
    .controls-section { flex: 1; min-width: 200px; }
    .score-reference { width: 100%; }

    .cells-container { overflow-x: auto; }

    .cell {
        width: 38px;
        height: 38px;
    }

    .cell-number { font-size: 12px; }

    .hs-entry { flex-direction: column; gap: 10px; }
    .hs-meta { min-width: unset; }
}

@media (max-width: 480px) {
    .game-header-title { font-size: 18px; }
    .die { width: 42px; height: 42px; }
    .cell { width: 32px; height: 32px; }
    .cell-number { font-size: 11px; }
    .score-ref-table { font-size: 9px; }
}

/* ============================================================
   MODE SELECTOR (index page)
   ============================================================ */

.mode-selector-section {
    margin-bottom: 20px;
}
.mode-selector-section > label {
    display: block;
    font-weight: 600;
    margin-bottom: 10px;
    color: #444;
}
.mode-cards {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}
.mode-card {
    flex: 1;
    min-width: 120px;
    border: 2px solid #ccc;
    border-radius: 10px;
    padding: 14px 12px;
    cursor: pointer;
    text-align: center;
    transition: all 0.15s;
    background: #fff;
}
.mode-card:hover:not(.mode-card-soon) { border-color: var(--btn-primary); }
.mode-card.active { border-color: var(--btn-primary); background: #E3F2FD; }
.mode-card-icon { font-size: 26px; margin-bottom: 6px; }
.mode-card-name { font-weight: 700; font-size: 14px; color: #333; }
.mode-card-desc { font-size: 12px; color: #888; margin-top: 4px; }
.mode-card-soon { opacity: 0.5; cursor: not-allowed; border-style: dashed; }

/* ============================================================
   REMOTE CARD (index page)
   ============================================================ */

.remote-card {
    margin-top: 20px;
}
.remote-card h2 {
    font-size: 20px;
    margin-bottom: 6px;
    color: #333;
}
.remote-subtitle {
    color: #666;
    font-size: 14px;
    margin-bottom: 18px;
}
.remote-sections {
    display: flex;
    gap: 0;
    align-items: stretch;
}
.remote-section {
    flex: 1;
    padding: 0 16px;
}
.remote-section:first-child { padding-left: 0; }
.remote-section:last-child  { padding-right: 0; }
.remote-section h3 {
    font-size: 15px;
    color: #444;
    margin-bottom: 12px;
}
.remote-divider {
    display: flex;
    align-items: center;
    color: #999;
    font-size: 13px;
    font-weight: 600;
    padding: 0 12px;
    position: relative;
}
.remote-divider::before, .remote-divider::after {
    content: '';
    position: absolute;
    left: 50%;
    width: 1px;
    background: #e0e0e0;
    top: 0; bottom: 0;
}
@media (max-width: 540px) {
    .remote-sections { flex-direction: column; gap: 16px; }
    .remote-divider { padding: 8px 0; }
    .remote-section { padding: 0; }
    .remote-divider::before, .remote-divider::after { display: none; }
}
.code-input { text-transform: uppercase; letter-spacing: 4px; font-weight: 700; }

/* ============================================================
   LOBBY PAGE
   ============================================================ */

.lobby-page {
    display: flex;
    justify-content: center;
    padding: 30px 16px 60px;
}
.lobby-container {
    width: 100%;
    max-width: 520px;
}
.lobby-card { }
.join-code-display {
    text-align: center;
    background: linear-gradient(135deg, #1a1a2e, #2a2a4e);
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}
.join-code-label {
    color: #aaa;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}
.join-code-value {
    font-size: 44px;
    font-weight: 900;
    letter-spacing: 10px;
    color: #FFD600;
    font-family: monospace;
}
.lobby-players-section h2 {
    font-size: 16px;
    color: #444;
    margin-bottom: 12px;
}
.lobby-player-list {
    list-style: none;
    margin-bottom: 14px;
}
.lobby-player-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-radius: 8px;
    background: #f5f5f5;
    margin-bottom: 8px;
}
.lobby-host { background: #E8F5E9; }
.lobby-player-name { font-weight: 600; font-size: 15px; flex: 1; }
.lobby-host-badge {
    background: #388E3C;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 12px;
    text-transform: uppercase;
}
.lobby-you-badge {
    background: #1565C0;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 12px;
}
.lobby-waiting {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #888;
    font-size: 14px;
    margin-bottom: 20px;
}
.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid #ddd;
    border-top-color: var(--btn-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }
.lobby-actions { text-align: center; padding-top: 4px; }
.lobby-hint { font-size: 13px; color: #888; margin-top: 8px; }

/* ============================================================
   WAITING NOTICE (game page, remote mode)
   ============================================================ */

.waiting-notice {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #F3E5F5;
    border: 2px solid #9C27B0;
    border-radius: 8px;
    padding: 12px 14px;
    color: #6A1B9A;
    font-weight: 600;
    font-size: 14px;
    animation: waitingPulse 2s ease-in-out infinite;
}
@keyframes waitingPulse {
    0%, 100% { border-color: #9C27B0; }
    50% { border-color: #6A1B9A; box-shadow: 0 0 0 3px rgba(106,27,154,0.15); }
}

/* ============================================================
   RULES MODAL
   ============================================================ */

.modal-rules {
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
}
.rules-modal-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    margin: 16px 0;
    text-align: left;
}
@media (max-width: 480px) {
    .rules-modal-grid { grid-template-columns: 1fr; }
}
