:root {
    color-scheme: dark;
    --bg: #080a12;
    --surface: rgba(13, 18, 29, 0.95);
    --surface-soft: rgba(15, 22, 35, 0.82);
    --border: rgba(146, 178, 203, 0.17);
    --border-strong: rgba(0, 210, 211, 0.38);
    --text: #e9eef5;
    --muted: #8c9bb0;
    --cyan: #00d2d3;
    --cyan-soft: #75e8ea;
    --green: #4ade80;
    --red: #fb7185;
    --shadow: 0 22px 60px rgba(0, 0, 0, 0.38);
}

* { box-sizing: border-box; }

html {
    min-width: 320px;
    background: var(--bg);
}

body {
    min-height: 100vh;
    margin: 0;
    overflow-x: hidden;
    font-family: 'Outfit', system-ui, sans-serif;
    color: var(--text);
    background:
        radial-gradient(circle at 18% 8%, rgba(0, 210, 211, 0.07), transparent 30rem),
        radial-gradient(circle at 82% 24%, rgba(30, 86, 126, 0.08), transparent 28rem),
        var(--bg);
}

button, a { font: inherit; }

button:focus-visible,
a:focus-visible,
canvas:focus-visible {
    outline: 2px solid var(--cyan);
    outline-offset: 3px;
}

.ambient-grid {
    position: fixed;
    inset: 0;
    pointer-events: none;
    opacity: 0.24;
    background-image: radial-gradient(rgba(114, 163, 190, 0.38) 1px, transparent 1px);
    background-size: 20px 20px;
    mask-image: linear-gradient(to bottom, black, transparent 85%);
}

.app-shell {
    position: relative;
    z-index: 1;
    width: min(1180px, calc(100% - 2rem));
    margin: 0 auto;
    padding: 2rem 0 3rem;
}

.site-header {
    position: relative;
    display: flex;
    justify-content: center;
    min-height: 116px;
    margin-bottom: 1.5rem;
}

.back-link {
    position: absolute;
    top: 0.5rem;
    left: 0;
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    color: var(--muted);
    font-size: 0.94rem;
    font-weight: 600;
    text-decoration: none;
    transition: color 160ms ease;
}

.back-link:hover { color: var(--cyan-soft); }
.back-link .material-symbols-outlined { font-size: 1.25rem; }
.title-block { text-align: center; }

.eyebrow,
.mode-tag,
.panel-kicker,
.result-kicker {
    color: var(--cyan-soft);
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.14em;
}

h1 {
    margin: 0.3rem 0 0;
    font-size: clamp(2.2rem, 6vw, 3.6rem);
    line-height: 1;
    letter-spacing: -0.04em;
    text-transform: uppercase;
}

.title-block p {
    margin: 0.45rem 0 0;
    color: var(--muted);
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.hidden { display: none !important; }
.view { width: 100%; }
.selection-view { max-width: 980px; margin: 0 auto; }

.selection-panel,
.rule-card,
.rules-note,
.match-header,
.table-shell,
.help-panel,
.result-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.selection-panel {
    padding: clamp(1.5rem, 5vw, 2.5rem);
    border-radius: 14px;
}

.selection-panel > p {
    max-width: 680px;
    margin: 0.45rem 0 1.35rem;
    color: var(--muted);
    line-height: 1.6;
}

.selection-panel h2 {
    margin: 0.7rem 0 0;
    font-size: clamp(1.7rem, 4vw, 2.4rem);
}

.centered-panel,
.matchmaking-panel { text-align: center; }

.centered-panel > p,
.matchmaking-panel > p { margin-inline: auto; }

.mode-tag {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 10px rgba(74, 222, 128, 0.6);
}

.mode-grid,
.difficulty-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.85rem;
}

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

.mode-button,
.difficulty-button {
    display: flex;
    align-items: center;
    gap: 1rem;
    min-height: 100px;
    border: 1px solid var(--border);
    border-radius: 11px;
    padding: 1.1rem;
    color: var(--text);
    text-align: left;
    background: rgba(255, 255, 255, 0.025);
    cursor: pointer;
    transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.mode-button:hover,
.difficulty-button:hover {
    transform: translateY(-2px);
    border-color: var(--border-strong);
    background: rgba(0, 210, 211, 0.06);
}

.mode-button .material-symbols-outlined {
    color: var(--cyan-soft);
    font-size: 2rem;
}

.mode-button > span:last-child,
.difficulty-button { display: grid; gap: 0.28rem; }
.mode-button strong,
.difficulty-button strong { font-size: 1.05rem; }
.mode-button small,
.difficulty-button small { color: var(--muted); line-height: 1.4; }

.difficulty-button { justify-items: center; text-align: center; }

.primary-button,
.secondary-button,
.text-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.55rem;
    min-height: 48px;
    border-radius: 8px;
    padding: 0.75rem 1rem;
    font-weight: 700;
    letter-spacing: 0.025em;
    cursor: pointer;
    text-decoration: none;
    transition: transform 160ms ease, border-color 160ms ease, background-color 160ms ease, color 160ms ease;
}

.primary-button { border: 1px solid var(--cyan); color: #041011; background: var(--cyan); }
.primary-button:hover { transform: translateY(-2px); background: var(--cyan-soft); }

.secondary-button {
    border: 1px solid var(--border);
    color: var(--text);
    background: rgba(255, 255, 255, 0.025);
}

.secondary-button:hover { border-color: var(--border-strong); color: var(--cyan-soft); background: rgba(0, 210, 211, 0.06); }
.compact-button { min-width: 190px; margin-top: 1rem; }

.text-button {
    width: 100%;
    margin-top: 0.85rem;
    border: 0;
    color: var(--muted);
    text-decoration: underline;
    text-underline-offset: 3px;
    background: transparent;
}

.text-button:hover { color: var(--cyan-soft); }

.search-pulse {
    display: block;
    width: 46px;
    height: 46px;
    margin: 0 auto 1rem;
    border: 3px solid rgba(0, 210, 211, 0.18);
    border-top-color: var(--cyan);
    border-radius: 50%;
    animation: search-spin 900ms linear infinite;
}

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

.rules-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.8rem;
    margin-top: 0.9rem;
}

.rule-card { min-height: 180px; border-radius: 12px; padding: 1.2rem; }
.rule-number { color: var(--cyan-soft); font-family: ui-monospace, monospace; font-size: 0.72rem; font-weight: 700; letter-spacing: 0.1em; }
.rule-card h3 { margin: 0.65rem 0 0.45rem; font-size: 1rem; }
.rule-card p,
.rules-note { color: var(--muted); font-size: 0.86rem; line-height: 1.55; }
.rules-note { margin: 0.8rem 0 0; border-radius: 10px; padding: 0.85rem 1rem; text-align: center; }
.rules-note strong { color: var(--text); }

.game-view { display: grid; gap: 0.9rem; }

.match-header {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 1rem;
    min-height: 84px;
    padding: 0.8rem 1.2rem;
    border-radius: 12px;
}

.scoreboard {
    display: flex;
    align-items: center;
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    background: #080d16;
}

.score-team { display: flex; align-items: center; gap: 0.65rem; min-width: 105px; padding: 0.45rem 0.8rem; }
.score-team span { font-size: 0.66rem; font-weight: 700; letter-spacing: 0.1em; }
.score-team strong { font-size: 2rem; line-height: 1; }
.top-score { color: #f5f5f2; }
.bottom-score { justify-content: flex-end; color: var(--cyan-soft); }

.score-center {
    display: grid;
    place-items: center;
    min-width: 72px;
    padding: 0.35rem 0.55rem;
    border-inline: 1px solid var(--border);
    color: var(--muted);
}

.score-center span { font-size: 0.5rem; font-weight: 700; letter-spacing: 0.08em; }
.score-center b { color: var(--text); font-size: 0.7rem; }

.side-summary { display: flex; align-items: center; gap: 0.7rem; }
.side-summary:last-child { justify-self: end; text-align: right; }
.side-summary div { display: grid; gap: 0.2rem; }
.side-summary small { color: var(--muted); font-size: 0.62rem; letter-spacing: 0.1em; }
.side-summary strong { font-size: 0.82rem; letter-spacing: 0.06em; }

.puck-swatch { flex: 0 0 auto; width: 23px; height: 23px; border-radius: 50%; box-shadow: 0 4px 9px rgba(0, 0, 0, 0.35); }
.white-swatch { border: 1px solid #cdd2d6; background: linear-gradient(145deg, #fff, #d4d7d9); }
.black-swatch { border: 1px solid #59616a; background: linear-gradient(145deg, #282c31, #050607); }

.game-layout { display: grid; grid-template-columns: minmax(0, 1fr) 310px; align-items: start; gap: 1rem; }
.table-column { min-width: 0; }

.table-shell {
    position: relative;
    width: min(100%, 650px);
    margin: 0 auto;
    padding: 0.55rem;
    border-radius: 14px;
    overflow: hidden;
    background: #070c14;
}

#game-canvas {
    display: block;
    width: 100%;
    aspect-ratio: 720 / 920;
    border-radius: 8px;
    background: #c48b4c;
    cursor: crosshair;
    touch-action: none;
    user-select: none;
}

#game-canvas.aiming { cursor: grabbing; }

.countdown-overlay {
    position: absolute;
    inset: 0.55rem;
    display: grid;
    place-items: center;
    border-radius: 8px;
    pointer-events: none;
    background: rgba(8, 10, 18, 0.36);
    backdrop-filter: blur(2px);
}

#countdown-label {
    display: grid;
    place-items: center;
    min-width: 112px;
    min-height: 112px;
    border: 1px solid rgba(117, 232, 234, 0.7);
    border-radius: 50%;
    color: #fff;
    font-size: clamp(3.4rem, 10vw, 5.6rem);
    font-weight: 800;
    line-height: 1;
    text-shadow: 0 0 24px rgba(0, 210, 211, 0.85);
    background: rgba(5, 12, 17, 0.82);
}

.match-status { min-height: 1.3rem; margin: 0.7rem 0 0; color: var(--muted); font-size: 0.86rem; text-align: center; }
.help-panel { position: sticky; top: 1rem; border-radius: 13px; padding: 1.15rem; }

.play-indicator {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    margin-top: 0.7rem;
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 0.75rem;
    background: rgba(255, 255, 255, 0.025);
}

.turn-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--cyan); box-shadow: 0 0 11px rgba(0, 210, 211, 0.56); }
.play-indicator.waiting .turn-dot { background: #facc15; box-shadow: 0 0 11px rgba(250, 204, 21, 0.5); }
.play-indicator.finished .turn-dot { background: var(--red); box-shadow: 0 0 11px rgba(251, 113, 133, 0.5); }
.play-indicator div { display: grid; gap: 0.18rem; }
.play-indicator small { color: var(--muted); font-size: 0.58rem; letter-spacing: 0.11em; }
.play-indicator strong { font-size: 0.85rem; }

.side-counts { display: grid; grid-template-columns: 1fr 1fr; gap: 0.55rem; margin-top: 0.7rem; }
.side-counts div { display: grid; gap: 0.25rem; border: 1px solid var(--border); border-radius: 8px; padding: 0.65rem; color: var(--muted); font-size: 0.7rem; text-align: center; }
.side-counts strong { color: var(--text); font-size: 1.3rem; }

.help-copy { margin-top: 1rem; border-top: 1px solid var(--border); padding-top: 0.9rem; }
.help-copy h2 { margin: 0 0 0.6rem; font-size: 1rem; }
.help-copy ol { display: grid; gap: 0.45rem; margin: 0; padding-left: 1.2rem; color: var(--muted); font-size: 0.8rem; line-height: 1.45; }
.help-copy p { margin: 0.8rem 0 0; color: var(--muted); font-size: 0.78rem; line-height: 1.5; }
.help-copy strong { color: var(--text); }

.action-buttons { display: grid; gap: 0.55rem; margin-top: 1rem; }
.action-buttons .secondary-button { width: 100%; min-height: 42px; padding: 0.55rem 0.75rem; font-size: 0.82rem; }
.action-buttons .material-symbols-outlined { font-size: 1.15rem; }

.overlay {
    position: fixed;
    z-index: 20;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 1rem;
    background: rgba(4, 7, 13, 0.9);
    backdrop-filter: blur(9px);
}

.result-panel { width: min(420px, 100%); border-radius: 14px; padding: 2.2rem; text-align: center; }
.result-panel h2 { margin: 0.75rem 0 0.25rem; font-size: 2rem; }
#winner-score { margin: 0 0 1.4rem; color: var(--muted); font-size: 1.3rem; font-weight: 700; }
.result-panel .primary-button,
.result-panel .secondary-button { width: 100%; }
.result-panel .secondary-button { margin-top: 0.65rem; }

@media (max-width: 900px) {
    .rules-grid { grid-template-columns: repeat(2, 1fr); }
    .game-layout { grid-template-columns: minmax(0, 1fr) 270px; }
}

@media (max-width: 760px) {
    .app-shell { width: min(100% - 1rem, 1180px); padding-top: 1rem; }
    .site-header { min-height: 126px; align-items: flex-end; }
    .back-link { top: 0; }
    .mode-grid,
    .difficulty-grid { grid-template-columns: 1fr; }
    .match-header { grid-template-columns: 1fr 1fr; gap: 0.7rem; }
    .scoreboard { grid-row: 1; grid-column: 1 / -1; justify-self: center; }
    .side-summary { grid-row: 2; }
    .game-layout { grid-template-columns: 1fr; }
    .help-panel { position: static; }
    .action-buttons { grid-template-columns: 1fr 1fr; }
    .action-buttons #game-menu { grid-column: 1 / -1; }
}

@media (max-width: 480px) {
    .back-link span:last-child { font-size: 0.84rem; }
    .rules-grid { grid-template-columns: 1fr; }
    .rule-card { min-height: 0; }
    .match-header { padding-inline: 0.65rem; }
    .score-team { min-width: 86px; }
    .score-center { min-width: 58px; }
    .side-summary strong { font-size: 0.7rem; }
    .side-summary small { font-size: 0.55rem; }
    .puck-swatch { width: 18px; height: 18px; }
    .table-shell { padding: 0.3rem; }
    .countdown-overlay { inset: 0.3rem; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
    .search-pulse { animation-duration: 1.8s; }
}
