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

:root {
    --bg-page: #FAFAFA;
    --bg-card: #FFFFFF;
    --text-primary: #1A1A1A;
    --text-secondary: #666666;
    --text-muted: #999999;
    --border: #E0E0E0;
    --border-light: #F0F0F0;
    --accent: #333333;
    --accent-light: #555555;
    --danger: #D32F2F;
    --success: #2E7D32;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg-page);
    color: var(--text-primary);
    min-height: 100dvh;
    -webkit-font-smoothing: antialiased;
}

/* Interactive appearance overrides */
[data-appearance="interactive"][data-phase="bidding"] { --bg-page: #FFF9C4; --accent: #E65100; }
[data-appearance="interactive"][data-phase="playing"] { --bg-page: #FCE4EC; --accent: #C2185B; }
[data-appearance="interactive"][data-phase="roundend"] { --bg-page: #BBDEFB; --accent: #1565C0; }
[data-appearance="interactive"][data-phase="scoreboard"] { --bg-page: #E8EAF6; --accent: #283593; }
[data-appearance="interactive"][data-phase="home"] { --bg-page: #F3E5F5; --accent: #6A1B9A; }
[data-appearance="interactive"] { font-size: 1.1em; }

#app {
    max-width: 420px;
    margin: 0 auto;
    padding: 16px;
    min-height: 100dvh;
}

/* Typography */
h1 { font-size: 2rem; font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: 1.4rem; font-weight: 600; }
h3 { font-size: 1rem; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 8px; }

.logo { text-align: center; margin-top: 48px; font-size: 2.4rem; }
.tagline { text-align: center; color: var(--text-secondary); margin-top: 4px; margin-bottom: 32px; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 24px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.97); }
.btn-primary {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    width: 100%;
    padding: 14px;
    font-size: 1.05rem;
}
.btn-primary:active { background: var(--accent-light); }
.btn-large { padding: 16px; font-size: 1.1rem; margin-top: 16px; }
.btn-small { padding: 8px 16px; font-size: 0.9rem; border-radius: var(--radius-sm); }
.btn-text { background: none; border: none; color: var(--text-secondary); font-size: 0.95rem; padding: 8px 0; cursor: pointer; }
.btn-text:hover { color: var(--text-primary); }
.btn-danger { background: #E57373; color: #fff; border-color: #E57373; }
.btn-back { background: none; border: 1px solid var(--border); color: var(--text-muted); font-size: 0.9rem; }
.bid-nav { display: flex; gap: 8px; justify-content: center; margin-top: 12px; }
.btn-remove {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.3rem;
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
}
.btn-remove:hover { color: var(--danger); }

/* Forms */
.form { display: flex; flex-direction: column; gap: 12px; }
input[type="text"], input[type="password"], select {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    background: var(--bg-card);
    color: var(--text-primary);
    outline: none;
    transition: border-color 0.15s;
}
input:focus, select:focus { border-color: var(--accent); }
input::placeholder { color: var(--text-muted); }

/* Tabs */
.tabs {
    display: flex;
    gap: 0;
    margin-bottom: 20px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.tab {
    flex: 1;
    padding: 10px;
    text-align: center;
    background: var(--bg-card);
    border: none;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
}
.tab.active { background: var(--accent); color: #fff; }

/* Recent playgrounds */
.recent-list { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 4px; }
.recent-item {
    padding: 6px 14px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: var(--bg-card);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.15s;
}
.recent-item:active { background: var(--accent); color: #fff; }
/* Room finder panel */
.room-finder {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: 12px; padding: 10px 12px; margin-bottom: 12px;
}
.room-finder-header {
    display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px;
}
.room-finder-label {
    font-size: 0.75rem; font-weight: 600; text-transform: uppercase;
    letter-spacing: 0.5px; color: var(--text-muted);
}
.browse-toggle {
    background: none; border: none; padding: 4px 0; font-size: 0.8rem;
    color: var(--accent); cursor: pointer; min-height: 44px;
    display: inline-flex; align-items: center;
}
.browse-toggle:active { opacity: 0.6; }
.room-finder-list { display: flex; flex-wrap: wrap; gap: 6px; }
.room-finder-search {
    width: 100%; padding: 8px 10px; margin-bottom: 8px;
    border: 1px solid var(--border); border-radius: 8px;
    font-size: 0.875rem; background: var(--bg-card); box-sizing: border-box;
}
.room-finder-search:focus { outline: none; border-color: var(--accent); }
.browse-item { font-size: 0.875rem; padding: 8px 14px; min-height: 44px; display: inline-flex; align-items: center; }

/* Player list (home) */
.player-list { display: flex; flex-direction: column; gap: 8px; }
.player-input-row { display: flex; gap: 8px; align-items: center; }
.player-input-row input { flex: 1; }

/* Visibility */
.hidden { display: none !important; }
.visible { display: flex !important; }

/* Error */
.error { color: var(--danger); font-size: 0.9rem; text-align: center; margin-top: 4px; }

/* Lobby */
.lobby { display: flex; flex-direction: column; gap: 20px; }
.lobby-header { text-align: center; padding: 16px 0; position: relative; }
.share-code { color: var(--text-secondary); margin-top: 4px; font-size: 0.95rem; }
.share-code strong { font-family: monospace; font-size: 1.1rem; letter-spacing: 0.1em; }

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

.lobby-player-list { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.lobby-player {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 8px;
    background: var(--bg-page);
    border-radius: var(--radius-sm);
    transition: transform 0.15s;
    position: relative;
}
.lobby-player.dragging { opacity: 0.7; z-index: 10; background: var(--bg-card); box-shadow: 0 2px 8px rgba(0,0,0,0.15); }
.drag-handle { color: var(--text-muted); font-size: 1.2rem; cursor: grab; touch-action: none; user-select: none; padding: 4px; }
.player-name-display { flex: 1; font-weight: 500; }

.add-player-row { display: flex; gap: 8px; }
.add-player-row input { flex: 1; }

/* Settings */
.settings-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px 12px;
    align-items: center;
}
.settings-grid label { font-size: 0.95rem; color: var(--text-secondary); }
.settings-grid select { padding: 8px 10px; font-size: 0.9rem; }

/* Toggle */
.toggle { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.toggle input { width: 18px; height: 18px; accent-color: var(--accent); }
.toggle-label { font-size: 0.9rem; }

/* Error screen */
.error-screen {
    text-align: center;
    padding: 48px 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

/* Screen placeholder */
.screen {
    text-align: center;
    padding: 48px 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

/* Dealer/cards floating island */
.game-island {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    background: var(--bg-card);
    border-radius: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    margin: 0 auto 12px;
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
}
.game-island .island-sep { color: var(--border); }
.island-toggle {
    background: none; border: none; cursor: pointer;
    font-size: 1.1rem; font-weight: 700; color: var(--text-muted);
    padding: 0 4px; line-height: 1;
}
.game-island.island-collapsed { font-size: 0; gap: 0; padding: 8px 14px; }
.game-island.island-collapsed > span { display: none; }
.game-island.island-collapsed .island-toggle { font-size: 1.1rem; display: inline; }

/* Round info bar */
.round-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
}
.trump { font-size: 1.3rem; }
.trump-red, .trump-red .trump-symbol, .trump-red .trump-name { color: #D32F2F; }

/* Bidding */
.bidding, .roundend { display: flex; flex-direction: column; gap: 12px; }
.bid-player-name { font-size: 1.8rem; font-weight: 700; text-align: center; margin: 16px 0 4px; }
.bid-prompt { text-align: center; color: var(--text-secondary); font-size: 1rem; margin-bottom: 4px; }
.claimed-info { text-align: center; color: var(--text-muted); font-size: 0.85rem; margin-bottom: 8px; min-height: 1.2em; }
.trump-below { text-align: center; margin-top: 16px; }
.trump-symbol-sm { font-size: 12rem; display: block; }
.trump-label { color: var(--text-secondary); font-size: 1.5rem; display: block; font-weight: 600; }
.dealer-info { text-align: center; color: var(--text-muted); font-size: 0.95rem; }
.share-code-mini { font-family: monospace; font-size: 0.8rem; color: var(--text-muted); letter-spacing: 0.05em; }
.btn-refresh {
    background: none; border: 1px solid var(--border); border-radius: 50%;
    width: 32px; height: 32px; font-size: 1.2rem; cursor: pointer;
    color: var(--text-secondary); display: flex; align-items: center; justify-content: center;
}
.btn-refresh:active { background: var(--border); }
.btn-home {
    background: none; border: 1px solid var(--border); border-radius: 50%;
    width: 32px; height: 32px; font-size: 1.1rem; cursor: pointer;
    color: var(--text-secondary); display: flex; align-items: center; justify-content: center;
    text-decoration: none; filter: grayscale(1);
}
.btn-home:active { background: var(--border); }
.btn-danger {
    background: #dc3545; color: #fff; border: none; border-radius: 8px;
    padding: 8px 16px; font-size: 0.85rem; cursor: pointer;
}
.btn-danger:active { background: #a71d2a; }
.stats-actions {
    text-align: right; padding: 8px 0;
}
.stats-actions.hidden { display: none; }
.bid-value-display {
    font-size: 4rem;
    font-weight: 700;
    text-align: center;
    padding: 24px 0;
}

/* Keypad */
.keypad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    max-width: 280px;
    margin: 0 auto;
}
.keypad-key {
    padding: 18px;
    font-size: 1.5rem;
    font-weight: 600;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
    cursor: pointer;
    transition: all 0.1s;
    -webkit-tap-highlight-color: transparent;
}
.keypad-key:active { background: var(--accent); color: #fff; transform: scale(0.95); }
.keypad-selected { background: var(--accent); color: #fff; transform: scale(1.05); box-shadow: 0 2px 8px rgba(0,0,0,0.2); }
.keypad-disabled { opacity: 0.25; cursor: not-allowed; }

/* Review timer overlay — REMOVED, kept class for safety */
.review-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.7);
    display: flex; flex-direction: column; align-items: center;
    justify-content: center; z-index: 100; gap: 16px;
}
.review-value { font-size: 6rem; font-weight: 800; color: #fff; }
.review-countdown { font-size: 1.5rem; color: rgba(255,255,255,0.7); }
.review-actions { display: flex; gap: 12px; margin-top: 8px; }
.review-confirm {
    background: var(--accent); color: #fff; padding: 12px 32px;
    border-radius: 8px; font-size: 1.1rem; border: none; cursor: pointer;
}
.review-change {
    color: rgba(255,255,255,0.8); font-size: 1rem;
    background: none; border: none; cursor: pointer; text-decoration: underline;
}
/* Review screen — pre-final score editing */
.review-screen { padding: 16px 0; max-width: 600px; margin: 0 auto; }
.review-hint { text-align: center; color: var(--text-muted); font-size: 0.85rem; margin-bottom: 12px; }
.review-round-row { cursor: pointer; transition: background 0.15s; }
.review-round-row:hover { background: var(--bg-hover, rgba(0,0,0,0.04)); }
.review-round-row.review-editing { background: var(--accent-light, rgba(59,130,246,0.1)); }
.review-edit-panel {
    background: var(--bg-card); border-radius: var(--radius); padding: 16px;
    margin: 12px 0; border: 1px solid var(--border);
}
.review-edit-panel h3 { margin: 0 0 12px 0; font-size: 1rem; }

.keypad-disabled:active { background: var(--bg-card); color: var(--text-primary); transform: none; }

/* Inline keypad (compact, for editing bids on confirm screen) */
.inline-keypad { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; padding: 8px 4px; }
.inline-keypad-key {
    padding: 8px 14px; font-size: 1rem; font-weight: 600;
    border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--bg-card); cursor: pointer; min-width: 38px;
}
.inline-keypad-key:active { background: var(--accent); color: #fff; }
.bid-summary-row.must-lose-warn { background: rgba(220, 53, 69, 0.08); }
.bid-summary-row.must-lose-warn .bid-summary-value { color: var(--danger); }


/* Bid summary / confirm */
.bid-summary {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 12px;
    box-shadow: var(--shadow);
}
.bid-summary-row {
    display: flex;
    align-items: center;
    padding: 8px 4px;
    border-bottom: 1px solid var(--border-light);
    gap: 8px;
}
.bid-summary-row span:first-child { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bid-summary-row:last-child { border-bottom: none; }
.bid-summary-value { font-weight: 700; font-size: 1.2rem; width: 32px; text-align: center; flex-shrink: 0; }
.btn-edit { font-size: 0.8rem; }
.bid-total {
    text-align: center;
    padding: 8px;
    font-size: 0.95rem;
    color: var(--text-secondary);
}
.overbid-warn { color: var(--danger); font-weight: 600; margin-left: 4px; }
.mismatch-warn { color: var(--danger); }

/* Play screen */
.play { display: flex; flex-direction: column; gap: 16px; }
.trump-display {
    text-align: center;
    padding: 24px;
}
.trump-symbol { font-size: 12rem; display: block; }
.trump-name { font-size: 1.8rem; color: var(--text-secondary); margin-top: 4px; display: block; font-weight: 600; }
.play-info { text-align: center; }
.play-info p { margin: 4px 0; }
.play-minimal { color: var(--text-muted); font-style: italic; }
.play-bids {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 12px;
    box-shadow: var(--shadow);
}
.play-bid-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 4px;
    border-bottom: 1px solid var(--border-light);
}
.play-bid-row:last-child { border-bottom: none; }
.play-bid-value { font-weight: 600; }

/* Scoreboard */
.scoreboard { display: flex; flex-direction: column; gap: 16px; }
.score-table {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.score-table:not(.score-table-full) { overflow: hidden; }
.score-header {
    display: flex;
    justify-content: space-between;
    padding: 10px 16px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border);
}
.score-row {
    display: flex;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-light);
}
.score-row:last-child { border-bottom: none; }
.score-leader { font-weight: 600; }
.score-value { font-weight: 700; font-size: 1.1rem; }
.score-negative { color: var(--danger); }

/* Round history (collapsible) */
.round-history { margin-top: 4px; }
.round-history summary {
    font-size: 0.9rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px 0;
}
.history-table {
    background: var(--bg-card);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    margin-top: 8px;
    font-size: 0.85rem;
}
.history-header, .history-row {
    display: flex;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-light);
}
.history-header { font-weight: 600; color: var(--text-secondary); }
.history-header span, .history-row span { flex: 1; text-align: center; }
.history-header span:first-child, .history-row span:first-child { flex: 0.5; text-align: left; }

/* Full scoresheet table */
.score-table-full { overflow-x: auto; max-height: 60vh; overflow-y: auto; }
.scoresheet {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}
.scoresheet th, .scoresheet td {
    padding: 6px 8px;
    text-align: center;
    border: 1px solid var(--border-light);
}
.scoresheet thead th {
    position: sticky; top: 0; z-index: 1;
    background: var(--bg-card, #fff);
}
.scoresheet th { font-weight: 600; color: var(--text-secondary); text-transform: uppercase; font-size: 0.75rem; }
.scoresheet th:first-child, .scoresheet td:first-child { text-align: left; width: 32px; }
.scoresheet .round-score { font-size: 0.75rem; color: var(--text-muted); display: block; }
.scoresheet .running-total { font-weight: 700; font-size: 0.9rem; }
.scoresheet .totals-row td { border-top: 2px solid var(--border); padding-top: 8px; }

/* End game button (inline in round-info) */
.btn-end-game {
    font-size: 0.7rem;
    padding: 2px 8px;
    border: 1px solid var(--danger);
    color: var(--danger);
    border-radius: var(--radius);
    background: transparent;
    cursor: pointer;
}

/* Active game actions in lobby */
.active-game-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.active-game-actions .btn { flex: 1; min-width: 120px; }

.scoreboard-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }

/* Winner celebration (used on scoreboard game-over + final screen) */
.final-celebration {
    display: flex; flex-direction: column; align-items: center;
    gap: 4px; padding: 16px 0 8px; position: relative; overflow: hidden;
}

/* Confetti */
.confetti-container {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    pointer-events: none; overflow: hidden;
}
.confetti-piece {
    position: absolute; top: -10px; border-radius: 2px;
    animation: confetti-fall linear forwards;
    transform: rotate(0deg);
}
@keyframes confetti-fall {
    0% { transform: translateY(0) rotate(0deg); opacity: 1; }
    100% { transform: translateY(300px) rotate(720deg); opacity: 0; }
}

/* Player rankings */
.final-rankings {
    margin-top: 16px;
    background: var(--bg-card); border-radius: var(--radius);
    box-shadow: var(--shadow); overflow: hidden;
}
.rank-row {
    display: flex; align-items: center; padding: 12px 16px;
    border-bottom: 1px solid var(--border-light); gap: 12px;
}
.rank-row:last-child { border-bottom: none; }
.rank-first { font-weight: 700; font-size: 1.05rem; }
.rank-badge { font-size: 1.3rem; width: 32px; text-align: center; }
.rank-name { flex: 1; }
.rank-score { font-weight: 700; font-size: 1.1rem; }

/* Final screen */
.final { display: flex; flex-direction: column; align-items: center; gap: 12px; padding-top: 24px; }
.final-trophy { font-size: 4rem; }
.final-winner { font-size: 1.8rem; }
.final-score { font-size: 1.2rem; color: var(--text-secondary); }
.final-standings {
    width: 100%;
    background: var(--bg-card);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    margin-top: 12px;
}
.final-row {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-light);
    gap: 12px;
}
.final-row:last-child { border-bottom: none; }
.final-first { font-weight: 600; }
.final-rank { width: 24px; font-weight: 700; color: var(--text-muted); }
.final-name { flex: 1; }
.final-pts { font-weight: 700; }
.final-actions { margin-top: 16px; width: 100%; }

/* Stats */
.stats { display: flex; flex-direction: column; gap: 12px; }
.stats-empty { text-align: center; color: var(--text-muted); padding: 32px 0; }
.stats-tabs { display: flex; gap: 0; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.stats-tab {
    flex: 1; padding: 10px 4px; text-align: center; background: var(--bg-card);
    border: none; font-size: 0.85rem; font-weight: 500; color: var(--text-secondary); cursor: pointer;
}
.stats-tab.active { background: var(--accent); color: #fff; }
.stats-section { display: flex; flex-direction: column; gap: 8px; }

/* Leaderboard cards */
.stats-card {
    display: flex; gap: 12px; align-items: center;
    background: var(--bg-card); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow);
}
.stats-first { border: 2px solid var(--accent); }
.stats-rank { font-size: 1.4rem; font-weight: 700; min-width: 32px; text-align: center; color: var(--text-muted); }
.stats-card-body { flex: 1; }
.stats-name { font-weight: 600; font-size: 1.1rem; margin-bottom: 4px; }
.stats-detail { display: flex; justify-content: space-between; font-size: 0.85rem; color: var(--text-secondary); }
.stats-highlight { font-weight: 600; color: var(--accent); }
.stats-muted { color: var(--text-muted); font-size: 0.8rem; }

/* Accuracy bars */
.stats-bar-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; }
.stats-bar-name { width: 70px; font-size: 0.9rem; font-weight: 500; }
.stats-bar-track { flex: 1; height: 20px; background: var(--border-light); border-radius: 10px; overflow: hidden; }
.stats-bar-fill { height: 100%; background: var(--text-muted); border-radius: 10px; transition: width 0.3s; }
.stats-bar-good { background: var(--success); }
.stats-bar-value { width: 40px; text-align: right; font-weight: 600; font-size: 0.9rem; }

/* Trends */

/* Awards tables */
.awards-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}
.awards-table th {
    text-align: left;
    font-size: 0.7rem;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 4px 8px;
    border-bottom: 1px solid var(--border-light);
}
.awards-table td {
    padding: 6px 8px;
    border-bottom: 1px solid var(--border-light);
}
.awards-table th:first-child,
.awards-table td:first-child {
    width: 30px;
    text-align: center;
    color: var(--text-muted);
}
.awards-table th:last-child,
.awards-table td:last-child {
    text-align: right;
    width: 50px;
}

/* Game history cards */
.stats-game-card {
    background: var(--bg-card); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow);
}
.stats-game-header {
    display: flex; justify-content: space-between; font-size: 0.8rem; color: var(--text-muted);
    margin-bottom: 8px; padding-bottom: 6px; border-bottom: 1px solid var(--border-light);
}
.stats-mode { text-transform: capitalize; }
.stats-game-scores { display: flex; flex-direction: column; gap: 4px; }
.stats-game-player { display: flex; justify-content: space-between; font-size: 0.9rem; padding: 2px 0; }
.stats-game-winner { font-weight: 600; color: var(--accent); }

/* Game detail expand */
.game-detail { margin-top: 12px; border-top: 1px solid var(--border-light); padding-top: 8px; }
.game-detail-legend { display: flex; gap: 16px; font-size: 0.75rem; color: var(--text-muted); margin-bottom: 4px; }
.legend-item { display: flex; align-items: center; gap: 4px; }
.legend-swatch { width: 14px; height: 14px; border-radius: 3px; display: inline-block; }
.legend-overbid { background: #BBDEFB; }
.legend-underbid { background: #FFE0B2; }
.cell-overbid { background: #BBDEFB; }
.cell-underbid { background: #FFE0B2; }

/* How To section */
.howto { text-align: left; line-height: 1.6; }
.howto h3 { font-size: 1.1rem; margin-bottom: 12px; }
.howto h4 { font-size: 0.95rem; margin: 16px 0 8px; }
.howto p { font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 8px; }
.howto-steps { display: flex; flex-direction: column; gap: 12px; margin-bottom: 16px; }
.howto-step {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 12px;
    box-shadow: var(--shadow);
}
.howto-step strong { font-size: 0.9rem; display: block; margin-bottom: 4px; }
.howto-step p { margin: 0; font-size: 0.8rem; }
.howto-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    margin-bottom: 16px;
}
.howto-table th, .howto-table td {
    padding: 6px 10px;
    border: 1px solid var(--border-light);
    text-align: center;
}
.howto-table th {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-muted);
}

/* ── Personality Cards ── */

.personality-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 8px 0 16px;
}

.personality-card {
    width: 100%;
    height: 480px;
    perspective: 1000px;
    cursor: pointer;
}

@media (max-height: 700px) {
    .personality-card {
        height: 400px;
    }
}

.personality-card-inner {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.6s ease;
}

.personality-card.flipped .personality-card-inner {
    transform: rotateY(180deg);
}

.personality-front,
.personality-back {
    position: absolute;
    inset: 0;
    backface-visibility: hidden;
    border-radius: 16px;
    padding: 24px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    box-sizing: border-box;
}

.personality-front {
    background: linear-gradient(145deg, var(--card-color, #37474F), color-mix(in srgb, var(--card-color, #37474F) 70%, black));
    color: #fff;
    justify-content: center;
    gap: 4px;
}

.personality-back {
    background: #fff;
    color: var(--text-primary, #222);
    transform: rotateY(180deg);
    justify-content: flex-start;
    gap: 6px;
    overflow-y: auto;
}

.personality-badge {
    font-size: 0.65rem;
    opacity: 0.6;
    letter-spacing: 0.5px;
    align-self: flex-end;
}

.personality-icon {
    font-size: 3rem;
    line-height: 1;
    margin-bottom: 4px;
}

.personality-type {
    font-size: 1.4rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.personality-tagline {
    font-size: 0.9rem;
    opacity: 0.85;
    text-align: center;
    font-style: italic;
    max-width: 220px;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.personality-player-name {
    font-size: 1.1rem;
    font-weight: 600;
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.3);
    width: 100%;
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.personality-flip-hint {
    font-size: 0.7rem;
    opacity: 0.5;
    margin-top: auto;
    padding-top: 8px;
}

.personality-card-locked .personality-front {
    background: linear-gradient(145deg, #78909C, #546E7A);
}

.personality-unlock-bar {
    width: 80%;
    height: 6px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
    margin-top: 12px;
    overflow: hidden;
}

.personality-unlock-fill {
    height: 100%;
    background: rgba(255, 255, 255, 0.7);
    border-radius: 3px;
    transition: width 0.3s ease;
}

.personality-unlock-text {
    font-size: 0.8rem;
    opacity: 0.7;
    margin-top: 6px;
}

.personality-name {
    font-size: 1.2rem;
    font-weight: 600;
    margin-top: 8px;
}

/* Card back */

.personality-back-title {
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted, #666);
    width: 100%;
    margin-bottom: 4px;
}

.accuracy-chart {
    width: 100%;
}

.accuracy-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
    font-size: 0.8rem;
}

.accuracy-label {
    width: 16px;
    text-align: right;
    font-weight: 600;
    color: var(--text-muted, #666);
}

.accuracy-bar-track {
    flex: 1;
    height: 8px;
    background: #f0f0f0;
    border-radius: 4px;
    overflow: hidden;
}

.accuracy-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #66BB6A, #43A047);
    border-radius: 4px;
    transition: width 0.3s ease;
}

.accuracy-value {
    width: 32px;
    text-align: right;
    font-weight: 600;
    font-size: 0.75rem;
}

.accuracy-rounds {
    width: 24px;
    font-size: 0.65rem;
    color: var(--text-muted, #999);
}

.personality-insights {
    width: 100%;
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.insight-strength,
.insight-growth {
    font-size: 0.82rem;
    line-height: 1.4;
    padding: 6px 8px;
    border-radius: 8px;
}

.insight-strength {
    background: #E8F5E9;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.insight-growth {
    background: #FFF8E1;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.personality-meta {
    display: flex;
    justify-content: space-between;
    width: 100%;
    font-size: 0.7rem;
    color: var(--text-muted, #999);
    margin-top: auto;
    padding-top: 8px;
}

.personality-evolution {
    font-size: 0.75rem;
    color: var(--text-muted, #888);
    font-style: italic;
    width: 100%;
    text-align: center;
}

.card-top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin-bottom: 6px;
    padding-bottom: 6px;
    border-bottom: 1px solid #eee;
}

.top-bar-wins {
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--text-primary, #333);
}

.accuracy-dial-small {
    line-height: 0;
}

.stats-table-compact {
    width: 100%;
    margin: 6px 0;
}

.stats-table-row {
    display: flex;
    justify-content: space-between;
    padding: 3px 0;
    font-size: 0.78rem;
    border-bottom: 1px solid #f5f5f5;
}

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

.stats-table-label {
    color: var(--text-muted, #888);
}

.stats-table-value {
    font-weight: 600;
    color: var(--text-primary, #333);
}

.trend-badge {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 8px;
}

.trend-up {
    background: #E8F5E9;
    color: #2E7D32;
}

.trend-down {
    background: #FFF3E0;
    color: #E65100;
}

.trend-steady {
    background: #F5F5F5;
    color: #757575;
}

.fun-facts {
    width: 100%;
    margin-top: 4px;
}

.fun-fact {
    font-size: 0.72rem;
    color: var(--text-muted, #666);
    padding: 2px 0;
}

/* Edit mode — orange outer background, cards stay white */
.stats.edit-mode { background: #FF9800; border-radius: var(--radius); }
.stats.edit-mode .stats-content { background: var(--bg-card); border-radius: 12px; padding: 8px; }
.stats.edit-mode .stats-tabs { background: var(--bg-card); border-radius: 12px; }
.edit-mode-bar {
    background: #FFF3E0; border: 1px solid #FFB74D; color: #E65100;
    font-size: 0.8rem; font-weight: 600; padding: 8px 12px;
    border-radius: 8px; text-align: center; margin-bottom: 8px;
}

/* Action dialog overlay */
.action-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5); z-index: 100;
    display: flex; align-items: center; justify-content: center;
}
.action-overlay.hidden { display: none; }
.action-dialog {
    background: var(--bg-card); border-radius: 16px; padding: 20px;
    width: 90%; max-width: 320px; position: relative;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}
.action-dialog-close {
    position: absolute; top: 8px; right: 12px; background: none; border: none;
    font-size: 1.5rem; color: var(--text-muted); cursor: pointer;
    width: 44px; height: 44px; display: flex; align-items: center; justify-content: center;
}
.action-btn {
    display: block; width: 100%; min-height: 48px; padding: 12px 16px;
    border: none; border-radius: 10px; font-size: 0.95rem; font-weight: 600;
    cursor: pointer; margin-bottom: 10px; text-align: center;
}
.action-btn-warning { background: #FFF3E0; color: #E65100; border: 1px solid #FFB74D; }
.action-btn-warning:active { background: #FFE0B2; }
.action-btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.action-btn-danger:active { background: #FFEBEE; }
.action-btn-cancel { background: var(--bg-card); color: var(--text-secondary); border: 1px solid var(--border); }
.action-btn-danger-confirm { background: var(--danger); color: #fff; }
.action-btn-danger-confirm:disabled { opacity: 0.4; cursor: not-allowed; }

/* Clear stats warning */
.clear-warning { margin-top: 10px; }
.clear-warning.hidden { display: none; }
.clear-warning-text { font-size: 0.85rem; color: var(--danger); line-height: 1.4; margin: 0 0 10px; }
.clear-confirm-input {
    width: 100%; padding: 10px 12px; border: 1px solid var(--danger); border-radius: 8px;
    font-size: 0.9rem; margin-bottom: 10px; box-sizing: border-box;
}
.clear-actions { display: flex; gap: 8px; }
.clear-actions .action-btn { flex: 1; margin-bottom: 0; }

/* Edit auth input */
.edit-auth { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.edit-auth input {
    flex: 1; min-height: 44px; padding: 8px 12px;
    border: 1px solid var(--border); border-radius: 8px; font-size: 0.9rem;
}
.edit-auth input.auth-error { border-color: var(--danger); }
.edit-auth .action-btn { flex: 0 0 auto; width: auto; min-width: 60px; }

/* ── Responsive breakpoints ── */

/* Tablet (portrait & landscape) */
@media (min-width: 600px) {
    #app {
        max-width: 560px;
        padding: 24px;
    }
    .logo { margin-top: 64px; font-size: 2.8rem; }
    .keypad-grid { gap: 12px; }
    .keypad-grid button { padding: 18px; font-size: 1.6rem; }
    .personality-card { height: 520px; }
}

/* Desktop / large tablet */
@media (min-width: 900px) {
    #app {
        max-width: 680px;
        padding: 32px 40px;
        margin-top: 24px;
        margin-bottom: 24px;
        background: var(--bg-page);
        border-radius: 16px;
        box-shadow: var(--shadow-lg);
    }
    body { background: var(--bg-page, #EEEEEE); }
    [data-appearance="standard"] #app { background: var(--bg-card); }
    .logo { margin-top: 48px; }
    .btn-primary { max-width: 400px; margin-left: auto; margin-right: auto; }
    .scoresheet { font-size: 0.95rem; }
}
