/* ---- The Sea Battle table ---- */
/* Drawn like a naval chart: deep blue water with fine lines and coordinates,
   brass for what matters, parchment for the lettering, the dark green of the
   site for the frames. */
#sea {
  max-width: 760px; margin: 0 auto;
  --sb-brass: #c9a24b;
  --sb-parchment: #f3ead6;
  --sb-frame: #173d2c;
  --sb-deep: #0a1c36;
  --sb-hit: #d8322c;
  --sb-serif: Georgia, 'Iowan Old Style', 'Times New Roman', serif;
  --sb-unit: 10px; /* one square of a ship in the strip of ships */
}
#sea #sb-title { text-align: center; font-weight: 700; font-size: 0.9rem; padding: 0 48px; min-height: 1.3em; margin-bottom: 6px; }

/* The two charts. On a narrow screen the one being fired at is large and comes
   first; the other sits below it at about half the width, its heading beside it. */
#sea #sb-boards { display: flex; flex-direction: column; align-items: center; gap: 10px; }
#sea .sb-panel { box-sizing: border-box; width: 100%; min-width: 0; }
#sea .sb-panel.sb-big { order: 0; }
#sea .sb-panel.sb-small { order: 1; display: grid; grid-template-columns: minmax(0, 54%) minmax(0, 1fr); column-gap: 12px; align-items: center; }
#sea .sb-panel.sb-small .sb-chart { order: 0; --sb-lab: 12px; padding: 0 3px 3px 0; border-width: 2px; }
#sea .sb-panel.sb-small .sb-head { order: 1; flex-direction: column; align-items: flex-start; margin: 0; }
#sea .sb-panel.sb-small .sb-cols span, #sea .sb-panel.sb-small .sb-rows span { font-size: 0.5rem; }
#sea .sb-panel.sb-small .sb-toast { font-size: 0.72rem; padding: 4px 8px; }

#sea .sb-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 0 2px 5px; min-height: 20px; }
#sea .sb-label { font-family: var(--sb-serif); font-size: 0.82rem; font-weight: 600; letter-spacing: 0.09em; text-transform: uppercase; color: var(--sb-parchment); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
#sea .sb-panel.sb-live .sb-label { color: var(--sb-brass); }

/* The strip of ships: the five hulls, crossed out as they are sunk. */
#sea .sb-strip { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 5px; flex: none; max-width: 100%; }
#sea .sb-mini { position: relative; display: block; width: calc(var(--sb-len) * var(--sb-unit)); height: var(--sb-unit); flex: none; }
#sea .sb-mini svg { display: block; width: 100%; height: 100%; overflow: visible; }
#sea .sb-mini.sb-gone { opacity: 0.8; }
#sea .sb-mini.sb-gone::after { content: ''; position: absolute; left: -1px; right: -1px; top: 50%; height: 1.5px; margin-top: -0.75px; background: #ff8f7e; transform: rotate(-9deg); border-radius: 1px; }

/* A chart: the letters along the top, the numbers down the side, and the sea. */
#sea .sb-chart {
  --sb-lab: 18px;
  display: grid; grid-template-columns: var(--sb-lab) minmax(0, 1fr); grid-template-rows: var(--sb-lab) auto;
  box-sizing: border-box; padding: 0 4px 4px 0;
  border: 3px solid var(--sb-frame); border-radius: 8px; background: var(--sb-deep);
  box-shadow: 0 0 0 1px rgba(201, 162, 75, 0.4), 0 6px 22px rgba(0, 0, 0, 0.5);
  -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none;
  transition: box-shadow 0.25s, filter 0.25s;
}
#sea .sb-panel.sb-live .sb-chart { box-shadow: 0 0 0 1.5px var(--sb-brass), 0 6px 22px rgba(0, 0, 0, 0.5); }
#sea .sb-cols { display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); }
#sea .sb-rows { display: grid; grid-template-rows: repeat(10, minmax(0, 1fr)); }
#sea .sb-cols span, #sea .sb-rows span { display: flex; align-items: center; justify-content: center; font-family: var(--sb-serif); font-size: 0.66rem; line-height: 1; color: var(--sb-parchment); opacity: 0.82; font-variant-numeric: lining-nums; }
#sea .sb-sea {
  position: relative; aspect-ratio: 1; min-width: 0;
  outline: 1px solid rgba(201, 162, 75, 0.38); outline-offset: -1px;
  background:
    linear-gradient(to right, rgba(201, 162, 75, 0.17) 1px, transparent 1px) 0 0 / 10% 100%,
    linear-gradient(to bottom, rgba(201, 162, 75, 0.17) 1px, transparent 1px) 0 0 / 100% 10%,
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Cg fill='none' stroke='%23c9a24b' stroke-opacity='.16' stroke-width='.6'%3E%3Ccircle cx='50' cy='50' r='31'/%3E%3Ccircle cx='50' cy='50' r='24'/%3E%3C/g%3E%3Cpath fill='%23c9a24b' fill-opacity='.1' d='M50 5 55.5 44.5 95 50 55.5 55.5 50 95 44.5 55.5 5 50 44.5 44.5Z'/%3E%3Cpath fill='%23c9a24b' fill-opacity='.07' d='M28 28 47 44 72 28 56 47 72 72 53 56 28 72 44 53Z'/%3E%3C/svg%3E") center / 70% no-repeat,
    radial-gradient(ellipse at 28% 18%, #17406b, #0e2a4d 55%, #0a1f3c);
}
#sea .sb-ships, #sea .sb-cells { position: absolute; inset: 0; }
#sea .sb-ships { pointer-events: none; }
#sea .sb-cells { display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); grid-template-rows: repeat(10, minmax(0, 1fr)); }

/* Ships: a steel hull with a lighter line along the deck. Drawn lying across;
   one that lies down the grid is turned about its bow square. */
#sea .sb-ship { position: absolute; height: 10%; }
#sea .sb-ship.sb-down { transform: rotate(90deg); }
#sea .sb-ship svg { display: block; width: 100%; height: 100%; overflow: visible; }
#sea .sb-hull { fill: #8794a1; stroke: #d5dde4; stroke-width: 0.9; stroke-linejoin: round; }
#sea .sb-deck { fill: none; stroke: #e6ecf1; stroke-width: 0.9; stroke-linecap: round; opacity: 0.75; }
#sea .sb-deck.sb-dashed { stroke-dasharray: 5 4; }
#sea .sb-top { fill: #b9c3cc; stroke: #5d6975; stroke-width: 0.6; }
#sea .sb-ship svg { filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.55)); }
/* Sunk: dark red-brown. */
#sea .sb-ship.sb-sunk .sb-hull, #sea .sb-mini.sb-gone .sb-hull { fill: #5c241c; stroke: #96503f; }
#sea .sb-ship.sb-sunk .sb-deck, #sea .sb-mini.sb-gone .sb-deck { stroke: #b06a58; opacity: 0.6; }
#sea .sb-ship.sb-sunk .sb-top, #sea .sb-mini.sb-gone .sb-top { fill: #7a352a; stroke: #3d1611; }
/* Picked up while setting up: brass round the hull. */
#sea .sb-ship.sb-picked .sb-hull { fill: #a9b4bf; stroke: var(--sb-brass); stroke-width: 1.8; }
#sea .sb-ship.sb-picked svg { filter: drop-shadow(0 0 5px rgba(201, 162, 75, 0.95)); }

/* The squares, and what has been fired at them. */
#sea .sb-cell { position: relative; min-width: 0; min-height: 0; width: auto; height: auto; margin: 0; padding: 0; border: 0; border-radius: 0; background: transparent; box-shadow: none; color: inherit; cursor: default; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
#sea .sb-cell:disabled { opacity: 1; }
#sea .sb-cell:not(:disabled) { cursor: pointer; }
#sea .sb-cell:focus-visible { outline: 2px solid var(--sb-brass); outline-offset: -2px; z-index: 1; }
#sea .sb-cell:not(:disabled):active, #sea .sb-cell.sb-sent { background: rgba(201, 162, 75, 0.32); }
#sea .sb-mark { position: absolute; display: none; pointer-events: none; border-radius: 50%; box-sizing: border-box; }
/* A miss: a small white ring, which ripples once as the shot lands. */
#sea .sb-cell.sb-miss .sb-mark { display: block; inset: 34%; border: 1.5px solid rgba(255, 255, 255, 0.88); }
#sea .sb-cell.sb-miss.sb-new .sb-mark::after { content: ''; position: absolute; inset: -1.5px; border-radius: 50%; border: 1.5px solid #fff; animation: sb-ripple 0.95s ease-out both; }
@keyframes sb-ripple { from { transform: scale(0.5); opacity: 0.95; } to { transform: scale(3.6); opacity: 0; } }
/* A hit: a red marker, with a flash as the shot lands. */
#sea .sb-cell.sb-hit .sb-mark { display: block; inset: 27%; background: radial-gradient(circle at 36% 30%, #ff9a86, var(--sb-hit) 52%, #8a1512); box-shadow: 0 0 0 1.5px rgba(0, 0, 0, 0.5); }
#sea .sb-cell.sb-hit.sb-new .sb-mark { animation: sb-flash 0.75s ease-out both; }
@keyframes sb-flash {
  0% { transform: scale(2.3); box-shadow: 0 0 0 7px rgba(255, 226, 170, 0.95), 0 0 26px 14px rgba(255, 120, 60, 0.85); }
  45% { transform: scale(1.15); box-shadow: 0 0 0 3px rgba(255, 200, 140, 0.6), 0 0 14px 6px rgba(255, 120, 60, 0.45); }
  100% { transform: none; box-shadow: 0 0 0 1.5px rgba(0, 0, 0, 0.5); }
}
/* The square fired at last: a fine brass box round it. */
#sea .sb-cell.sb-last::before { content: ''; position: absolute; inset: 1px; border: 1.5px solid var(--sb-brass); border-radius: 3px; pointer-events: none; }
@media (hover: hover) {
  /* With a mouse: the square under it is marked, with a small cross to aim by. */
  #sea .sb-cell:not(:disabled):hover { background: rgba(201, 162, 75, 0.2); }
  #sea .sb-aim .sb-cell:not(:disabled):hover::after { content: ''; position: absolute; inset: 22%; pointer-events: none; background: linear-gradient(var(--sb-brass), var(--sb-brass)) center / 1.5px 100% no-repeat, linear-gradient(var(--sb-brass), var(--sb-brass)) center / 100% 1.5px no-repeat; opacity: 0.9; }
}
/* A ship went down: the chart shakes a little, and a slip of parchment says which. */
#sea .sb-sea.sb-shake { animation: sb-shake 0.55s ease-in-out; }
@keyframes sb-shake { 0%, 100% { transform: none; } 15% { transform: translate(-3px, 1px); } 30% { transform: translate(3px, -1px); } 45% { transform: translate(-2px, -1px); } 60% { transform: translate(2px, 1px); } 80% { transform: translate(-1px, 0); } }
#sea .sb-toast { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 3; max-width: 92%; box-sizing: border-box; white-space: nowrap; pointer-events: none; padding: 7px 14px; border-radius: 4px; background: var(--sb-parchment); color: #2a1a12; border: 1px solid var(--sb-brass); box-shadow: 0 4px 16px rgba(0, 0, 0, 0.55); font-family: var(--sb-serif); font-weight: 700; font-size: 0.95rem; letter-spacing: 0.02em; }
#sea .sb-toast.sb-show { animation: sb-toast 2.6s ease-out both; }
@keyframes sb-toast { 0% { opacity: 0; transform: translate(-50%, -50%) scale(0.8); } 8% { opacity: 1; transform: translate(-50%, -50%); } 82% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -50%); } }
/* While a battle is on, the chart nobody is firing at steps back a little. */
#sea[data-phase="playing"] .sb-panel:not(.sb-live) .sb-chart { filter: brightness(0.86) saturate(0.85); }

/* The two players: picture, name, whose shot, the countdown and games won. */
#sea .sb-bar { position: relative; box-sizing: border-box; display: flex; align-items: center; gap: 8px; margin: 8px auto; padding: 5px 8px; border-radius: 12px; min-height: 48px; border: 1px solid transparent; }
#sea .sb-bar.sb-on { border-color: var(--sb-brass); background: rgba(255, 255, 255, 0.06); }
#sea .sb-bar.sb-vacant { cursor: pointer; }
#sea .sb-bar.sb-vacant .sb-name { text-decoration: underline; }
#sea .sb-cam { width: 72px; height: 72px; border-radius: 50%; object-fit: cover; background: #000; box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.6); flex: none; transform: none; /* my own picture is shown as the others see it, not mirrored */ }
#sea .sb-cam.blank { display: none; }
#sea .sb-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 0 1 auto; }
#sea .sb-ready { font-size: 0.72rem; color: #1b1b1b; background: var(--t15); border-radius: 999px; padding: 1px 8px; font-weight: 700; flex: none; white-space: nowrap; }
#sea .sb-stats { margin-left: auto; display: flex; align-items: center; gap: 8px; flex: none; font-variant-numeric: tabular-nums; }
#sea .sb-turn { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--sb-brass); white-space: nowrap; }
#sea .sb-clock { font-weight: 700; font-size: 0.95rem; padding: 2px 8px; border-radius: 8px; background: rgba(0, 0, 0, 0.45); min-width: 2.6em; text-align: center; }
#sea .sb-clock.sb-low { background: var(--danger); color: #fff; }
#sea .sb-score { font-weight: 800; font-size: 1.1rem; padding: 2px 10px; border-radius: 8px; background: rgba(0, 0, 0, 0.45); min-width: 1.2em; text-align: center; }
/* The time left, as a thin line along the bottom of the bar. */
#sea .sb-left { position: absolute; left: 10px; bottom: 1px; height: 3px; max-width: calc(100% - 20px); border-radius: 2px; background: var(--sb-brass); transition: width 0.2s linear; pointer-events: none; }
#sea .sb-left.sb-low { background: var(--danger); }
#sea .sb-bubble { position: absolute; left: 8px; top: calc(100% + 4px); z-index: 6; max-width: min(320px, 86%); background: #fdfdfd; color: #161616; border-radius: 12px; padding: 7px 11px; font-size: 0.88rem; font-weight: 600; line-height: 1.25; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5); pointer-events: none; }
#sea .sb-bubble::after { content: ''; position: absolute; left: 18px; top: -12px; border: 6px solid transparent; border-bottom-color: #fdfdfd; }
#sea .sb-bubble.sb-up { top: auto; bottom: calc(100% + 4px); }
#sea .sb-bubble.sb-up::after { top: auto; bottom: -12px; border-bottom-color: transparent; border-top-color: #fdfdfd; }
#sea .sb-bubble.sb-pop { animation: sb-pop 0.22s ease-out; }
@keyframes sb-pop { from { transform: scale(0.7); opacity: 0; } }

/* Under the charts. */
#sea #sb-status { text-align: center; font-weight: 700; min-height: 1.5em; margin: 6px 0 2px; }
#sea #sb-note { text-align: center; min-height: 1.2em; margin: 0; font-family: var(--sb-serif); font-size: 0.9rem; color: var(--sb-parchment); }
#sea #sb-error { text-align: center; min-height: 1.2em; margin: 0; }
/* Setting up: the countdown, what the other player is doing, and the two buttons. */
#sea #sb-place { margin: 6px auto; padding: 10px 14px 12px; border-radius: 10px; background: var(--panel); border: 1px solid rgba(201, 162, 75, 0.55); max-width: 460px; box-sizing: border-box; }
#sea #sb-place-top { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
#sea #sb-place-clock { font-family: var(--sb-serif); font-weight: 700; font-size: 1.5rem; color: var(--sb-brass); font-variant-numeric: tabular-nums lining-nums; min-width: 2.6em; }
#sea #sb-place-clock.sb-low { color: #ff8f7e; }
#sea #sb-place-other { font-size: 0.88rem; color: var(--sb-parchment); text-align: right; min-width: 0; }
#sea #sb-place-help { text-align: left; margin: 6px 0 0; }
#sea #sb-place-hint { text-align: left; margin: 4px 0 0; min-height: 1.2em; color: var(--sb-brass); }
#sea #sb-result { text-align: center; margin: 6px auto; padding: 12px 14px; border-radius: 10px; background: var(--panel); border: 1px solid var(--sb-brass); max-width: 460px; box-sizing: border-box; animation: sb-pop 0.3s ease-out 0.6s backwards; }
#sea #sb-result-text { font-family: var(--sb-serif); font-weight: 700; font-size: 1.5rem; letter-spacing: 0.02em; }
#sea #sb-result.sb-won #sb-result-text { color: var(--sb-brass); }
#sea #sb-result.sb-lost { border-color: var(--danger); }
#sea #sb-result-how, #sea #sb-result-shots { margin: 2px 0 0; }
#sea #sb-result .row { margin-top: 10px; }
#sea .row { max-width: 460px; margin-left: auto; margin-right: auto; }
#sea .row > button { min-height: 46px; }
#sea #sb-setup p { text-align: center; margin: 6px 0; }
#sea #sb-bot { margin-top: 10px; }
#sea #sb-bot-levels { flex-wrap: wrap; justify-content: center; }
#sea #sb-bot-levels button { flex: 1 1 150px; }

@media (max-width: 699px) {
  #sea { padding-top: 46px; } /* room for the row of round buttons along the top */
  #sea #sb-title { padding: 0; }
  /* The large chart runs nearly to the edges of the screen, so that a square is big enough for a thumb. */
  #sea .sb-panel.sb-big .sb-chart { --sb-lab: 16px; padding: 0 3px 3px 0; margin-left: -12px; margin-right: -12px; }
  #sea .sb-bar { margin-top: 6px; margin-bottom: 6px; padding: 4px 6px; gap: 6px; }
  #sea .sb-cam { width: 56px; height: 56px; }
  #sea .sb-score { font-size: 1rem; padding: 2px 8px; }
  #sea .sb-stats { gap: 6px; }
  #sea .sb-turn { font-size: 0.66rem; }
  #sea .sb-label { font-size: 0.76rem; }
}

/* A wide screen: the two charts side by side, enemy waters on the left, both
   the same size. The section is made wider than the page's narrow column and
   centred on it. */
@media (min-width: 900px) {
  #sea { --sb-w: min(980px, calc(100vw - 32px)); max-width: none; width: var(--sb-w); margin-left: calc(50% - var(--sb-w) / 2); margin-right: 0; --sb-unit: 13px; }
  #sea #sb-boards { flex-direction: row; justify-content: center; align-items: flex-start; gap: 30px; }
  #sea .sb-panel, #sea .sb-panel.sb-big, #sea .sb-panel.sb-small { display: block; order: 0; flex: 1 1 0; width: auto; min-width: 250px; max-width: min(460px, calc(100dvh - 340px)); }
  #sea .sb-panel.sb-small .sb-chart { --sb-lab: 18px; padding: 0 4px 4px 0; border-width: 3px; }
  #sea .sb-panel.sb-small .sb-head { flex-direction: row; align-items: center; margin: 0 2px 5px; }
  #sea .sb-panel.sb-small .sb-cols span, #sea .sb-panel.sb-small .sb-rows span { font-size: 0.66rem; }
  #sea .sb-panel.sb-small .sb-toast { font-size: 0.95rem; padding: 7px 14px; }
  #sea .sb-bar { max-width: 950px; }
  #sea #sb-status { margin-top: 10px; font-size: 1.05rem; }
}

@media (prefers-reduced-motion: reduce) {
  #sea .sb-cell.sb-miss.sb-new .sb-mark::after { display: none; }
  #sea .sb-cell.sb-hit.sb-new .sb-mark, #sea .sb-sea.sb-shake, #sea .sb-toast.sb-show, #sea .sb-bubble.sb-pop, #sea #sb-result { animation: none; }
  #sea .sb-chart, #sea .sb-left { transition: none; }
}
