:root {
    --bg: #ffffff;
    --panel: #ffffff;
    --ink: #1a2233;
    --muted: #5c6472;
    --line: #d5dbe6;
    --shadow: 0 10px 24px rgba(20, 33, 61, 0.08);
    --x: #d12c3f;
    --o: #1f5fbf;
    --ok: #1e8e50;
    --warn: #b9781a;
    --field-bg: #ffffff;
    --field-hover: #edf4ff;
    --list-hover: #f4f8ff;
    --board-bg: #121212;
    --board-border: #1d1d1d;
    --cell-bg: #ffffff;
}

html.theme-dark {
    --bg: #0e1522;
    --panel: #162235;
    --ink: #e8edf7;
    --muted: #aebbd0;
    --line: #2e3f59;
    --shadow: 0 12px 28px rgba(0, 0, 0, 0.35);
    --x: #f52039;
    --o: #2d42e4;
    --ok: #4cc482;
    --warn: #ffc05f;
    --field-bg: #0f1b2d;
    --field-hover: #1a2a44;
    --list-hover: #1c2a42;
    --board-bg: #121212;
    --board-border: #1d1d1d;
    --cell-bg: #eee;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--ink);
    font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
}

.page {
    position: relative;
    width: min(1100px, calc(100% - 32px));
    margin: 0 auto;
    padding: 32px 0 56px;
}

.brand-header {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 18px;
}

.brand-logo {
    width: 64px;
    height: 64px;
    object-fit: contain;
}

.brand-home-link {
    display: inline-flex;
    align-items: center;
}

.brand-text {
    display: grid;
    gap: 2px;
}

.brand-title {
    margin: 0;
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--ink);
}

.brand-subtitle {
    margin: 0;
    font-size: 0.88rem;
    color: var(--muted);
}

.hero {
    display: grid;
    gap: 18px;
    margin-bottom: 28px;
}

.eyebrow {
    margin: 0;
    font-size: 0.82rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--o);
}

h1,
h2,
h3 {
    margin: 0;
    font-family: Georgia, "Times New Roman", serif;
    font-weight: 700;
}

h1 {
    font-size: clamp(2.2rem, 5vw, 4.2rem);
    line-height: 0.98;
    max-width: 12ch;
}

.lead {
    max-width: 60ch;
    margin: 0;
    color: var(--muted);
    line-height: 1.6;
}

.layout {
    display: grid;
    gap: 20px;
}

.layout.columns-2 {
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 16px;
    box-shadow: var(--shadow);
    padding: 22px;
}

.panel.highlight {
    border-color: rgba(31, 95, 191, 0.35);
    box-shadow: 0 10px 24px rgba(31, 95, 191, 0.08);
}

.stack {
    display: grid;
    gap: 14px;
}

label {
    display: grid;
    gap: 8px;
    font-weight: 700;
    color: var(--ink);
}

input,
select,
button,
textarea {
    font: inherit;
}

input,
select {
    width: 100%;
    padding: 14px 16px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: var(--field-bg);
    color: var(--ink);
}

button {
    cursor: pointer;
    border: 0;
    padding: 14px 18px;
    border-radius: 10px;
    font-weight: 700;
    color: #ffffff;
    background: linear-gradient(135deg, #1f5fbf, #184b97);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    box-shadow: 0 8px 18px rgba(31, 95, 191, 0.22);
}

button.secondary {
    background: linear-gradient(135deg, #d12c3f, #b32031);
    box-shadow: 0 8px 18px rgba(209, 44, 63, 0.22);
}

button.ghost {
    background: var(--field-bg);
    color: var(--ink);
    border: 1px solid var(--line);
    box-shadow: none;
}

button:hover {
    transform: translateY(-1px);
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.65;
    transform: none;
}

.inline-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.status {
    padding: 12px 14px;
    border-radius: 14px;
    font-size: 0.95rem;
    line-height: 1.45;
}

.status.info {
    background: rgba(31, 95, 191, 0.1);
    color: #1a4b96;
}

.status.success {
    background: rgba(31, 122, 78, 0.12);
    color: var(--ok);
}

.status.warning {
    background: rgba(183, 107, 18, 0.12);
    color: var(--warn);
}

.status.error {
    background: rgba(199, 66, 44, 0.12);
    color: var(--x);
}

.meta-list {
    display: grid;
    gap: 10px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.meta-list li {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding-bottom: 10px;
    border-bottom: 1px dashed var(--line);
}

.meta-label {
    color: var(--muted);
}

.meta-value {
    font-weight: 700;
    text-align: right;
}

.invite-code {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: fit-content;
    padding: 10px 14px;
    border-radius: 999px;
    background: rgba(31, 95, 191, 0.08);
    font-weight: 700;
    letter-spacing: 0.12em;
}

.board {
    display: grid;
    gap: 2px;
    width: min(100%, 720px);
    padding: 12px;
    border-radius: 10px;
    background: var(--board-bg);
    border: 1px solid var(--board-border);
}

.cell {
    aspect-ratio: 1 / 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: var(--cell-bg);
    box-shadow: none;
    font-size: clamp(0.72rem, 1vw, 1rem);
    font-weight: 700;
    color: #a5aebe;
    transition: background 0.15s ease, transform 0.15s ease;
}

.cell:hover {
    transform: none;
}

.cell:disabled {
    opacity: 1;
}

.cell.clickable {
    cursor: pointer;
    background: var(--cell-bg);
}

.cell.clickable:hover {
    background: var(--field-hover);
}

.cell.x {
    color: var(--x);
}

.cell.o {
    color: var(--o);
}

.mono {
    font-family: "Courier New", monospace;
}

.small {
    font-size: 0.92rem;
    color: var(--muted);
}

.hidden {
    display: none !important;
}

.home-page .home-topbar {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.page-topbar {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 8px;
}

.theme-toggle-button {
    min-width: 124px;
}

.active-match-banner {
    margin-bottom: 14px;
}

.active-match-button {
    display: block;
    width: 100%;
    text-align: center;
    padding: 16px 18px;
    border-radius: 12px;
    font-weight: 800;
    letter-spacing: 0.01em;
    text-decoration: none;
    color: #ffffff;
    background: linear-gradient(135deg, #1f5fbf, #d12c3f);
    box-shadow: 0 12px 24px rgba(31, 95, 191, 0.2);
}

.active-match-button:hover {
    filter: brightness(1.03);
}

.home-page #main-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-auto-flow: row;
    align-items: start;
}

.home-page #create-panel {
    grid-column: 1;
    grid-row: 1;
}

.home-page #join-panel {
    grid-column: 2;
    grid-row: 1;
}

.home-page #faq-panel {
    grid-column: 1 / -1;
    grid-row: 2;
}

.home-page #recent-matches-panel {
    grid-column: 1 / -1;
    grid-row: 3;
}

.home-page #name-panel {
    grid-column: 1 / -1;
    grid-row: 4;
}

.home-page.no-player #name-panel {
    grid-column: 1 / -1;
    grid-row: 1;
    border-color: rgba(31, 95, 191, 0.5);
    box-shadow: 0 14px 30px rgba(31, 95, 191, 0.12);
}

.home-page.no-player #create-panel,
.home-page.no-player #join-panel,
.home-page.no-player #faq-panel,
.home-page.no-player #recent-matches-panel {
    display: none;
}

.home-page.invite-prefill #join-panel {
    grid-column: 1 / -1;
    grid-row: 1;
}

.home-page.invite-prefill #faq-panel {
    grid-column: 1 / -1;
    grid-row: 2;
}

.home-page.invite-prefill #recent-matches-panel {
    grid-column: 1 / -1;
    grid-row: 3;
}

.home-page.invite-prefill #name-panel {
    grid-column: 1 / -1;
    grid-row: 4;
}

.home-page.invite-prefill #create-panel {
    grid-column: 1 / -1;
    grid-row: 5;
}

.invite-priority {
    border-color: rgba(31, 95, 191, 0.65) !important;
    box-shadow: 0 14px 30px rgba(31, 95, 191, 0.16);
}

.match-history-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 8px;
}

.match-history-item {
    border: 1px solid var(--line);
    background: var(--field-bg);
    border-radius: 10px;
}

.match-history-link {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    text-decoration: none;
    color: inherit;
}

.match-history-link:hover {
    background: var(--list-hover);
}

.match-history-pairing {
    font-weight: 700;
}

.match-history-date {
    color: var(--muted);
    font-size: 0.9rem;
    white-space: nowrap;
}

.match-history-result {
    font-weight: 700;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
}

.match-history-result.win {
    color: var(--ok);
}

.match-history-result.loss {
    color: var(--x);
}

.match-history-result.draw {
    color: var(--warn);
}

.match-history-result.pending {
    color: var(--muted);
}

@media (max-width: 720px) {
    .page {
        width: min(100% - 20px, 1100px);
        padding-top: 22px;
    }

    .panel {
        padding: 18px;
        border-radius: 20px;
    }

    .meta-list li {
        display: grid;
        gap: 4px;
    }

    .meta-value {
        text-align: left;
    }

    .match-history-link {
        grid-template-columns: 1fr;
        gap: 4px;
    }

    .home-page #main-actions {
        grid-template-columns: 1fr;
    }

    .home-page #create-panel,
    .home-page #join-panel,
    .home-page #faq-panel,
    .home-page #recent-matches-panel,
    .home-page #name-panel {
        grid-column: 1;
        grid-row: auto;
    }

    .home-page.invite-prefill #join-panel {
        grid-row: 1;
    }

    .home-page.invite-prefill #faq-panel {
        grid-row: 2;
    }

    .home-page.invite-prefill #recent-matches-panel {
        grid-row: 3;
    }

    .home-page.invite-prefill #name-panel {
        grid-row: 4;
    }

    .home-page.invite-prefill #create-panel {
        grid-row: 5;
    }
}
