/* ================== Tokens (light / dark follows the OS) ================== */
:root {
  --bg: #f6f6f5;
  --surface: #ffffff;
  --surface-2: #f1f1ef;
  --border: #e4e4e1;
  --border-strong: #d0d0cc;
  --text: #1c1c1a;
  --muted: #6b6b66;
  --accent: #1c1c1a;
  --accent-text: #ffffff;
  --map-bg: #ebebe8;

  --alive: #2f8f5b;
  --dead: #c2413b;
  --soon: #c77d12;

  --radius: 8px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.06);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141413;
    --surface: #1c1c1b;
    --surface-2: #252524;
    --border: #2e2e2c;
    --border-strong: #3c3c39;
    --text: #ededeb;
    --muted: #9a9a94;
    --accent: #ededeb;
    --accent-text: #141413;
    --map-bg: #0f0f0e;

    --alive: #4fb37e;
    --dead: #e0625c;
    --soon: #e0a03a;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--font);
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

/* ================== Controls ================== */
button, input, select { font: inherit; color: inherit; }
.btn, dialog menu button {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 12px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  cursor: pointer; white-space: nowrap;
  transition: background .12s, border-color .12s;
}
.btn:hover, dialog menu button:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn:focus-visible, input:focus-visible, select:focus-visible, .mode:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
.btn.primary, dialog .primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 500; }
.btn.primary:hover, dialog .primary:hover { opacity: .9; background: var(--accent); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.icon-btn { width: 32px; padding: 0; justify-content: center; }

input, select {
  height: 32px; padding: 0 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
}
input:hover, select:hover { border-color: var(--border-strong); }

/* ================== Topbar ================== */
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 15px; font-weight: 600; margin: 0; letter-spacing: -.01em; }
.modes {
  display: inline-flex; padding: 3px; gap: 2px;
  background: var(--surface-2); border-radius: var(--radius);
}
.mode {
  height: 26px; padding: 0 12px; border: 0; border-radius: 5px;
  background: transparent; color: var(--muted); cursor: pointer;
}
.mode.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); font-weight: 500; }
.tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-left: auto; }
.inline { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.inline input { width: 64px; }
.inline input.small { width: 52px; }
.divider { width: 1px; height: 20px; background: var(--border); }

.live { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.live::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--alive); }
.live.off::before { background: var(--dead); }

/* ================== Layout ================== */
.layout { flex: 1; display: flex; min-height: 0; }
.viewport {
  position: relative; flex: 1; overflow: hidden;
  background: var(--map-bg);
  cursor: grab; touch-action: none;
}
.viewport.panning { cursor: grabbing; }
.viewport.edit { cursor: crosshair; }
.stage { position: absolute; top: 0; left: 0; transform-origin: 0 0; }
.stage img { display: block; user-select: none; pointer-events: none; max-width: none; }
#markers { position: absolute; inset: 0; }

.hint {
  position: absolute; inset: 0; display: grid; place-items: center;
  color: var(--muted); pointer-events: none;
}
.mode-hint {
  position: absolute; left: 12px; bottom: 12px; padding: 6px 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--muted); font-size: 12px; pointer-events: none; box-shadow: var(--shadow);
}
.toast {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  padding: 8px 14px; z-index: 10; pointer-events: none;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  font-size: 13px;
}

/* ================== Markers ================== */
/* The marker itself is a zero-size point exactly on the spawn position.
   It's scaled around that point (transform-origin 0 0), so it never drifts when zooming. */
.marker {
  position: absolute; width: 0; height: 0;
  transform-origin: 0 0;
  cursor: pointer; user-select: none;
}
.marker .icon {
  position: absolute; left: 0; top: 0;
  width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center; font-size: 16px;
  background: #fff; border: 2.5px solid var(--alive);
  box-shadow: 0 1px 4px rgba(0,0,0,.25);
  transform: translate(-50%, -50%);
  transition: transform .12s;
}
.marker:hover .icon { transform: translate(-50%, -50%) scale(1.1); }
.marker .label {
  position: absolute; left: 0; top: 19px;
  transform: translateX(-50%);
  padding: 2px 7px; border-radius: 4px;
  background: rgba(20,20,19,.82); color: #fff;
  font-size: 11px; line-height: 1.35; white-space: nowrap; text-align: center;
  font-variant-numeric: tabular-nums; pointer-events: none;
}
.marker .by { display: block; font-size: 10px; opacity: .7; }
.marker .by:empty { display: none; }
.marker.dead .icon { border-color: var(--dead); filter: grayscale(1); opacity: .75; }
.marker.soon .icon { border-color: var(--soon); animation: pulse 1.2s infinite; }
.marker.just-up .icon { animation: pop .6s ease-out 3; }
.edit .marker { cursor: move; }

@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(199,125,18,.25); } }
@keyframes pop { 50% { transform: translate(-50%, -50%) scale(1.3); } }

/* ================== Sidebar ================== */
.sidebar {
  width: 300px; background: var(--surface); border-left: 1px solid var(--border);
  overflow-y: auto; padding: 16px;
}
#list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
#list li {
  position: relative;
  display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; align-items: center;
  padding: 10px 12px 10px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  cursor: pointer; transition: border-color .12s;
}
#list li:hover { border-color: var(--border-strong); }
#list li::before {
  content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px;
  border-radius: 0 2px 2px 0; background: var(--alive);
}
#list li.dead::before { background: var(--dead); }
#list li.soon::before { background: var(--soon); }
#list .name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#list .time { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 13px; }
#list li.alive .time { color: var(--alive); }
#list li.dead .time { color: var(--dead); }
#list li.soon .time { color: var(--soon); }
#list .sub { grid-column: 1 / -1; color: var(--muted); font-size: 12px; }
#list .by { color: var(--text); font-weight: 500; }
#list .actions { grid-column: 1 / -1; display: flex; gap: 6px; margin-top: 8px; }
#list .actions .btn { flex: 1; justify-content: center; height: 28px; font-size: 12px; }
#list .empty { color: var(--muted); border-style: dashed; cursor: default; display: block; }
#list .empty::before { display: none; }

/* ================== User menu ================== */
.user { position: relative; }
.role-badge {
  font-size: 11px; color: var(--muted);
  padding: 1px 6px; border-radius: 4px; background: var(--surface-2);
}
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 20;
  min-width: 180px; padding: 4px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex; flex-direction: column;
}
.menu button {
  background: none; border: 0; text-align: left; padding: 7px 10px;
  border-radius: 4px; cursor: pointer;
}
.menu button:hover { background: var(--surface-2); }

/* ================== Dialogs ================== */
dialog {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 12px;
  padding: 20px; width: min(380px, 92vw); box-shadow: var(--shadow);
}
dialog.wide { width: min(640px, 94vw); }
dialog::backdrop { background: rgba(0,0,0,.35); }
dialog h3 { margin: 0 0 16px; font-size: 16px; font-weight: 600; }
dialog h4 { margin: 20px 0 8px; font-size: 13px; font-weight: 600; }
dialog label { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; color: var(--muted); font-size: 13px; }
dialog label input { color: var(--text); }
dialog menu { display: flex; gap: 8px; padding: 0; margin: 18px 0 0; }
dialog .danger { color: var(--dead); }
.spacer { flex: 1; }

table.users { width: 100%; border-collapse: collapse; }
table.users th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12px; padding: 0 8px 6px; }
table.users td { padding: 8px; border-top: 1px solid var(--border); }
table.users td:last-child { text-align: right; white-space: nowrap; }
table.users select { height: 28px; }
table.users .btn { height: 28px; font-size: 12px; padding: 0 10px; }
.new-user .row { display: flex; flex-wrap: wrap; gap: 6px; }
.new-user input { flex: 1 1 130px; }

.error { color: var(--dead); margin: 8px 0 0; font-size: 13px; }
.muted { color: var(--muted); }

/* ================== Login ================== */
.login-page { display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(360px, 100%); padding: 28px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow);
}
.login-card h1 { font-size: 18px; font-weight: 600; margin: 0 0 4px; }
.login-card .muted { margin: 0 0 20px; font-size: 13px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; margin: 0 0 14px; color: var(--muted); font-size: 13px; }
.login-card input { height: 36px; color: var(--text); }
.login-card .btn { width: 100%; height: 36px; justify-content: center; margin-top: 6px; }

/* ================== Mobile ================== */
@media (max-width: 760px) {
  .layout { flex-direction: column; }
  .sidebar { width: auto; max-height: 40vh; border-left: 0; border-top: 1px solid var(--border); }
  .tools { margin-left: 0; }
}

/* ================== Sidebar tabs ================== */
.tabs {
  display: flex; gap: 2px; padding: 3px; margin-bottom: 12px;
  background: var(--surface-2); border-radius: var(--radius);
}
.tab {
  flex: 1; height: 28px; border: 0; border-radius: 5px; cursor: pointer;
  background: transparent; color: var(--muted); font-size: 13px;
}
.tab.active { background: var(--surface); color: var(--text); font-weight: 500; box-shadow: 0 1px 2px rgba(0,0,0,.08); }

/* ================== Log ================== */
.log { list-style: none; margin: 0; padding: 0; font-size: 12.5px; }
.log li {
  display: grid; grid-template-columns: auto 1fr; gap: 10px;
  padding: 8px 2px; border-bottom: 1px solid var(--border);
}
.log li:last-child { border-bottom: 0; }
.log time { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.log b { font-weight: 600; }
.log .log-respawn span { color: var(--alive); }
.log .log-reset span { color: var(--muted); }
.log .empty { color: var(--muted); display: block; border: 0; }

/* ================== Kill popup ================== */
.popover {
  position: fixed; z-index: 30; width: 220px; padding: 12px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow);
}
.pop-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.pop-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pop-close {
  border: 0; background: none; color: var(--muted); cursor: pointer;
  font-size: 18px; line-height: 1; padding: 2px 4px; border-radius: 4px;
}
.pop-close:hover { background: var(--surface-2); color: var(--text); }
.pop-sub { margin: 2px 0 10px; color: var(--muted); font-size: 12px; }
.pop-options { display: flex; flex-direction: column; gap: 6px; }
.pop-option { justify-content: space-between; height: 36px; }
.pop-option .opt-label { font-weight: 500; }
.pop-option .opt-time { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.pop-reset { width: 100%; justify-content: center; margin-top: 8px; color: var(--dead); }
