/* Tic-Tac-Toe — dumbshit.app */

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

:root {
    --bg: #09090b;
    --bg-2: #18181b;
    --bg-3: #27272a;
    --border: #3f3f46;
    --text: #fafafa;
    --text-dim: #a1a1aa;
    --text-mute: #71717a;
    --accent: #10b981;
    --accent-hov: #34d399;
    --danger: #ef4444;
    --warn: #fbbf24;
    --x-color: #ec4899;     /* pink */
    --o-color: #06b6d4;     /* cyan */
    --win-color: #fbbf24;   /* gold */
}

html, body {
    margin: 0; padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }

/* ===== topbar ===== */
.topbar {
    padding: 24px 24px 8px;
    max-width: 1100px;
    margin: 0 auto;
}
.back { color: var(--text-mute); text-decoration: none; font-family: ui-monospace, monospace; font-size: 12px; }
.back:hover { color: var(--text); }
.topbar h1 { margin: 12px 0 4px; font-size: clamp(28px, 4vw, 40px); font-weight: 800; letter-spacing: -0.02em; }
.topbar .sub { margin: 0; color: var(--text-dim); font-size: 15px; }

.app {
    max-width: 1100px;
    margin: 0 auto;
    padding: 16px 24px 60px;
}

/* ===== forms / cards ===== */
.card {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 18px;
    max-width: 480px;
    margin: 16px auto;
}
.field { display: block; margin-bottom: 12px; }
.lbl {
    display: block;
    font-family: ui-monospace, monospace;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 10px;
    color: var(--text-mute);
    margin-bottom: 6px;
}
input[type=text] {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    font-family: inherit;
    font-size: 15px;
    padding: 11px 14px;
    width: 100%;
    transition: border-color 0.15s;
}
input[type=text]:focus { outline: none; border-color: var(--accent); }
.btn {
    appearance: none;
    border: 1px solid var(--border);
    background: var(--bg-3);
    color: var(--text);
    font-family: inherit;
    font-weight: 600;
    font-size: 14px;
    padding: 11px 16px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.12s;
    width: 100%;
    margin-top: 6px;
}
.btn:hover:not(:disabled) { background: var(--border); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--bg); border-color: var(--accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hov); border-color: var(--accent-hov); }
.btn-ghost {
    appearance: none;
    background: transparent;
    color: var(--text-mute);
    border: 0;
    cursor: pointer;
    font-family: ui-monospace, monospace;
    font-size: 12px;
    padding: 6px 10px;
    border-radius: 6px;
    width: auto;
}
.btn-ghost:hover { color: var(--text); }
.hint { color: var(--text-mute); font-size: 12px; margin: 4px 0; }

/* ===== tabs ===== */
.tabs { display: flex; gap: 4px; background: var(--bg); border-radius: 8px; padding: 4px; margin-bottom: 12px; }
.tab {
    appearance: none;
    border: 0;
    background: transparent;
    color: var(--text-mute);
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    padding: 7px 12px;
    border-radius: 6px;
    cursor: pointer;
    flex: 1;
}
.tab:hover { color: var(--text); }
.tab.is-active { background: var(--bg-3); color: var(--text); }
.pane { padding-top: 4px; }
.chk { display: flex; align-items: center; gap: 8px; color: var(--text-dim); font-size: 13px; margin-bottom: 10px; cursor: pointer; }
.chk input { width: 16px; height: 16px; accent-color: var(--accent); }

.lobby-head { display: flex; align-items: center; justify-content: space-between; font-family: ui-monospace, monospace; font-size: 11px; color: var(--text-mute); margin-bottom: 8px; }
.lobby-head .dot { display: inline-block; width: 6px; height: 6px; border-radius: 999px; background: var(--accent); margin-left: 4px; animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 0.4; } 50% { opacity: 1; } }
.lobby-head .count { color: var(--text-dim); }
.lobby-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 4px; max-height: 240px; overflow-y: auto; }
.lobby-list .empty { color: var(--text-mute); font-style: italic; text-align: center; padding: 14px; font-size: 13px; }
.lobby-list .lobby-row {
    display: grid;
    grid-template-columns: 1fr auto auto;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: ui-monospace, monospace;
    font-size: 12px;
}
.lobby-list .lobby-row .who { color: var(--text); }
.lobby-list .lobby-row .when { color: var(--text-mute); font-size: 11px; }
.lobby-list .lobby-row .join {
    appearance: none;
    border: 0;
    background: var(--accent);
    color: var(--bg);
    padding: 5px 10px;
    border-radius: 6px;
    font-family: inherit;
    font-weight: 600;
    font-size: 11px;
    cursor: pointer;
}
.lobby-list .lobby-row .join:hover { background: var(--accent-hov); }

/* ===== waiting screen ===== */
.share-row { display: flex; gap: 6px; margin: 12px 0; }
.share-row input { flex: 1; font-family: ui-monospace, monospace; font-size: 12px; color: var(--text-dim); }
.share-row .btn { width: auto; margin: 0; padding: 11px 14px; }
.waiting-status { display: flex; align-items: center; gap: 8px; color: var(--text-dim); font-family: ui-monospace, monospace; font-size: 12px; margin: 12px 0; }
.waiting-status .pulse { width: 8px; height: 8px; border-radius: 999px; background: var(--accent); animation: pulse 1.6s ease-in-out infinite; }
.join-sub { color: var(--text-dim); margin-top: 0; }
.join-error { margin-top: 10px; padding: 10px 12px; background: rgba(239,68,68,0.08); border: 1px solid var(--danger); border-radius: 8px; color: #fecaca; font-size: 13px; }

/* ===== game shell ===== */
.game-shell {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 16px;
    align-items: start;
}
.game-main {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 20px;
    position: relative;
}

/* ===== scoreboard ===== */
.scoreboard {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 12px;
    margin-bottom: 18px;
}
.score-side {
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: ui-monospace, monospace;
}
.score-side.end { justify-content: flex-end; }
.score-alias { color: var(--text); font-weight: 700; font-size: 14px; max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.score-mark { color: var(--text-mute); font-size: 11px; }
.score-side:nth-child(1) .score-mark { color: var(--x-color); }
.score-side:nth-child(3) .score-mark { color: var(--o-color); }
.score-num {
    font-size: 28px;
    font-weight: 800;
    color: var(--text);
    font-variant-numeric: tabular-nums;
    min-width: 28px;
    text-align: center;
}
.game-counter {
    font-family: ui-monospace, monospace;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-mute);
    text-align: center;
}

/* ===== board ===== */
.board {
    position: relative;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 6px;
    aspect-ratio: 1 / 1;
    max-width: 420px;
    margin: 0 auto;
    padding: 6px;
    border-radius: 14px;
    background: var(--bg-3);
    transition: box-shadow 0.2s, opacity 0.2s;
}
.board.my-turn  { box-shadow: 0 0 0 2px var(--accent), 0 0 32px rgba(16,185,129,0.25); }
.board.opp-turn { opacity: 0.65; }
.board.over     { opacity: 1; }

.cell {
    appearance: none;
    border: 0;
    background: var(--bg);
    border-radius: 8px;
    aspect-ratio: 1 / 1;
    cursor: pointer;
    display: grid;
    place-items: center;
    transition: background 0.12s, transform 0.06s;
    padding: 0;
}
.cell:hover:not(:disabled):not(.filled) { background: var(--bg-2); }
.cell:active:not(:disabled):not(.filled) { transform: scale(0.97); }
.cell.filled { cursor: default; }
.cell svg { width: 70%; height: 70%; display: block; }

/* ===== X / O marks ===== */
.mark-x line {
    stroke: var(--x-color);
    stroke-width: 10;
    stroke-linecap: round;
    fill: none;
    stroke-dasharray: 86;       /* approx hypotenuse */
    stroke-dashoffset: 86;
    animation: drawStroke 0.22s ease-out forwards;
}
.mark-x line:nth-child(2) { animation-delay: 0.18s; }

.mark-o circle {
    stroke: var(--o-color);
    stroke-width: 10;
    stroke-linecap: round;
    fill: none;
    stroke-dasharray: 188.5;    /* 2 π r ≈ 188.5 at r=30 */
    stroke-dashoffset: 188.5;
    animation: drawStroke 0.28s ease-out forwards;
}

@keyframes drawStroke { to { stroke-dashoffset: 0; } }

/* ===== winning line ===== */
.win-line-svg {
    position: absolute;
    inset: 6px;
    pointer-events: none;
}
.win-line {
    stroke: var(--win-color);
    stroke-width: 4;
    stroke-linecap: round;
    fill: none;
    stroke-dasharray: 200;
    stroke-dashoffset: 200;
    animation: drawStroke 0.45s ease-out forwards, shimmer 1.8s ease-in-out infinite 0.4s;
    filter: drop-shadow(0 0 6px rgba(251, 191, 36, 0.5));
}
@keyframes shimmer {
    0%, 100% { stroke: var(--win-color); }
    50%      { stroke: #fde047; }
}

/* ===== game foot ===== */
.game-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--bg-3);
    gap: 12px;
}
.turn-status {
    font-family: ui-monospace, monospace;
    font-size: 12px;
    color: var(--text-dim);
}
.turn-status.your { color: var(--accent); }
.turn-status.opp  { color: var(--text-mute); }

/* ===== overlays ===== */
.overlay {
    position: absolute;
    inset: 0;
    background: rgba(9, 9, 11, 0.84);
    backdrop-filter: blur(6px);
    border-radius: 16px;
    display: grid;
    place-items: center;
    z-index: 5;
    padding: 20px;
}
.overlay-card { text-align: center; max-width: 360px; }
.overlay-eyebrow { font-family: ui-monospace, monospace; font-size: 10px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--text-mute); margin-bottom: 6px; }
.overlay-card h2 { margin: 0 0 8px; font-size: 28px; font-weight: 800; letter-spacing: -0.02em; }
.overlay-stats { color: var(--text-dim); margin: 0 0 16px; font-family: ui-monospace, monospace; font-size: 13px; }
.overlay-actions { display: flex; flex-direction: column; gap: 8px; }
.overlay-actions .btn { width: 100%; margin: 0; }

/* ===== responsive ===== */
@media (max-width: 900px) {
    .game-shell { grid-template-columns: 1fr; }
    .chat-panel { height: 220px; }
}

/* ===== foot ===== */
.foot {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 24px;
    max-width: 1100px;
    margin: 0 auto;
    color: var(--text-mute);
    font-family: ui-monospace, monospace;
    font-size: 11px;
    letter-spacing: 0.04em;
}
.bmc-link { display: inline-flex; align-items: center; gap: 6px; color: var(--text-mute); text-decoration: none; transition: color 0.15s; }
.bmc-link:hover { color: #FFDD00; }
