:root {
  --bg: #0a0f1a;
  --card: #111827;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --line: #1f2937;
  --green: #22c55e;
  --yellow: #eab308;
  --orange: #f97316;
  --red: #ef4444;
  --accent: #3b82f6;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: radial-gradient(1200px 600px at 10% -10%, #132033 0%, var(--bg) 55%);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Noto Sans TC", sans-serif;
  line-height: 1.55;
}
a { color: #93c5fd; text-decoration: none; }
a:hover { text-decoration: underline; }

.container { max-width: 1200px; margin: 0 auto; padding: 22px; }
.container.narrow { max-width: 720px; }

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.brand { display: flex; gap: 12px; align-items: center; }
.logo { font-size: 40px; line-height: 1; }
h1 { margin: 0; font-size: 26px; letter-spacing: -0.02em; }
.subtitle { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.header-right { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.stage-badge {
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: #1f2937;
}
.overall-score {
  font-size: 30px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  min-width: 64px;
  text-align: right;
}

button, .btn-link {
  background: #1f2937;
  color: var(--text);
  border: 1px solid #374151;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  display: inline-block;
}
button:hover, .btn-link:hover { background: #374151; text-decoration: none; }
button:disabled { opacity: 0.55; cursor: wait; }

.meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  color: #6b7280;
  font-size: 12px;
  margin-bottom: 14px;
}
.note { color: #6b7280; font-size: 12px; }

.hero-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) 1.4fr;
  gap: 12px;
  background: linear-gradient(180deg, #0f172a, #111827);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 14px;
}
.hero-strip .k { font-size: 11px; color: var(--muted); }
.hero-strip .v { font-size: 22px; font-weight: 800; margin-top: 4px; }
.hero-note { font-size: 12px; color: #cbd5e1; align-self: center; }

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
}
.actions .chip {
  background: #0b1220;
  border: 1px solid #243044;
  color: #dbeafe;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
}

.sec-title {
  margin: 22px 0 10px;
  font-size: 15px;
  color: #cbd5e1;
  font-weight: 700;
}

.panels-grid, .markets-grid, .mil-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
}

.panel, .m-card, .mil-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
}
.panel-header, .m-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: baseline;
}
.panel-name { font-size: 14px; font-weight: 700; }
.panel-score { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }
.pol {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #64748b;
}
.score-bar {
  height: 6px;
  background: #0b1220;
  border-radius: 99px;
  overflow: hidden;
  margin: 10px 0;
}
.score-fill { height: 100%; }
.panel-body, .m-body { font-size: 12px; color: var(--muted); }
.panel-body .value, .m-body b { color: #e5e7eb; font-weight: 600; }

.warn {
  font-size: 12px;
  color: #fde68a;
  background: #1c1917;
  border: 1px solid #78350f;
  border-radius: 10px;
  padding: 10px 12px;
  margin: 0 0 12px;
}
.constraints {
  margin: 12px 0 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 13px;
}
.mil-card h3 { margin: 0 0 8px; font-size: 15px; }
.mil-card .row { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); padding: 2px 0; }
.mil-card .row b { color: var(--text); }

.footer-note {
  margin-top: 28px;
  text-align: center;
  color: #6b7280;
  font-size: 12px;
}

.buf-form {
  display: grid;
  gap: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
}
.buf-form label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: #cbd5e1;
}
.buf-form input, .buf-form textarea {
  width: 100%;
  background: #0b1220;
  border: 1px solid #334155;
  border-radius: 8px;
  color: var(--text);
  padding: 10px 12px;
  font: inherit;
}
.buf-form .row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.auth-err { color: #f87171; min-height: 1.2em; margin: 0; font-size: 13px; }
.ok { color: #86efac; min-height: 1.2em; margin: 0; font-size: 13px; }

.auth-box {
  max-width: 380px;
  margin: 12vh auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 22px;
}
.auth-box h1 { font-size: 22px; margin-bottom: 8px; }
.auth-box label { display: block; margin-top: 10px; font-size: 13px; color: var(--muted); }
.auth-box input {
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid #334155;
  background: #0b1220;
  color: var(--text);
}
.auth-box button { width: 100%; margin-top: 14px; }
.auth-lead { color: var(--muted); font-size: 13px; }

@media (max-width: 900px) {
  .hero-strip { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 560px) {
  .hero-strip { grid-template-columns: 1fr; }
  h1 { font-size: 22px; }
}

/* —— 階梯圖例 / 緊急門檻 —— */
.legend-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px 18px 18px;
  margin: 0 0 16px;
}
.legend-disc {
  margin: 8px 0 12px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.55;
}
.ladder-table {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}
.ladder-row {
  border: 1px solid #243044;
  border-radius: 12px;
  padding: 10px 12px;
  background: #0b1220;
}
.ladder-row.active {
  border-color: #f59e0b;
  box-shadow: 0 0 0 1px rgba(245, 158, 11, 0.35);
}
.ladder-row .lr-range {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  margin-bottom: 4px;
}
.ladder-row .lr-name {
  font-size: 15px;
  font-weight: 800;
  margin-bottom: 4px;
}
.ladder-row .lr-mean {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.45;
}
.legend-emergency-box {
  border: 1px solid #7f1d1d;
  background: linear-gradient(180deg, #1c1010, #111827);
  border-radius: 12px;
  padding: 12px 14px;
}
.em-title {
  font-weight: 800;
  color: #fecaca;
  margin-bottom: 8px;
  font-size: 14px;
}
.em-rules {
  margin: 0 0 10px;
  padding-left: 18px;
  font-size: 12px;
  color: #e7e5e4;
  line-height: 1.55;
}
.em-details summary {
  cursor: pointer;
  color: #93c5fd;
  font-size: 13px;
  font-weight: 600;
}
.em-list {
  margin: 10px 0 0;
  padding-left: 20px;
  font-size: 13px;
  color: #e5e7eb;
  line-height: 1.55;
}
.em-list li { margin: 4px 0; }

.threshold-banner {
  border-radius: 12px;
  padding: 12px 14px;
  margin: 0 0 14px;
  font-size: 13px;
  line-height: 1.5;
  border: 1px solid #b45309;
  background: #1c1408;
  color: #fde68a;
}
.threshold-banner.critical {
  border-color: #b91c1c;
  background: #1c1010;
  color: #fecaca;
}
.threshold-banner.hidden { display: none; }
.threshold-banner strong { font-weight: 800; }
.threshold-banner button.linkish {
  background: transparent;
  border: none;
  color: #93c5fd;
  padding: 0;
  font-size: 13px;
  text-decoration: underline;
  cursor: pointer;
}

/* modal */
.modal.hidden { display: none; }
.modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.72);
}
.modal-panel {
  position: relative;
  z-index: 1;
  width: min(560px, 100%);
  max-height: min(88vh, 900px);
  overflow: auto;
  background: #111827;
  border: 1px solid #7f1d1d;
  border-radius: 16px;
  padding: 18px 18px 16px;
  box-shadow: 0 25px 50px rgba(0,0,0,0.5);
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.modal-head h2 {
  margin: 0;
  font-size: 18px;
  color: #fecaca;
}
.modal-close {
  border: none;
  background: #1f2937;
  color: #e5e7eb;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.modal-lead {
  font-size: 13px;
  color: #e7e5e4;
  line-height: 1.55;
}
.modal-foot {
  font-size: 11px;
  color: #a8a29e;
  margin: 12px 0;
}
.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.btn-muted {
  background: #0b1220 !important;
  color: #94a3b8 !important;
}
