: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; }
details { margin: 12px 0 0; }
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; }
}

/* warp traders additions */
#map .x {}
.port-table { width: 100%; border-collapse: collapse; margin: 6px 0; }
.port-table th, .port-table td { text-align: left; padding: 3px 4px; border-bottom: 1px solid var(--line); font-weight: normal; }
.port-table th { color: var(--dim); }
.port-table input { width: 64px; padding: 2px 4px; }
.warps { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.enc { border: 1px solid var(--bad); padding: 8px; margin: 8px 0; }

#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); }

a.btn { font: inherit; color: var(--text); background: #101b30; border: 1px solid var(--line); border-radius: 4px; padding: 4px 10px; text-decoration: none; }
@media (max-width: 760px) { a.btn { flex: 1 1 auto; min-height: 40px; text-align: center; line-height: 30px; } }
