/* ═══════════════════════════════════════════════════
   DOTS & BOXES — CLEAN, BRIGHT PAPER-STYLE THEME
   (Inspired by gametable.org)
   ═══════════════════════════════════════════════════ */

:root {
    --bg-page: #f8fafc;
    --bg-card: #ffffff;
    --bg-subtle: #f1f5f9;
    --bg-hover: #e2e8f0;

    --border: #e2e8f0;
    --border-dark: #cbd5e1;

    --text-main: #0f172a;
    --text-muted: #64748b;
    --text-light: #94a3b8;

    /* Player 1 (Blue) */
    --p1-color: #2563eb;
    --p1-dark: #1d4ed8;
    --p1-light: #eff6ff;
    --p1-fill: rgba(37, 99, 235, 0.12);
    --p1-border: rgba(37, 99, 235, 0.25);

    /* Player 2 (Red/Coral) */
    --p2-color: #e11d48;
    --p2-dark: #be123c;
    --p2-light: #fff1f2;
    --p2-fill: rgba(225, 29, 72, 0.12);
    --p2-border: rgba(225, 29, 72, 0.25);

    /* Neutral Dots & Inactive Edges */
    --dot-color: #334155;
    --edge-empty: #e2e8f0;
    --edge-empty-hover: #94a3b8;

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-full: 9999px;

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
    --shadow-card: 0 4px 20px -2px rgba(15, 23, 42, 0.08);
    --shadow-elevated: 0 12px 35px -4px rgba(15, 23, 42, 0.12);

    --font-sans: 'Plus Jakarta Sans', -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
}

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

body {
    font-family: var(--font-sans);
    background: var(--bg-page);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

.game-wrapper {
    width: 100%;
    max-width: 680px;
    padding: 16px 20px 40px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* ═══════════════ HEADER ═══════════════ */
.game-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 0 8px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
}

.logo-dots {
    display: grid;
    grid-template-columns: repeat(2, 6px);
    gap: 4px;
}

.logo-dots i {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--p1-color);
    display: block;
}

.logo-dots i:nth-child(2),
.logo-dots i:nth-child(3) {
    background: var(--p2-color);
}

.logo-text {
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--text-main);
    letter-spacing: -0.02em;
}

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

.conn-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
}

.conn-status .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-light);
}

.conn-status .dot.connected {
    background: #10b981;
    box-shadow: 0 0 6px rgba(16, 185, 129, 0.4);
}

.conn-status .dot.disconnected {
    background: #ef4444;
}

.header-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 600;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: all 0.15s ease;
}

.header-btn:hover {
    color: var(--text-main);
    border-color: var(--border-dark);
}

/* ═══════════════ TOOLBAR CONTROLS ═══════════════ */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-card);
    border: 1px solid var(--border);
    padding: 10px 16px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-card);
    flex-wrap: wrap;
    gap: 12px;
}

.tool-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.tool-group label {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.select-wrapper {
    position: relative;
}

.game-select {
    appearance: none;
    background: var(--bg-subtle);
    border: 1px solid var(--border);
    color: var(--text-main);
    font-family: var(--font-sans);
    font-size: 0.82rem;
    font-weight: 700;
    padding: 6px 28px 6px 10px;
    border-radius: var(--radius-sm);
    outline: none;
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    transition: border-color 0.15s ease;
}

.game-select:focus {
    border-color: var(--p1-color);
}

.seg-control {
    display: flex;
    background: var(--bg-subtle);
    padding: 3px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    gap: 2px;
}

.seg-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-family: var(--font-sans);
    font-size: 0.78rem;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.seg-btn:hover {
    color: var(--text-main);
}

.seg-btn.active {
    background: var(--bg-card);
    color: var(--text-main);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.btn-restart {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--text-main);
    border: none;
    color: #ffffff;
    font-family: var(--font-sans);
    font-size: 0.82rem;
    font-weight: 700;
    padding: 7px 14px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.15s ease;
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.2);
}

.btn-restart:hover {
    background: #334155;
    transform: translateY(-1px);
}

/* ═══════════════ SCOREBOARD ═══════════════ */
.scoreboard {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 12px;
    align-items: center;
}

.score-card {
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: var(--shadow-sm);
    transition: all 0.25s ease;
}

.score-card.p1 {
    justify-content: flex-start;
}

.score-card.p2 {
    justify-content: flex-end;
}

.score-card.p1.active-turn {
    border-color: var(--p1-color);
    background: var(--p1-light);
    box-shadow: 0 4px 14px var(--p1-border);
}

.score-card.p2.active-turn {
    border-color: var(--p2-color);
    background: var(--p2-light);
    box-shadow: 0 4px 14px var(--p2-border);
}

.score-avatar {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 0.75rem;
    letter-spacing: 0.04em;
    flex-shrink: 0;
}

.score-avatar.p1 {
    background: var(--p1-color);
    color: #ffffff;
}

.score-avatar.p2 {
    background: var(--p2-color);
    color: #ffffff;
}

.score-info {
    display: flex;
    flex-direction: column;
}

.score-info.right {
    text-align: right;
}

.score-title {
    font-size: 0.85rem;
    font-weight: 800;
    color: var(--text-main);
}

.score-status {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
}

.score-card.p1.active-turn .score-status {
    color: var(--p1-color);
    font-weight: 700;
}

.score-card.p2.active-turn .score-status {
    color: var(--p2-color);
    font-weight: 700;
}

.score-digits {
    font-size: 1.8rem;
    font-family: var(--font-mono);
    font-weight: 800;
    color: var(--text-main);
    line-height: 1;
    margin-left: auto;
}

.score-card.p2 .score-digits {
    margin-left: 0;
    margin-right: auto;
}

.score-card.p1.active-turn .score-digits { color: var(--p1-color); }
.score-card.p2.active-turn .score-digits { color: var(--p2-color); }

.score-divider {
    font-size: 0.75rem;
    font-weight: 800;
    color: var(--text-light);
}

/* ═══════════════ BOARD STAGE ═══════════════ */
.board-container {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px 0;
}

.board-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 32px;
    box-shadow: var(--shadow-elevated);
    display: flex;
    justify-content: center;
    align-items: center;
    user-select: none;
}

#game-board {
    display: grid;
    position: relative;
    user-select: none;
}

/* Dots */
.dot {
    width: 14px;
    height: 14px;
    background: var(--dot-color);
    border-radius: 50%;
    z-index: 5;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

/* Edges */
.edge {
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.edge-line {
    border-radius: 3px;
    background: var(--edge-empty);
    transition: all 0.15s ease;
}

.edge-h {
    width: 60px;
    height: 14px;
}

.edge-h .edge-line {
    width: 100%;
    height: 4px;
}

.edge-h:not(.placed):hover .edge-line {
    background: var(--edge-empty-hover);
    height: 6px;
}

.edge-v {
    width: 14px;
    height: 60px;
}

.edge-v .edge-line {
    width: 4px;
    height: 100%;
}

.edge-v:not(.placed):hover .edge-line {
    background: var(--edge-empty-hover);
    width: 6px;
}

/* Placed Edges */
.edge.placed.p1 .edge-line {
    background: var(--p1-color);
    height: 6px;
    box-shadow: 0 2px 6px rgba(37, 99, 235, 0.35);
}

.edge.placed.p2 .edge-line {
    background: var(--p2-color);
    height: 6px;
    box-shadow: 0 2px 6px rgba(225, 29, 72, 0.35);
}

.edge-v.placed.p1 .edge-line {
    width: 6px;
    height: 100%;
}

.edge-v.placed.p2 .edge-line {
    width: 6px;
    height: 100%;
}

/* Disabled Edges during AI Turn */
.edge.disabled {
    cursor: default;
}

.edge.disabled:not(.placed):hover .edge-line {
    background: var(--edge-empty);
    height: 4px;
    width: 4px;
}

/* Boxes */
.box-cell {
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
    font-weight: 800;
    border-radius: 6px;
    transition: all 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.box-cell.p1-box {
    background: var(--p1-fill);
    color: var(--p1-color);
    border: 1px solid var(--p1-border);
    animation: boxPop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.box-cell.p2-box {
    background: var(--p2-fill);
    color: var(--p2-color);
    border: 1px solid var(--p2-border);
    animation: boxPop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes boxPop {
    0% { transform: scale(0.6); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

/* Footer Instructions */
.game-footer {
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-muted);
    padding: 8px 0;
}

/* ═══════════════ GAME OVER MODAL ═══════════════ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    z-index: 100;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-overlay.show {
    display: flex;
    animation: modalIn 0.2s ease;
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.modal-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 32px 28px;
    width: 100%;
    max-width: 380px;
    text-align: center;
    box-shadow: var(--shadow-elevated);
}

.modal-badge {
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.modal-headline {
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--text-main);
    margin-bottom: 8px;
}

.modal-headline.win { color: var(--p1-color); }
.modal-headline.lose { color: var(--p2-color); }
.modal-headline.draw { color: #f59e0b; }

.modal-score {
    font-size: 2.2rem;
    font-family: var(--font-mono);
    font-weight: 800;
    margin-bottom: 8px;
}

.modal-sub {
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-bottom: 24px;
}

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

.btn-modal-primary {
    background: var(--text-main);
    border: none;
    color: #ffffff;
    font-family: var(--font-sans);
    font-size: 0.9rem;
    font-weight: 700;
    padding: 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn-modal-primary:hover {
    background: #334155;
}

.btn-modal-secondary {
    background: transparent;
    border: 1px solid var(--border-dark);
    color: var(--text-main);
    font-family: var(--font-sans);
    font-size: 0.85rem;
    font-weight: 600;
    padding: 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.btn-modal-secondary:hover {
    background: var(--bg-subtle);
}

/* ═══════════════ HISTORY DRAWER ═══════════════ */
.history-drawer {
    position: fixed;
    top: 0;
    right: -360px;
    width: 340px;
    height: 100vh;
    background: var(--bg-card);
    border-left: 1px solid var(--border);
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.08);
    z-index: 120;
    transition: right 0.25s ease;
    display: flex;
    flex-direction: column;
}

.history-drawer.open {
    right: 0;
}

.drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.drawer-header h3 {
    font-size: 0.95rem;
    font-weight: 800;
}

.drawer-close {
    background: transparent;
    border: none;
    font-size: 1.1rem;
    color: var(--text-muted);
    cursor: pointer;
}

.drawer-close:hover {
    color: var(--text-main);
}

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

.history-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.78rem;
    text-align: left;
}

.history-table th {
    color: var(--text-muted);
    font-weight: 700;
    padding: 6px 8px;
    border-bottom: 1px solid var(--border);
}

.history-table td {
    padding: 8px;
    border-bottom: 1px solid var(--bg-subtle);
}

.empty-text {
    text-align: center;
    color: var(--text-muted);
    padding: 20px 0;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(80px);
    background: var(--text-main);
    color: #ffffff;
    padding: 8px 18px;
    border-radius: var(--radius-full);
    font-size: 0.8rem;
    font-weight: 600;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
    z-index: 200;
    transition: transform 0.2s ease;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
}

.toast.error {
    background: #ef4444;
}

/* Responsive */
@media (max-width: 600px) {
    .toolbar {
        flex-direction: column;
        align-items: stretch;
    }
    .tool-group {
        justify-content: space-between;
    }
    .btn-restart {
        justify-content: center;
    }
}