:root {
  /* 특보 색상 — 범례·지도·배지 공용 */
  --wind-watch: #6aa9e8;
  --wind-warn: #1b4fa8;
  --typhoon-watch: #f08f8a;
  --typhoon-warn: #c62828;
  --sea: #eaf3f8;
  --land: #d9e6d4;
  --ink: #1f2933;
  --ink-muted: #8a949c;
  --line: #d8dee4;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  color: var(--ink);
  background: #f4f6f8;
}

.callsign input { width: 130px; }

/* 누를 수 있는 버튼은 전부 파란 배경 + 흰 글자로 통일 */
.btn {
  font-size: 13px;
  padding: 6px 12px;
  border: 1px solid #2563eb;
  border-radius: 6px;
  background: #2563eb;
  color: #fff;
  cursor: pointer;
}
.btn:hover { background: #1d4ed8; border-color: #1d4ed8; }
.btn:disabled { opacity: .45; cursor: default; pointer-events: none; }
.btn.small { padding: 3px 8px; font-size: 12px; }

.toggle { cursor: pointer; user-select: none; }
.toggle input { display: none; }
.toggle .knob {
  width: 36px; height: 20px;
  border-radius: 10px;
  background: #c4cdd6;
  position: relative;
  transition: background .15s;
}
.toggle .knob::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: left .15s;
}
.toggle input:checked + .knob { background: #22c55e; }
.toggle input:checked + .knob::after { left: 18px; }
.countdown {
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  background: #eef2f7;
  padding: 3px 8px;
  border-radius: 6px;
}

/* ---------- 본문 2패널 ----------
   지도 패널은 지도 고유 비율(약 0.96:1, JS가 정확값 지정)에 고정되어
   창 높이에 따라 폭이 정해지고, 나머지 폭이 전부 텍스트 패널이 된다. */
main {
  display: grid;
  grid-template-columns: auto minmax(280px, 1fr);
  height: 100vh;
}

#mapPanel {
  position: relative;
  background: var(--land);
  overflow: hidden;
  height: 100%;
  aspect-ratio: 863 / 900; /* 폴백 — renderMap()이 정확값으로 갱신 */
}
#map { width: 100%; height: 100%; display: block; }

/* ---------- 지도 ---------- */
/* 구역 설정 버튼 — 지도 왼쪽 상단 상시 노출, 다른 버튼보다 크게 */
#mapPanel > #zoneSettingBtn {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 5;
  font-size: 16px;
  font-weight: 700;
  padding: 12px 22px;
  border-radius: 9px;
  box-shadow: 0 2px 10px rgba(37, 99, 235, .4);
}

.region {
  fill: var(--sea);
  stroke: #7d8b96;
  stroke-width: .8;
  vector-effect: non-scaling-stroke;
  transition: fill .35s; /* 선택 모드 진입/특보 색칠이 부드럽게 전환되도록 */
}
.region.unselected { fill: #f3f5f6; }
.region.wind-watch { fill: var(--wind-watch); }
.region.wind-warn { fill: var(--wind-warn); }
.region.typhoon-watch { fill: var(--typhoon-watch); }
.region.typhoon-warn { fill: var(--typhoon-warn); }
/* 예비특보 빗금 오버레이 — 발효 중 특보 채움 위에 겹쳐 그린다 */
.preOverlay { fill: none; pointer-events: none; }
.preOverlay.pre-wind { fill: url(#preWind); }
.preOverlay.pre-typhoon { fill: url(#preTyphoon); }
.preOverlay.pre-both { fill: url(#preBoth); }

/* 북한 해역 — 특보구역이 아닌 바다(클릭·색칠 대상 아님). 미수신 구역과 같은 회색 */
.nksea {
  fill: #f3f5f6;
  stroke: #7d8b96;
  stroke-width: .8;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

.label {
  font-size: 11px;
  fill: var(--ink);
  text-anchor: middle;
  pointer-events: none;
  paint-order: stroke;
  stroke: rgba(255,255,255,.88);
  stroke-width: 3px;
  stroke-linejoin: round;
}
.label.off { fill: #adb6bd; }
.label.inverse { fill: #fff; stroke: rgba(0,0,0,.45); }

/* 구역 설정 모드 */
svg.selecting .region { cursor: pointer; fill: #fff; }
svg.selecting .nksea { fill: #fff; }
svg.selecting .preOverlay { display: none; }
svg.selecting .region.picked {
  fill: #ef9a9a;
  animation: pickPop .3s ease;
}
@keyframes pickPop {
  0% { fill: #e05353; }
  100% { fill: #ef9a9a; }
}
svg.selecting .region:hover { stroke-width: 2; stroke: #444; }
svg.selecting .label { fill: var(--ink); }

#selectModeBar {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: #fff7ed;
  border-bottom: 1px solid #fdba74;
  font-size: 14px;
  animation: barIn .25s ease;
}
@keyframes barIn {
  from { transform: translateY(-100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
#selectModeBar .pickHint {
  color: var(--ink-muted);
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
#selectModeBar .pickHint b { color: #c0392b; }
#selectModeBar button:first-of-type { margin-left: auto; }

/* 선택/해제 색상 견본 */
.pickSwatch {
  width: 18px; height: 13px;
  border: 1px solid #9aa5ad;
  border-radius: 3px;
  background: #fff;
  display: inline-block;
  flex: none;
}
.pickSwatch.on {
  background: #ef9a9a;
  animation: swatchBlink 1.4s ease infinite;
}
@keyframes swatchBlink {
  50% { background: #e05353; }
}

/* 시나리오 선택 + 갱신/기준시각 — 지도 상단 중앙 상시 노출. 리플레이 중엔 주황톤 */
#scenarioBar {
  position: absolute;
  top: 14px; left: 50%;
  transform: translateX(-50%);
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 8px;
  background: #1f2937;
  color: #fff;
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 16px;
  opacity: .95;
  white-space: nowrap;
}
#scenarioBar.replay { background: #9a3412; }
#scenarioBar select {
  font-size: 12px;
  padding: 3px 6px;
  border: none;
  border-radius: 6px;
  background: rgba(255,255,255,.95);
  color: var(--ink);
}
#scenarioBar #lastUpdated { color: rgba(255,255,255,.8); }

/* 범례 */
#legend {
  position: absolute;
  left: 12px; bottom: 12px;
  z-index: 4;
  background: rgba(255,255,255,.94);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  display: grid;
  grid-template-columns: auto auto;
  gap: 6px 18px;
  font-size: 12px;
}
.legendItem { display: flex; align-items: center; gap: 7px; white-space: nowrap; }
.swatch {
  width: 22px; height: 14px;
  border: 1px solid #9aa5ad;
  border-radius: 3px;
  flex: none;
}
.swatch.wind-watch { background: var(--wind-watch); }
.swatch.wind-warn { background: var(--wind-warn); }
.swatch.typhoon-watch { background: var(--typhoon-watch); }
.swatch.typhoon-warn { background: var(--typhoon-warn); }
.swatch.pre-wind { background: repeating-linear-gradient(45deg, var(--sea) 0 5px, rgba(27,79,168,.45) 5px 7.5px); }
.swatch.pre-typhoon { background: repeating-linear-gradient(45deg, #fdf1f0 0 5px, rgba(198,40,40,.45) 5px 7.5px); }
/* 발효 중 특보 + 예비특보 겹침 예시 (풍랑주의보 채움 + 태풍예비 빗금) */
.swatch.overlap { background: repeating-linear-gradient(45deg, var(--wind-watch) 0 5px, #fff 5px 6px, rgba(198,40,40,.75) 6px 7.5px); }

/* ---------- 텍스트 패널 ---------- */
#textPanel {
  background: #fff;
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#textPanelBody {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 14px 16px;
}

/* ---------- API 연결 점검 로그 — 하단 1/5 고정, 터미널(매트릭스) 감성 ---------- */
#connLog {
  flex: 0 0 20%;
  min-height: 110px;
  display: flex;
  flex-direction: column;
  background: #050805;
  color: #e8efe8;
  font-family: "SF Mono", Menlo, Consolas, "Courier New", monospace;
}
.connLogHead {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 7px 12px;
  border-bottom: 1px solid #143314;
  background: #0a120a;
}
.connLogHead h3 {
  margin: 0 !important;
  font-size: 12px !important;
  font-weight: 700;
  color: #39ff5e !important;
  text-shadow: 0 0 6px rgba(57, 255, 94, .55);
  letter-spacing: .5px;
}
.connLogHint { font-size: 11px; color: #4a7a4a; }
#connNext { margin-left: auto; font-size: 11px; color: #39ff5e; opacity: .85; }
#connLogList {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 6px 12px;
  font-size: 12px;
  line-height: 1.7;
}
#connLogList::-webkit-scrollbar { width: 8px; }
#connLogList::-webkit-scrollbar-thumb { background: #1d4022; border-radius: 4px; }
#connLogList::-webkit-scrollbar-track { background: transparent; }
.logRow { white-space: nowrap; }
.logRow .t { color: #6f8a6f; }
.logRow .ok { color: #39ff5e; font-weight: 700; text-shadow: 0 0 5px rgba(57, 255, 94, .45); }
.logRow .fail { color: #ff5f56; font-weight: 700; text-shadow: 0 0 5px rgba(255, 95, 86, .45); }
.logRow.latest .cursor {
  display: inline-block;
  width: 7px; height: 12px;
  margin-left: 6px;
  background: #39ff5e;
  vertical-align: -1px;
  animation: caretBlink 1s steps(1) infinite;
}
@keyframes caretBlink { 50% { opacity: 0; } }

/* 방송 통합 컨트롤 — 방송/미리보기 + 호출명·자동방송 */
#bcastControls {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 12px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--line);
}
.bcRow { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.bcRow label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  white-space: nowrap;
}
.bcRow input[type="text"], .bcRow select {
  font-size: 13px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
}
#broadcastStatus { display: inline-flex; align-items: center; gap: 8px; }

/* 멘트보기 — 방송문 편집창 */
#scriptEditor { display: flex; flex-direction: column; gap: 8px; }
#scriptEditor textarea {
  width: 100%;
  padding: 10px;
  background: #f7f9fb;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  font-size: 13px;
  line-height: 1.6;
  resize: vertical;
}
#scriptEditor .editorActions { justify-content: flex-end; }
.panelHead { display: flex; align-items: center; justify-content: space-between; }
#textPanel h2 { font-size: 16px; margin: 0 0 10px; }
#textPanel h3 { font-size: 13px; margin: 18px 0 8px; color: var(--ink-muted); }
.onair { color: #dc2626; font-size: 13px; font-weight: 600; animation: blink 1.2s infinite; }
@keyframes blink { 50% { opacity: .35; } }

.empty {
  color: var(--ink-muted);
  font-size: 14px;
  text-align: center;
  padding: 48px 0;
}

.alertCard {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 12px;
}
.alertCard .cardHead {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.badge {
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  padding: 3px 9px;
  border-radius: 5px;
  white-space: nowrap;
}
.badge.wind-watch { background: var(--wind-watch); }
.badge.wind-warn { background: var(--wind-warn); }
.badge.typhoon-watch { background: var(--typhoon-watch); }
.badge.typhoon-warn { background: var(--typhoon-warn); }
.badge.pre-wind { background: var(--wind-watch); outline: 2px dashed var(--wind-warn); outline-offset: -2px; }
.badge.pre-typhoon { background: var(--typhoon-watch); outline: 2px dashed var(--typhoon-warn); outline-offset: -2px; }

.cardHead .regions { font-size: 14px; font-weight: 600; flex: 1; min-width: 0; }

.cardMeta { font-size: 12px; color: var(--ink-muted); margin: 6px 0 8px; }

.detailTable {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.detailTable th, .detailTable td {
  text-align: left;
  padding: 3px 6px;
  border-top: 1px solid #eef1f4;
  white-space: nowrap;
}
.detailTable th { color: var(--ink-muted); font-weight: 500; border-top: none; }
.detailTable td:first-child { white-space: normal; }

.scriptPreview {
  margin: 8px 0 0;
  padding: 10px;
  background: #f7f9fb;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
}

.releasedCard {
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 8px;
  color: var(--ink-muted);
  font-size: 13px;
}
.releasedCard b { color: var(--ink); font-weight: 600; }
