* { box-sizing: border-box; margin: 0; padding: 0; }

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    background: linear-gradient(160deg, #0f3d4a 0%, #1a6b5c 45%, #5daf7a 100%);
    min-height: 100vh;
    min-height: 100dvh;
    color: #1a1a1a;
    padding: max(12px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
    -webkit-font-smoothing: antialiased;
    touch-action: manipulation;
}

.wrap {
    max-width: min(420px, 100%);
    margin: 0 auto;
}

.head { text-align: center; margin-bottom: clamp(12px, 3vw, 16px); }

.head h1 {
    font-size: clamp(1.25rem, 4.2vw, 1.55rem);
    color: #fff;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
    margin-bottom: 12px;
    letter-spacing: 0.02em;
}

.stats {
    display: flex;
    justify-content: center;
    gap: clamp(10px, 3vw, 20px);
    flex-wrap: wrap;
}

.stat {
    background: rgba(255, 255, 255, 0.96);
    padding: 10px 16px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    border-radius: 12px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
}

.stat .lbl { color: #555; margin-right: 8px; font-size: 0.88rem; }

.controls-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: clamp(12px, 3vw, 16px);
}

.lbl-inline {
    color: #fff;
    font-size: 0.92rem;
    display: flex;
    align-items: center;
    gap: 8px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

.lbl-inline select {
    min-height: 44px;
    padding: 8px 14px;
    border-radius: 10px;
    border: none;
    font-size: 1rem;
    background: #fff;
    color: #134e5e;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23134e5e' d='M2 4l4 4 4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 32px;
}

.btn {
    min-height: 44px;
    padding: 10px 20px;
    border: none;
    border-radius: 12px;
    background: #fff;
    color: #134e5e;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.14);
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    transition: transform 0.08s ease, box-shadow 0.12s ease, filter 0.12s ease;
}

.btn:hover { filter: brightness(1.03); }

.btn:active {
    transform: scale(0.98);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

.board {
    display: grid;
    gap: clamp(4px, 1.8vw, 8px);
    padding: clamp(8px, 2.5vw, 12px);
    width: 100%;
    max-width: min(92vw, 400px);
    aspect-ratio: 1;
    margin-inline: auto;
    background: rgba(0, 0, 0, 0.22);
    border-radius: 16px;
    box-shadow: inset 0 2px 12px rgba(0, 0, 0, 0.15), 0 8px 28px rgba(0, 0, 0, 0.12);
    outline: none;
    -webkit-tap-highlight-color: transparent;
}

.board:focus-visible {
    box-shadow: inset 0 2px 12px rgba(0, 0, 0, 0.15), 0 0 0 3px rgba(255, 255, 255, 0.55);
    border-radius: 16px;
}

.tile {
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(0.8rem, calc(22vw / var(--sp-n, 4)), 1.5rem);
    font-weight: 700;
    border-radius: clamp(8px, 2vw, 12px);
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    border: 2px solid rgba(255, 255, 255, 0.45);
    color: #fff;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.tile:not(.empty):active {
    transform: scale(0.96);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

.tile.empty {
    visibility: hidden;
    pointer-events: none;
    cursor: default;
    border: none;
}

@media (hover: hover) and (pointer: fine) {
    .tile:not(.empty):hover {
        transform: scale(1.03);
        box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18);
    }
}

.hint {
    text-align: center;
    color: rgba(255, 255, 255, 0.92);
    font-size: clamp(0.8rem, 2.8vw, 0.9rem);
    margin-top: 14px;
    line-height: 1.55;
    padding: 0 4px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}

.win-banner {
    margin-top: 14px;
    text-align: center;
    padding: 14px 12px;
    background: rgba(255, 255, 255, 0.96);
    border-radius: 14px;
    font-weight: 700;
    color: #134e5e;
    font-size: clamp(1rem, 3.2vw, 1.12rem);
    outline: none;
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.1);
}

.win-banner:focus-visible {
    box-shadow: 0 0 0 3px rgba(19, 78, 94, 0.45), 0 4px 18px rgba(0, 0, 0, 0.1);
}

.win-banner.hidden { display: none; }

@media (prefers-reduced-motion: reduce) {
    .btn,
    .tile {
        transition: none;
    }
    .btn:active,
    .tile:not(.empty):active {
        transform: none;
    }
}
