/* Sea Battle – deep-sea sonar look (dark) and nautical chart (light) */
@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 100 900;
    font-display: swap;
    src: url('fonts/inter-latin-wght-normal.woff2') format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 100 900;
    font-display: swap;
    src: url('fonts/inter-latin-ext-wght-normal.woff2') format('woff2');
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* Site-wide brand font, used only for the credit in the footer */
@font-face {
    font-family: 'Stack Sans Notch';
    src: url('/fonts/StackSansNotch.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

:root {
    --bg: #06182A;
    --bg-glow: #0B2D4A;
    --surface: #0C2539;
    --surface-2: #11314C;
    --surface-3: #17405F;
    --border: rgba(125, 190, 230, 0.16);
    --border-strong: rgba(125, 190, 230, 0.3);
    --text: #E4F0FA;
    --muted: #8EA8BE;
    --accent: #2DD4BF;
    --accent-strong: #5EEAD4;
    --accent-ink: #032824;
    --accent-soft: rgba(45, 212, 191, 0.14);
    --sea: #0A3150;
    --sea-2: #0D3A5E;
    --grid-line: rgba(140, 200, 240, 0.13);
    --label: rgba(160, 205, 235, 0.55);
    --hit: #FF5B4F;
    --hit-glow: rgba(255, 91, 79, 0.55);
    --miss: #A8D2EE;
    --sunk-bg: rgba(255, 91, 79, 0.2);
    --good: #34D399;
    --gold: #F5C451;
    --warm: #F59E0B;
    --danger: #F87171;
    --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
    --hull: #8A9BAE;
    --hull-dark: #4E5F72;
    --lab: 18px;
    --radius: 16px;
    color-scheme: dark;
}

:root[data-theme="light"] {
    --bg: #EDF3F7;
    --bg-glow: #DCEBF5;
    --surface: #FFFFFF;
    --surface-2: #F2F7FA;
    --surface-3: #E3EEF5;
    --border: #D3E0EA;
    --border-strong: #B7CBDA;
    --text: #0B2540;
    --muted: #546E86;
    --accent: #0E8C83;
    --accent-strong: #0B7068;
    --accent-ink: #FFFFFF;
    --accent-soft: rgba(14, 140, 131, 0.1);
    --sea: #D3E8F5;
    --sea-2: #C2DEF0;
    --grid-line: rgba(11, 37, 64, 0.12);
    --label: rgba(11, 37, 64, 0.5);
    --hit: #DD3426;
    --hit-glow: rgba(221, 52, 38, 0.4);
    --miss: #4F7FA4;
    --sunk-bg: rgba(221, 52, 38, 0.14);
    --good: #059669;
    --gold: #B7791F;
    --warm: #C2410C;
    --danger: #DC2626;
    --shadow: 0 16px 40px rgba(11, 37, 64, 0.14);
    color-scheme: light;
}

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

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

body {
    font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
    background: radial-gradient(1200px 700px at 15% -10%, var(--bg-glow), transparent 60%), var(--bg);
    background-attachment: fixed;
    color: var(--text);
    min-height: 100vh;
    min-height: 100dvh;
    line-height: 1.45;
    font-feature-settings: 'cv11', 'ss01';
}

button, input {
    font: inherit;
    color: inherit;
}

button {
    cursor: pointer;
    background: none;
    border: none;
}

button:disabled {
    cursor: not-allowed;
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.hidden {
    display: none !important;
}

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

.center {
    text-align: center;
}

/* ---------- Buttons & controls ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 46px;
    padding: 10px 18px;
    border-radius: 12px;
    font-weight: 700;
    font-size: 15px;
    letter-spacing: 0.01em;
    transition: transform 0.12s, background 0.15s, border-color 0.15s, opacity 0.15s;
    text-decoration: none;
}

.btn:active:not(:disabled) {
    transform: translateY(1px);
}

.btn:disabled {
    opacity: 0.45;
}

.btn-block {
    width: 100%;
}

.btn-primary {
    background: var(--accent);
    color: var(--accent-ink);
    box-shadow: 0 6px 20px var(--accent-soft);
}

.btn-primary:hover:not(:disabled) {
    background: var(--accent-strong);
}

.btn-secondary {
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--surface-3);
}

.btn-ghost {
    color: var(--muted);
}

.btn-ghost:hover:not(:disabled) {
    color: var(--text);
    background: var(--surface-2);
}

.btn-danger {
    background: var(--danger);
    color: #fff;
}

.btn.loading {
    position: relative;
    color: transparent !important;
}

.btn.loading::after {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    border: 2.5px solid var(--accent-ink);
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

.btn-secondary.loading::after {
    border-color: var(--text);
    border-right-color: transparent;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.btn-icon {
    display: inline-grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    color: var(--muted);
    transition: background 0.15s, color 0.15s;
}

.btn-icon:hover {
    background: var(--surface-2);
    color: var(--text);
}

.btn-icon.muted-icon {
    opacity: 0.4;
}

.link-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--accent);
    font-weight: 600;
    font-size: 14px;
    padding: 6px 2px;
}

.link-btn:hover {
    color: var(--accent-strong);
    text-decoration: underline;
    text-underline-offset: 3px;
}

input[type="text"] {
    width: 100%;
    min-height: 48px;
    padding: 12px 14px;
    border-radius: 12px;
    border: 1px solid var(--border-strong);
    background: var(--surface-2);
    font-size: 16px;
    transition: border-color 0.15s, box-shadow 0.15s;
}

input[type="text"]:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.chip input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.chip > span {
    display: inline-flex;
    align-items: center;
    min-height: 36px;
    padding: 6px 13px;
    border-radius: 999px;
    border: 1px solid var(--border-strong);
    font-size: 14px;
    font-weight: 600;
    color: var(--muted);
    cursor: pointer;
    transition: all 0.15s;
}

.chip input:checked + span {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--text);
}

.chip input:focus-visible + span {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.switch {
    appearance: none;
    flex-shrink: 0;
    width: 44px;
    height: 26px;
    border-radius: 999px;
    background: var(--surface-3);
    border: 1px solid var(--border-strong);
    position: relative;
    cursor: pointer;
    transition: background 0.2s;
}

.switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--muted);
    transition: transform 0.2s, background 0.2s;
}

.switch:checked {
    background: var(--accent);
    border-color: var(--accent);
}

.switch:checked::after {
    transform: translateX(18px);
    background: var(--accent-ink);
}

.option-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.option-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 10px 0;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
}

.option-row small {
    display: block;
    font-weight: 500;
    font-size: 12.5px;
    color: var(--muted);
}

.option-row.compact {
    padding: 4px 0;
    font-size: 14px;
}

/* ---------- Screens ---------- */
.screen {
    display: none;
}

.screen.active {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
}

/* ---------- Lobby ---------- */
#screen-lobby {
    padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
}

.top-tools {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    max-width: 1080px;
    width: 100%;
    margin: 0 auto;
}

.theme-selector, .lang-selector {
    display: flex;
    gap: 2px;
    padding: 3px;
    border-radius: 11px;
    background: var(--surface);
    border: 1px solid var(--border);
}

.theme-tab, .lang-btn {
    padding: 6px 11px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 700;
    color: var(--muted);
}

.theme-tab.active, .lang-btn.active {
    background: var(--surface-3);
    color: var(--text);
}

.theme-toggle, .lang-toggle {
    display: none;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border-radius: 11px;
    background: var(--surface);
    border: 1px solid var(--border);
    font-size: 13px;
    font-weight: 700;
}

.lobby-container {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 48px;
    align-items: center;
    max-width: 1080px;
    width: 100%;
    margin: 0 auto;
    padding: 32px 0;
}

.hero {
    position: relative;
}

.radar {
    position: relative;
    width: 132px;
    height: 132px;
    border-radius: 50%;
    margin-bottom: 22px;
    background: radial-gradient(circle, transparent 0 22%, var(--grid-line) 22.5% 23.5%, transparent 24% 46%, var(--grid-line) 46.5% 47.5%, transparent 48% 70%, var(--grid-line) 70.5% 71.5%, transparent 72%),
    linear-gradient(var(--grid-line), var(--grid-line)) center / 1px 100% no-repeat,
    linear-gradient(var(--grid-line), var(--grid-line)) center / 100% 1px no-repeat,
    var(--sea);
    border: 1px solid var(--border-strong);
    overflow: hidden;
    box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.35), 0 0 40px var(--accent-soft);
}

.radar.small {
    width: 96px;
    height: 96px;
    margin: 0 auto 20px;
}

.radar-sweep {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: conic-gradient(from 0deg, transparent 0deg 300deg, rgba(45, 212, 191, 0.05) 310deg, rgba(45, 212, 191, 0.5) 360deg);
    animation: sweep 3.2s linear infinite;
}

@keyframes sweep {
    to {
        transform: rotate(360deg);
    }
}

.radar-blip {
    position: absolute;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 10px var(--accent);
    animation: blip 3.2s ease-out infinite;
}

.radar-blip.b1 {
    top: 28%;
    left: 62%;
    animation-delay: 0.3s;
}

.radar-blip.b2 {
    top: 64%;
    left: 70%;
    animation-delay: 1.1s;
}

.radar-blip.b3 {
    top: 58%;
    left: 24%;
    animation-delay: 2.2s;
    background: var(--hit);
    box-shadow: 0 0 10px var(--hit);
}

@keyframes blip {
    0%, 100% {
        opacity: 0;
        transform: scale(0.6);
    }
    8% {
        opacity: 1;
        transform: scale(1.2);
    }
    50% {
        opacity: 0.25;
        transform: scale(1);
    }
}

.logo-title {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: clamp(34px, 5vw, 50px);
    font-weight: 850;
    letter-spacing: -0.03em;
    line-height: 1.05;
}

.logo-mark {
    border-radius: 11px;
}

.logo-subtitle {
    margin-top: 10px;
    font-size: 18px;
    color: var(--muted);
    max-width: 30ch;
}

.hero-links {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 18px;
    margin-top: 14px;
}

.howto-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin-top: 28px;
}

.howto-list li {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.howto-num {
    flex-shrink: 0;
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 800;
    font-size: 14px;
    font-variant-numeric: tabular-nums;
}

.howto-list strong {
    font-size: 15px;
}

.howto-list p {
    font-size: 14px;
    color: var(--muted);
}

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

.lobby-step {
    display: none;
}

.lobby-step.active {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.step-title {
    font-size: 22px;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.step-hint {
    color: var(--muted);
    font-size: 14px;
    margin-top: -8px;
}

.greeting {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
}

.mode-tabs {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
    padding: 4px;
    border-radius: 14px;
    background: var(--surface-2);
    border: 1px solid var(--border);
}

.mode-tab {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 10px 6px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 700;
    color: var(--muted);
}

.mode-tab.active {
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.mode-panel {
    display: none;
    flex-direction: column;
    gap: 12px;
}

.mode-panel.active {
    display: flex;
}

.mode-card {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px;
    border-radius: var(--radius);
    background: var(--surface-2);
    border: 1px solid var(--border);
}

.mode-card.highlight {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.mode-head {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.mode-head h3 {
    font-size: 16px;
    font-weight: 750;
}

.mode-head p {
    font-size: 13.5px;
    color: var(--muted);
}

.mode-icon {
    flex-shrink: 0;
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: var(--accent-soft);
    color: var(--accent);
}

.mode-icon.alt {
    background: rgba(120, 170, 255, 0.14);
    color: #7FB0FF;
}

:root[data-theme="light"] .mode-icon.alt {
    color: #2F6BD6;
}

.mode-icon.warm {
    background: rgba(245, 158, 11, 0.14);
    color: var(--warm);
}

.field {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.field-label {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
}

.code-input {
    text-align: center;
    font-size: 22px !important;
    font-weight: 800;
    letter-spacing: 0.3em;
    font-variant-numeric: tabular-nums;
}

.site-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    max-width: 1080px;
    width: 100%;
    margin: 0 auto;
    padding-top: 12px;
    border-top: 1px solid var(--border);
    font-size: 13px;
}

.credit-block {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.credit {
    color: var(--muted);
    text-decoration: none;
}

.credit-name {
    font-family: 'Stack Sans Notch', 'Inter', sans-serif;
    color: var(--text);
    font-weight: 700;
}

.credit-ai {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    color: var(--muted);
    font-size: 12px;
}

.footer-actions {
    display: flex;
    gap: 6px;
    align-items: center;
}

.foot-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 10px;
    border-radius: 8px;
    border: 1px solid var(--border);
    color: var(--muted);
    font-size: 12.5px;
    font-weight: 600;
    text-decoration: none;
}

.foot-btn:hover {
    color: var(--text);
    border-color: var(--border-strong);
}

.donate-btn {
    color: var(--hit);
}

/* ---------- Waiting ---------- */
.waiting-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 10px;
    padding: 24px 16px;
    max-width: 440px;
    margin: 0 auto;
}

.brand-mark {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 800;
    margin-bottom: 18px;
}

.brand-mark img {
    border-radius: 8px;
}

.waiting-container h2 {
    font-size: 22px;
}

.room-code-display {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    margin: 8px 0;
    padding: 12px 20px;
    border-radius: 14px;
    background: var(--surface);
    border: 1px dashed var(--accent);
    font-size: 30px;
    font-weight: 850;
    letter-spacing: 0.22em;
    font-variant-numeric: tabular-nums;
    color: var(--accent);
}

.waiting-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
    margin-top: 10px;
}

/* ---------- Game screen ---------- */
#screen-game {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    padding-top: env(safe-area-inset-top);
}

.game-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 14px;
    border-bottom: 1px solid var(--border);
    background: color-mix(in srgb, var(--bg) 80%, transparent);
}

.game-title {
    display: flex;
    align-items: center;
    gap: 9px;
    font-weight: 800;
    font-size: 17px;
    color: var(--text);
    text-decoration: none;
}

.game-title img {
    border-radius: 7px;
}

.game-header-right {
    display: flex;
    align-items: center;
    gap: 2px;
}

.mode-badge {
    margin-right: 6px;
    padding: 4px 10px;
    border-radius: 999px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    font-size: 12px;
    font-weight: 700;
    color: var(--muted);
}

.scoreboard {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
}

.captain {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    padding: 6px 10px;
    border-radius: 12px;
    border: 1px solid transparent;
    transition: background 0.2s, border-color 0.2s;
}

.captain.right {
    justify-content: flex-end;
    text-align: right;
}

.captain.active-turn {
    background: var(--accent-soft);
    border-color: color-mix(in srgb, var(--accent) 50%, transparent);
}

.captain-dot {
    flex-shrink: 0;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--border-strong);
}

.captain.active-turn .captain-dot {
    background: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-soft);
}

.captain-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.captain-name {
    font-weight: 750;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.captain-sub {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    color: var(--muted);
}

.captain.right .captain-sub {
    justify-content: flex-end;
}

.online-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--good);
}

.online-dot.offline {
    background: var(--danger);
}

.captain-clock {
    padding: 4px 9px;
    border-radius: 8px;
    background: var(--surface-2);
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    font-size: 15px;
}

.captain-clock.running {
    background: var(--surface-3);
    color: var(--text);
}

.captain-clock.low-time.running {
    color: var(--hit);
}

.turn-indicator {
    text-align: center;
    font-weight: 750;
    font-size: 14px;
    color: var(--muted);
    padding: 6px 12px;
    border-radius: 999px;
    max-width: 34ch;
}

.turn-indicator.mine {
    color: var(--accent);
}

.turn-indicator.over {
    color: var(--gold);
    cursor: pointer;
}

.banner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
    margin: 0 14px 8px;
    padding: 8px 12px;
    border-radius: 12px;
    background: rgba(245, 158, 11, 0.14);
    border: 1px solid rgba(245, 158, 11, 0.35);
    font-size: 14px;
    font-weight: 600;
}

.banner .btn {
    min-height: 36px;
    padding: 6px 14px;
    font-size: 14px;
}

.game-body {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 14px;
    padding: 0 14px;
}

.board-title {
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
}

.board-hint {
    font-size: 14px;
    color: var(--muted);
    margin: 4px 0 12px;
}

/* ---------- The grid ---------- */
.grid-wrap {
    width: 100%;
}

.sea-grid {
    display: grid;
    grid-template-columns: var(--lab) repeat(10, minmax(0, 1fr));
    grid-template-rows: var(--lab) repeat(10, auto);
    width: 100%;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

body.no-coords .sea-grid {
    --lab: 0px;
}

body.no-coords .grid-label {
    display: none;
}

.grid-label {
    display: grid;
    place-items: center;
    font-size: 10.5px;
    font-weight: 700;
    color: var(--label);
    font-variant-numeric: tabular-nums;
}

.cell {
    position: relative;
    aspect-ratio: 1;
    background: var(--sea);
    border-right: 1px solid var(--grid-line);
    border-bottom: 1px solid var(--grid-line);
    transition: background 0.12s;
}

.cell[data-i$="0"] {
    border-left: 1px solid var(--grid-line);
}

.cell[data-i="0"], .cell[data-i="1"], .cell[data-i="2"], .cell[data-i="3"], .cell[data-i="4"],
.cell[data-i="5"], .cell[data-i="6"], .cell[data-i="7"], .cell[data-i="8"], .cell[data-i="9"] {
    border-top: 1px solid var(--grid-line);
}

.cell[data-i="0"] {
    border-top-left-radius: 8px;
}

.cell[data-i="9"] {
    border-top-right-radius: 8px;
}

.cell[data-i="90"] {
    border-bottom-left-radius: 8px;
}

.cell[data-i="99"] {
    border-bottom-right-radius: 8px;
}

.sea-grid.armed .cell:not(:disabled):hover {
    background: var(--sea-2);
    box-shadow: inset 0 0 0 2px var(--accent);
    cursor: crosshair;
}

.sea-grid.armed .cell:not(:disabled):hover::before {
    content: '';
    position: absolute;
    inset: 30%;
    border-radius: 50%;
    border: 2px solid var(--accent);
    z-index: 2;
}

button.cell:disabled {
    cursor: default;
}

/* Ships sit on top of the cells; marks sit on top of the ships */
.ship {
    position: relative;
    z-index: 1;
    margin: 3px;
    border-radius: 999px;
    background: linear-gradient(180deg, var(--hull) 0%, var(--hull-dark) 100%);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 3px 8px rgba(0, 0, 0, 0.35);
    pointer-events: none;
    transition: opacity 0.2s;
}

.ship-v {
    background: linear-gradient(90deg, var(--hull) 0%, var(--hull-dark) 100%);
}

.ship-deck {
    position: absolute;
    inset: 30% 16%;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.16);
    border: 1px solid rgba(0, 0, 0, 0.18);
}

.ship-v .ship-deck {
    inset: 16% 30%;
}

.ship.sunk {
    background: linear-gradient(180deg, #6B3A37, #3B1E1D);
    opacity: 0.92;
}

.ship.revealed {
    opacity: 0.55;
    background: transparent;
    border: 2px dashed var(--hull);
    box-shadow: none;
}

.ship.revealed .ship-deck {
    display: none;
}

.ship.ghost {
    opacity: 0.55;
}

.ship.lifted {
    opacity: 0.3;
}

.cell::after {
    position: absolute;
    z-index: 2;
    pointer-events: none;
}

.cell.c-miss::after {
    content: '';
    inset: 36%;
    border-radius: 50%;
    background: var(--miss);
    opacity: 0.85;
}

.cell.c-hit::after, .cell.c-sunk::after {
    content: '';
    inset: 22%;
    border-radius: 50%;
    background: radial-gradient(circle at 40% 35%, #FFE3B0 0 18%, #FF9A4A 35%, var(--hit) 62%, transparent 66%);
    filter: drop-shadow(0 0 6px var(--hit-glow));
}

.cell.c-sunk {
    background: var(--sunk-bg);
}

.cell.c-sunk::after {
    inset: 26%;
    background: linear-gradient(45deg, transparent 42%, var(--hit) 42% 58%, transparent 58%),
    linear-gradient(-45deg, transparent 42%, var(--hit) 42% 58%, transparent 58%);
    filter: none;
}

.cell.c-cleared::after {
    content: '';
    inset: 44%;
    border-radius: 50%;
    background: var(--miss);
    opacity: 0.35;
}

.cell.c-last {
    box-shadow: inset 0 0 0 2px var(--gold);
}

.cell.c-fresh.c-miss::before, .cell.c-fresh.c-hit::before, .cell.c-fresh.c-sunk::before {
    content: '';
    position: absolute;
    inset: 10%;
    border-radius: 50%;
    z-index: 3;
    border: 2px solid var(--miss);
    animation: ripple 0.8s ease-out forwards;
    pointer-events: none;
}

.cell.c-fresh.c-hit::before, .cell.c-fresh.c-sunk::before {
    border: none;
    background: radial-gradient(circle, #FFF2C8 0 20%, #FF9A4A 40%, var(--hit) 60%, transparent 70%);
    animation: blast 0.6s ease-out forwards;
}

@keyframes ripple {
    from {
        transform: scale(0.2);
        opacity: 1;
    }
    to {
        transform: scale(1.8);
        opacity: 0;
    }
}

@keyframes blast {
    from {
        transform: scale(0.3);
        opacity: 1;
    }
    to {
        transform: scale(2.2);
        opacity: 0;
    }
}

.cell.c-preview {
    background: color-mix(in srgb, var(--accent) 28%, var(--sea));
}

.cell.c-preview-bad {
    background: color-mix(in srgb, var(--hit) 35%, var(--sea));
}

.cell.c-hint {
    animation: hint 0.8s ease-in-out 3;
    box-shadow: inset 0 0 0 3px var(--gold);
}

@keyframes hint {
    50% {
        background: color-mix(in srgb, var(--gold) 40%, var(--sea));
    }
}

#grid-place .cell {
    cursor: pointer;
}

#grid-place.locked .cell {
    cursor: default;
}

/* ---------- Placement ---------- */
.placement {
    display: grid;
    grid-template-columns: minmax(0, 520px) minmax(240px, 300px);
    justify-content: center;
    align-content: start;
    gap: 28px;
    overflow-y: auto;
    padding: 6px 2px 16px;
}

.placement-side {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding-top: 34px;
}

.dock {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.dock-ship {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 10px 12px;
    border-radius: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    text-align: left;
    transition: border-color 0.15s, background 0.15s;
}

.dock-ship:hover:not(:disabled) {
    border-color: var(--border-strong);
}

.dock-ship.selected {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.dock-hull, .rule-ship, .pip {
    display: inline-flex;
    gap: 2px;
}

.dock-hull i, .rule-ship i, .pip i {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    background: linear-gradient(180deg, var(--hull), var(--hull-dark));
}

.dock-hull i:first-child, .rule-ship i:first-child, .pip i:first-child {
    border-radius: 6px 3px 3px 6px;
}

.dock-hull i:last-child, .rule-ship i:last-child, .pip i:last-child {
    border-radius: 3px 6px 6px 3px;
}

.dock-ship:not(.placed) .dock-hull i {
    background: transparent;
    border: 1.5px dashed var(--border-strong);
}

.dock-name {
    font-weight: 650;
    font-size: 14px;
}

.dock-len {
    font-size: 12px;
    font-weight: 800;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.placement-tools {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 8px;
}

.placement-tools .btn {
    min-height: 42px;
    padding: 8px 10px;
    font-size: 14px;
}

.place-timer {
    font-size: 13px;
    text-align: center;
    min-height: 1em;
}

/* ---------- Battle ---------- */
.battle {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
    gap: 20px;
    align-items: start;
    overflow-y: auto;
    padding: 4px 2px 16px;
}

.board-card {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 14px;
    border-radius: 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    transition: border-color 0.25s, box-shadow 0.25s;
}

.battle:not(.defending) .board-card.enemy,
.battle.defending .board-card.own {
    border-color: color-mix(in srgb, var(--accent) 45%, transparent);
    box-shadow: 0 0 0 4px var(--accent-soft);
}

.battle.defending .board-card.own {
    border-color: color-mix(in srgb, var(--hit) 45%, transparent);
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--hit) 12%, transparent);
}

.board-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.fleet-pips {
    list-style: none;
    display: flex;
    gap: 7px;
    flex-wrap: wrap;
}

.pip i {
    width: 8px;
    height: 8px;
}

.pip.sunk i {
    background: var(--hit);
    opacity: 0.45;
}

/* ---------- Side panel ---------- */
.side-panel {
    min-height: 0;
    padding-bottom: 12px;
}

.side-inner {
    height: 100%;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 14px;
    border-radius: 18px;
    background: var(--surface);
    border: 1px solid var(--border);
}

.side-title {
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 8px;
}

.log-wrap {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.log-list {
    flex: 1;
    min-height: 60px;
    overflow-y: auto;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.log-item {
    position: relative;
    padding: 5px 8px 5px 20px;
    border-radius: 8px;
    font-size: 13px;
    color: var(--muted);
}

.log-item::before {
    content: '';
    position: absolute;
    left: 7px;
    top: 50%;
    width: 7px;
    height: 7px;
    margin-top: -3.5px;
    border-radius: 50%;
    background: var(--miss);
}

.log-item.hit::before, .log-item.sunk::before {
    background: var(--hit);
}

.log-item.sunk {
    color: var(--text);
    font-weight: 650;
    background: var(--sunk-bg);
}

.log-item.info::before {
    background: var(--accent);
}

.log-item.info {
    color: var(--text);
    font-weight: 600;
}

.log-item.mine {
    color: var(--text);
}

.chat {
    flex: 1.2;
    min-height: 0;
    display: flex;
    flex-direction: column;
    border-top: 1px solid var(--border);
    padding-top: 12px;
}

.chat-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-close {
    display: none;
}

.chat-list {
    flex: 1;
    min-height: 60px;
    overflow-y: auto;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 4px 0 8px;
}

.chat-msg {
    max-width: 85%;
    padding: 7px 11px;
    border-radius: 14px;
    font-size: 14px;
    overflow-wrap: anywhere;
}

.chat-msg.me {
    align-self: flex-end;
    background: var(--accent);
    color: var(--accent-ink);
    border-bottom-right-radius: 4px;
}

.chat-msg.them {
    align-self: flex-start;
    background: var(--surface-3);
    border-bottom-left-radius: 4px;
}

.chat-form {
    display: flex;
    gap: 6px;
}

.chat-form input {
    min-height: 42px;
    padding: 8px 12px;
    font-size: 15px;
}

.chat-send {
    flex-shrink: 0;
    width: 42px;
    border-radius: 12px;
    background: var(--accent);
    color: var(--accent-ink);
    display: grid;
    place-items: center;
}

.panel-backdrop {
    display: none;
}

/* ---------- Action bar ---------- */
.game-actions {
    display: flex;
    justify-content: center;
    gap: 8px;
    padding: 10px 14px max(10px, env(safe-area-inset-bottom));
    border-top: 1px solid var(--border);
}

.action-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 9px 14px;
    border-radius: 11px;
    background: var(--surface);
    border: 1px solid var(--border);
    font-size: 14px;
    font-weight: 650;
    position: relative;
}

.action-btn:hover:not(:disabled) {
    border-color: var(--border-strong);
}

.action-btn:disabled {
    opacity: 0.4;
}

.action-btn.danger {
    color: var(--danger);
}

.action-btn.primary {
    background: var(--accent);
    color: var(--accent-ink);
    border-color: var(--accent);
}

.action-btn.has-unread::after {
    content: '';
    position: absolute;
    top: 6px;
    right: 6px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--hit);
}

.panel-toggle {
    display: none;
}

/* ---------- Same-device curtain ---------- */
.curtain {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: grid;
    place-items: center;
    padding: 24px;
    background: radial-gradient(800px 500px at 50% 20%, var(--bg-glow), transparent 70%), var(--bg);
}

.curtain-inner {
    max-width: 420px;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: center;
}

.curtain-inner h2 {
    font-size: 26px;
    letter-spacing: -0.02em;
}

/* ---------- Modals ---------- */
.modal {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: grid;
    place-items: center;
    padding: 16px;
    background: rgba(2, 10, 20, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    width: 100%;
    max-width: 440px;
    max-height: calc(100dvh - 32px);
    overflow-y: auto;
    padding: 24px;
    border-radius: 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.modal-content h3 {
    font-size: 20px;
    padding-right: 36px;
}

.modal-close {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: grid;
    place-items: center;
    color: var(--muted);
}

.modal-close:hover {
    background: var(--surface-2);
    color: var(--text);
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 8px;
}

.rules-content {
    max-width: 560px;
}

.rules-body {
    display: flex;
    flex-direction: column;
    gap: 16px;
    font-size: 14.5px;
}

.rules-body h4 {
    font-size: 15px;
    color: var(--accent);
    margin-bottom: 4px;
}

.rules-body p, .rules-body li {
    color: var(--muted);
}

.rules-body ul {
    padding-left: 20px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.rules-body ul.rule-fleet {
    list-style: none;
    padding: 8px 0 0;
}

.rule-fleet li {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text);
}

.rule-ship {
    min-width: 72px;
}

.rule-ship i {
    width: 11px;
    height: 11px;
}

.custom-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.custom-title {
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
}

.hull-options {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 6px;
}

.hull-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 10px;
    border: 1px solid var(--border);
    font-size: 13.5px;
    font-weight: 600;
}

.hull-option.active {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.hull-swatch {
    width: 26px;
    height: 12px;
    border-radius: 999px;
}

.lang-options {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.lang-option {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 12px;
    border-radius: 12px;
    font-weight: 600;
    text-align: left;
}

.lang-option:hover {
    background: var(--surface-2);
}

.lang-code {
    width: 30px;
    font-size: 12px;
    font-weight: 800;
    color: var(--muted);
}

.lang-check {
    margin-left: auto;
    color: var(--accent);
    opacity: 0;
}

.lang-option.active .lang-check {
    opacity: 1;
}

.release strong {
    color: var(--accent);
}

.release ul {
    padding: 6px 0 14px 20px;
    font-size: 14px;
    color: var(--muted);
}

.donate-content {
    text-align: center;
    align-items: center;
}

.donate-icon {
    color: var(--hit);
}

.gameover-content {
    text-align: center;
    align-items: center;
}

.gameover-content h2 {
    font-size: 26px;
    letter-spacing: -0.02em;
}

.stats {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 4px 0;
}

.stat {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 12px;
    border-radius: 10px;
    background: var(--surface-2);
    font-size: 13.5px;
}

.stat dt {
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.stat dd {
    color: var(--muted);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.score-line {
    font-weight: 700;
}

.rematch-status {
    font-size: 13px;
    min-height: 1em;
}

.gameover-actions {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    position: fixed;
    left: 50%;
    bottom: calc(80px + env(safe-area-inset-bottom));
    z-index: 80;
    transform: translate(-50%, 20px);
    max-width: calc(100% - 32px);
    padding: 10px 16px;
    border-radius: 12px;
    background: var(--text);
    color: var(--bg);
    font-size: 14px;
    font-weight: 650;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s, transform 0.2s;
}

.toast.visible {
    opacity: 1;
    transform: translate(-50%, 0);
}

/* On wide screens the grids also have to fit the height of the window */
@media (min-width: 821px) {
    .placement .grid-wrap {
        max-width: max(280px, calc(100dvh - 300px));
    }

    .battle .grid-wrap {
        max-width: max(260px, calc(100dvh - 270px));
        margin: 0 auto;
    }
}

/* ---------- Medium screens ---------- */
@media (max-width: 1100px) {
    .game-body {
        grid-template-columns: 1fr;
    }

    .side-panel {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 40;
        height: min(70dvh, 520px);
        padding: 0;
        transform: translateY(100%);
        transition: transform 0.25s ease;
    }

    .side-panel.open {
        transform: translateY(0);
    }

    .side-inner {
        border-radius: 20px 20px 0 0;
        padding-bottom: max(14px, env(safe-area-inset-bottom));
    }

    .panel-backdrop {
        position: fixed;
        inset: 0;
        z-index: 39;
        background: rgba(2, 10, 20, 0.5);
    }

    .panel-backdrop.open {
        display: block;
    }

    .panel-toggle {
        display: inline-flex;
    }

    .chat-close {
        display: grid;
    }
}

/* ---------- Phones ---------- */
@media (max-width: 820px) {
    .lobby-container {
        grid-template-columns: 1fr;
        gap: 24px;
        padding: 20px 0;
    }

    .radar {
        width: 96px;
        height: 96px;
        margin-bottom: 14px;
    }

    .howto-list {
        display: none;
    }

    .theme-selector, .lang-selector {
        display: none;
    }

    .theme-toggle, .lang-toggle {
        display: inline-flex;
    }

    .lobby-panel {
        padding: 18px;
    }

    .placement {
        grid-template-columns: 1fr;
        gap: 14px;
    }

    .placement-side {
        padding-top: 0;
        gap: 10px;
    }

    /* Ready stays in sight right under the grid; the list of ships follows */
    .placement-tools {
        order: 0;
    }

    #btn-ready {
        order: 1;
    }

    .place-timer, #place-waiting {
        order: 2;
    }

    .dock {
        order: 3;
    }

    .dock {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }

    .dock li:last-child {
        grid-column: span 2;
    }

    .dock-ship {
        gap: 8px;
        padding: 8px 10px;
    }

    .dock-hull i {
        width: 9px;
        height: 9px;
    }

    .dock-name {
        font-size: 13px;
    }

    .board-hint {
        font-size: 13px;
        margin: 2px 0 8px;
    }

    .battle {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    /* The board where the action is takes the room; the other one shrinks */
    .battle .board-card.own {
        order: 2;
    }

    .battle .board-card.own .grid-wrap {
        max-width: 170px;
        margin: 0 auto;
    }

    .battle.defending .board-card.own {
        order: 0;
    }

    .battle.defending .board-card.own .grid-wrap {
        max-width: none;
    }

    .battle.defending .board-card.enemy .grid-wrap {
        max-width: 170px;
        margin: 0 auto;
    }

    .board-card {
        padding: 10px;
    }

    .scoreboard {
        grid-template-columns: 1fr 1fr;
        padding: 8px 10px;
    }

    .turn-indicator {
        grid-column: 1 / -1;
        grid-row: 2;
        max-width: none;
        padding: 2px;
    }

    .captain {
        padding: 5px 8px;
    }

    .game-body {
        padding: 0 10px;
    }

    .game-actions {
        gap: 6px;
        padding-left: 10px;
        padding-right: 10px;
    }

    .action-btn {
        flex: 1;
        justify-content: center;
        flex-direction: column;
        gap: 2px;
        padding: 7px 4px;
        font-size: 11.5px;
    }

    .mode-badge {
        display: none;
    }

    .game-title span {
        display: none;
    }

    :root {
        --lab: 14px;
    }
}

@media (max-width: 380px) {
    .mode-tab span {
        font-size: 12.5px;
    }

    .mode-tab svg {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ---------- Opponent offline countdown ---------- */
.offline-content {
    text-align: center;
    align-items: center;
    max-width: 360px;
}

.offline-content h3 {
    padding-right: 0;
}

.offline-clock {
    position: relative;
    width: 128px;
    height: 128px;
    margin-bottom: 4px;
}

.offline-clock svg {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.offline-clock circle {
    fill: none;
    stroke-width: 7;
}

.offline-track {
    stroke: var(--surface-3);
}

.offline-ring {
    stroke: var(--warm);
    stroke-linecap: round;
    stroke-dasharray: 283;
    stroke-dashoffset: 0;
    transition: stroke-dashoffset 0.25s linear;
}

#offline-count {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    font-size: 30px;
    font-weight: 850;
    font-variant-numeric: tabular-nums;
}
