/* Domino Advisor - Visual Table UI */

* {
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    margin: 0;
    padding: 10px;
    background: #1a1a2e;
    color: #eee;
    min-height: 100vh;
}

/* App Header */
.app-header {
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    margin-bottom: 18px;
}

.brand {
    text-align: center;
}

h1 {
    text-align: center;
    color: #00d4ff;
    margin: 0;
    font-size: 1.5rem;
}

h1 .version {
    font-size: 0.7rem;
    color: #666;
    font-weight: normal;
    vertical-align: middle;
}

.subtitle {
    margin: 2px 0 0 0;
    font-size: 11px;
    color: #888;
    font-weight: normal;
}

.attribution {
    position: absolute;
    bottom: -14px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 10px;
    color: #666;
    margin: 0;
    white-space: nowrap;
}

.attribution a {
    color: #666;
    text-decoration: none;
}

.attribution a:hover {
    color: #00d4ff;
    text-decoration: underline;
}

.header-buttons {
    position: absolute;
    right: 0;
    display: flex;
    gap: 5px;
    align-items: center;
}

/* Language Toggle */
.lang-toggle {
    background: transparent;
    border: 1px solid #444;
    color: #888;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: bold;
    transition: border-color 0.2s;
    display: flex;
    align-items: center;
    gap: 2px;
}

.lang-toggle:hover {
    border-color: #00d4ff;
}

.lang-separator {
    color: #444;
    margin: 0 1px;
}

.lang-option {
    transition: color 0.2s;
}

.lang-option.active {
    color: #00d4ff;
}

.lang-option:not(.active) {
    color: #666;
}

.settings-btn,
.help-btn,
.docs-btn {
    background: transparent;
    border: none;
    color: #888;
    cursor: pointer;
    padding: 5px;
    border-radius: 4px;
    transition: color 0.2s, background 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}

.settings-btn:hover,
.help-btn:hover,
.docs-btn:hover {
    color: #00d4ff;
    background: rgba(0, 212, 255, 0.1);
}

/* Main Layout */
.game-wrapper {
    display: flex;
    gap: 15px;
    max-width: 1200px;
    margin: 0 auto;
}

.table-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.sidebar {
    width: 180px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: calc(100vh - 80px);
}

/* Scores */
.scores {
    display: flex;
    justify-content: center;
    gap: 30px;
    padding: 8px;
    background: #16213e;
    border-radius: 8px;
}

.score-box {
    text-align: center;
}

.score-box.your-team { color: #00d4ff; }
.score-box.opponent-team { color: #ff6b6b; }

.score-label {
    font-size: 11px;
    color: #888;
}

.score-value {
    font-size: 20px;
    font-weight: bold;
}

/* The Table */
.table {
    background: linear-gradient(135deg, #2d5016 0%, #1e3a0f 100%);
    border-radius: 20px;
    border: 12px solid #4a3728;
    box-shadow: inset 0 0 50px rgba(0,0,0,0.3), 0 10px 30px rgba(0,0,0,0.5);
    position: relative;
    min-height: 400px;
    display: grid;
    grid-template-rows: 60px 1fr 60px;
    grid-template-columns: 60px 1fr 60px;
}

/* Player Positions Around Table */
.player-position {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
}

.player-top { grid-row: 1; grid-column: 2; }
.player-bottom { grid-row: 3; grid-column: 2; }
.player-left { grid-row: 2; grid-column: 1; flex-direction: column; }
.player-right { grid-row: 2; grid-column: 3; flex-direction: column; }

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

.player-name {
    font-size: 11px;
    color: rgba(255,255,255,0.7);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.player-name.current-turn {
    color: #ffd93d;
    font-weight: bold;
}

.thinking-indicator {
    font-size: 10px;
    color: rgba(255, 255, 255, 0.5);
    letter-spacing: 0.5px;
    animation: thinking-pulse 1.2s ease-in-out infinite;
}

@keyframes thinking-pulse {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 1; }
}

.player-name.your-team { color: #7dd3fc; }
.player-name.opponent-team { color: #fca5a5; }

.diff-badge {
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.4px;
    text-transform: uppercase;
    padding: 1px 5px;
    border-radius: 8px;
    line-height: 1.4;
}

.diff-badge-beginner {
    background: rgba(255, 217, 61, 0.12);
    color: #ffd93d;
    border: 1px solid rgba(255, 217, 61, 0.3);
}

.diff-badge-experienced {
    background: rgba(129, 140, 248, 0.12);
    color: #818cf8;
    border: 1px solid rgba(129, 140, 248, 0.3);
}

.diff-badge-master {
    background: rgba(0, 212, 255, 0.08);
    color: rgba(0, 212, 255, 0.6);
    border: 1px solid rgba(0, 212, 255, 0.15);
}

/* Individual player colors */
.player-color-0 { color: #ffffff; } /* You - White */
.player-color-1 { color: #ef4444; } /* Opp 1 - Red */
.player-color-2 { color: #3b82f6; } /* Partner - Blue */
.player-color-3 { color: #eab308; } /* Opp 2 - Yellow */

.player-bg-0 { background-color: #ffffff; }
.player-bg-1 { background-color: #ef4444; }
.player-bg-2 { background-color: #3b82f6; }
.player-bg-3 { background-color: #eab308; }

.player-border-0 { border-color: #ffffff; }
.player-border-1 { border-color: #ef4444; }
.player-border-2 { border-color: #3b82f6; }
.player-border-3 { border-color: #eab308; }

/* Pass Badge - pulses on player position */
.pass-badge {
    font-size: 12px;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #fff;
    background: rgba(255, 70, 70, 0.9);
    padding: 3px 10px;
    border-radius: 4px;
    animation: pass-pulse 4s ease-out forwards;
    position: absolute;
    white-space: nowrap;
    box-shadow: 0 0 8px rgba(255, 70, 70, 0.6);
}

.player-info {
    position: relative;
}

@keyframes pass-pulse {
    0%   { opacity: 1; transform: scale(1.15); }
    8%   { opacity: 1; transform: scale(0.95); }
    16%  { opacity: 1; transform: scale(1.1); }
    24%  { opacity: 1; transform: scale(0.95); }
    32%  { opacity: 1; transform: scale(1.05); }
    50%  { opacity: 1; transform: scale(1); }
    100% { opacity: 0; transform: scale(0.9); }
}

/* Tile Count Display */
.tile-count {
    display: flex;
    gap: 2px;
}

.tile-count.horizontal {
    flex-direction: row;
}

.tile-count.vertical {
    flex-direction: column;
}

.mini-tile {
    width: 12px;
    height: 20px;
    background: linear-gradient(135deg, #f5f5dc 0%, #d4d4aa 100%);
    border-radius: 2px;
    border: 1px solid #333;
    box-shadow: 1px 1px 2px rgba(0,0,0,0.3);
}

.tile-count.vertical .mini-tile {
    width: 20px;
    height: 12px;
}

.tile-count-badge {
    background: rgba(0,0,0,0.5);
    color: #fff;
    font-size: 14px;
    font-weight: bold;
    padding: 2px 8px;
    border-radius: 10px;
    min-width: 24px;
    text-align: center;
}

/* Chain Area (center of table) */
.chain-container {
    grid-row: 2;
    grid-column: 2;
    overflow: auto;
    padding: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.chain {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
}

/* Each tile row: 3 columns — left arm | start tile | right arm */
.chain-paired-row {
    display: grid;
    grid-template-columns: 1fr 60px 1fr;
    align-items: center;
}

.chain-left-cell {
    display: flex;
    flex-direction: row;
    justify-content: flex-end;
    align-items: center;
    gap: 2px;
}

.chain-right-cell {
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    align-items: center;
    gap: 2px;
}

.chain-start-cell {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 2px;
}

/* Full-width continuation row (left arm above anchor, right arm below) */
.chain-cont-row {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 2px;
}

/* Full-width turn connector between continuation rows */
.chain-cont-connector {
    display: flex;
    flex-direction: row;
    align-items: center;
    height: 20px;
}

.chain-row {
    display: flex;
    align-items: center;
    gap: 2px;
}

.chain-row.reverse {
    flex-direction: row-reverse;
    justify-content: flex-start;
}

/* Turn connector between rows - L-shaped to show direction */
.chain-turn {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    padding: 2px 0;
}

.chain-turn.left-side {
    align-items: flex-start;
}

.turn-connector {
    position: relative;
    width: 24px;
    height: 20px;
}

/* Right-side turn: vertical line on right */
.turn-connector::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 4px;
    height: 100%;
    background: rgba(255,255,255,0.4);
    border-radius: 2px;
}

/* Left-side turn: vertical line on left */
.chain-turn.left-side .turn-connector::before {
    right: auto;
    left: 0;
}

/* Domino Tile Styling */
.domino {
    display: flex;
    background: linear-gradient(135deg, #f5f5dc 0%, #e8e8c8 100%);
    border-radius: 6px;
    border: 2px solid #333;
    box-shadow: 2px 2px 4px rgba(0,0,0,0.4);
    overflow: hidden;
}

.domino.horizontal {
    flex-direction: row;
    width: 56px;
    height: 28px;
}

.domino.vertical {
    flex-direction: column;
    width: 28px;
    height: 56px;
}

.domino-half {
    width: 26px;
    height: 26px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    padding: 3px;
    position: relative;
}

.domino.horizontal .domino-half {
    border-right: 1px solid #999;
}

.domino.horizontal .domino-half:last-child {
    border-right: none;
}

.domino.vertical .domino-half {
    border-bottom: 1px solid #999;
}

.domino.vertical .domino-half:last-child {
    border-bottom: none;
}

.pip {
    width: 5px;
    height: 5px;
    background: #1a1a2e;
    border-radius: 50%;
    justify-self: center;
    align-self: center;
}

/* Pip positions for values 0-6 */
.pip.center { grid-column: 2; grid-row: 2; }
.pip.top-left { grid-column: 1; grid-row: 1; }
.pip.top-right { grid-column: 3; grid-row: 1; }
.pip.middle-left { grid-column: 1; grid-row: 2; }
.pip.middle-right { grid-column: 3; grid-row: 2; }
.pip.bottom-left { grid-column: 1; grid-row: 3; }
.pip.bottom-right { grid-column: 3; grid-row: 3; }

/* Spinner (first double) styling */
.domino.spinner {
    flex-direction: column;
    width: 28px;
    height: 56px;
}

/* Your Hand Area */
.hand-area {
    background: #16213e;
    border-radius: 8px;
    padding: 10px;
}

.hand-label {
    font-size: 11px;
    color: #888;
    margin-bottom: 8px;
    display: flex;
    justify-content: space-between;
}

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

/* Hand tiles are larger and interactive */
.hand .domino {
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    transform-origin: bottom center;
}

.hand .domino:hover:not(.disabled) {
    box-shadow: 0 8px 20px rgba(0, 212, 255, 0.3);
}

.hand .domino.playable {
    box-shadow: 0 0 0 2px #00d4ff;
}

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

/* Genín Advice */
.genin-advice-container {
    position: relative;
    display: flex;
    justify-content: flex-end;
    padding: 4px 8px;
}

.genin-advice-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
}

.genin-advice-icon {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    box-shadow: 0 0 8px rgba(0, 255, 255, 0.3);
    animation: genin-bob 3s ease-in-out infinite;
    background: radial-gradient(circle, #f5f5f5 60%, #e0e0e0 100%);
    padding: 4px;
    object-fit: contain;
}

@keyframes genin-bob {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-4px); }
}

.genin-speech-bubble {
    position: absolute;
    bottom: 100%;
    right: 0;
    margin-bottom: 8px;
    background: #1a2744;
    border: 1px solid rgba(0, 255, 255, 0.3);
    border-radius: 12px;
    padding: 12px;
    min-width: 220px;
    max-width: 320px;
    z-index: 50;
    animation: bubble-pop 0.2s ease-out;
}

@keyframes bubble-pop {
    from { transform: scale(0.8); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.speech-bubble-arrow {
    position: absolute;
    bottom: -8px;
    right: 16px;
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 8px solid #1a2744;
}

.speech-bubble-content {
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

.speech-recommendation {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.speech-domino {
    width: 18px;
    height: 37px;
    flex-shrink: 0;
}

.speech-domino .domino {
    transform: scale(0.65);
    transform-origin: top left;
}

.speech-end {
    font-weight: bold;
    color: #4ecdc4;
    font-size: 0.85em;
}

.speech-reason {
    color: rgba(255, 255, 255, 0.85);
    font-size: 0.85em;
    margin: 0;
}

.speech-detail {
    color: rgba(255, 255, 255, 0.6);
    font-size: 0.8em;
    margin: 4px 0 0 0;
    line-height: 1.4;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-top: 4px;
    white-space: pre-line;
}

.speech-detail:empty {
    display: none;
}

.speech-reason.sassy {
    color: #fbbf24;
    font-style: italic;
}

/* Controls */
.controls {
    display: flex;
    gap: 8px;
    justify-content: center;
}

button {
    padding: 8px 16px;
    background: #00d4ff;
    color: #000;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    font-weight: bold;
}

button:hover { background: #00b4d8; }
button:disabled {
    background: #555;
    color: #888;
    cursor: not-allowed;
}

.pass-btn { background: #ff6b6b; }
.pass-btn:hover { background: #ee5a5a; }

.quiz-btn { background: #8b5cf6; }
.quiz-btn:hover:not(:disabled) { background: #7c3aed; }

/* Tile Attribution Toggle */
.attribution-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: #888;
    cursor: pointer;
    user-select: none;
}

.attribution-toggle input[type="checkbox"] {
    accent-color: #00d4ff;
    cursor: pointer;
}

.attribution-toggle:hover {
    color: #fff;
}

/* Player indicator on tiles */
.domino.show-player {
    position: relative;
}

.player-indicator {
    position: absolute;
    top: -5px;
    right: -5px;
    width: 16px;
    height: 16px;
    background: transparent;
    border: none;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
    text-shadow: 0 0 3px #000, 0 0 3px #000;
}

.domino.vertical .player-indicator {
    top: -5px;
    right: -5px;
}

/* Player indicator colors */
.player-indicator.player-0 { color: #ffffff; -webkit-text-stroke: 1.5px #000; text-shadow: none; }
.player-indicator.player-1 { color: #ef4444; }
.player-indicator.player-2 { color: #3b82f6; }
.player-indicator.player-3 { color: #eab308; }

/* Glow effect when attribution is on */
.domino.show-player.played-by-0 { box-shadow: 0 0 8px rgba(255, 255, 255, 0.6); }
.domino.show-player.played-by-1 { box-shadow: 0 0 8px rgba(239, 68, 68, 0.5); }
.domino.show-player.played-by-2 { box-shadow: 0 0 8px rgba(59, 130, 246, 0.5); }
.domino.show-player.played-by-3 { box-shadow: 0 0 8px rgba(234, 179, 8, 0.5); }

/* Semi-transparent color overlay over the full tile */
.domino.show-player {
    position: relative;
}

.domino.show-player::after {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
}

/* No overlay for Player 0 (you) — tiles stay plain */
.domino.show-player.played-by-1::after { background: rgba(239, 68, 68, 0.28); }
.domino.show-player.played-by-2::after { background: rgba(59, 130, 246, 0.28); }
.domino.show-player.played-by-3::after { background: rgba(234, 179, 8, 0.28); }

/* Tile slam animation — [6|6] or domino */
.tile-slam {
    animation: tile-slam 500ms ease-out forwards;
    position: relative;
    z-index: 10;
}

@keyframes tile-slam {
    0%   { transform: scale(1);    box-shadow: none; }
    20%  { transform: scale(1.45); box-shadow: 0 0 22px #00d4ff; }
    55%  { transform: scale(0.92); box-shadow: 0 0 6px rgba(0, 212, 255, 0.4); }
    80%  { transform: scale(1.08); box-shadow: none; }
    100% { transform: scale(1);    box-shadow: none; }
}

/* Player legend */
.player-legend {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-top: 8px;
    font-size: 10px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

.legend-dot {
    font-size: 12px;
    line-height: 1;
}

.legend-dot.player-0::before { content: '●'; color: #ffffff; -webkit-text-stroke: 1px #000; }
.legend-dot.player-1::before { content: '▶'; color: #ef4444; }
.legend-dot.player-2::before { content: '▲'; color: #3b82f6; }
.legend-dot.player-3::before { content: '◀'; color: #eab308; }

.legend-label {
    color: #888;
}

.attribution-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    margin-top: 8px;
}

/* Sidebar - Log & Info */
.log-area {
    background: #16213e;
    border-radius: 8px;
    padding: 10px;
    flex: 1;
    min-height: 0; /* Allow flex shrinking for proper scrolling */
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.log-area h3 {
    margin: 0 0 8px 0;
    font-size: 12px;
    color: #888;
}

.log {
    font-family: monospace;
    font-size: 11px;
    line-height: 1.6;
    overflow-y: auto;
    flex: 1;
    min-height: 0; /* Allow flex shrinking for proper scrolling */
}

.log-entry {
    padding: 2px 0;
    border-bottom: 1px solid #0f3460;
}

.log-entry.player-0 { color: #ffffff; } /* You - White */
.log-entry.player-1 { color: #ef4444; } /* Opp 1 - Red */
.log-entry.player-2 { color: #3b82f6; } /* Partner - Blue */
.log-entry.player-3 { color: #eab308; } /* Opp 2 - Yellow */
.log-entry.system { color: #ffd93d; }

/* Pass entries - more prominent */
.log-entry.pass-entry {
    font-weight: bold;
    font-style: italic;
    background: rgba(255, 255, 255, 0.06);
    padding: 3px 6px;
    border-radius: 3px;
    border-left: 3px solid currentColor;
}

/* Hand separator - prominent visual break between hands */
.log-separator {
    display: flex;
    align-items: center;
    margin: 12px 0 8px 0;
    gap: 8px;
}

.log-separator::before,
.log-separator::after {
    content: '';
    flex: 1;
    height: 2px;
    background: linear-gradient(90deg, transparent, #00d4ff, transparent);
}

.log-separator span {
    color: #00d4ff;
    font-size: 10px;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 1px;
    white-space: nowrap;
}

/* Modals */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 99;
}

.modal-overlay.visible { display: block; }

.end-selection, .message-box {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #16213e;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    z-index: 100;
    text-align: center;
}

.end-selection.visible, .message-box.visible { display: block; }

.end-selection h3 {
    margin-top: 0;
    color: #00d4ff;
}

.end-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.end-btn {
    padding: 10px 20px;
    background: #0a3d62;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.end-btn:hover { background: #00d4ff; color: #000; }
.end-btn.secondary { background: #333; }

.message-box h2 {
    margin-top: 0;
    color: #00d4ff;
}

.message-box.opponent-win h2 { color: #ff6b6b; }

.message-box p {
    white-space: pre-line;
    text-align: left;
    font-family: monospace;
    font-size: 12px;
    max-height: 300px;
    overflow-y: auto;
    background: rgba(0,0,0,0.2);
    padding: 10px;
    border-radius: 4px;
    margin: 15px 0;
}

.message-genin {
    width: 80px;
    height: 80px;
    margin-bottom: 10px;
}

/* Open Ends Indicator */
.open-ends {
    text-align: center;
    font-size: 12px;
    color: rgba(255,255,255,0.6);
    margin-top: 5px;
}

.open-ends span {
    display: inline-block;
    background: rgba(0,0,0,0.3);
    padding: 2px 8px;
    border-radius: 4px;
    margin: 0 5px;
}

/* Message Buttons */
.message-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 15px;
}

.review-btn {
    background: #6366f1;
}

.review-btn:hover {
    background: #4f46e5;
}

/* Settings Modal */
/* Help Modal */
.help-modal {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #16213e;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    z-index: 101;
    width: 90%;
    max-width: 500px;
    max-height: 85vh;
    overflow: hidden;
    display: none;
    flex-direction: column;
}

.help-modal.visible {
    display: flex;
}

.help-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    border-bottom: 1px solid #0f3460;
    flex-shrink: 0;
}

.help-header-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.help-header h2 {
    margin: 0;
    color: #00d4ff;
    font-size: 1.2rem;
}

.help-content {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.help-section {
    margin-bottom: 20px;
}

.help-section:last-child {
    margin-bottom: 0;
}

.help-section.genin-intro {
    background: rgba(0, 212, 255, 0.08);
    border-left: 3px solid #00d4ff;
    padding: 12px 15px;
    border-radius: 0 6px 6px 0;
    margin-bottom: 25px;
}

.help-section.genin-intro p {
    margin: 0;
    font-size: 14px;
    color: #ddd;
}

.help-section h3 {
    color: #00d4ff;
    font-size: 1rem;
    margin: 0 0 10px 0;
    border-bottom: 1px solid #0f3460;
    padding-bottom: 5px;
}

.help-section p {
    margin: 0 0 10px 0;
    color: #ccc;
    line-height: 1.5;
}

.help-section ol,
.help-section ul {
    margin: 0;
    padding-left: 20px;
    color: #ccc;
}

.help-section li {
    margin-bottom: 8px;
    line-height: 1.4;
}

.help-section strong {
    color: #fff;
}

/* Settings Modal */
.settings-modal {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #16213e;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    z-index: 101;
    width: 90%;
    max-width: 450px;
}

.settings-modal.visible {
    display: block;
}

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    border-bottom: 1px solid #0f3460;
}

.settings-header h2 {
    margin: 0;
    color: #00d4ff;
    font-size: 1.2rem;
}

.close-btn {
    background: none;
    border: none;
    color: #888;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.close-btn:hover {
    color: #fff;
}

.settings-content {
    padding: 20px;
}

.settings-section h3 {
    margin: 0 0 10px 0;
    color: #fff;
    font-size: 1rem;
}

.settings-description {
    color: #888;
    font-size: 12px;
    margin: 0 0 15px 0;
    line-height: 1.5;
}

.settings-description.api-key-note {
    color: #6b7a99;
    font-style: italic;
    margin-top: -8px;
}

.api-key-input-group {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}

.api-key-input-group input {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid #0f3460;
    border-radius: 6px;
    background: #0a1628;
    color: #fff;
    font-size: 14px;
}

.api-key-input-group input::placeholder {
    color: #666;
}

.save-btn {
    background: #00d4ff;
    color: #000;
}

.key-actions {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}

.test-btn {
    background: #0a3d62;
    color: #fff;
    flex: 1;
}

.test-btn:hover {
    background: #00d4ff;
    color: #000;
}

.clear-btn {
    background: #333;
    color: #fff;
    flex: 1;
}

.clear-btn:hover {
    background: #ff6b6b;
}

.key-status {
    font-size: 12px;
    padding: 8px;
    border-radius: 4px;
    text-align: center;
}

.key-status.configured {
    background: rgba(0, 212, 255, 0.1);
    color: #00d4ff;
}

.key-status.not-configured {
    background: rgba(255, 107, 107, 0.1);
    color: #ff6b6b;
}

.key-status.success {
    background: rgba(34, 197, 94, 0.1);
    color: #22c55e;
}

.key-status.error {
    background: rgba(255, 107, 107, 0.1);
    color: #ff6b6b;
}

.key-status.loading {
    background: rgba(255, 217, 61, 0.1);
    color: #ffd93d;
}

.key-status.info {
    background: rgba(99, 102, 241, 0.1);
    color: #6366f1;
}

.difficulty-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
    gap: 8px;
}

.difficulty-label {
    font-size: 13px;
    color: #a8b2c8;
    min-width: 44px;
    flex-shrink: 0;
}

.difficulty-buttons {
    display: flex;
    gap: 4px;
    flex: 1;
}

.diff-btn {
    flex: 1;
    padding: 5px 4px;
    background: #0a1628;
    border: 1px solid #0f3460;
    border-radius: 6px;
    color: #a8b2c8;
    font-size: 11px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.diff-btn:hover {
    background: #162040;
    color: #c8d2e8;
}

.diff-btn.active {
    background: rgba(0, 212, 255, 0.1);
    border-color: #00d4ff;
    color: #00d4ff;
    font-weight: bold;
}

/* Debrief Modal */
.debrief-modal {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #16213e;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    z-index: 101;
    width: 95%;
    max-width: 700px;
    max-height: 90vh;
    overflow: hidden;
    flex-direction: column;
}

.debrief-modal.visible {
    display: flex;
}

.debrief-header {
    padding: 15px 20px;
    border-bottom: 1px solid #0f3460;
    position: relative;
}

.debrief-header-content {
    display: flex;
    align-items: center;
    gap: 15px;
}

.genin-avatar {
    width: 60px;
    height: 60px;
    flex-shrink: 0;
    background: radial-gradient(circle, #f5f5f5 60%, #e0e0e0 100%);
    border-radius: 50%;
    padding: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    object-fit: contain;
}

.genin-avatar.small {
    width: 40px;
    height: 40px;
}

.debrief-header h2 {
    margin: 0 0 5px 0;
    color: #00d4ff;
    font-size: 1.3rem;
}

.debrief-header p {
    margin: 0;
    color: #888;
    font-size: 13px;
}

.debrief-header .close-btn {
    position: absolute;
    top: 15px;
    right: 15px;
}

/* Debrief Tabs */
.debrief-tabs {
    display: flex;
    border-bottom: 1px solid #0f3460;
    padding: 0 10px;
}

.tab-btn {
    background: none;
    border: none;
    color: #888;
    padding: 12px 20px;
    cursor: pointer;
    font-size: 13px;
    border-bottom: 2px solid transparent;
    transition: color 0.2s, border-color 0.2s;
}

.tab-btn:hover {
    color: #fff;
}

.tab-btn.active {
    color: #00d4ff;
    border-bottom-color: #00d4ff;
}

/* Debrief Content */
.debrief-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Stat Cards */
.stat-cards {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-bottom: 20px;
}

.stat-card {
    background: #0a1628;
    border-radius: 8px;
    padding: 15px;
    text-align: center;
    border: 2px solid transparent;
}

.stat-card.optimal {
    border-color: #22c55e;
}

.stat-card.good {
    border-color: #00d4ff;
}

.stat-card.questionable {
    border-color: #ffd93d;
}

.stat-card.mistake {
    border-color: #ff6b6b;
}

.stat-value {
    font-size: 28px;
    font-weight: bold;
    color: #fff;
}

.stat-label {
    font-size: 11px;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 5px;
}

/* Key Moments Section */
.key-moments-section {
    margin-bottom: 20px;
}

.key-moments-section h3 {
    margin: 0 0 10px 0;
    color: #fff;
    font-size: 14px;
}

.moments-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.moment-item {
    background: #0a1628;
    border-radius: 6px;
    padding: 12px;
    border-left: 3px solid #ff6b6b;
}

.moment-item.questionable {
    border-left-color: #ffd93d;
}

.moment-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.moment-label {
    font-size: 12px;
    color: #888;
}

.moment-badge {
    font-size: 10px;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: bold;
    text-transform: uppercase;
}

.moment-badge.mistake {
    background: rgba(255, 107, 107, 0.2);
    color: #ff6b6b;
}

.moment-badge.questionable {
    background: rgba(255, 217, 61, 0.2);
    color: #ffd93d;
}

.moment-played {
    color: #fff;
    font-size: 13px;
    margin-bottom: 5px;
}

.moment-recommended {
    color: #00d4ff;
    font-size: 12px;
}

/* LLM Analysis Section */
.llm-analysis-section {
    margin-top: 20px;
}

.llm-analysis-section h3 {
    margin: 0 0 10px 0;
    color: #fff;
    font-size: 14px;
}

.analyze-btn {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: #fff;
    padding: 12px 24px;
    font-size: 14px;
    border-radius: 8px;
    width: 100%;
}

.analyze-btn:hover {
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
}

.llm-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 20px;
    background: #0a1628;
    border-radius: 8px;
    color: #888;
}

.llm-loading .genin-avatar {
    animation: thinking 2s ease-in-out infinite;
}

@keyframes thinking {
    0%, 100% { opacity: 0.7; }
    50% { opacity: 1; }
}

.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid #333;
    border-top-color: #00d4ff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.llm-result {
    background: #0a1628;
    border-radius: 8px;
    padding: 15px;
    font-size: 13px;
    line-height: 1.6;
    color: #ddd;
    white-space: pre-wrap;
}

.llm-no-key {
    background: rgba(99, 102, 241, 0.1);
    border-radius: 8px;
    padding: 15px;
    text-align: center;
}

.llm-no-key p {
    margin: 0;
    color: #888;
    font-size: 13px;
}

.llm-no-key a {
    color: #6366f1;
    text-decoration: none;
}

.llm-no-key a:hover {
    text-decoration: underline;
}

/* Plays List */
.plays-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.play-item {
    background: #0a1628;
    border-radius: 6px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.play-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.play-info {
    font-size: 12px;
    color: #888;
}

.play-badge {
    font-size: 10px;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: bold;
    text-transform: uppercase;
}

.play-badge.optimal {
    background: rgba(34, 197, 94, 0.2);
    color: #22c55e;
}

.play-badge.good {
    background: rgba(0, 212, 255, 0.2);
    color: #00d4ff;
}

.play-badge.questionable {
    background: rgba(255, 217, 61, 0.2);
    color: #ffd93d;
}

.play-badge.mistake {
    background: rgba(255, 107, 107, 0.2);
    color: #ff6b6b;
}

.play-badge.pass {
    background: rgba(136, 136, 136, 0.2);
    color: #888;
}

.play-badge.ai {
    background: rgba(99, 102, 241, 0.2);
    color: #6366f1;
}

.play-tile {
    color: #fff;
    font-size: 14px;
}

.play-recommendation {
    font-size: 12px;
    color: #00d4ff;
    padding-left: 10px;
    border-left: 2px solid #0f3460;
}

/* Hand Selector */
.hand-selector {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 15px;
}

.hand-selector label {
    color: #888;
    font-size: 13px;
}

.hand-selector select {
    background: #0a1628;
    border: 1px solid #0f3460;
    color: #fff;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
}

/* Debrief Footer */
.debrief-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 15px 20px;
    border-top: 1px solid #0f3460;
}

#debrief-close-btn {
    background: #333;
}

#debrief-new-match-btn {
    background: #00d4ff;
    color: #000;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 30px;
    color: #666;
    font-size: 13px;
}

/* Responsive */
/* Quiz Modal */
.quiz-modal {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #16213e;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    z-index: 101;
    width: 95%;
    max-width: 500px;
    max-height: 90vh;
    overflow: hidden;
    flex-direction: column;
}

.quiz-modal.visible {
    display: flex;
}

.quiz-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    border-bottom: 1px solid #0f3460;
}

.quiz-header-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.quiz-header h2 {
    margin: 0;
    color: #8b5cf6;
    font-size: 1.2rem;
}

.quiz-content {
    padding: 20px;
    overflow-y: auto;
}

.quiz-target-selector {
    margin-bottom: 15px;
}

.quiz-target-selector label {
    display: block;
    color: #888;
    font-size: 12px;
    margin-bottom: 8px;
}

.quiz-target-buttons {
    display: flex;
    gap: 8px;
}

.target-btn {
    flex: 1;
    padding: 10px;
    background: #0a1628;
    border: 2px solid #0f3460;
    color: #fff;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.target-btn:hover {
    border-color: #8b5cf6;
}

.target-btn.active {
    background: #8b5cf6;
    border-color: #8b5cf6;
}

.target-btn[data-player="2"] {
    color: #7dd3fc;
}

.target-btn[data-player="1"],
.target-btn[data-player="3"] {
    color: #fca5a5;
}

.target-btn.active {
    color: #fff;
}

.quiz-context {
    background: #0a1628;
    border-radius: 6px;
    padding: 12px;
    margin-bottom: 15px;
}

.quiz-context p {
    margin: 0;
    color: #888;
    font-size: 13px;
    line-height: 1.5;
}

.quiz-context .known-facts {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid #0f3460;
}

.quiz-context .fact {
    color: #ffd93d;
    font-size: 12px;
    margin: 4px 0;
}

.quiz-tile-picker {
    margin-bottom: 15px;
}

.picker-instructions {
    color: #888;
    font-size: 12px;
    margin: 0 0 10px 0;
}

.tile-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 6px;
    margin-bottom: 10px;
}

.tile-grid .domino {
    width: 100%;
    aspect-ratio: 1/2;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    transform: scale(0.9);
}

.tile-grid .domino:hover:not(.disabled) {
    transform: scale(1);
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);
}

.tile-grid .domino.selected {
    box-shadow: 0 0 0 3px #8b5cf6;
    transform: scale(1);
}

.tile-grid .domino.disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.tile-grid .domino.impossible {
    opacity: 0.3;
    background: linear-gradient(135deg, #ff6b6b33, #ff6b6b11);
}

.selection-count {
    text-align: center;
    color: #888;
    font-size: 12px;
}

.selection-count span {
    color: #8b5cf6;
    font-weight: bold;
}

.quiz-actions {
    display: flex;
    gap: 10px;
}

.submit-quiz-btn {
    flex: 2;
    background: #8b5cf6;
    color: #fff;
}

.submit-quiz-btn:hover:not(:disabled) {
    background: #7c3aed;
}

.skip-quiz-btn {
    flex: 1;
    background: #333;
}

/* Quiz Result Display */
.quiz-result {
    padding: 20px;
    text-align: center;
}

.quiz-result h3 {
    margin: 0 0 15px 0;
    color: #fff;
}

.quiz-score {
    margin-bottom: 20px;
}

.quiz-score .score-label {
    color: #888;
    font-size: 14px;
}

.quiz-score .score-value {
    display: block;
    font-size: 48px;
    font-weight: bold;
    color: #8b5cf6;
    margin-top: 5px;
}

.quiz-breakdown {
    text-align: left;
    background: #0a1628;
    border-radius: 6px;
    padding: 15px;
    margin-bottom: 20px;
}

.breakdown-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    font-size: 13px;
    border-bottom: 1px solid #0f3460;
}

.breakdown-row:last-child {
    border-bottom: none;
}

.breakdown-row .label {
    color: #888;
}

.breakdown-row .value {
    font-weight: bold;
}

.breakdown-row.correct .value { color: #22c55e; }
.breakdown-row.wrong .value { color: #ff6b6b; }
.breakdown-row.missed .value { color: #ffd93d; }

.quiz-tiles-display {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid #0f3460;
}

.quiz-tiles-display h4 {
    margin: 0 0 10px 0;
    color: #888;
    font-size: 12px;
    font-weight: normal;
}

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

.quiz-tiles-row .tile-mini {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 11px;
    font-family: monospace;
}

.quiz-tiles-row .tile-mini.correct {
    background: rgba(34, 197, 94, 0.2);
    color: #22c55e;
}

.quiz-tiles-row .tile-mini.wrong {
    background: rgba(255, 107, 107, 0.2);
    color: #ff6b6b;
}

.quiz-tiles-row .tile-mini.missed {
    background: rgba(255, 217, 61, 0.2);
    color: #ffd93d;
}

.quiz-done-btn {
    background: #8b5cf6;
    padding: 12px 30px;
}

.quiz-confirmation {
    text-align: center;
    padding: 20px 10px;
}

.quiz-confirmation p {
    margin: 0 0 10px 0;
    color: #ddd;
    font-size: 14px;
}

.quiz-confirmation .quiz-hint {
    color: #8b5cf6;
    font-style: italic;
    font-size: 13px;
}

/* Predictions Tab in Debrief */
.predictions-summary,
.predictions-history,
.deduction-timeline {
    margin-bottom: 25px;
}

.predictions-summary h3,
.predictions-history h3,
.deduction-timeline h3 {
    margin: 0 0 15px 0;
    color: #fff;
    font-size: 14px;
}

.prediction-stats {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.prediction-stat-row {
    display: flex;
    justify-content: space-between;
    background: #0a1628;
    padding: 10px 12px;
    border-radius: 6px;
    font-size: 13px;
}

.prediction-stat-row .stat-label {
    color: #888;
}

.prediction-stat-row .stat-value {
    color: #8b5cf6;
    font-weight: bold;
}

/* Quiz Results Detail in Debrief */
.quiz-results-detail {
    margin-bottom: 20px;
}

.quiz-results-detail h4,
.quiz-summary h4 {
    margin: 0 0 12px 0;
    color: #00d4ff;
    font-size: 14px;
    font-weight: 600;
}

.quiz-result-card {
    background: #0a1628;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 12px;
    border-left: 3px solid #8b5cf6;
}

.quiz-result-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.quiz-result-header .quiz-target {
    color: #ddd;
    font-weight: 500;
}

.quiz-score-badge {
    background: #8b5cf6;
    color: #fff;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: bold;
}

.quiz-result-breakdown {
    display: flex;
    gap: 15px;
    margin-bottom: 10px;
}

.quiz-result-breakdown .quiz-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.quiz-result-breakdown .quiz-stat .label {
    font-size: 10px;
    color: #888;
    margin-bottom: 2px;
}

.quiz-result-breakdown .quiz-stat .value {
    font-size: 16px;
    font-weight: bold;
}

.quiz-result-breakdown .quiz-stat.correct .value { color: #22c55e; }
.quiz-result-breakdown .quiz-stat.wrong .value { color: #ff6b6b; }
.quiz-result-breakdown .quiz-stat.missed .value { color: #ffd93d; }

.quiz-tiles-detail {
    border-top: 1px solid #1a2a4a;
    padding-top: 10px;
}

.quiz-tiles-detail .tile-group {
    margin-bottom: 8px;
}

.quiz-tiles-detail .tile-group:last-child {
    margin-bottom: 0;
}

.quiz-tiles-detail .group-label {
    display: block;
    font-size: 11px;
    color: #888;
    margin-bottom: 4px;
}

.quiz-tiles-detail .tiles {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.quiz-tiles-detail .tile-mini {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 11px;
    font-family: monospace;
    background: rgba(255, 255, 255, 0.1);
    color: #ccc;
}

.quiz-tiles-detail .tile-group.correct .tile-mini {
    background: rgba(34, 197, 94, 0.2);
    color: #22c55e;
}

.quiz-tiles-detail .tile-group.wrong .tile-mini {
    background: rgba(255, 107, 107, 0.2);
    color: #ff6b6b;
}

.quiz-tiles-detail .tile-group.missed .tile-mini {
    background: rgba(255, 217, 61, 0.2);
    color: #ffd93d;
}

.quiz-summary {
    background: #0f1a2e;
    padding: 12px;
    border-radius: 8px;
}

.accuracy-cards {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-bottom: 15px;
}

.accuracy-card {
    background: #0a1628;
    border-radius: 8px;
    padding: 12px;
    text-align: center;
}

.accuracy-label {
    color: #888;
    font-size: 11px;
    margin-bottom: 5px;
}

.accuracy-value {
    color: #8b5cf6;
    font-size: 20px;
    font-weight: bold;
}

.accuracy-trend {
    text-align: center;
    padding: 10px;
    background: #0a1628;
    border-radius: 6px;
    font-size: 13px;
}

.accuracy-trend.improving {
    color: #22c55e;
}

.accuracy-trend.declining {
    color: #ff6b6b;
}

.accuracy-trend.stable {
    color: #888;
}

.timeline-description {
    color: #888;
    font-size: 12px;
    margin: 0 0 12px 0;
}

.timeline-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.timeline-item {
    background: #0a1628;
    border-radius: 6px;
    padding: 12px;
    border-left: 3px solid #8b5cf6;
}

.timeline-item.pass {
    border-left-color: #ffd93d;
}

.timeline-item .timeline-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 6px;
}

.timeline-item .timeline-play {
    color: #888;
    font-size: 11px;
}

.timeline-item .timeline-type {
    font-size: 10px;
    padding: 2px 6px;
    background: rgba(139, 92, 246, 0.2);
    color: #8b5cf6;
    border-radius: 3px;
    text-transform: uppercase;
}

.timeline-item.pass .timeline-type {
    background: rgba(255, 217, 61, 0.2);
    color: #ffd93d;
}

.timeline-item .timeline-description {
    color: #ddd;
    font-size: 13px;
    margin: 0;
}

/* Responsive - Tablet */
@media (max-width: 800px) {
    .game-wrapper {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        flex-direction: row;
    }

    .log-area {
        max-height: 150px;
    }

    .table {
        min-height: 350px;
    }

    .stat-cards {
        grid-template-columns: repeat(2, 1fr);
    }

    .debrief-modal {
        max-height: 85vh;
    }

    .quiz-modal {
        max-height: 85vh;
    }

    .tile-grid {
        grid-template-columns: repeat(5, 1fr);
    }

    .accuracy-cards {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Responsive - Mobile */
@media (max-width: 480px) {
    body {
        padding: 5px;
    }

    /* Header adjustments */
    .app-header {
        flex-direction: column;
        gap: 6px;
        margin-bottom: 8px;
    }

    .header-buttons {
        position: static;
        justify-content: center;
        gap: 10px;
    }

    .attribution {
        position: static;
        font-size: 8px;
        margin-top: 0;
    }

    h1 {
        font-size: 1.2rem;
    }

    /* Larger icons and tap targets on mobile */
    .settings-btn svg,
    .help-btn svg,
    .docs-btn svg,
    .stats-btn svg {
        width: 26px;
        height: 26px;
    }

    .settings-btn,
    .help-btn,
    .docs-btn,
    .stats-btn {
        padding: 8px;
    }

    .lang-toggle {
        font-size: 13px;
        padding: 6px 10px;
    }

    /* Hide corner indicator on mobile — bottom stripe is sufficient */
    .player-indicator {
        display: none;
    }

    /* Table adjustments */
    .table {
        min-height: 280px;
        border-width: 8px;
        border-radius: 12px;
        grid-template-rows: 45px 1fr 45px;
        grid-template-columns: 45px 1fr 45px;
    }

    .player-name {
        font-size: 9px;
    }

    .mini-tile {
        width: 8px;
        height: 14px;
    }

    .tile-count.vertical .mini-tile {
        width: 14px;
        height: 8px;
    }

    /* Smaller dominoes on chain for mobile */
    .chain-container {
        padding: 5px;
    }

    .chain-paired-row,
    .chain-turn-pair {
        grid-template-columns: 1fr 46px 1fr;
    }

    .chain .domino.horizontal {
        width: 44px;
        height: 22px;
    }

    .chain .domino.vertical {
        width: 22px;
        height: 44px;
    }

    .chain .domino .domino-half {
        width: 20px;
        height: 20px;
        padding: 2px;
    }

    .chain .domino .pip {
        width: 4px;
        height: 4px;
    }

    .chain .domino.spinner {
        width: 22px;
        height: 44px;
    }

    /* Player indicator on chain tiles */
    .player-indicator {
        width: 10px;
        height: 10px;
        font-size: 6px;
        top: -3px;
        right: -3px;
    }

    /* Hand area - scrollable on mobile */
    .hand-area {
        padding: 8px;
    }

    .hand {
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        gap: 4px;
        padding-bottom: 5px;
        justify-content: flex-start;
    }

    /* Hand dominoes - slightly smaller */
    .hand .domino.horizontal {
        width: 48px;
        height: 24px;
        flex-shrink: 0;
    }

    .hand .domino .domino-half {
        width: 22px;
        height: 22px;
        padding: 2px;
    }

    .hand .domino .pip {
        width: 4px;
        height: 4px;
    }

    /* Genín advice */
    .genin-advice-icon {
        width: 36px;
        height: 36px;
    }

    .genin-speech-bubble {
        min-width: 180px;
        max-width: 260px;
        padding: 10px;
    }

    /* Larger touch targets for controls */
    .controls {
        gap: 6px;
    }

    button {
        padding: 12px 14px;
        font-size: 12px;
        min-height: 44px; /* Apple's minimum touch target */
    }

    .quiz-btn {
        padding: 12px 10px;
    }

    /* Scores - more compact */
    .scores {
        padding: 6px;
        gap: 20px;
    }

    .score-value {
        font-size: 18px;
    }

    .score-label {
        font-size: 10px;
    }

    /* Open ends indicator */
    .open-ends {
        font-size: 11px;
    }

    /* Attribution area */
    .attribution-area {
        margin-top: 5px;
    }

    .attribution-toggle {
        font-size: 10px;
    }

    .player-legend {
        gap: 8px;
        font-size: 9px;
    }

    .legend-dot {
        font-size: 10px;
    }

    /* Sidebar / Log area */
    .sidebar {
        order: 1;
    }

    .log-area {
        max-height: 120px;
    }

    .log {
        font-size: 10px;
    }

    .log-area h3 {
        font-size: 11px;
    }

    /* Modals - full screen on mobile */
    .end-selection,
    .message-box {
        width: 90%;
        max-width: none;
        padding: 15px;
    }

    .end-buttons {
        flex-direction: column;
        gap: 8px;
    }

    .end-btn {
        padding: 14px 20px;
        width: 100%;
    }

    .message-box p {
        font-size: 11px;
        max-height: 200px;
    }

    .message-buttons {
        flex-direction: column;
        gap: 8px;
    }

    .message-buttons button {
        width: 100%;
    }

    /* Quiz modal */
    .quiz-modal {
        width: 95%;
        max-height: 90vh;
    }

    .quiz-header {
        padding: 12px 15px;
    }

    .quiz-header h2 {
        font-size: 1rem;
    }

    .quiz-content {
        padding: 15px;
    }

    .quiz-target-buttons {
        flex-direction: column;
        gap: 6px;
    }

    .target-btn {
        padding: 12px;
    }

    .tile-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 4px;
    }

    .quiz-actions {
        flex-direction: column;
        gap: 8px;
    }

    .submit-quiz-btn,
    .skip-quiz-btn {
        width: 100%;
    }

    /* Debrief modal */
    .debrief-modal {
        width: 98%;
        max-height: 95vh;
    }

    .debrief-header {
        padding: 12px 15px;
    }

    .debrief-header h2 {
        font-size: 1.1rem;
    }

    .debrief-tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .tab-btn {
        padding: 10px 12px;
        font-size: 11px;
        white-space: nowrap;
    }

    .debrief-content {
        padding: 15px;
    }

    .stat-cards {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }

    .stat-card {
        padding: 10px;
    }

    .stat-value {
        font-size: 22px;
    }

    .accuracy-cards {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }

    .accuracy-card {
        padding: 10px;
    }

    .accuracy-value {
        font-size: 16px;
    }

    .debrief-footer {
        padding: 12px 15px;
        flex-direction: column;
        gap: 8px;
    }

    .debrief-footer button {
        width: 100%;
    }

    /* Help modal */
    .help-modal {
        width: 95%;
        max-height: 90vh;
    }

    .help-header {
        padding: 12px 15px;
    }

    .help-content {
        padding: 15px;
    }

    .help-section h3 {
        font-size: 0.9rem;
    }

    .help-section p,
    .help-section li {
        font-size: 13px;
    }

    /* Settings modal */
    .settings-modal {
        width: 95%;
    }

    .settings-content {
        padding: 15px;
    }

    .api-key-input-group {
        flex-direction: column;
    }

    .key-actions {
        flex-direction: column;
    }

    .key-actions button {
        width: 100%;
    }
}

/* Very small screens */
@media (max-width: 360px) {
    .table {
        min-height: 240px;
        grid-template-rows: 40px 1fr 40px;
        grid-template-columns: 40px 1fr 40px;
    }

    .chain-paired-row,
    .chain-turn-pair {
        grid-template-columns: 1fr 40px 1fr;
    }

    .chain .domino.horizontal {
        width: 38px;
        height: 19px;
    }

    .chain .domino.vertical {
        width: 19px;
        height: 38px;
    }

    .chain .domino .domino-half {
        width: 17px;
        height: 17px;
    }

    .chain .domino .pip {
        width: 3px;
        height: 3px;
    }

    .hand .domino.horizontal {
        width: 42px;
        height: 21px;
    }

    .hand .domino .domino-half {
        width: 19px;
        height: 19px;
    }

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

/* ==================== Stats Button ==================== */
.stats-btn {
    background: transparent;
    border: none;
    color: #888;
    cursor: pointer;
    padding: 5px;
    border-radius: 4px;
    transition: color 0.2s, background 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.stats-btn:hover {
    color: #00d4ff;
    background: rgba(0, 212, 255, 0.1);
}

/* ==================== Stats Modal ==================== */
.stats-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #16213e;
    border: 1px solid #333;
    border-radius: 12px;
    width: 90%;
    max-width: 560px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

.stats-modal.visible {
    opacity: 1;
    pointer-events: auto;
}

.stats-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid #333;
    flex-shrink: 0;
}

.stats-header h2 {
    margin: 0;
    font-size: 1.1rem;
    color: #00d4ff;
}

.stats-body {
    overflow-y: auto;
    padding: 16px 20px;
    flex: 1;
}

.stats-empty {
    text-align: center;
    color: #888;
    padding: 40px 0;
    font-size: 0.95rem;
}

.stats-section {
    margin-bottom: 24px;
}

.stats-section h3 {
    color: #00d4ff;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 0 0 10px 0;
    border-bottom: 1px solid #2a3a5a;
    padding-bottom: 6px;
}

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #0f1a2e;
    padding: 8px 12px;
    border-radius: 6px;
}

.stat-item .stat-label {
    font-size: 0.8rem;
    color: #888;
}

.stat-item .stat-value {
    font-size: 1rem;
    font-weight: bold;
    color: #eee;
}

/* Reason breakdown table */
.stats-reason-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
    font-size: 0.82rem;
}

.stats-reason-table th,
.stats-reason-table td {
    padding: 6px 10px;
    text-align: center;
    border: 1px solid #2a3a5a;
}

.stats-reason-table th {
    color: #888;
    background: #0f1a2e;
}

.stats-reason-table td:first-child {
    text-align: left;
    color: #aaa;
}

/* Badge grid */
.stats-badge-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.badge-card {
    background: #0f1a2e;
    border: 1px solid #2a3a5a;
    border-radius: 8px;
    padding: 12px 8px;
    text-align: center;
    transition: border-color 0.2s;
}

.badge-card.locked {
    opacity: 0.4;
    filter: grayscale(1);
}

.badge-card-icon {
    font-size: 1.8rem;
    margin-bottom: 6px;
}

.badge-card-title {
    font-size: 0.75rem;
    font-weight: bold;
    color: #eee;
    margin-bottom: 4px;
}

.badge-card-desc {
    font-size: 0.7rem;
    color: #888;
    line-height: 1.3;
}

/* ==================== Badge Toast ==================== */
#badge-toast-container {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: translateY(0); }
}

.badge-toast {
    display: flex;
    align-items: center;
    gap: 12px;
    background: #16213e;
    border: 1px solid #00d4ff;
    border-radius: 10px;
    padding: 12px 16px;
    min-width: 220px;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.4s, transform 0.4s;
    pointer-events: auto;
}

.badge-toast.visible {
    opacity: 1;
    transform: translateY(0);
}

.badge-toast-icon {
    font-size: 1.8rem;
    flex-shrink: 0;
}

.badge-toast-title {
    font-weight: bold;
    color: #eee;
    font-size: 0.9rem;
}

.badge-toast-earned {
    font-size: 0.75rem;
    color: #00d4ff;
}
