:root {
    --font-head: 'Black Ops One', 'Impact', sans-serif;
    --font-main: 'Share Tech Mono', ui-monospace, monospace;
    --bg-dark: #04080e;
    --bg-card: rgba(9, 17, 28, 0.94);
    --bg-inset: #060d17;
    --sea: #0b1a2b;
    --steel: #8ea6be;
    --steel-light: #cdd9e5;
    --text-dim: #5d7189;
    --border-color: #1c2f45;
    --border-strong: #2b4562;
    --signal: #ff4b1f;
    --signal-soft: #ff7a4d;
    --amber: #f2b45a;
    --good: #3fbf7f;
    --cream: #e8d5c4;
    --shadow: rgba(30, 80, 140, 0.18);
    --board: 100%;
}

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

body {
    font-family: var(--font-main);
    background: radial-gradient(ellipse at 50% 0%, #0b1726 0%, var(--bg-dark) 70%);
    background-color: var(--bg-dark);
    color: var(--steel);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 16px;
    overflow-x: hidden;
    position: relative;
}

/* Rising bubbles */
.bubbles {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 1;
    overflow: hidden;
}
.bubble {
    position: absolute;
    bottom: -12px;
    width: 6px;
    height: 6px;
    border: 1px solid rgba(150, 195, 235, 0.45);
    border-radius: 50%;
    box-shadow: 0 0 6px rgba(120, 180, 230, 0.25);
    opacity: 0;
    animation: bubble-rise 12s ease-in infinite;
}
.bubble.small { width: 4px; height: 4px; }
.bubble.large { width: 9px; height: 9px; }
.bubble:nth-child(1) { left: 4%; animation-delay: 0s; animation-duration: 13s; }
.bubble:nth-child(2) { left: 9%; animation-delay: 3s; animation-duration: 10s; }
.bubble:nth-child(3) { left: 14%; animation-delay: 6s; animation-duration: 14s; }
.bubble:nth-child(4) { left: 19%; animation-delay: 1.5s; animation-duration: 12s; }
.bubble:nth-child(5) { left: 24%; animation-delay: 8s; animation-duration: 11s; }
.bubble:nth-child(6) { left: 7%; animation-delay: 4.5s; animation-duration: 15s; }
.bubble:nth-child(7) { left: 17%; animation-delay: 9.5s; animation-duration: 12s; }
.bubble:nth-child(8) { left: 27%; animation-delay: 2.2s; animation-duration: 13s; }
.bubble:nth-child(9) { left: 74%; animation-delay: 0.7s; animation-duration: 12s; }
.bubble:nth-child(10) { left: 79%; animation-delay: 5s; animation-duration: 14s; }
.bubble:nth-child(11) { left: 84%; animation-delay: 2.8s; animation-duration: 10s; }
.bubble:nth-child(12) { left: 89%; animation-delay: 7.2s; animation-duration: 13s; }
.bubble:nth-child(13) { left: 94%; animation-delay: 1.1s; animation-duration: 11s; }
.bubble:nth-child(14) { left: 77%; animation-delay: 9s; animation-duration: 15s; }
.bubble:nth-child(15) { left: 87%; animation-delay: 4s; animation-duration: 12s; }
.bubble:nth-child(16) { left: 97%; animation-delay: 6.5s; animation-duration: 13s; }

@keyframes bubble-rise {
    0% { transform: translate(0, 0); opacity: 0; }
    10% { opacity: 0.7; }
    50% { transform: translate(10px, -50vh); opacity: 0.5; }
    100% { transform: translate(-6px, -105vh); opacity: 0; }
}


/* ---------- Layout ----------
   One column, 600px like the other games. Every row is the board's width.
   Spacing steps: 8, 12, 16. */
.container {
    width: 554px;  /* a 490px board plus padding and border */
    max-width: 100%;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 14px 31px 10px;
    position: relative;
    z-index: 10;
    box-shadow: 0 0 40px var(--shadow), inset 0 0 80px rgba(20, 60, 110, 0.12);
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 16px;
    margin-bottom: 12px;
}
h1 {
    font-family: var(--font-head);
    font-weight: normal;
    font-size: 1.45em;
    letter-spacing: 1.5px;
    color: var(--steel-light);
    line-height: 1.1;
}
h1 .cruel { color: var(--signal); }
.subtitle { color: var(--text-dim); font-size: 0.78em; margin-top: 3px; }
.sea-no {
    text-align: right;
    color: var(--text-dim);
    font-size: 0.78em;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    white-space: nowrap;
}
.sea-no .num { font-size: 1.5em; letter-spacing: 0; color: var(--steel-light); }
.today-link { display: block; margin-top: 2px; color: var(--amber); text-decoration: none; text-transform: none; letter-spacing: 0; }
.today-link[hidden] { display: none; }

.board-wrap {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    background: var(--bg-inset);
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    transition: box-shadow 0.25s;
}
.board-wrap.hit { box-shadow: 0 0 0 2px var(--signal), 0 0 18px rgba(255, 75, 31, 0.5); }
.board-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#seaCanvas { cursor: crosshair; touch-action: none; transition: opacity 0.125s ease; }
#seaCanvas.fading { opacity: 0; }
.placing #seaCanvas { cursor: default; }
.placing #seaCanvas.grab { cursor: grab; }
.placing #seaCanvas.carrying { cursor: none; }

/* The bar under the board */
.bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px 12px;
    margin-top: 10px;
    min-height: 36px;
}
.bar-left, .bar-right { display: flex; align-items: center; gap: 8px; }
.bar-right { margin-left: auto; }

.tools { display: none; gap: 6px; }
.placing .tools { display: flex; }
.tool {
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 0 12px;
    font-family: var(--font-main);
    font-size: 0.85em;
    color: var(--steel-light);
    background: var(--bg-inset);
    border: 1px solid var(--border-strong);
    border-radius: 5px;
    cursor: pointer;
    white-space: nowrap;
}
.tool:hover { border-color: var(--steel); background: #0e2032; }
.tool:active { transform: translateY(1px); }
.tool svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tool svg .dot { fill: currentColor; stroke: none; }

.place-count { display: none; color: var(--text-dim); font-size: 0.85em; }
.placing .place-count { display: inline; }
.place-count b { color: var(--steel-light); font-weight: normal; }
.place-count.done b { color: var(--good); }

#readyBtn { display: none; height: 36px; padding: 0 16px; font-size: 0.95em; }
.placing #readyBtn { display: inline-flex; align-items: center; }
.btn-primary:disabled { background: #1d3047; color: var(--text-dim); cursor: default; }

.tally { color: var(--text-dim); font-size: 0.85em; white-space: nowrap; }
.tally b { font-weight: normal; color: var(--steel-light); }
.tally b.bad { color: var(--signal-soft); }
.placing .tally, .placing .toggle { display: none; }

#touchAction { display: none; }
.btn.big { width: 100%; height: 46px; font-size: 1.05em; letter-spacing: 2px; }
.touch-active #touchAction { display: block; flex-basis: 100%; }

/* One message line, two lines tall so nothing jumps */
.message {
    margin-top: 8px;
    min-height: 2.9em;
    font-size: 0.88em;
    line-height: 1.45;
    color: var(--steel-light);
}
.message .them { color: var(--text-dim); }
.message .bad { color: var(--signal-soft); }
.message .good { color: var(--amber); }
.message .taunt { display: block; color: var(--cream); font-style: italic; }
.message .line2 { display: block; }

/* Fleets: straight rows of silhouettes, labels in a fixed column */
.fleets { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.fleet-row { display: flex; align-items: center; gap: 12px; }
.fleet-label {
    width: 52px;
    flex: none;
    font-size: 0.7em;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: var(--text-dim);
}
.ship-list { list-style: none; display: flex; align-items: flex-end; gap: 14px; }
.ship-list li { position: relative; display: flex; align-items: flex-end; }
.ship-list svg { display: block; height: 11px; width: auto; }
.fleet-row li.sunk { opacity: 0.35; }
.fleet-row li.sunk::after {
    content: '';
    position: absolute;
    left: -3px;
    width: calc(100% + 6px);
    top: 50%;
    height: 2px;
    background: var(--signal);
    transform: rotate(-6deg);
}
.fleet-row.dock { display: none; }
.placing .fleet-row.dock { display: flex; }
.placing .fleet-row.theirs, .placing .fleet-row.yours { display: none; }

.dock-ships { gap: 6px; }
.dock-ship {
    position: relative;
    padding: 6px 8px;
    border: 1px solid transparent;
    border-radius: 5px;
    cursor: pointer;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    transition: border-color 0.15s, opacity 0.15s, background 0.15s;
}
.dock-ship:first-child { margin-left: -9px; }
.dock-ship svg { height: 13px; }
.dock-ship:hover { background: var(--bg-inset); }
.dock-ship .tick { display: none; position: absolute; top: -3px; right: -1px; font-size: 0.7em; color: var(--good); }
.dock-ship.placed { opacity: 0.45; }
.dock-ship.placed .tick { display: block; }
.dock-ship.carrying { border-color: var(--good); background: rgba(63, 191, 127, 0.1); opacity: 1; }

/* Links and footer, centred like the other games */
.actions {
    display: flex;
    justify-content: center;
    gap: 18px;
    margin-top: 14px;
    padding-top: 10px;
    border-top: 1px solid var(--border-color);
}
.footer { margin-top: 6px; text-align: center; font-size: 0.8em; color: var(--text-dim); }
.footer a { color: var(--steel-light); text-decoration: none; }
.footer a:hover { color: var(--signal-soft); }
.footer .sep { color: var(--border-strong); margin: 0 4px; }
.footer .toms { display: block; margin-top: 4px; }
.footer .toms a { color: var(--text-dim); }

/* Buttons */
.btn {
    padding: 8px 14px;
    border: none;
    border-radius: 4px;
    font-family: var(--font-main);
    font-size: 0.9em;
    cursor: pointer;
    background: transparent;
    color: var(--steel);
    letter-spacing: 0.5px;
}
.btn-primary {
    background: var(--signal);
    color: #fff4ee;
    font-family: var(--font-head);
    letter-spacing: 1px;
}
.btn-primary:hover { background: #ff6236; }
.btn-secondary {
    background: var(--bg-inset);
    color: var(--steel-light);
    border: 1px solid var(--border-strong);
}
.btn-secondary:hover { border-color: var(--steel); }
.btn-quiet {
    padding: 6px 12px;
    font-size: 0.85em;
    color: var(--steel-light);
    border: 1px solid var(--border-strong);
}
.btn-quiet:hover { border-color: var(--steel); }
.btn-link { padding: 4px 8px; color: var(--text-dim); font-size: 0.85em; }
.btn-link:hover { color: var(--steel-light); }

/* Show my sea: a quiet text button */
.toggle {
    position: relative;
    padding: 4px 2px;
    font-size: 0.85em;
    color: var(--text-dim);
    background: none;
    border: none;
    border-bottom: 1px dotted var(--border-strong);
    border-radius: 0;
    transition: color 0.2s, border-color 0.2s, text-shadow 0.2s;
}
.toggle:hover { color: var(--steel-light); border-bottom-color: var(--steel); }
.toggle.hit {
    color: var(--signal);
    border-bottom-color: var(--signal);
    text-shadow: 0 0 10px rgba(255, 75, 31, 0.7);
}
.badge {
    display: none;
    margin-left: 7px;
    min-width: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: var(--signal);
    color: #fff4ee;
    font-size: 0.85em;
    line-height: 18px;
    text-align: center;
}
.badge.on { display: inline-block; }

/* Modals */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    inset: 0;
    background-color: rgba(2, 6, 12, 0.88);
    overflow-y: auto;
}

.modal-content {
    background: #0a1522;
    margin: 12vh auto;
    padding: 24px;
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    width: 90%;
    max-width: 420px;
}

.close {
    color: var(--text-dim);
    float: right;
    font-size: 26px;
    cursor: pointer;
    line-height: 18px;
}
.close:hover { color: var(--steel-light); }

.modal h2 {
    font-family: var(--font-head);
    font-weight: normal;
    color: var(--steel-light);
    margin-bottom: 18px;
    font-size: 1.25em;
    letter-spacing: 2px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin: 16px 0;
}

.stat-box {
    background: var(--bg-inset);
    border: 1px solid var(--border-color);
    padding: 12px;
    border-radius: 4px;
    text-align: center;
}
.stat-box.wide { grid-column: span 2; }

.stat-value {
    font-size: 1.5em;
    color: var(--steel-light);
    margin-bottom: 4px;
}

.stat-name {
    font-size: 0.72em;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.dist-title {
    font-family: var(--font-head);
    font-weight: normal;
    font-size: 0.85em;
    letter-spacing: 1.5px;
    color: var(--text-dim);
    margin: 18px 0 8px;
    text-transform: uppercase;
}

.dist-row {
    display: grid;
    grid-template-columns: 112px 1fr;
    align-items: center;
    gap: 8px;
    margin: 4px 0;
    font-size: 0.82em;
}
.dist-label {
    color: var(--text-dim);
    text-align: right;
    white-space: nowrap;
}
.dist-bar {
    background: #1d3550;
    color: var(--steel-light);
    padding: 2px 6px;
    min-width: 22px;
    width: fit-content;
    text-align: right;
    border-radius: 2px;
}
.dist-row.current .dist-bar {
    background: var(--signal);
    color: #fff4ee;
}

.help-content {
    color: var(--steel);
    line-height: 1.55;
    font-size: 0.9em;
}
.help-content p { margin-bottom: 12px; }
.help-content strong { color: var(--steel-light); }
.help-content ul {
    margin-left: 18px;
    margin-bottom: 12px;
}
.help-content li { margin-bottom: 6px; }

/* Result modal */
.victory-content { text-align: center; }

.victory-title {
    font-family: var(--font-head);
    color: var(--amber);
    font-size: 1.6em;
    margin: 6px 0 18px;
    letter-spacing: 2px;
}
.victory-title.lost { color: var(--signal); }

.victory-stats {
    display: flex;
    justify-content: center;
    gap: 22px;
    margin: 16px 0;
}
.victory-stat {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.victory-label {
    font-size: 0.72em;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-dim);
}
.victory-stat span:last-child {
    color: var(--steel-light);
    font-size: 1.3em;
}

.victory-puzzle {
    font-size: 0.85em;
    color: var(--text-dim);
    margin: 14px 0 20px;
}

.victory-share-btn { margin: 8px 5px; }

.victory-footer {
    margin-top: 22px;
    padding-top: 14px;
    border-top: 1px solid var(--border-color);
    font-size: 0.82em;
}
.victory-footer a {
    color: var(--steel);
    text-decoration: none;
}
.victory-footer a:hover { color: var(--steel-light); }

/* Calendar */
.calendar-info {
    margin: 12px 0;
    color: var(--text-dim);
}
.calendar-input {
    display: flex;
    gap: 10px;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    margin: 14px 0;
}
.calendar-input input[type="date"] {
    padding: 8px;
    border: 1px solid var(--border-strong);
    border-radius: 4px;
    font-family: var(--font-main);
    font-size: 0.95em;
    color: var(--steel-light);
    background: var(--bg-inset);
    color-scheme: dark;
}



/* Final say on shared pieces */
.btn-link { padding: 4px 0; color: var(--text-dim); font-size: 0.85em; }
.btn-link:hover { color: var(--steel-light); }
.toggle { padding: 4px 0; font-family: var(--font-main); }
.toggle[hidden] { display: none; }

/* ---------- Phone ---------- */
@media (max-width: 600px) {
    body { padding: 10px; align-items: flex-start; }
    .container { padding: 12px 12px 10px; }
    .topbar { margin-bottom: 10px; }
    h1 { font-size: 1.2em; }
    .subtitle { font-size: 0.7em; }
    .bar { margin-top: 8px; gap: 8px; }
    .tool { height: 40px; padding: 0 9px; font-size: 0.8em; gap: 4px; }
    #readyBtn { height: 40px; padding: 0 12px; font-size: 0.85em; }
    .placing .place-count { display: none; }
    .tally { font-size: 0.8em; }
    .message { margin-top: 6px; font-size: 0.85em; }
    .fleets { margin-top: 4px; gap: 4px; }
    .fleet-label { width: 46px; }
    .ship-list { gap: 10px; }
    .ship-list svg { height: 9px; }
    .dock-ships { gap: 2px; justify-content: space-between; flex: 1; }
    .dock-ship { padding: 7px 5px; }
    .dock-ship:first-child { margin-left: 0; }
    .dock-ship svg { height: 10px; }
    .placing .fleet-row.dock .fleet-label { display: none; }
    .actions { margin-top: 10px; padding-top: 8px; }
    .modal-content { margin: 8vh auto; padding: 18px; }
    .dist-row { grid-template-columns: 96px 1fr; }
}

/* Fit a 1280x800 screen without scrolling */
@media (min-width: 601px) {
    body { padding: 6px 16px; }
    .actions { margin-top: 10px; padding-top: 8px; }
    .fleets { margin-top: 4px; }
}

/* Room for the shared games menu without scrolling at 1280x800 */
@media (min-width: 601px) {
    .container { width: 544px; }  /* a 480px board */
    .footer { margin-top: 4px; }
    .footer .cruel-menu { font-size: 0.95em; line-height: 1.4; }
    .message { min-height: 2.8em; }
    .actions { margin-top: 8px; padding-top: 6px; }
}
@media (min-width: 601px) { .container { padding-bottom: 6px; } .level-bar { margin-bottom: 8px; } }
