* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -webkit-user-drag: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

input {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: black;
    touch-action: none;
}

body {
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    /* Сохраняем градиент поверх черного фона, если нужно, или убираем, если пользователь хочет чисто черный */
    background: radial-gradient(circle at top left, #4f46e5, #020617 55%, #0f172a);
    color: #e5e7eb;
}

.app {
    width: 100%;
    max-width: 440px;
    padding: 16px;
    transform-origin: center;
}

.game-card {
    background: rgba(15, 23, 42, 0.92);
    border-radius: 24px;
    padding: 24px 20px 20px;
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.9);
    border: 1px solid rgba(148, 163, 184, 0.25);
    backdrop-filter: blur(20px);
    overflow: hidden;
}

.game-header {
    text-align: center;
    margin-bottom: 18px;
}

.game-title {
    font-size: 1.75rem;
    letter-spacing: 0.02em;
    font-weight: 800;
    color: #f9fafb;
}

.game-subtitle {
    margin-top: 6px;
    font-size: 0.95rem;
    color: #9ca3af;
}

.controls {
    margin-bottom: 14px;
}

.screen.hidden {
    display: none;
}

.menu-actions {
    display: grid;
    gap: 12px;
    margin-top: 12px;
}

.menu-btn {
    width: 100%;
}

.topbar {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 12px;
    margin: 6px 0 16px;
}

.topbar-title {
    text-align: center;
    font-weight: 800;
    letter-spacing: 0.02em;
    color: #f9fafb;
    font-size: 0.95rem;
}

.topbar-spacer {
    width: 48px;
}

.icon-btn {
    border-radius: 999px;
    padding: 10px 14px;
    border: 1px solid rgba(148, 163, 184, 0.45);
    background: rgba(15, 23, 42, 0.85);
    color: #e5e7eb;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.12s ease-out, filter 0.12s ease-out, background 0.12s ease-out;
}

.icon-btn:hover {
    filter: brightness(1.05);
}

.icon-btn:active {
    transform: translateY(1px) scale(0.98);
}

.setup-block {
    margin: 14px 0;
    padding: 14px 12px;
    border-radius: 18px;
    background: rgba(15, 23, 42, 0.7);
    border: 1px solid rgba(148, 163, 184, 0.25);
}

.setup-label {
    font-weight: 800;
    font-size: 0.95rem;
    margin-bottom: 10px;
    color: #e5e7eb;
}

.preset-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.chip-btn {
    border: 1px solid rgba(148, 163, 184, 0.45);
    border-radius: 14px;
    padding: 8px 6px;
    font-weight: 800;
    color: #e5e7eb;
    background: rgba(2, 6, 23, 0.35);
    cursor: pointer;
    transition: transform 0.12s ease-out, filter 0.12s ease-out, border-color 0.12s ease-out;
    font-size: 0.95rem;
}

.chip-btn.active {
    border-color: rgba(34, 197, 94, 0.8);
    background: radial-gradient(circle at top left, rgba(34, 197, 94, 0.25), rgba(2, 6, 23, 0.2));
}

.chip-btn:active {
    transform: translateY(1px) scale(0.98);
}

.custom-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-top: 12px;
}

.field {
    display: grid;
    gap: 8px;
}

.field-inline {
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 12px;
}

.field-label {
    font-size: 0.85rem;
    color: #9ca3af;
}

.field-input {
    width: 100%;
    border-radius: 14px;
    border: 1px solid rgba(148, 163, 184, 0.45);
    background: rgba(2, 6, 23, 0.35);
    color: #f9fafb;
    padding: 10px 12px;
    font-size: 1rem;
    font-weight: 800;
    outline: none;
}

.field-input:focus {
    border-color: rgba(6, 182, 212, 0.85);
}

.field-input::-webkit-outer-spin-button,
.field-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.field-input[type=number] {
    -moz-appearance: textfield;
}

.mod-grid {
    display: grid;
    gap: 12px;
}

.check {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 10px;
    align-items: center;
    font-size: 0.95rem;
    color: #e5e7eb;
}

.check input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: #06b6d4;
}

.mode-switch {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 6px;
    background: rgba(15, 23, 42, 0.9);
    border-radius: 999px;
    border: 1px solid rgba(148, 163, 184, 0.5);
}

.mode-btn {
    border: none;
    border-radius: 999px;
    padding: 10px 12px;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    background: transparent;
    color: #9ca3af;
    transition: all 0.18s ease-out;
}

.mode-btn.active {
    background: linear-gradient(135deg, #4f46e5, #06b6d4);
    color: #f9fafb;
    box-shadow: 0 18px 44px rgba(59, 130, 246, 0.25);
}

.mode-btn:hover:not(.active) {
    background: rgba(30, 64, 175, 0.55);
    color: #e5e7eb;
}

.info-panel {
    margin-top: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.players-info {
    display: flex;
    gap: 8px;
}

.player-label {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border-radius: 999px;
    font-size: 0.85rem;
    background: rgba(15, 23, 42, 0.9);
    border: 1px solid transparent;
    color: #9ca3af;
}

.player-label.active {
    border-color: #4f46e5;
    background: radial-gradient(circle at top left, rgba(79, 70, 229, 0.4), rgba(15, 23, 42, 0.95));
    color: #e5e7eb;
}

.player-label .mark {
    font-weight: 900;
    font-size: 0.95rem;
}

.status {
    font-size: 0.9rem;
    color: #e5e7eb;
    padding: 6px 10px;
    border-radius: 999px;
    background: rgba(31, 41, 55, 0.9);
    border: 1px solid rgba(55, 65, 81, 0.9);
    white-space: nowrap;
}

.board {
    margin: 12px auto 16px;
    width: min(420px, 100%);
    display: grid;
    grid-template-columns: repeat(var(--cols, 3), 1fr);
    gap: var(--gap, 6px);
    padding: 14px;
    border-radius: 24px;
    background: radial-gradient(circle at top, rgba(15, 23, 42, 0.9), rgba(15, 23, 42, 0.6));
    border: 1px solid rgba(148, 163, 184, 0.3);
}

.cell {
    aspect-ratio: 1 / 1;
    border-radius: 16px;
    border: 1px solid rgba(75, 85, 99, 0.9);
    background: radial-gradient(circle at top left, rgba(30, 64, 175, 0.25), rgba(15, 23, 42, 0.98));
    color: #f9fafb;
    font-size: var(--cell-font, 2.2rem);
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.12s ease-out, box-shadow 0.12s ease-out, background 0.12s ease-out, border-color 0.12s ease-out;
}

.cell:hover:not(.filled) {
    transform: translateY(-1px);
    box-shadow: 0 18px 44px rgba(15, 23, 42, 0.55);
    border-color: #4f46e5;
}

.cell:active:not(.filled) {
    transform: translateY(1px) scale(0.98);
    box-shadow: none;
}

.cell.filled {
    cursor: default;
    border-color: rgba(75, 85, 99, 0.9);
}

.cell.winning {
    background: radial-gradient(circle at center, #22c55e, #15803d);
    box-shadow: 0 0 44px rgba(34, 197, 94, 0.55);
}

.mark-anim {
    display: inline-block;
    animation: popIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes popIn {
    0% {
        opacity: 0;
        transform: scale(0.5) rotate(-15deg);
    }
    100% {
        opacity: 1;
        transform: scale(1) rotate(0deg);
    }
}

.board.restarting {
    animation: fadeOutScale 0.4s ease-in forwards;
}

@keyframes fadeOutScale {
    0% {
        opacity: 1;
        transform: scale(1);
    }
    100% {
        opacity: 0;
        transform: scale(0.95);
    }
}

.game-footer {
    display: flex;
    justify-content: center;
}

.primary-btn {
    border-radius: 999px;
    padding: 11px 20px;
    border: none;
    font-size: 0.95rem;
    font-weight: 800;
    cursor: pointer;
    background: linear-gradient(135deg, #06b6d4, #4f46e5);
    color: #f9fafb;
    box-shadow: 0 18px 44px rgba(8, 47, 73, 0.45);
    transition: transform 0.12s ease-out, box-shadow 0.12s ease-out, filter 0.12s ease-out;
}

.primary-btn:hover {
    filter: brightness(1.05);
    transform: translateY(-1px);
}

.primary-btn:active {
    transform: translateY(1px) scale(0.97);
    box-shadow: 0 10px 28px rgba(8, 47, 73, 0.55);
}

@media (max-width: 480px) {
    .app {
        padding: 12px;
    }

    .game-card {
        padding: 18px 16px 16px;
        border-radius: 20px;
    }

    .status {
        display: none;
    }
}

/* Fix for high zoom-out (25%) where borders look too thick */
.low-dpr .game-card,
.low-dpr .setup-block,
.low-dpr .chip-btn,
.low-dpr .field-input,
.low-dpr .mode-switch,
.low-dpr .board,
.low-dpr .cell,
.low-dpr .status,
.low-dpr .icon-btn,
.low-dpr .player-label {
    border-width: 0.5px;
}
