:root {
  color-scheme: dark;
  --bg: #071019;
  --panel: rgba(11, 22, 34, .90);
  --panel2: rgba(17, 31, 46, .86);
  --line: rgba(148, 163, 184, .20);
  --text: #f8fafc;
  --muted: #94a3b8;
  --amber: #f59e0b;
  --danger: #fb7185;
}

* { box-sizing: border-box; }
html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, Pretendard, "Noto Sans KR", system-ui, sans-serif;
}
button, select { font: inherit; }
button { color: inherit; }

#app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  width: 100%;
  height: 100%;
}

#stage {
  position: relative;
  min-width: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 18% 12%, rgba(14, 165, 233, .10), transparent 34%),
    radial-gradient(circle at 82% 88%, rgba(245, 158, 11, .08), transparent 32%),
    #071019;
}

#map {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}
#map.dragging { cursor: grabbing; }

.glass {
  border: 1px solid var(--line);
  background: rgba(7, 16, 25, .80);
  box-shadow: 0 16px 40px rgba(0, 0, 0, .26);
  backdrop-filter: blur(12px);
}

.topbar {
  position: absolute;
  z-index: 5;
  top: 14px;
  right: 14px;
  left: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 14px;
}
.brandMark {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 9px;
  background: linear-gradient(145deg, #fbbf24, #f97316);
  color: #1c0b00;
  font-weight: 1000;
}
.brand strong {
  display: block;
  font-size: 13px;
  letter-spacing: .05em;
}
.brand small {
  display: block;
  margin-top: 1px;
  color: var(--muted);
  font-size: 10px;
}

.status {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px;
  border-radius: 14px;
}
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  padding: 5px 9px;
  border: 0;
  border-radius: 10px;
  background: rgba(30, 41, 59, .58);
  color: #cbd5e1;
  font-size: 11px;
  white-space: nowrap;
}
.pill strong { color: white; }
.pill.ready { background: rgba(22, 101, 52, .34); color: #bbf7d0; }
.pill.wait { background: rgba(146, 64, 14, .30); color: #fde68a; }

.mapHelp {
  position: absolute;
  z-index: 4;
  bottom: 14px;
  left: 14px;
  max-width: 540px;
  padding: 9px 12px;
  border-radius: 12px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
  pointer-events: none;
}

#sidebar {
  min-width: 0;
  overflow: auto;
  padding: 16px;
  border-left: 1px solid var(--line);
  background: linear-gradient(180deg, #0b1622, #071019);
}

.card {
  margin-bottom: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel2);
  box-shadow: 0 12px 30px rgba(0, 0, 0, .16);
}
.card h2 { margin: 0 0 10px; font-size: 13px; }
.card p { margin: 7px 0; color: var(--muted); font-size: 11px; line-height: 1.55; }
.empty { color: var(--muted); font-size: 11px; line-height: 1.6; }
.unitPanel { min-height: 132px; }

.toggleRow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 32px;
  color: #cbd5e1;
  font-size: 11px;
  cursor: pointer;
}
.toggleRow + .toggleRow {
  margin-top: 5px;
  padding-top: 5px;
  border-top: 1px solid rgba(148, 163, 184, .12);
}
.switch {
  position: relative;
  width: 34px;
  height: 19px;
  flex: 0 0 auto;
}
.switch input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}
.switch > span {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: #334155;
  transition: .18s ease;
}
.switch > span::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #e2e8f0;
  box-shadow: 0 1px 5px rgba(0, 0, 0, .35);
  transition: .18s ease;
}
.switch input:checked + span { background: #0284c7; }
.switch input:checked + span::after { transform: translateX(15px); }
.switch input:focus-visible + span {
  outline: 2px solid #7dd3fc;
  outline-offset: 2px;
}

.factionBadge { display: flex; align-items: center; gap: 9px; }
.factionBadge strong { font-size: 14px; }
.swatch {
  width: 13px;
  height: 13px;
  flex: 0 0 auto;
  border-radius: 50%;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, .08);
}

.unitTitle { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.unitTitle strong { font-size: 14px; }
.tag {
  padding: 3px 7px;
  border-radius: 999px;
  background: rgba(51, 65, 85, .72);
  color: #cbd5e1;
  font-size: 10px;
}

.hpTrack, .captureTrack {
  overflow: hidden;
  border-radius: 999px;
  background: rgba(15, 23, 42, .92);
}
.hpTrack { height: 7px; margin: 9px 0; }
.hpFill { height: 100%; background: linear-gradient(90deg, #22c55e, #a3e635); }
.unitStats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.miniStat { padding: 7px; border-radius: 10px; background: rgba(15, 23, 42, .58); text-align: center; }
.miniStat b { display: block; font-size: 12px; }
.miniStat span { display: block; margin-top: 2px; color: var(--muted); font-size: 9px; }

.captureRow { margin-top: 9px; }
.captureHead { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 5px; font-size: 10px; }
.captureHead span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.captureTrack { height: 5px; }
.captureFill { height: 100%; background: linear-gradient(90deg, #f59e0b, #ef4444); }

.feed { display: grid; gap: 6px; max-height: 210px; overflow: auto; }
.feedItem {
  padding: 7px 8px;
  border-left: 2px solid rgba(148, 163, 184, .32);
  background: rgba(15, 23, 42, .45);
  color: #cbd5e1;
  font-size: 10px;
  line-height: 1.45;
}
.feedItem.hit { border-color: #f59e0b; }
.feedItem.capture { border-color: #a3e635; }
.rules { display: grid; gap: 6px; }
.rule { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 10px; }
.rule b { color: #e2e8f0; }

.modalWrap {
  position: fixed;
  z-index: 30;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(2, 6, 23, .76);
  backdrop-filter: blur(12px);
}
.modalWrap.show { display: flex; }
.modal {
  width: min(540px, 100%);
  padding: 22px;
  border: 1px solid rgba(148, 163, 184, .25);
  border-radius: 22px;
  background: #0b1724;
  box-shadow: 0 28px 80px rgba(0, 0, 0, .55);
}
.modal h1 { margin: 0; font-size: 22px; }
.modal p { color: var(--muted); font-size: 12px; line-height: 1.65; }
.modal label { display: block; margin-top: 16px; color: #cbd5e1; font-size: 11px; font-weight: 800; }
.modal select {
  width: 100%;
  margin: 7px 0 8px;
  padding: 12px;
  border: 1px solid rgba(148, 163, 184, .28);
  border-radius: 12px;
  background: #111f2f;
  color: white;
}
.modal select option {
  background: #111f2f;
  color: var(--faction-option-color, #f8fafc);
}
.joinFactionPreview {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 34px;
  margin-bottom: 12px;
  padding: 7px 10px;
  border: 1px solid rgba(148, 163, 184, .16);
  border-radius: 10px;
  background: rgba(15, 23, 42, .55);
  color: #e2e8f0;
  font-size: 11px;
}
.joinFactionPreview .swatch {
  width: 16px;
  height: 16px;
  border: 1px solid rgba(255, 255, 255, .65);
}
.eyebrow { margin: 0 0 7px !important; color: #fbbf24 !important; font-size: 10px !important; font-weight: 900; letter-spacing: .16em; }
.eyebrow.danger { color: #fb7185 !important; }
.primary {
  width: 100%;
  padding: 12px 16px;
  border: 0;
  border-radius: 12px;
  cursor: pointer;
  background: linear-gradient(135deg, #fbbf24, #f97316);
  color: #1c0b00;
  font-weight: 900;
}
.primary:disabled { cursor: wait; opacity: .45; }
.warning { color: #fde68a !important; }

.mapTooltip {
  position: fixed;
  z-index: 24;
  width: max-content;
  max-width: min(360px, calc(100vw - 24px));
  padding: 9px 11px;
  border: 1px solid rgba(255, 255, 255, .22);
  border-radius: 10px;
  background: rgba(2, 6, 23, .94);
  box-shadow: 0 12px 34px rgba(0, 0, 0, .48);
  opacity: 0;
  pointer-events: none;
  transform: translate(10px, 10px);
  transition: opacity .1s ease;
}
.mapTooltip.show { opacity: 1; }
.mapTooltip strong {
  display: block;
  overflow: hidden;
  color: #f8fafc;
  font-size: 12px;
  line-height: 1.45;
  text-overflow: ellipsis;
}
.mapTooltip small {
  display: block;
  margin-top: 4px;
  color: #cbd5e1;
  font-size: 10px;
}
.mapTooltip .tooltipViews {
  display: inline-flex;
  margin-top: 7px;
  padding: 3px 7px;
  border-radius: 999px;
  background: rgba(148, 163, 184, .16);
  color: #f8fafc;
  font-size: 10px;
  font-weight: 800;
}

#toast {
  position: fixed;
  z-index: 50;
  bottom: 24px;
  left: 50%;
  max-width: min(520px, calc(100vw - 30px));
  padding: 10px 14px;
  border: 1px solid rgba(251, 113, 133, .35);
  border-radius: 12px;
  background: rgba(76, 5, 25, .94);
  color: #ffe4e6;
  font-size: 12px;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 18px);
  transition: .2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
.mobileOnly { display: none; }

@media (max-width: 820px) {
  #app { grid-template-columns: 1fr; }
  #sidebar {
    position: fixed;
    z-index: 20;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(330px, 88vw);
    border-left: 1px solid var(--line);
    box-shadow: -20px 0 55px rgba(0, 0, 0, .45);
    transform: translateX(101%);
    transition: transform .22s ease;
  }
  #sidebar.open { transform: translateX(0); }
  .mobileOnly { display: inline-flex; cursor: pointer; }
  .status .pill:first-child { display: none; }
  .mapHelp { right: 14px; }
}
