:root {
    --game-primary: #c90c0f;
    --game-secondary: #f4c430;
    --ttt-wood-dark: #2a1810;
    --ttt-wood: #6b3f22;
    --ttt-chalk: #f4efe4;
    --ttt-red: #c90c0f;
    --ttt-gold: #f4c430;
}

body.ttt-page {
    margin: 0;
    min-height: 100vh;
    font-family: "Rockwell", "Rockwell Nova", "Roboto Slab", serif;
    color: #f8f4ea;
    background:
        radial-gradient(circle at 14% 10%, rgba(244, 196, 48, 0.16), transparent 42%),
        radial-gradient(circle at 88% 8%, rgba(201, 12, 15, 0.22), transparent 46%),
        linear-gradient(180deg, #2a1810 0%, #4a2c18 46%, #1a120c 100%);
}

body.ttt-page.game-menu-active {
    overflow-y: auto;
    overflow-x: hidden;
}

body.ttt-page.game-menu-active #game-header {
    display: none !important;
}

.ttt-page .game-screen {
    display: none;
    min-height: 100vh;
}

.ttt-page .game-screen.active {
    display: block;
}

body.ttt-page.with-game-header .ttt-shell {
    padding-top: 5.5rem;
}

.ttt-shell {
    max-width: min(920px, 96vw);
    margin: 0 auto;
    padding: 1.1rem 0.75rem 2.5rem;
}

.ttt-hud {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin: 0 auto 0.85rem;
    padding: 0.55rem 0.7rem;
    background: linear-gradient(180deg, #5a351c, #3b2414);
    border: 3px solid #1a120c;
    border-radius: 12px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12), 0 10px 24px rgba(0, 0, 0, 0.35);
}

.ttt-lcd {
    min-width: 6.2rem;
    padding: 0.2rem 0.45rem;
    background: #140414;
    color: #f5c518;
    font-family: "Courier New", ui-monospace, monospace;
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-align: center;
    border-radius: 6px;
    box-shadow: inset 0 0 0 2px #7f1d1d, inset 0 8px 16px rgba(0, 0, 0, 0.45);
}

.ttt-lcd span {
    display: block;
    font-size: 0.62rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #fca5a5;
}

.ttt-chip {
    padding: 0.45rem 0.7rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    color: #fde68a;
    font-weight: 700;
}

.ttt-chip.is-busy {
    background: #b91c1c;
    color: #fff;
}

.ttt-toolbar {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.45rem;
    margin: 0 auto 0.85rem;
}

.ttt-tool-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 0.75rem;
    border-radius: 999px;
    border: 1px solid rgba(244, 196, 48, 0.35);
    background: rgba(26, 18, 12, 0.75);
    color: #f8fafc;
    font-weight: 700;
    cursor: pointer;
}

.ttt-tool-btn:hover {
    border-color: #f4c430;
    color: #fde68a;
    background: rgba(26, 18, 12, 0.95);
}

.ttt-tool-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.ttt-table {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.ttt-board-wrap {
    width: min(78vh, 94vw, 420px);
    padding: 0.85rem;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.14), transparent 42%),
        linear-gradient(180deg, #7a4a28, #5a3418 58%, #3b2414);
    border: 6px solid #2a1810;
    border-radius: 18px;
    box-shadow: 0 22px 44px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

.ttt-board {
    position: relative;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    aspect-ratio: 1 / 1;
    background: #1a120c;
    border: 4px solid #140c08;
    border-radius: 10px;
    overflow: hidden;
    gap: 6px;
    padding: 6px;
}

.ttt-cell {
    position: relative;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 8px;
    background: #f4efe4;
    cursor: pointer;
    min-width: 0;
    min-height: 72px;
    touch-action: manipulation;
}

.ttt-cell:focus-visible {
    outline: 3px solid #f4c430;
    outline-offset: -3px;
    z-index: 3;
}

.ttt-cell.is-legal:hover,
.ttt-cell.is-hot {
    background: #fff8e7;
}

.ttt-cell.is-filled,
.ttt-cell:disabled {
    cursor: default;
}

.ttt-cell.is-win {
    background: #ffe08a;
    box-shadow: inset 0 0 0 3px #c90c0f;
}

.ttt-mark {
    width: 78%;
    height: 78%;
    display: block;
    margin: auto;
    overflow: visible;
}

.ttt-mark-x line {
    fill: none;
    stroke: #c90c0f;
    stroke-width: 10;
    stroke-linecap: round;
    stroke-dasharray: 92;
    stroke-dashoffset: 92;
    animation: ttt-draw 0.28s ease forwards;
}

.ttt-mark-x .ttt-x-b {
    animation-delay: 0.14s;
}

.ttt-mark-o circle {
    fill: none;
    stroke: #b8860b;
    stroke-width: 10;
    stroke-linecap: round;
    stroke-dasharray: 176;
    stroke-dashoffset: 176;
    animation: ttt-draw 0.38s ease forwards;
}

.ttt-win-line {
    position: absolute;
    inset: 6px;
    width: calc(100% - 12px);
    height: calc(100% - 12px);
    pointer-events: none;
    z-index: 4;
}

.ttt-win-line line {
    stroke: #c90c0f;
    stroke-width: 10;
    stroke-linecap: round;
    filter: drop-shadow(0 0 6px rgba(244, 196, 48, 0.85));
    stroke-dasharray: 280;
    stroke-dashoffset: 280;
    animation: ttt-draw 0.45s ease 0.12s forwards;
}

.ttt-hint {
    margin: 0.85rem 0 0;
    text-align: center;
    color: #fde68a;
    font-size: 0.95rem;
}

.ttt-page .modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.72);
    z-index: 12000;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.ttt-page .modal.active {
    display: flex;
}

.ttt-page .modal-content {
    width: min(560px, 96vw);
    max-height: 90vh;
    overflow: auto;
    background: #fff;
    color: #1a1a1a;
    border-radius: 16px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.4);
}

.ttt-page .modal-content.modal-large {
    width: min(680px, 96vw);
}

.ttt-page .modal-header,
.ttt-page .modal-footer {
    padding: 1.1rem 1.4rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.ttt-page .modal-header { border-bottom: 2px solid #eee; }
.ttt-page .modal-header h2 { margin: 0; color: #c90c0f; font-size: 1.35rem; }

.ttt-page .modal-close {
    background: #fff;
    border: 2px solid #c90c0f;
    color: #c90c0f;
    border-radius: 8px;
    cursor: pointer;
    padding: 0.35rem 0.55rem;
}

.ttt-page .modal-close:hover {
    background: #c90c0f;
    color: #fff;
}

.ttt-page .modal-body { padding: 1.2rem 1.4rem; }
.ttt-page .modal-footer { border-top: 2px solid #eee; justify-content: flex-end; }

.ttt-page .help-section { margin-bottom: 1.1rem; }
.ttt-page .help-section h3 { color: #c90c0f; margin: 0 0 0.4rem; }
.ttt-page .help-section ul { margin: 0.3rem 0 0; padding-left: 1.2rem; }

.ttt-page .stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.ttt-page .stat-card {
    background: #f8fafc;
    border-radius: 12px;
    padding: 0.85rem;
    text-align: center;
}

.ttt-page .stat-value { font-size: 1.6rem; color: #c90c0f; font-weight: 700; }
.ttt-page .stat-label { color: #64748b; font-size: 0.85rem; }

.ttt-page .win-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.6rem;
    text-align: center;
}

.ttt-page .win-stat strong { display: block; font-size: 1.35rem; color: #c90c0f; }
.ttt-page .win-stat span { color: #64748b; font-size: 0.82rem; }

.ttt-page .result-message { font-size: 1.05rem; margin: 0 0 1rem; color: #1a1a1a; }

.ttt-page .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.65rem 1.1rem;
    border-radius: 0.55rem;
    border: 2px solid transparent;
    font-weight: 700;
    cursor: pointer;
}

.ttt-page .btn-primary {
    background: #c90c0f;
    color: #fff;
}

.ttt-page .btn-primary:hover {
    background: #a00a0c;
    color: #fff;
}

.ttt-page .btn-secondary {
    background: #fff;
    color: #c90c0f;
    border-color: #c90c0f;
}

.ttt-page .btn-secondary:hover {
    background: #c90c0f;
    color: #fff;
}

.ttt-page .difficulty-stats {
    display: grid;
    gap: 0.45rem;
}

.ttt-page .difficulty-stats div {
    display: flex;
    justify-content: space-between;
    padding: 0.45rem 0.6rem;
    background: #f8fafc;
    border-radius: 8px;
}

.ttt-settings-panel__title {
    font-weight: 700;
    margin-bottom: 0.55rem;
    color: #c90c0f;
}

.ttt-settings-panel__label {
    margin: 0.35rem 0 0.4rem;
    font-weight: 600;
    color: #1a1a1a;
}

.ttt-settings-panel__buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    margin-bottom: 0.75rem;
}

.ttt-settings-note {
    color: #475569;
    font-size: 0.9rem;
    margin: 0.4rem 0 0;
}

.ttt-page .difficulty-pill {
    border: 2px solid #cbd5e1;
    border-radius: 999px;
    padding: 0.5rem 0.85rem;
    background: #f1f5f9;
    color: #0f172a;
    font-weight: 600;
    cursor: pointer;
}

.ttt-page .difficulty-pill:hover {
    background: #e2e8f0;
    color: #0f172a;
    border-color: #c90c0f;
}

.ttt-page .difficulty-pill.is-selected {
    background: #c90c0f;
    color: #fff;
    border-color: #c90c0f;
}

@keyframes ttt-draw {
    to { stroke-dashoffset: 0; }
}

@media (prefers-reduced-motion: reduce) {
    .ttt-mark-x line,
    .ttt-mark-o circle,
    .ttt-win-line line {
        animation: none;
        stroke-dashoffset: 0;
    }
}

@media (max-width: 640px) {
    .ttt-tool-btn span { display: none; }
    .ttt-lcd { min-width: 4.6rem; font-size: 1rem; }
    .ttt-cell { min-height: 64px; }
}
