:root {
  --bg: #05070d;
  --panel: #0b1220;
  --line: #1c2a44;
  --text: #cfe3ff;
  --dim: #7d90b0;
  --accent: #5ee0b0;
  --warn: #ffb454;
  --bad: #ff6b6b;
  --e1: #5ee0b0;
  --e2: #ffb454;
  --e3: #ff6b6b;
  --e4: #b48cff;
  --e0: #6b7a94;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}

body { display: flex; flex-direction: column; }

#topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  flex-wrap: wrap;
}
.brand { font-weight: bold; letter-spacing: 3px; color: var(--accent); }
.brand span { margin-left: 8px; letter-spacing: 0; font-weight: normal; color: var(--dim); font-size: 12px; }
.stat { color: var(--dim); }
.stat b { color: var(--text); }
.stat small { color: var(--accent); }
.spacer { flex: 1; }

button, select, input {
  font: inherit;
  color: var(--text);
  background: #101b30;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 4px 10px;
}
button { cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.4; cursor: default; }
button.primary { background: #123a2e; border-color: var(--accent); color: var(--accent); }
button.small { padding: 0 8px; }

main { flex: 1; display: flex; min-height: 0; }

#mapwrap { position: relative; flex: 1; min-width: 0; }
#map { width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
#map.targeting { cursor: crosshair; }
#map.dragging { cursor: grabbing; }

#banner {
  position: absolute;
  left: 50%; top: 40%;
  transform: translate(-50%, -50%);
  padding: 20px 32px;
  background: rgba(5, 7, 13, 0.92);
  border: 1px solid var(--accent);
  text-align: center;
  font-size: 18px;
}
#banner button { margin-top: 12px; }

#tip {
  position: absolute;
  pointer-events: none;
  background: rgba(5, 7, 13, 0.92);
  border: 1px solid var(--line);
  padding: 4px 8px;
  font-size: 12px;
  white-space: nowrap;
}

#side {
  width: 340px;
  flex-shrink: 0;
  overflow-y: auto;
  border-left: 1px solid var(--line);
  background: var(--panel);
}
#side section { padding: 10px 12px; border-bottom: 1px solid var(--line); }
#side h2, #side h3 { margin: 0 0 6px; font-size: 14px; }
#side h2 small { color: var(--dim); font-weight: normal; margin-left: 6px; }
.kv { display: grid; grid-template-columns: 90px 1fr; gap: 2px 8px; }
.kv > :nth-child(odd) { color: var(--dim); }
.btns { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.dim { color: var(--dim); }
.good { color: var(--accent); }
.bad { color: var(--bad); }
.hint { color: var(--warn); }
.send-row { display: flex; align-items: center; gap: 8px; margin: 2px 0; }
.send-row .nm { width: 80px; }
.send-row .n { width: 40px; text-align: center; }

#log { list-style: none; margin: 0; padding: 0; max-height: 260px; overflow-y: auto; font-size: 12px; }
#log li { margin: 2px 0; color: var(--dim); }
#log li.good { color: var(--accent); }
#log li.bad { color: var(--bad); }
#log li.battle { color: var(--warn); }
#log li b { color: var(--text); font-weight: normal; margin-right: 4px; }

dialog {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--accent);
  border-radius: 6px;
  max-width: 520px;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog h2 { margin-top: 0; color: var(--accent); }
dialog li { margin: 4px 0; }
dialog .fine { color: var(--dim); font-size: 12px; }
dialog label { display: block; margin: 8px 0; }
dialog label select, dialog label input { display: block; width: 100%; margin-top: 4px; }
dialog .row { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
kbd { border: 1px solid var(--line); padding: 0 4px; border-radius: 3px; }

button, summary { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
dialog { max-width: min(520px, calc(100vw - 24px)); max-height: calc(100vh - 24px); max-height: calc(100dvh - 24px); overflow-y: auto; }
#b-fit { position: absolute; bottom: 8px; right: 8px; opacity: 0.85; }
#device-qr { background: #fff; padding: 8px; border-radius: 6px; width: 232px; max-width: 100%; margin: 8px auto; line-height: 0; }
#device-qr svg { width: 100%; height: auto; display: block; }
#device-link { width: 100%; font-size: 13px; margin: 6px 0; }
#p-device .who { margin: 0 0 8px; }
[hidden] { display: none !important; }
.gamerow { border-top: 1px solid var(--line); padding: 8px 0; }
.gamerow.open { border-left: 3px solid var(--accent); padding-left: 8px; }
.gamerow .row { justify-content: flex-start; margin-top: 6px; }
.badge { display: inline-block; background: var(--accent); color: #05070d; border-radius: 9px; padding: 0 7px; font-size: 12px; font-weight: bold; }
details { margin: 12px 0 0; }
dialog details { border-top: 1px solid var(--line); padding: 8px 0; margin: 0; }
dialog details > summary { color: var(--text); font-size: 14px; padding: 4px 0; }
dialog details[open] > summary { color: var(--accent); }
dialog ol, dialog ul { padding-left: 20px; margin: 6px 0; }
.shiptable { width: 100%; border-collapse: collapse; font-size: 13px; }
.shiptable td, .shiptable th { text-align: left; padding: 4px 6px 4px 0; border-bottom: 1px solid var(--line); vertical-align: top; font-weight: normal; }
.shiptable th { color: var(--dim); }
.ship-row { display: flex; align-items: center; gap: 8px; margin: 4px 0; }
.ship-row button { flex: none; min-width: 112px; text-align: left; }
.ship-row .why { color: var(--dim); font-size: 12px; line-height: 1.25; }
.tip { border: 1px dashed var(--accent); border-radius: 4px; padding: 6px 8px; margin: 8px 0; font-size: 13px; }
.linkish { background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; font-size: 12px; }
summary { cursor: pointer; color: var(--dim); font-size: 12px; }
details input { width: 100%; margin-top: 8px; }
.invite { margin: 12px 0; }
.invite input { width: 100%; margin: 4px 0 6px; font-size: 13px; }
.invite .row { margin: 0; justify-content: flex-start; }

@media (pointer: coarse) {
  button, select, input { min-height: 40px; }
  button.small { min-width: 40px; }
  .btns { gap: 8px; }
  .send-row .n { width: 32px; }
}

/* phones */
@media (max-width: 760px) {
  html, body { height: 100vh; height: 100dvh; font-size: 15px; }
  #topbar { gap: 4px 14px; padding: 6px 12px; padding-top: calc(6px + env(safe-area-inset-top)); padding-left: calc(12px + env(safe-area-inset-left)); padding-right: calc(12px + env(safe-area-inset-right)); }
  .brand { font-size: 13px; letter-spacing: 2px; flex-basis: 100%; }
  .brand span { display: none; }
  .stat { font-size: 13px; }
  .spacer { flex-basis: 100%; height: 0; } /* line break: stats above, buttons below */
  #topbar button { flex: 1 1 auto; min-height: 40px; padding: 4px 8px; }
  select, input, textarea { font-size: 16px; } /* iOS zooms the page when a smaller field is focused */
  main { flex-direction: column; }
  #mapwrap { flex: none; height: 40vh; height: 40dvh; }
  #side { width: auto; flex: 1; border-left: 0; border-top: 1px solid var(--line); -webkit-overflow-scrolling: touch; }
  #banner { padding: 14px 20px; font-size: 16px; width: 80%; }
  #log { max-height: none; }
  dialog { padding: 14px; }
  dialog .row button { flex: 1; min-height: 44px; }
}

@media (max-width: 760px) {
  /* End turn is the thing you press most, so it stays under your thumb */
  #b-end { position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; border-radius: 0; border-width: 1px 0 0; min-height: 56px; font-size: 16px; padding-bottom: env(safe-area-inset-bottom); }
  #side { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
}

#v-intro { display: block; width: min(880px, 92vw); max-height: 70vh; background: #000; border-radius: 6px; }
#d-intro { max-width: min(920px, 96vw); padding: 10px; }
dialog label.check { display: flex; gap: 10px; align-items: flex-start; }
dialog label.check input { display: inline-block; width: auto; margin: 4px 0 0; flex: none; }
dialog label.check .fine { display: block; }
dialog input[type=range] { padding: 0; accent-color: var(--accent); }
dialog input[type=checkbox] { accent-color: var(--accent); }

.chip { padding: 2px 10px; border-radius: 12px; color: var(--dim); font-size: 12px; }
.chip.on { color: var(--accent); border-color: var(--accent); }
#friend-toast { position: fixed; left: 50%; bottom: 76px; transform: translateX(-50%); z-index: 20; background: #123a2e; border: 1px solid var(--accent); color: var(--accent); padding: 8px 18px; border-radius: 18px; box-shadow: 0 6px 24px rgba(0,0,0,.5); }
.friendsnow { padding: 6px 0 8px; }
.friendrow { margin: 4px 0; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
@media (max-width: 1360px) { .brand span { display: none; } }
