:root {
    --bg-depth: #0a0d12;
    --bg-surface: #141820;
    --primary: #00e676;
    --secondary: #ff1744;
    --accent: #ffab00;
    --text-main: #f0f0f0;
    --text-muted: #8892a4;
    --glass: rgba(20, 24, 32, 0.8);
    --glass-border: rgba(255, 255, 255, 0.08);
    --radius: 12px;
}

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

body {
    font-family: 'Inter', 'Noto Sans JP', sans-serif;
    background: var(--bg-depth);
    color: var(--text-main);
    min-height: 100vh;
    overflow-x: hidden;
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
        radial-gradient(ellipse at 20% 20%, rgba(0,230,118,0.06) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 80%, rgba(255,23,68,0.06) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}

.app-wrap {
    position: relative;
    z-index: 1;
    max-width: 480px;
    margin: 0 auto;
    padding: 16px;
    min-height: 100vh;
}

/* --- Header --- */
.app-header {
    text-align: center;
    padding: 24px 0 16px;
}
.app-header h1 {
    font-size: 1.8rem;
    font-weight: 800;
    letter-spacing: 0.04em;
}
.app-header h1 a {
    text-decoration: none;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    border-bottom: 2px solid var(--primary);
    padding-bottom: 2px;
}
.app-header .subtitle {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 4px;
}

/* --- Glass Card --- */
.glass-card {
    background: var(--glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
}

/* --- Screens --- */
.screen { display: none; }
.screen.active { display: block; }

/* --- Setup Screen --- */
.mode-selector {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 16px;
}
.mode-btn {
    padding: 12px 8px;
    border: 2px solid var(--glass-border);
    border-radius: 8px;
    background: transparent;
    color: var(--text-main);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}
.mode-btn.selected {
    border-color: var(--primary);
    background: rgba(0, 230, 118, 0.1);
    color: var(--primary);
}
.mode-btn:hover { border-color: var(--primary); }

.option-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 0;
}
.option-row label {
    font-size: 0.85rem;
    color: var(--text-muted);
    flex: 1;
}
.option-row label.toggle-switch {
    flex: 0 0 44px;
}
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    min-width: 44px;
    height: 24px;
    cursor: pointer;
    flex: 0 0 44px;
}
.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}
.toggle-slider {
    position: absolute;
    inset: 0;
    background: #333;
    border-radius: 12px;
    cursor: pointer;
    transition: 0.3s;
}
.toggle-slider::before {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    left: 3px;
    bottom: 3px;
    background: #fff;
    border-radius: 50%;
    transition: 0.3s;
}
.toggle-switch input:checked + .toggle-slider {
    background: var(--primary);
}
.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(20px);
}

.player-inputs {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 12px 0;
}
.player-input-row {
    display: flex;
    gap: 8px;
    align-items: center;
}
.player-input-row input {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    background: rgba(255,255,255,0.05);
    color: var(--text-main);
    font-size: 0.9rem;
    outline: none;
}
.player-input-row input:focus {
    border-color: var(--primary);
}
.player-remove-btn {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background: rgba(255,23,68,0.2);
    color: var(--secondary);
    font-size: 1.1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.player-add-btn {
    padding: 8px;
    border: 1px dashed var(--glass-border);
    border-radius: 8px;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.85rem;
    cursor: pointer;
}
.player-add-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.btn-primary {
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--primary), #00c853);
    color: #000;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: opacity 0.2s;
    margin-top: 12px;
}
.btn-primary:hover { opacity: 0.9; }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-secondary {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    background: transparent;
    color: var(--text-main);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 8px;
}
.btn-secondary:hover {
    border-color: var(--primary);
    color: var(--primary);
}

/* --- Game Screen --- */
.game-info-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    font-size: 0.8rem;
    color: var(--text-muted);
}
.game-info-bar .round-info {
    font-weight: 600;
    color: var(--accent);
}

/* Scoreboard */
.scoreboard {
    margin-bottom: 12px;
}
.scoreboard-01 {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 4px;
}
.player-score-card {
    flex: 1;
    min-width: 80px;
    padding: 12px 8px;
    border-radius: 8px;
    background: var(--glass);
    border: 2px solid transparent;
    text-align: center;
    transition: border-color 0.3s;
}
.player-score-card.active {
    border-color: var(--primary);
    box-shadow: 0 0 12px rgba(0,230,118,0.2);
}
.player-score-card .player-name {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.player-score-card .player-score {
    font-size: 1.6rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
}

/* Cricket scoreboard */
.cricket-board {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}
.cricket-board th,
.cricket-board td {
    padding: 6px 4px;
    text-align: center;
    border-bottom: 1px solid var(--glass-border);
}
.cricket-board th {
    color: var(--text-muted);
    font-weight: 600;
}
.cricket-board .target-col {
    color: var(--accent);
    font-weight: 700;
}
.cricket-board td.active-col {
    background: rgba(0,230,118,0.08);
}
.cricket-mark { font-size: 0.9rem; }

/* Practice stats */
.practice-stats {
    padding: 4px 0;
}
.practice-stats .stats-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
}
.practice-stats .stat-item {
    padding: 8px 4px;
}
.practice-stats .stat-value {
    font-size: 1rem;
}

/* Current throws display */
.current-throws {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin: 12px 0;
}
.throw-slot {
    width: 64px;
    height: 64px;
    border: 2px dashed var(--glass-border);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    color: var(--text-muted);
    transition: all 0.3s;
}
.throw-slot.filled {
    border-style: solid;
    border-color: var(--primary);
    background: rgba(0,230,118,0.08);
    color: var(--text-main);
}
.throw-slot.bust {
    border-color: var(--secondary);
    background: rgba(255,23,68,0.1);
    color: var(--secondary);
}
.throw-slot .throw-points {
    font-size: 1.2rem;
    font-weight: 700;
}
.throw-slot .throw-label {
    font-size: 0.6rem;
    margin-top: 2px;
}

/* Input mode tabs */
.input-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 12px;
}
.input-tab {
    flex: 1;
    padding: 8px;
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    transition: all 0.2s;
}
.input-tab.active {
    border-color: var(--primary);
    color: var(--primary);
    background: rgba(0,230,118,0.08);
}
.input-panel { display: none; }
.input-panel.active { display: block; }

/* SVG Dartboard */
.board-container {
    display: flex;
    justify-content: center;
    padding: 8px 0;
}
.board-container svg {
    width: 100%;
    max-width: 360px;
    height: auto;
}

/* Manual input */
.manual-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
    margin-bottom: 12px;
}
.manual-num-btn {
    padding: 10px 4px;
    border: 1px solid var(--glass-border);
    border-radius: 6px;
    background: var(--glass);
    color: var(--text-main);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    transition: all 0.15s;
}
.manual-num-btn:active {
    background: rgba(0,230,118,0.2);
    border-color: var(--primary);
}
.manual-num-btn.selected {
    border-color: var(--accent);
    background: rgba(255,171,0,0.15);
    color: var(--accent);
}
.ring-selector {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    margin-bottom: 12px;
}
.ring-btn {
    padding: 10px 4px;
    border: 1px solid var(--glass-border);
    border-radius: 6px;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    transition: all 0.15s;
}
.ring-btn.selected {
    border-color: var(--primary);
    background: rgba(0,230,118,0.1);
    color: var(--primary);
}
.ring-btn:active { opacity: 0.7; }

/* Game action buttons */
.game-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}
.game-actions button {
    flex: 1;
    padding: 10px;
    border-radius: 8px;
    border: none;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
}
.btn-undo {
    background: rgba(255,255,255,0.1);
    color: var(--text-main);
}
.btn-next {
    background: var(--primary);
    color: #000;
}
.btn-miss {
    background: rgba(255,23,68,0.2);
    color: var(--secondary);
}

/* Checkout suggestion */
.checkout-hint {
    padding: 8px 12px;
    border-radius: 8px;
    background: rgba(255,171,0,0.1);
    border: 1px solid rgba(255,171,0,0.2);
    font-size: 0.75rem;
    color: var(--accent);
    text-align: center;
    margin: 8px 0;
}

/* --- Results Screen --- */
.result-title {
    font-size: 1.4rem;
    font-weight: 800;
    text-align: center;
    margin-bottom: 8px;
}
.result-winner {
    text-align: center;
    font-size: 1.1rem;
    color: var(--accent);
    margin-bottom: 16px;
}
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 16px;
}
.stat-item {
    padding: 12px;
    border-radius: 8px;
    background: rgba(255,255,255,0.04);
    text-align: center;
}
.stat-item .stat-label {
    font-size: 0.7rem;
    color: var(--text-muted);
}
.stat-item .stat-value {
    font-size: 1.3rem;
    font-weight: 700;
    margin-top: 4px;
}

/* --- Edit dialog --- */
.dialog-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.dialog-card {
    width: 100%;
    max-width: 400px;
    max-height: 80vh;
    overflow-y: auto;
    animation: fadeIn 0.2s ease-out;
}
.dialog-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    font-weight: 700;
    font-size: 0.95rem;
}
.dialog-close {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background: rgba(255,255,255,0.1);
    color: var(--text-main);
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.dialog-actions {
    display: flex;
    gap: 8px;
    margin-top: 16px;
}
.dialog-actions .btn-secondary,
.dialog-actions .btn-primary {
    flex: 1;
    margin-top: 0;
}
.edit-throw-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 0;
    border-bottom: 1px solid var(--glass-border);
}
.edit-throw-row:last-child { border-bottom: none; }
.edit-throw-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    width: 40px;
    flex-shrink: 0;
}
.edit-throw-select {
    flex: 1;
    padding: 8px 10px;
    border: 1px solid var(--glass-border);
    border-radius: 6px;
    background: var(--bg-surface);
    color: var(--text-main);
    font-size: 0.85rem;
    outline: none;
}
.edit-throw-select option {
    background: var(--bg-surface);
    color: var(--text-main);
}
.edit-throw-select:focus {
    border-color: var(--primary);
}
.edit-throw-pts {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--primary);
    width: 36px;
    text-align: right;
    flex-shrink: 0;
}

/* --- History table --- */
.history-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.75rem;
}
.history-table th,
.history-table td {
    padding: 6px 6px;
    text-align: center;
    border-bottom: 1px solid var(--glass-border);
}
.history-table th {
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.7rem;
}
.history-round {
    color: var(--accent);
    font-weight: 700;
}
.history-throws {
    color: var(--text-muted);
    font-size: 0.7rem;
}
.history-total {
    font-weight: 700;
    color: var(--primary);
}
.history-total.bust {
    color: var(--secondary);
}
.history-cell-clickable {
    cursor: pointer;
    transition: background 0.15s;
}
.history-cell-clickable:hover {
    background: rgba(255,255,255,0.06);
}

/* --- Practice history page --- */
.chart-container {
    overflow-x: auto;
}
.chart-bars {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    padding-bottom: 20px;
    min-width: fit-content;
}
.chart-bar-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
    min-width: 32px;
}
.chart-bar {
    width: 100%;
    max-width: 28px;
    background: linear-gradient(180deg, var(--primary), rgba(0,230,118,0.3));
    border-radius: 4px 4px 0 0;
    transition: height 0.3s;
}
.chart-bar-val {
    font-size: 0.6rem;
    color: var(--primary);
    font-weight: 700;
    margin-top: 4px;
}
.chart-bar-label {
    font-size: 0.55rem;
    color: var(--text-muted);
    margin-top: 2px;
}
.btn-clear-records {
    padding: 4px 10px;
    border: 1px solid rgba(255,23,68,0.3);
    border-radius: 6px;
    background: transparent;
    color: var(--secondary);
    font-size: 0.7rem;
    font-weight: 600;
    cursor: pointer;
}
.btn-clear-records:hover {
    background: rgba(255,23,68,0.1);
}
.btn-delete-record {
    width: 24px;
    height: 24px;
    border: none;
    border-radius: 50%;
    background: rgba(255,23,68,0.15);
    color: var(--secondary);
    font-size: 0.9rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}
.btn-delete-record:hover {
    background: rgba(255,23,68,0.3);
}

/* --- Animations --- */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
.fade-in {
    animation: fadeIn 0.3s ease-out;
}
@keyframes scoreFlash {
    0% { transform: scale(1); }
    50% { transform: scale(1.15); }
    100% { transform: scale(1); }
}
.score-flash {
    animation: scoreFlash 0.3s ease;
}
@keyframes bustFlash {
    0%, 100% { background: transparent; }
    50% { background: rgba(255,23,68,0.15); }
}
.bust-flash {
    animation: bustFlash 0.4s ease;
}

/* --- Responsive: small mobile --- */
@media (max-width: 380px) {
    .app-wrap { padding: 8px; }
    .glass-card { padding: 14px; }
    .player-score-card .player-score { font-size: 1.3rem; }
    .manual-grid { grid-template-columns: repeat(4, 1fr); }
}

/* --- Responsive: PC / wide screen --- */
@media (min-width: 769px) {
    .app-wrap {
        max-width: 1100px;
        padding: 24px 32px;
    }

    .app-header h1 { font-size: 2.4rem; }
    .app-header .subtitle { font-size: 0.95rem; }

    /* Setup: side-by-side cards */
    #setup-screen {
        display: none;
        max-width: 700px;
        margin: 0 auto;
    }
    #setup-screen.active {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 16px;
        align-items: start;
    }
    #setup-screen .btn-primary {
        grid-column: 1 / -1;
    }
    .mode-selector {
        grid-template-columns: 1fr 1fr 1fr;
    }

    /* Game: two-column layout */
    .game-layout {
        display: grid;
        grid-template-columns: 380px 1fr;
        gap: 24px;
        align-items: start;
    }

    .game-col-score .glass-card {
        position: sticky;
        top: 24px;
    }

    .player-score-card .player-score {
        font-size: 2rem;
    }
    .player-score-card .player-name {
        font-size: 0.85rem;
    }

    .throw-slot {
        width: 80px;
        height: 80px;
    }
    .throw-slot .throw-points { font-size: 1.5rem; }
    .throw-slot .throw-label { font-size: 0.7rem; }

    .board-container svg {
        max-width: 520px;
    }

    .game-actions button {
        padding: 14px;
        font-size: 0.95rem;
    }

    .manual-grid {
        grid-template-columns: repeat(7, 1fr);
    }
    .ring-selector {
        grid-template-columns: repeat(5, 1fr);
    }

    /* Result: wider stats */
    #result-screen {
        max-width: 700px;
        margin: 0 auto;
    }
    .stats-grid {
        grid-template-columns: repeat(4, 1fr);
    }
    .result-title { font-size: 1.8rem; }
    .result-winner { font-size: 1.3rem; }

    /* Practice stats on PC */
    .practice-stats .stats-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 10px;
    }
    .practice-stats .stat-value {
        font-size: 1.2rem;
    }
}

/* Footer & Ad */
.dart-footer {
    width: 100%;
    max-width: 900px;
    margin: 40px auto 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
    padding: 0 16px 24px;
}
.ad-area {
    width: 100%;
    max-width: 600px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 16px;
    padding: 15px;
    text-align: center;
}
.ad-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin: 0 0 10px;
}
.footer-links {
    text-align: center;
    padding-bottom: 12px;
}
.back-link {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.9rem;
    transition: color 0.2s ease;
}
.back-link:hover {
    color: #fff;
}
