/* =========================================================
   TIC TAC TOE ARENA
   Complete UI Redesign
========================================================= */

:root {
    --bg: #080a0f;
    --bg-soft: #0e1118;
    --panel: #121620;
    --panel-light: #181d28;
    --panel-hover: #1d2330;

    --line: rgba(255, 255, 255, 0.09);
    --line-strong: rgba(255, 255, 255, 0.15);

    --text: #f4f6f8;
    --muted: #8d96a5;

    --x: #4f7cff;
    --o: #ff5c7a;

    --accent: #ffffff;

    --radius: 18px;
}


/* =========================================================
   RESET
========================================================= */

*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    width: 100%;
    min-height: 100%;
    background: var(--bg);
    overflow-x: hidden;
}

body {
    width: 100%;
    min-width: 320px;
    min-height: 100vh;
    min-height: 100dvh;

    background:
        radial-gradient(
            circle at 50% -20%,
            rgba(92, 157, 255, 0.12),
            transparent 38%
        ),
        var(--bg);

    color: var(--text);

    font-family:
        Inter,
        ui-sans-serif,
        system-ui,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;

    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;

    overflow-x: hidden;
    overflow-y: auto;
}

button {
    font: inherit;
    border: 0;
    outline: none;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

button:focus-visible {
    outline: 2px solid var(--text);
    outline-offset: 3px;
}


/* =========================================================
   APP
========================================================= */

#app {
    width: 100%;
    min-height: 100vh;
    min-height: 100dvh;
}


/* =========================================================
   GENERAL SCREEN
========================================================= */

.screen {
    width: 100%;
    min-height: 100vh;
    min-height: 100dvh;
}


/* =========================================================
   LOADING SCREEN
========================================================= */

#loadingScreen {
    position: fixed;
    inset: 0;

    z-index: 9999;

    display: flex;
    align-items: center;
    justify-content: center;

    width: 100%;
    height: 100%;

    background: var(--bg);
    color: var(--text);
}

.loading-content {
    width: min(90%, 420px);

    text-align: center;

    animation: loadingAppear 0.7s ease both;
}

.loading-mark {
    width: 76px;
    height: 76px;

    margin: 0 auto 28px;

    display: flex;
    align-items: center;
    justify-content: center;

    border: 1px solid var(--line-strong);
    border-radius: 20px;

    background: var(--panel);

    font-size: 20px;
    font-weight: 800;
    letter-spacing: 2px;
}

.loading-content h1 {
    font-size: clamp(28px, 6vw, 42px);
    font-weight: 800;
    letter-spacing: -1.5px;
}

.loading-line {
    width: 130px;
    height: 2px;

    margin: 24px auto 16px;

    overflow: hidden;

    background: var(--line);
}

.loading-line span {
    display: block;

    width: 45%;
    height: 100%;

    background: var(--text);

    animation: loadingBar 1.1s ease-in-out infinite;
}

.loading-content p {
    color: var(--muted);

    font-size: 13px;
    letter-spacing: 1.5px;
    text-transform: uppercase;
}


/* =========================================================
   HOME SCREEN
========================================================= */

.menu-screen {
    display: flex;
    align-items: center;
    justify-content: center;

    width: 100%;
    min-height: 100vh;
    min-height: 100dvh;

    padding: 40px 20px;
}

.menu-content {
    width: min(100%, 920px);
    max-width: 920px;

    position: relative;
    margin: 0 auto;
}


/* =========================================================
   BRAND
========================================================= */

.brand {
    display: flex;
    align-items: center;
    gap: 14px;

    margin-bottom: 70px;
}

.brand-mark {
    width: 48px;
    height: 48px;

    flex: 0 0 48px;

    display: flex;
    align-items: center;
    justify-content: center;

    border: 1px solid var(--line-strong);
    border-radius: 14px;

    background: var(--panel);

    font-size: 14px;
    font-weight: 800;
    letter-spacing: 1px;
}

.brand-text {
    display: flex;
    flex-direction: column;
}

.brand-small {
    color: var(--muted);

    font-size: 10px;
    font-weight: 700;
    letter-spacing: 2.5px;
}

.brand-text h1 {
    margin-top: 2px;

    font-size: 22px;
    line-height: 1;

    font-weight: 800;
    letter-spacing: 2px;
}


/* =========================================================
   MENU HEADING
========================================================= */

.menu-heading {
    max-width: 650px;

    margin-bottom: 34px;
}

.eyebrow {
    display: block;

    margin-bottom: 12px;

    color: var(--muted);

    font-size: 10px;
    font-weight: 800;
    letter-spacing: 2.5px;
}

.menu-heading h2 {
    margin: 0;

    font-size: clamp(38px, 7vw, 68px);
    line-height: 0.98;

    font-weight: 800;
    letter-spacing: -3px;
}

.menu-heading p {
    max-width: 540px;

    margin-top: 18px;

    color: var(--muted);

    font-size: 16px;
    line-height: 1.6;
}


/* =========================================================
   GAME MODE CARDS
========================================================= */

.mode-grid {
    display: grid;

    grid-template-columns: repeat(2, minmax(0, 1fr));

    gap: 14px;

    width: 100%;
}

.mode-card {
    min-height: 180px;

    position: relative;

    display: flex;
    flex-direction: column;
    align-items: flex-start;

    width: 100%;

    padding: 25px;

    border: 1px solid var(--line);
    border-radius: var(--radius);

    background: var(--panel);

    color: var(--text);

    text-align: left;

    transition:
        transform 0.25s ease,
        border-color 0.25s ease,
        background 0.25s ease;
}

.mode-card:hover {
    transform: translateY(-5px);

    border-color: var(--line-strong);

    background: var(--panel-light);
}

.mode-card:active {
    transform: translateY(-1px);
}

.mode-number {
    position: absolute;

    top: 22px;
    right: 24px;

    color: #4d5563;

    font-size: 11px;
    font-weight: 800;
    letter-spacing: 1px;
}

.mode-icon {
    width: 48px;
    height: 48px;

    margin-bottom: 28px;

    display: flex;
    align-items: center;
    justify-content: center;

    border-radius: 13px;

    font-size: 12px;
    font-weight: 900;
    letter-spacing: 1px;
}

.mode-icon-local {
    background: rgba(92, 157, 255, 0.12);
    color: var(--x);
}

.mode-icon-ai {
    background: rgba(255, 101, 120, 0.12);
    color: var(--o);
}

.mode-card-content {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.mode-card-content strong {
    font-size: 18px;
    font-weight: 750;
}

.mode-card-content small {
    color: var(--muted);

    font-size: 13px;
    line-height: 1.4;
}

.mode-arrow {
    position: absolute;

    right: 23px;
    bottom: 22px;

    color: #5d6572;

    font-size: 20px;

    transition:
        transform 0.25s ease,
        color 0.25s ease;
}

.mode-card:hover .mode-arrow {
    color: var(--text);
    transform: translateX(4px);
}


/* =========================================================
   AI DIFFICULTY SCREEN
========================================================= */

#aiMenuToggle {
    display: none;
}

.difficulty-screen {
    display: none;

    margin-top: 30px;
}

#aiMenuToggle:checked ~ .difficulty-screen {
    display: block;

    animation: screenSlide 0.35s ease both;
}

#aiMenuToggle:checked ~ .difficulty-screen + .menu-footer {
    display: none;
}

#aiMenuToggle:checked ~ .mode-grid {
    display: none;
}

.difficulty-header {
    margin-bottom: 28px;
}

.back-to-modes {
    width: auto;

    margin-bottom: 32px;
    padding: 0;

    background: transparent;

    color: var(--muted);

    font-size: 13px;
    font-weight: 700;

    box-shadow: none;

    transition: color 0.2s ease;
}

.back-to-modes:hover {
    color: var(--text);
}

.difficulty-header h3 {
    font-size: clamp(34px, 6vw, 54px);
    line-height: 1;

    letter-spacing: -2px;
}

.difficulty-header p {
    margin-top: 13px;

    color: var(--muted);

    font-size: 15px;
}

.difficulty-grid {
    display: grid;

    grid-template-columns: repeat(3, minmax(0, 1fr));

    gap: 12px;

    width: 100%;
}

.difficulty-card {
    min-height: 190px;

    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-end;

    width: 100%;

    padding: 23px;

    border: 1px solid var(--line);
    border-radius: var(--radius);

    background: var(--panel);

    color: var(--text);

    text-align: left;

    box-shadow: none;

    transition:
        transform 0.25s ease,
        border-color 0.25s ease,
        background 0.25s ease;
}

.difficulty-card:hover {
    transform: translateY(-5px);

    background: var(--panel-light);

    border-color: var(--line-strong);
}

.difficulty-level {
    margin-bottom: auto;

    color: var(--muted);

    font-size: 9px;
    font-weight: 800;
    letter-spacing: 2px;
}

.difficulty-card strong {
    margin-bottom: 8px;

    font-size: 20px;
}

.difficulty-card > span:last-child {
    color: var(--muted);

    font-size: 12px;
    line-height: 1.5;
}

.difficulty-easy:hover {
    border-color: rgba(92, 157, 255, 0.45);
}

.difficulty-medium:hover {
    border-color: rgba(255, 190, 80, 0.45);
}

.difficulty-hard:hover {
    border-color: rgba(255, 101, 120, 0.45);
}


/* =========================================================
   MENU FOOTER
========================================================= */

.menu-footer {
    display: flex;
    justify-content: space-between;

    margin-top: 35px;

    color: #4f5764;

    font-size: 9px;
    font-weight: 800;
    letter-spacing: 1.8px;
}


/* =========================================================
   GAME SCREEN
========================================================= */

.game-screen {
    width: 100%;
    min-height: 100vh;
    min-height: 100dvh;

    padding: 20px;

    overflow-x: hidden;
}

.game-shell {
    width: min(100%, 720px);
    max-width: 720px;

    min-height: calc(100vh - 40px);
    min-height: calc(100dvh - 40px);

    margin: 0 auto;

    display: flex;
    flex-direction: column;
}


/* =========================================================
   GAME TOP BAR
========================================================= */

.game-topbar {
    min-height: 58px;

    display: grid;
    grid-template-columns: 1fr auto 1fr;

    align-items: center;

    border-bottom: 1px solid var(--line);
}

.game-title {
    display: flex;
    flex-direction: column;
    align-items: center;

    line-height: 1;
}

.game-title span {
    margin-bottom: 4px;

    color: var(--muted);

    font-size: 8px;
    font-weight: 800;
    letter-spacing: 2px;
}

.game-title strong {
    font-size: 13px;
    letter-spacing: 1px;
}

.icon-button {
    width: auto;
    height: auto;

    display: inline-flex;
    align-items: center;
    gap: 8px;

    margin: 0;
    padding: 8px 0;

    background: transparent;

    color: var(--muted);

    font-size: 13px;
    font-weight: 700;

    box-shadow: none;

    transition: color 0.2s ease;
}

.icon-button:hover {
    color: var(--text);
    transform: none;
}

.icon-button:first-child {
    justify-self: start;
}

.icon-button:last-child {
    justify-self: end;
}

.icon-button span:first-child {
    font-size: 18px;
}

.sound-symbol {
    font-size: 11px !important;
    text-transform: uppercase;
    letter-spacing: 1px;
}


/* =========================================================
   GAME STATUS
========================================================= */

.game-status {
    padding: 42px 0 25px;

    text-align: center;
}

.status-label {
    color: var(--muted);

    font-size: 9px;
    font-weight: 800;
    letter-spacing: 2px;
}

#status {
    margin: 8px 0 0;

    padding: 0;

    background: transparent;

    color: var(--text);

    font-size: clamp(24px, 5vw, 34px);
    font-weight: 800;

    letter-spacing: -1px;

    border-radius: 0;
}


/* =========================================================
   SCOREBOARD
========================================================= */

.scoreboard {
    display: grid;

    grid-template-columns: 1fr 0.7fr 1fr;

    gap: 10px;

    width: 100%;

    margin-bottom: 28px;
}

.score-card {
    min-height: 72px;

    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;

    border: 1px solid var(--line);
    border-radius: 14px;

    background: var(--panel);
}

.score-player {
    color: var(--muted);

    font-size: 8px;
    font-weight: 800;
    letter-spacing: 1.5px;
}

.score-card strong {
    margin-top: 4px;

    font-size: 23px;
    line-height: 1;
}

.score-x strong {
    color: var(--x);
}

.score-o strong {
    color: var(--o);
}

.score-draw strong {
    color: var(--text);
}


/* =========================================================
   BOARD
========================================================= */

.board-wrapper {
    width: min(100%, 420px);
    max-width: 420px;

    margin: 0 auto;
}

.board-label {
    margin-bottom: 10px;

    color: #555d69;

    font-size: 8px;
    font-weight: 800;
    letter-spacing: 2px;

    text-align: center;
}

.board {
    width: 100%;
    aspect-ratio: 1 / 1;

    display: grid;

    grid-template-columns: repeat(3, minmax(0, 1fr));

    gap: 8px;

    padding: 8px;

    border: 1px solid var(--line);
    border-radius: 20px;

    background: #0d1016;

    overflow: hidden;
}

.board button {
    width: 100%;
    height: 100%;

    min-width: 0;
    min-height: 0;

    margin: 0;

    display: flex;
    align-items: center;
    justify-content: center;

    border: 1px solid rgba(255, 255, 255, 0.055);
    border-radius: 14px;

    background: #151922;

    color: var(--text);

    font-size: clamp(42px, 9vw, 76px);
    font-weight: 800;
    line-height: 1;

    box-shadow: none;

    transition:
        background 0.18s ease,
        border-color 0.18s ease,
        transform 0.18s ease;
}

.board button:hover {
    background: #1b202b;

    border-color: rgba(255, 255, 255, 0.12);

    transform: scale(0.985);
}

.board button:active {
    transform: scale(0.95);
}

.board button.pop {
    animation: boardPop 0.2s ease;
}

.board button.winner {
    background: #1d2a3d;

    border-color: rgba(92, 157, 255, 0.5);

    animation: winnerPulse 0.8s ease-in-out infinite alternate;
}


/* =========================================================
   GAME CONTROLS
========================================================= */

.game-controls {
    display: grid;

    grid-template-columns: 1fr 1fr;

    gap: 10px;

    width: min(100%, 420px);
    max-width: 420px;

    margin: 18px auto 0;
}

.primary-control,
.secondary-control {
    width: 100%;
    height: 50px;

    margin: 0;

    border-radius: 12px;

    font-size: 13px;
    font-weight: 750;

    box-shadow: none;

    transition:
        transform 0.2s ease,
        background 0.2s ease;
}

.primary-control {
    background: var(--text);

    color: #090b10;
}

.primary-control:hover {
    background: #dce1e7;

    transform: translateY(-2px);
}

.secondary-control {
    border: 1px solid var(--line);

    background: transparent;

    color: var(--muted);
}

.secondary-control:hover {
    background: var(--panel);

    color: var(--text);

    transform: translateY(-2px);
}


/* =========================================================
   GAME FOOTER
========================================================= */

.game-footer {
    display: flex;
    justify-content: space-between;

    margin-top: auto;
    padding-top: 25px;

    color: #444c59;

    font-size: 8px;
    font-weight: 800;
    letter-spacing: 1.5px;
}


/* =========================================================
   X AND O MARKS
========================================================= */

.board button .mark {
    display: block;
    position: relative;

    width: 58%;
    height: 58%;
}

/* X */

.board button .mark-x::before,
.board button .mark-x::after {
    content: "";

    position: absolute;

    top: 50%;
    left: 50%;

    width: 10px;
    height: 100%;

    border-radius: 999px;

    background: var(--x);
}

.board button .mark-x::before {
    transform: translate(-50%, -50%) rotate(45deg);
}

.board button .mark-x::after {
    transform: translate(-50%, -50%) rotate(-45deg);
}

/* O */

.board button .mark-o {
    width: 62%;
    height: 62%;

    border: 10px solid var(--o);
    border-radius: 50%;
}

/* Winning marks */

.board button.winner .mark-x::before,
.board button.winner .mark-x::after {
    background: #ffffff;
}

.board button.winner .mark-o {
    border-color: #ffffff;
}


/* =========================================================
   ANIMATIONS
========================================================= */

@keyframes loadingAppear {
    from {
        opacity: 0;
        transform: translateY(12px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes loadingBar {
    0% {
        transform: translateX(-120%);
    }

    100% {
        transform: translateX(320%);
    }
}

@keyframes screenSlide {
    from {
        opacity: 0;
        transform: translateY(12px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes boardPop {
    0% {
        transform: scale(0.65);
        opacity: 0;
    }

    70% {
        transform: scale(1.08);
        opacity: 1;
    }

    100% {
        transform: scale(1);
    }
}

@keyframes winnerPulse {
    from {
        transform: scale(1);
    }

    to {
        transform: scale(0.96);
    }
}


/* =========================================================
   TABLET
========================================================= */

@media (max-width: 760px) {

    .menu-screen {
        padding: 30px 18px;
    }

    .brand {
        margin-bottom: 55px;
    }

    .menu-heading h2 {
        font-size: 48px;
    }

    .mode-grid {
        grid-template-columns: 1fr;
    }

    .difficulty-grid {
        grid-template-columns: 1fr;
    }

    .difficulty-card {
        min-height: 145px;
    }

    .game-shell {
        width: 100%;
        max-width: 720px;
    }

    .board-wrapper {
        width: min(100%, 420px);
        max-width: 420px;
    }

    .game-controls {
        width: min(100%, 420px);
        max-width: 420px;
    }
}


/* =========================================================
   MOBILE
========================================================= */

@media (max-width: 520px) {

    body {
        min-height: 100dvh;
    }

    .menu-screen {
        min-height: 100dvh;

        align-items: flex-start;

        padding: 24px 16px;
    }

    .menu-content {
        width: 100%;
        max-width: 920px;

        padding-top: 5px;
    }

    .brand {
        margin-bottom: 48px;
    }

    .brand-mark {
        width: 42px;
        height: 42px;

        flex-basis: 42px;

        border-radius: 12px;

        font-size: 12px;
    }

    .brand-text h1 {
        font-size: 19px;
    }

    .menu-heading {
        margin-bottom: 25px;
    }

    .menu-heading h2 {
        font-size: clamp(38px, 11vw, 48px);

        letter-spacing: -2px;
    }

    .menu-heading p {
        margin-top: 14px;

        font-size: 14px;
    }

    .mode-card {
        min-height: 155px;

        padding: 21px;
    }

    .mode-icon {
        width: 42px;
        height: 42px;

        margin-bottom: 22px;
    }

    .mode-card-content strong {
        font-size: 16px;
    }

    .mode-card-content small {
        font-size: 12px;
    }

    .menu-footer {
        margin-top: 28px;
    }


    /* -----------------------------------------------------
       GAME - MOBILE
    ----------------------------------------------------- */

    .game-screen {
        width: 100%;
        min-height: 100dvh;

        padding: 12px;
    }

    .game-shell {
        width: 100%;
        max-width: 720px;

        min-height: calc(100dvh - 24px);
    }

    .game-topbar {
        min-height: 52px;
    }

    .game-status {
        padding: 27px 0 18px;
    }

    #status {
        font-size: 24px;
    }

    .scoreboard {
        gap: 6px;

        margin-bottom: 18px;
    }

    .score-card {
        min-height: 62px;

        border-radius: 12px;
    }

    .score-card strong {
        font-size: 20px;
    }

    .score-player {
        font-size: 7px;
    }

    .board-wrapper {
        width: min(100%, 420px);
        max-width: 420px;
    }

    .board {
        width: 100%;
        aspect-ratio: 1 / 1;

        gap: 6px;

        padding: 6px;

        border-radius: 17px;
    }

    .board button {
        border-radius: 11px;

        font-size: clamp(38px, 16vw, 62px);
    }

    .game-controls {
        width: min(100%, 420px);
        max-width: 420px;

        gap: 7px;

        margin-top: 12px;
    }

    .primary-control,
    .secondary-control {
        height: 46px;

        font-size: 12px;
    }

    .game-footer {
        padding-top: 16px;

        font-size: 7px;
    }

    .board button .mark {
        width: 58%;
        height: 58%;
    }

    .board button .mark-x::before,
    .board button .mark-x::after {
        width: 8px;
    }

    .board button .mark-o {
        border-width: 7px;
    }
}


/* =========================================================
   SMALL PHONES
========================================================= */

@media (max-width: 380px) {

    .menu-screen {
        padding: 20px 13px;
    }

    .brand {
        margin-bottom: 38px;
    }

    .menu-heading h2 {
        font-size: 35px;
    }

    .mode-card {
        min-height: 140px;

        padding: 18px;
    }

    .mode-icon {
        margin-bottom: 18px;
    }


    /* Game */

    .game-screen {
        padding: 9px;
    }

    .game-shell {
        min-height: calc(100dvh - 18px);
    }

    .game-status {
        padding: 22px 0 14px;
    }

    #status {
        font-size: 21px;
    }

    .score-card {
        min-height: 56px;
    }

    .board-wrapper {
        width: 100%;
        max-width: 380px;
    }

    .board {
        gap: 5px;
        padding: 5px;
    }

    .board button {
        border-radius: 9px;
    }

    .game-controls {
        grid-template-columns: 1fr;
    }

    .game-footer {
        display: none;
    }
}


/* =========================================================
   LANDSCAPE MOBILE
========================================================= */

@media (max-height: 600px) and (orientation: landscape) {

    .menu-screen {
        padding: 20px;
    }

    .brand {
        margin-bottom: 25px;
    }

    .menu-heading {
        margin-bottom: 18px;
    }

    .menu-heading h2 {
        font-size: 34px;
    }

    .menu-heading p {
        display: none;
    }

    .mode-card {
        min-height: 120px;
    }


    /* Game */

    .game-screen {
        padding: 12px 20px;
    }

    .game-shell {
        min-height: calc(100dvh - 24px);
    }

    .game-status {
        padding: 15px 0 10px;
    }

    .scoreboard {
        margin-bottom: 10px;
    }

    .board-wrapper {
        width: min(50vh, 420px);
        max-width: 420px;
    }

    .game-controls {
        margin-top: 8px;
    }

    .game-footer {
        display: none;
    }
}


/* =========================================================
   EXTRA-WIDE SCREENS
   Prevent excessive game scaling
========================================================= */

@media (min-width: 1200px) {

    .game-shell {
        width: 720px;
        max-width: 720px;
    }

    .board-wrapper {
        width: 420px;
        max-width: 420px;
    }

    .game-controls {
        width: 420px;
        max-width: 420px;
    }
}


/* =========================================================
   ACCESSIBILITY
========================================================= */

@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}