:root {
  --ink: #2b1d0e; --paper: #f3e3bf; --paper-2: #e6d1a1; --edge: #8a6a3a;
  --sea: #0b2a42; --gold: #d9a520; --red: #b3261e; --green: #2e7d4f;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--sea); color: var(--ink);
  font-family: Georgia, 'Times New Roman', serif; -webkit-tap-highlight-color: transparent; overscroll-behavior: none; }
[hidden] { display: none !important; }
#sea { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

#screens { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px;
  overflow-y: auto; pointer-events: none; }
#screens > * { pointer-events: auto; }
.card { background: linear-gradient(160deg, var(--paper), var(--paper-2)); border: 3px solid var(--edge); border-radius: 14px;
  box-shadow: 0 10px 40px rgba(0,0,0,.55), inset 0 0 40px rgba(138,106,58,.25); padding: 22px 26px; width: min(420px, 100%);
  max-height: 100%; overflow-y: auto; }
.card.wide { width: min(820px, 100%); }
h1 { margin: 0 0 6px; font-size: 1.9rem; letter-spacing: .5px; }
h1 small { font-size: .9rem; font-weight: normal; opacity: .7; }
h2 { margin: 14px 0 6px; font-size: 1.1rem; border-bottom: 1px solid var(--edge); padding-bottom: 3px; }
.sub { margin: 0 0 14px; opacity: .85; }
label { display: block; margin: 12px 0 5px; font-weight: bold; font-size: .92rem; }
input, select { font: inherit; padding: 8px 10px; border: 2px solid var(--edge); border-radius: 8px; background: #fff8e6; color: var(--ink); width: 100%; }
input:disabled, select:disabled { background: transparent; border-style: dashed; opacity: .8; }
button { font: inherit; font-weight: bold; padding: 10px 16px; border: 2px solid var(--edge); border-radius: 9px; background: #fff3d3;
  color: var(--ink); cursor: pointer; }
button:hover:not(:disabled) { filter: brightness(1.06); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--red); border-color: #6d1510; color: #fff; }
button.link { background: none; border: none; padding: 4px 6px; text-decoration: underline; font-weight: normal; }
.row { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; align-items: center; }
.row > .primary { flex: 1; }
form .primary { width: 100%; margin-top: 18px; }
.error { color: var(--red); min-height: 1.2em; margin: 10px 0 0; }
.status { background: rgba(255,255,255,.4); border: 1px dashed var(--edge); border-radius: 8px; padding: 10px 12px; }
.timer { float: right; font-variant-numeric: tabular-nums; color: var(--red); }

.colors { display: flex; gap: 8px; flex-wrap: wrap; }
.colors button { width: 34px; height: 34px; padding: 0; border-radius: 50%; border: 3px solid rgba(0,0,0,.35); }
.colors button.sel { outline: 3px solid var(--ink); outline-offset: 2px; }
.colors button.taken { opacity: .2; cursor: not-allowed; }

.tabs { display: flex; gap: 4px; margin: 10px 0 0; border-bottom: 3px solid var(--edge); }
.tabs button { border-bottom: none; border-radius: 9px 9px 0 0; background: transparent; opacity: .7; }
.tabs button.active { background: #fff3d3; opacity: 1; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 0 26px; }
@media (max-width: 640px) { .cols { grid-template-columns: 1fr; } .card { padding: 16px; } h1 { font-size: 1.5rem; } }

.players { list-style: none; margin: 0; padding: 0; }
.players li { display: flex; align-items: center; gap: 8px; padding: 6px 4px; border-bottom: 1px dotted var(--edge); }
.players .dot { width: 16px; height: 16px; border-radius: 50%; border: 2px solid rgba(0,0,0,.4); flex: none; }
.players .tag { margin-left: auto; font-size: .8rem; opacity: .75; }
.players .off { opacity: .45; }

.settings .field, #config-groups .field { display: grid; grid-template-columns: 1fr 130px; gap: 4px 10px; align-items: center; padding: 6px 0;
  border-bottom: 1px dotted rgba(138,106,58,.5); }
.settings .field { grid-template-columns: 1fr 200px; }
.field .name { font-size: .95rem; }
.field .help { grid-column: 1 / -1; font-size: .78rem; opacity: .7; margin-top: -2px; }
.field .inp { display: flex; align-items: center; gap: 5px; font-size: .8rem; }
.field input[type=checkbox] { width: 22px; height: 22px; }
details { margin-top: 8px; border: 1px solid var(--edge); border-radius: 9px; padding: 4px 12px; background: rgba(255,255,255,.25); }
summary { cursor: pointer; font-weight: bold; padding: 6px 0; }

/* ship builder */
.builder .gold { font-size: 1.2rem; margin: 4px 0 12px; }
.builder .gold b { color: #8a5a00; }
.builder .stat { display: grid; grid-template-columns: 130px 1fr 150px; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px dotted var(--edge); }
.builder .stat .val { text-align: right; font-variant-numeric: tabular-nums; font-size: .9rem; }
.builder .stat .val b { font-size: 1.1rem; }
.builder input[type=range] { padding: 0; accent-color: var(--red); height: 28px; }
.builder .note { font-size: .82rem; opacity: .75; margin-top: 10px; }
@media (max-width: 640px) { .builder .stat { grid-template-columns: 1fr 1fr; } .builder .stat input { grid-column: 1 / -1; grid-row: 2; } }

table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { padding: 6px 8px; text-align: right; border-bottom: 1px dotted var(--edge); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .5px; }
tr.winner td { background: rgba(217,165,32,.3); font-weight: bold; }
.scroll-x { overflow-x: auto; }

/* HUD */
#hud { position: fixed; inset: 0; pointer-events: none; color: #fff; font-family: system-ui, sans-serif; user-select: none; -webkit-user-select: none; }
#hud button, #hud .card { pointer-events: auto; }
.panel { background: rgba(8,24,40,.72); border: 1px solid rgba(255,255,255,.2); border-radius: 10px; padding: 8px 10px; }
#hud-stats { position: absolute; left: max(10px, env(safe-area-inset-left)); top: max(10px, env(safe-area-inset-top)); width: 210px; font-size: 13px; }
.bar { position: relative; height: 15px; background: rgba(255,255,255,.14); border-radius: 8px; margin: 3px 0 7px; overflow: hidden; }
.bar i { position: absolute; inset: 0 auto 0 0; border-radius: 8px; transition: width .2s; }
.bar span { position: absolute; inset: 0; text-align: center; font-size: 11px; line-height: 15px; text-shadow: 0 1px 2px #000; }
.bar.low i { animation: pulse .7s infinite alternate; }
@keyframes pulse { to { opacity: .45; } }
.kv { display: flex; justify-content: space-between; margin-top: 2px; }
.kv b { font-variant-numeric: tabular-nums; }
.reload { display: flex; gap: 6px; margin-top: 6px; }
.reload div { flex: 1; text-align: center; font-size: 11px; padding: 3px; border-radius: 6px; background: rgba(255,255,255,.14); }
.reload div.ready { background: var(--green); }
#hud-right { position: absolute; right: max(10px, env(safe-area-inset-right)); top: max(10px, env(safe-area-inset-top)); width: 170px; }
#minimap { width: 170px; height: 170px; border-radius: 10px; border: 1px solid rgba(255,255,255,.3); display: block; }
#hud-score { margin-top: 6px; font-size: 12px; }
#hud-score div { display: flex; gap: 6px; align-items: center; padding: 1px 0; }
#hud-score .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; border: 1px solid rgba(255,255,255,.5); }
#hud-score .n { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#hud-score .dead { opacity: .45; text-decoration: line-through; }
#hud-feed { position: absolute; left: 50%; transform: translateX(-50%); top: 12px; text-align: center; font-size: 14px; text-shadow: 0 1px 3px #000; }
#hud-feed div { margin-bottom: 3px; animation: fade 6s forwards; }
@keyframes fade { 0%, 80% { opacity: 1; } 100% { opacity: 0; } }
#hud-hint { position: absolute; left: 50%; transform: translateX(-50%); bottom: 150px; text-align: center; font-size: 16px; font-weight: 600;
  text-shadow: 0 1px 4px #000, 0 0 12px #000; max-width: 90vw; }
#hud-buttons { position: absolute; left: max(10px, env(safe-area-inset-left)); bottom: max(12px, env(safe-area-inset-bottom)); display: flex; gap: 8px; }
#hud-buttons button { background: rgba(8,24,40,.8); color: #fff; border-color: rgba(255,255,255,.35); font-size: 13px; padding: 8px 12px; }
kbd { background: rgba(255,255,255,.2); border-radius: 4px; padding: 0 5px; font-size: 11px; }
#overlay { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); color: var(--ink); font-family: Georgia, serif;
  max-height: calc(100% - 24px); width: min(760px, calc(100% - 24px)); }
#spectate { position: absolute; left: 50%; transform: translateX(-50%); bottom: 24px; font-size: 14px; pointer-events: auto; }
#spectate button { padding: 4px 10px; font-size: 13px; }

#touch { position: absolute; left: 0; right: 0; bottom: max(8px, env(safe-area-inset-bottom)); display: flex; justify-content: space-between;
  align-items: flex-end; padding: 0 10px; gap: 8px; }
#touch .pad { display: flex; gap: 8px; }
#touch button { min-width: 62px; height: 62px; border-radius: 16px; background: rgba(8,24,40,.6); color: #fff; border: 2px solid rgba(255,255,255,.4);
  font-size: 15px; padding: 0 8px; touch-action: none; }
#touch button.down { background: rgba(217,165,32,.75); }
#touch .left button, #touch .right button { font-size: 20px; }
#touch .right button { font-size: 15px; }
body.touch #hud-buttons { bottom: 84px; }
body.touch #hud-hint { bottom: 170px; font-size: 14px; }
@media (max-width: 700px) { #hud-stats { width: 165px; font-size: 12px; } #hud-right, #minimap { width: 110px; } #minimap { height: 110px; }
  #hud-feed { top: 130px; font-size: 12px; } #touch button { min-width: 52px; height: 56px; } }

dialog { border: 3px solid var(--edge); border-radius: 14px; background: var(--paper); color: var(--ink); max-width: min(860px, 94vw); max-height: 88vh; padding: 20px; }
dialog kbd { background: rgba(0,0,0,.14); font-size: 13px; padding: 1px 7px; }
dialog::backdrop { background: rgba(0,0,0,.6); }
#toasts { position: fixed; left: 50%; top: 64px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; z-index: 50; pointer-events: none; width: min(92vw, 460px); }
#toasts div { background: #2b1d0e; color: #ffe9b5; border: 2px solid var(--gold); border-radius: 10px; padding: 9px 14px; text-align: center;
  font-family: system-ui, sans-serif; font-size: 14px; animation: fade 4.5s forwards; }
#offline { position: fixed; top: 0; left: 0; right: 0; background: var(--red); color: #fff; text-align: center; padding: 5px; font-family: system-ui; z-index: 60; }

/* phones in landscape: short screens */
@media (max-height: 480px) {
  #screens { padding: 6px; align-items: flex-start; }
  .card { padding: 10px 16px; }
  h1 { font-size: 1.25rem; margin-bottom: 2px; }
  .sub { margin-bottom: 6px; font-size: .88rem; }
  .row { margin-top: 8px; }
  button { padding: 7px 14px; }
  .builder .gold { font-size: 1rem; margin: 0 0 4px; }
  .builder .stat { padding: 3px 0; }
  .builder .note { margin-top: 4px; font-size: .74rem; }
  #hud-stats { width: 150px; font-size: 11px; padding: 5px 7px; }
  .bar { height: 11px; margin: 1px 0 3px; } .bar span { font-size: 9px; line-height: 11px; }
  .reload { margin-top: 3px; } .reload div { padding: 1px; font-size: 10px; }
  #hud-right, #minimap { width: 100px; } #minimap { height: 100px; }
  #hud-score { font-size: 10px; padding: 4px 6px; }
  #hud-feed { top: 6px; font-size: 12px; }
  body.touch #hud-hint, #hud-hint { bottom: 76px; font-size: 13px; }
  body.touch #hud-buttons { bottom: auto; top: 6px; left: 170px; }
  #touch button { min-width: 54px; height: 54px; }
  #overlay { top: 6px; transform: translate(-50%, 0); max-height: calc(100% - 12px); }
}
