:root {
  --bg: #f3f4f4; --fg: #1c2024; --muted: #636b73; --line: #d5d8db;
  --panel: #ffffff; --tile-flat: #8b9299; --accent: #2f5d8a;
  --up: #1f8a55; --down: #c43a3a;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17191b; --fg: #e6e8ea; --muted: #9aa2a9; --line: #33383c;
    --panel: #212427; --tile-flat: #4a5056; --accent: #86b1da;
    --up: #4cc38a; --down: #ec6a6a;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; padding: 10px max(12px, env(safe-area-inset-left, 0px));
  background: var(--bg); color: var(--fg);
  font: 14px/1.4 -apple-system, "Apple SD Gothic Neo", "Noto Sans KR", system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
}
body.center { display: grid; place-items: center; min-height: 100vh; }
button { font: inherit; color: inherit; cursor: pointer; }
header { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
header form { margin: 0; }
nav { display: flex; flex-wrap: wrap; gap: 4px; }
nav button { padding: 6px 12px; border: 1px solid var(--line); background: var(--panel); border-radius: 6px; }
nav button.on { background: var(--accent); border-color: var(--accent); color: var(--panel); }
button.plain { border: 0; background: none; color: var(--muted); padding: 6px; }
#summary { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 10px 0; }
#summary b { font-size: 18px; }
.up { color: var(--up); } .down { color: var(--down); } .muted { color: var(--muted); }
.warn { color: var(--down); font-weight: 600; }
#periods { margin-bottom: 8px; }
#map { position: relative; width: 100%; height: 68vh; min-height: 340px; overflow: hidden; }
.tile {
  position: absolute; padding: 6px; overflow: hidden; border: 1px solid var(--bg);
  display: flex; flex-direction: column; gap: 1px; text-align: left; background: var(--tile-flat);
  color: #fff; line-height: 1.2;
}
.tile:focus-visible { outline: 2px solid var(--fg); outline-offset: -2px; }
.tile .nm { font-weight: 600; }
.tile .tag { font-size: 11px; opacity: .85; }
.sector h2 { font-size: 14px; margin: 14px 0 6px; color: var(--muted); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 4px; }
.grid .tile { position: relative; min-height: 96px; border: 0; }
#report article { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 12px; margin-bottom: 8px; }
#report h2 { font-size: 15px; margin: 0 0 6px; }
#report pre { white-space: pre-wrap; font: inherit; margin: 0; }
#detail {
  position: fixed; right: 0; top: 0; bottom: 0; width: min(380px, 100%); padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; z-index: 5;
}
#detail h2 { margin: 0 0 2px; font-size: 18px; }
#detail h3 { margin: 16px 0 6px; font-size: 13px; color: var(--muted); }
#detail table { width: 100%; border-collapse: collapse; }
#detail td { padding: 3px 0; vertical-align: top; }
#detail td:last-child { text-align: right; white-space: nowrap; padding-left: 8px; }
#detail ul { margin: 0; padding-left: 18px; }
#detail li { margin-bottom: 6px; }
#detail a { color: var(--accent); }
#detail .close { float: right; }
footer { color: var(--muted); font-size: 12px; margin-top: 10px; }
.box { display: grid; gap: 10px; width: min(340px, 90vw); }
.box h1 { font-size: 20px; margin: 0; }
.box input, .box button { font: inherit; padding: 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); color: var(--fg); }
.box .err { color: var(--down); margin: 0; min-height: 1.4em; }
