:root {
  --ink: #17202a;
  --archi-body: #6fa3d3;
  --archi-face: #dbe7f5;
  --vest: #e8622c;
  --cheek: #f2a3bd;
  --paper: #fdf3e3;
  --kcg-navy: #0a2e5c;
  --signal-green: #118447;
  --signal-yellow: #c47a05;
  --signal-red: #c9352a;
  --panel: #ffffff;
  --muted: rgba(23, 32, 42, 0.7);
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: "Pretendard Variable", Pretendard, -apple-system, "Malgun Gothic", sans-serif;
  letter-spacing: 0;
}

body { display: flex; justify-content: center; }
button, select, input, textarea { font: inherit; }
button, select, a { min-height: 44px; }
button:focus-visible, select:focus-visible, a:focus-visible, input:focus-visible {
  outline: 4px solid var(--cheek);
  outline-offset: 2px;
}
[hidden] { display: none !important; }

.app {
  width: min(900px, 100%);
  min-height: 100vh;
  background: var(--paper);
  border-inline: 2px solid var(--ink);
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  padding: 10px 14px;
  background: var(--panel);
  border-bottom: 3px solid var(--ink);
}

.header-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto;
  gap: 12px;
  align-items: center;
}

.brand-block { min-width: 0; }
h1 {
  margin: 0;
  color: var(--kcg-navy);
  font-size: 20px;
  line-height: 1.15;
  font-weight: 900;
}

.generated {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
  font-weight: 800;
}

.location-row {
  display: grid;
  grid-template-columns: minmax(150px, 240px) auto;
  gap: 8px;
  align-items: center;
  min-width: 0;
}

.site-select {
  width: 100%;
  min-width: 0;
  border: 2px solid var(--ink);
  border-radius: 8px;
  padding: 7px 30px 7px 10px;
  background: var(--panel);
  color: var(--ink);
  font-weight: 900;
}

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 8px;
  border: 1.5px solid var(--ink);
  border-radius: 7px;
  background: var(--archi-face);
  color: var(--ink);
  font-size: 11px;
  line-height: 1.2;
  font-weight: 900;
  white-space: nowrap;
}

.badge.good { background: rgba(17, 132, 71, 0.16); }
.badge.warn { background: rgba(196, 122, 5, 0.18); }
.badge.danger { background: rgba(201, 53, 42, 0.16); }
.badge.neutral { background: rgba(23, 32, 42, 0.1); }
.badge.sim { display: none; background: var(--cheek); }
body.tools-on.sim-on .badge.sim { display: inline-flex; }
.station-compact { background: var(--archi-face); }

.mode-switch {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
  margin-top: 8px;
  padding: 3px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--archi-face);
}

.mode-btn {
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  font-weight: 900;
  cursor: pointer;
}

.mode-btn.active { background: var(--kcg-navy); color: #fff; }

.tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-bottom: 3px solid var(--ink);
  background: var(--panel);
}

.tab-btn {
  border: 0;
  border-right: 2px solid var(--ink);
  background: var(--panel);
  color: var(--ink);
  font-weight: 900;
  cursor: pointer;
}
.tab-btn:last-child { border-right: 0; }
.tab-btn.active { background: var(--kcg-navy); color: #fff; }

.view { display: none; }
.view.active { display: block; }
body.expert-mode .visitor-only { display: none !important; }
#expertMode { display: none; }
body.expert-mode #expertMode { display: block; }

.signal-card {
  --state-color: var(--signal-red);
  display: grid;
  gap: 12px;
  min-height: calc(100vh - 222px);
  padding: 16px;
  background: var(--paper);
  color: var(--ink);
}
.signal-card.green { --state-color: var(--signal-green); }
.signal-card.yellow { --state-color: var(--signal-yellow); }
.signal-card.red { --state-color: var(--signal-red); }
.signal-card.neutral { --state-color: var(--ink); }

.status-bubble {
  position: relative;
  z-index: 2;
  padding: 14px 16px;
  border: 3px solid var(--state-color);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: 4px 4px 0 var(--ink);
}

.main-message {
  margin: 0;
  color: var(--state-color);
  font-size: clamp(24px, 5vw, 38px);
  line-height: 1.12;
  font-weight: 900;
  overflow-wrap: anywhere;
}

.action-message {
  margin: 7px 0 0;
  color: var(--ink);
  font-size: clamp(15px, 2.4vw, 20px);
  line-height: 1.35;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.status-visual {
  display: grid;
  place-items: center;
  height: 235px;
  overflow: hidden;
}

.status-archi {
  width: min(280px, 68vw);
  height: auto;
  transform: translateY(-3px);
}

.signal-icon {
  width: 118px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border: 5px solid var(--ink);
  border-radius: 50%;
  background: var(--state-color);
  color: #fff;
  box-shadow: 4px 4px 0 var(--ink);
  font-size: 64px;
  line-height: 1;
  font-weight: 900;
}

.deadline-board {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: center;
  min-height: 84px;
  padding: 10px 16px;
  border: 3px solid var(--ink);
  border-radius: 16px;
  background: var(--state-color);
  color: #fff;
  box-shadow: 4px 4px 0 var(--ink);
}

.deadline-label {
  font-size: 14px;
  line-height: 1.25;
  font-weight: 900;
}

.deadline-value {
  min-width: 0;
  text-align: right;
  font-size: clamp(32px, 9vw, 56px);
  line-height: 1;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.remaining-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
  padding: 7px 12px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--panel);
}

.quick-label {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.25;
  font-weight: 900;
}

.quick-value {
  color: var(--ink);
  text-align: right;
  font-size: 19px;
  line-height: 1.15;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.alarm-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.alarm-btn,
.ics-btn {
  min-width: 0;
  border: 3px solid var(--ink);
  border-radius: 8px;
  padding: 10px 8px;
  font-size: 15px;
  font-weight: 900;
  cursor: pointer;
}
.alarm-btn { background: var(--vest); color: #fff; }
.ics-btn { background: var(--panel); color: var(--ink); }
.alarm-btn.on { background: var(--kcg-navy); }
.alarm-btn:disabled, .ics-btn:disabled { opacity: 0.42; cursor: default; }

.call-button {
  display: grid;
  place-items: center;
  border: 3px solid var(--ink);
  border-radius: 8px;
  background: var(--vest);
  color: #fff;
  text-decoration: none;
  font-size: 20px;
  line-height: 1.2;
  font-weight: 900;
  box-shadow: 3px 3px 0 var(--ink);
}
.signal-call { min-height: 50px; }

.sim-panel {
  display: none;
  gap: 10px;
  padding: 12px;
  border: 2px dashed var(--ink);
  border-radius: 8px;
  background: var(--archi-face);
}
body.tools-on.sim-on .sim-panel { display: grid; }
.sim-top {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  font-weight: 900;
}
#simSlider { width: 100%; }

.plain-btn,
.dark-btn,
.danger-btn {
  border: 2px solid var(--ink);
  border-radius: 8px;
  padding: 8px 12px;
  font-weight: 900;
  cursor: pointer;
}
.plain-btn { background: var(--panel); color: var(--ink); }
.dark-btn { background: var(--kcg-navy); color: #fff; }
.danger-btn { background: var(--signal-red); color: #fff; }
.wide-btn { width: 100%; }

.section { margin: 18px 16px 24px; }
.section-head {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 0 0 10px;
  border-bottom: 3px solid var(--ink);
}
.section-title {
  margin: 0;
  color: var(--kcg-navy);
  font-size: 20px;
  line-height: 1.2;
  font-weight: 900;
}
.section-sub {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
  font-weight: 800;
}

.timeline {
  display: grid;
  gap: 8px;
  padding: 12px 0;
}
.timeline-row {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 10px;
  align-items: center;
  min-height: 46px;
  padding: 0 12px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--panel);
}
.timeline-time { font-size: 17px; font-weight: 900; font-variant-numeric: tabular-nums; }
.timeline-copy { color: var(--ink); font-size: 14px; line-height: 1.35; font-weight: 800; }

.curve-wrap {
  margin-top: 12px;
  padding: 10px 10px 12px;
  border: 3px solid var(--ink);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: 4px 4px 0 var(--ink);
}
#tideCanvas,
#expertTideCanvas {
  display: block;
  width: 100%;
  background: var(--archi-face);
}
#tideCanvas { height: 190px; }
#expertTideCanvas { height: 290px; }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  padding: 8px 4px 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}
.legend-item { display: inline-flex; align-items: center; gap: 5px; }
.swatch { width: 20px; height: 8px; border: 1px solid var(--ink); border-radius: 3px; }
.swatch.green { background: rgba(17, 132, 71, 0.28); }
.swatch.yellow { background: rgba(196, 122, 5, 0.3); }
.swatch.blue { background: var(--archi-body); }
.dot { width: 10px; aspect-ratio: 1; border: 2px solid var(--ink); border-radius: 50%; background: var(--panel); }

.expert-summary { margin-top: 18px; }
.expert-kpis,
.info-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  padding: 12px 0 0;
}
.expert-kpi,
.info-card,
.extrema-card {
  min-width: 0;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--panel);
  padding: 12px;
}
.expert-kpi { border-top: 7px solid var(--archi-body); }
.kpi-label,
.info-label,
.extrema-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
  font-weight: 900;
}
.kpi-value,
.info-value,
.extrema-value {
  display: block;
  margin-top: 7px;
  color: var(--ink);
  font-size: 18px;
  line-height: 1.22;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.kpi-note,
.info-note {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  font-weight: 800;
  overflow-wrap: anywhere;
}
.expert-curve-wrap { margin-top: 12px; }
.extrema-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 12px 0 0;
}
.extrema-card.low { border-top: 7px solid var(--archi-body); }
.extrema-card.high { border-top: 7px solid var(--signal-yellow); }
.data-grid { padding-top: 10px; }

.map-shell {
  height: calc(100vh - 230px);
  min-height: 430px;
  position: relative;
  margin-top: 12px;
  overflow: hidden;
  border: 3px solid var(--ink);
  border-radius: 16px;
  background: var(--archi-face);
  box-shadow: 4px 4px 0 var(--ink);
}
#map { width: 100%; height: 100%; background: var(--archi-face); }
.map-fallback {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  padding: 20px;
  color: var(--ink);
  text-align: center;
  font-weight: 900;
  background: var(--archi-face);
}

.help-grid {
  display: grid;
  gap: 14px;
  margin: 16px;
}
.help-card {
  border: 3px solid var(--ink);
  border-radius: 16px;
  padding: 14px;
  background: var(--panel);
  box-shadow: 4px 4px 0 var(--ink);
}
.help-card.danger { border-color: var(--signal-red); }
.help-title { margin: 0 0 8px; color: var(--kcg-navy); font-size: 18px; font-weight: 900; }
.help-text { margin: 0; color: var(--ink); font-size: 15px; line-height: 1.5; font-weight: 800; }
.report-call { min-height: 72px; font-size: 30px; }
.report-kicker { margin: 0; color: var(--signal-red); font-size: 17px; font-weight: 900; }
.read-script {
  margin: 10px 0 0;
  padding: 14px;
  border: 2px dashed var(--signal-red);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  font-size: 18px;
  line-height: 1.5;
  font-weight: 900;
}
.report-note { margin-top: 10px; font-size: 13px; }
.waiting-card {
  display: grid;
  grid-template-columns: 1fr minmax(110px, 180px);
  gap: 10px;
  align-items: end;
  overflow: hidden;
}
.waiting-copy { min-width: 0; }
.safety-steps { margin: 0; padding-left: 22px; color: var(--ink); font-size: 15px; line-height: 1.55; font-weight: 800; }
.report-archi { width: 190px; max-width: 100%; transform: scale(1.25); transform-origin: center bottom; }
.haeroad-note {
  margin: 0;
  padding: 10px 12px;
  border-left: 6px solid var(--archi-body);
  background: var(--panel);
  color: var(--ink);
  font-size: 13px;
  line-height: 1.45;
  font-weight: 800;
}

.data-panel {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: none;
  overflow: auto;
  padding: 18px;
  background: var(--kcg-navy);
  color: #fff;
}
.data-panel.open { display: block; }
.data-panel h2 { margin: 0 0 8px; font-size: 20px; }
.data-panel p { margin: 0 0 12px; color: var(--archi-face); line-height: 1.55; font-size: 14px; }
.data-panel a { color: #fff; }
.data-panel pre {
  overflow: auto;
  max-height: 52vh;
  padding: 12px;
  border: 2px solid var(--archi-body);
  border-radius: 8px;
  background: var(--ink);
  color: var(--archi-face);
  font-size: 12px;
  line-height: 1.45;
}
.data-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.notice {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 9px;
  align-items: center;
  padding: 9px 12px;
  border-top: 3px solid var(--ink);
  background: var(--kcg-navy);
  color: #fff;
  font-size: 11px;
  line-height: 1.35;
  font-weight: 800;
}
.kcg-emblem { width: auto; height: 20px; }
.notice span { display: block; }
.cooperation { margin-top: 2px; color: var(--archi-face); }

.setup-toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  z-index: 1000;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: center;
  width: min(360px, calc(100vw - 28px));
  padding: 10px 14px;
  border: 3px solid var(--ink);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: 4px 4px 0 var(--ink);
  opacity: 0;
  transform: translate(-50%, 24px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}
.setup-toast.open { opacity: 1; transform: translate(-50%, 0); }
.setup-toast img { width: 64px; height: 64px; object-fit: contain; transform: scale(1.35); }
.setup-toast strong, .setup-toast span { display: block; }
.setup-toast strong { color: var(--signal-green); font-size: 18px; }
.setup-toast span { margin-top: 3px; font-size: 12px; line-height: 1.35; font-weight: 800; }
.kcg-assets-off .waiting-card,
.kcg-assets-off .setup-toast { grid-template-columns: 1fr; }

.alert-overlay {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(23, 32, 42, 0.92);
}
.alert-overlay.open { display: flex; }
.alert-box {
  width: min(420px, 100%);
  padding: 24px 18px;
  border: 5px solid var(--ink);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  text-align: center;
}
.alert-overlay.urgent .alert-box { border-color: var(--signal-red); }
.alert-title { margin-bottom: 10px; color: var(--signal-red); font-size: 26px; font-weight: 900; }
.alert-body { margin: 0 0 18px; font-size: 17px; line-height: 1.5; font-weight: 800; }
.alert-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.alert-close {
  border: 3px solid var(--ink);
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font-size: 17px;
  font-weight: 900;
  cursor: pointer;
}

.selftest-panel {
  margin: 16px;
  overflow: hidden;
  border: 3px solid var(--ink);
  border-radius: 8px;
  background: var(--panel);
}
.selftest-panel h2 { margin: 0; padding: 12px 14px; background: var(--kcg-navy); color: #fff; font-size: 16px; }
.selftest-panel pre { margin: 0; padding: 12px 14px; overflow: auto; font-size: 13px; line-height: 1.5; }
.sim-toggle { display: none; }
body.tools-on .sim-toggle { display: inline-flex; }

@media (max-width: 560px) {
  .app { border-inline: 0; }
  .app-header { padding: 7px 9px; }
  .header-row { display: block; }
  .brand-block, .badges { display: none; }
  .location-row { grid-template-columns: minmax(0, 1fr) auto; gap: 6px; }
  .site-select { min-height: 42px; padding-block: 6px; }
  .station-compact {
    max-width: 132px;
    min-height: 42px;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .mode-switch { margin-top: 6px; }
  .mode-btn { min-height: 38px; }
  .tab-btn { min-height: 43px; }
  .signal-card {
    gap: 8px;
    min-height: 0;
    padding: 10px 11px 12px;
  }
  .status-bubble { padding: 10px 12px; border-radius: 12px; box-shadow: 3px 3px 0 var(--ink); }
  .main-message { font-size: 23px; line-height: 1.08; }
  .action-message { margin-top: 5px; font-size: 14px; line-height: 1.3; }
  .status-visual { height: 176px; }
  .status-archi { width: 220px; transform: translateY(-3px); }
  .signal-icon { width: 82px; border-width: 4px; font-size: 44px; box-shadow: 3px 3px 0 var(--ink); }
  .deadline-board {
    min-height: 68px;
    padding: 8px 12px;
    border-radius: 12px;
    box-shadow: 3px 3px 0 var(--ink);
  }
  .deadline-label { max-width: 72px; font-size: 12px; }
  .deadline-value { font-size: 34px; }
  .remaining-row { min-height: 40px; padding-block: 5px; }
  .quick-value { font-size: 17px; }
  .alarm-grid { gap: 7px; }
  .alarm-btn, .ics-btn { min-height: 46px; padding: 7px 5px; font-size: 14px; }
  .signal-call { min-height: 47px; font-size: 18px; }
  .section { margin: 14px 12px 20px; }
  .section-head { align-items: start; }
  .section-title { font-size: 18px; }
  .expert-kpis, .info-grid, .extrema-list { grid-template-columns: 1fr; }
  #expertTideCanvas { height: 240px; }
  .map-shell { height: calc(100vh - 210px); min-height: 420px; }
  .help-grid { margin: 12px; }
  .report-call { min-height: 64px; font-size: 27px; }
  .read-script { font-size: 16px; }
  .waiting-card { grid-template-columns: 1fr 96px; }
  .report-archi { width: 125px; }
  .safety-steps { font-size: 14px; }
  .notice { font-size: 10px; }
}

@media (max-width: 370px) {
  .station-compact { max-width: 112px; font-size: 10px; }
  .main-message { font-size: 21px; }
  .action-message { font-size: 13px; }
  .deadline-value { font-size: 30px; }
}

@media (prefers-reduced-motion: reduce) {
  .setup-toast { transition: none; }
}
