:root {
  --ink: #1d2433;
  --muted: #6b7385;
  --card: #ffffff;
  --line: #e4e7ee;
  --brand: #2f6fed;
  --brand-ink: #ffffff;
  --accent: #ffd43b;
  --radius: 18px;
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #bfe3f5; overscroll-behavior: none; }
#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

.bar {
  position: fixed; top: calc(env(safe-area-inset-top) + 12px); left: 12px; right: 12px;
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  pointer-events: none;
}
.brand, .count {
  background: rgba(255,255,255,.92); backdrop-filter: blur(8px);
  border-radius: 999px; padding: 8px 14px; box-shadow: 0 2px 10px rgba(0,0,0,.08);
  font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.brand b { color: var(--brand); letter-spacing: .5px; margin-right: 8px; }
.count #count { font-weight: 700; color: var(--brand); }

.offline {
  position: fixed; top: calc(env(safe-area-inset-top) + 60px); left: 50%; transform: translateX(-50%);
  background: #fff3bf; color: #7a5a00; padding: 6px 12px; border-radius: 10px; font-size: 13px;
}

.loading {
  position: fixed; inset: 0; display: grid; place-content: center; justify-items: center;
  background: #bfe3f5; color: var(--ink); font-size: 15px;
}
.spinner {
  width: 36px; height: 36px; border: 4px solid rgba(47,111,237,.2); border-top-color: var(--brand);
  border-radius: 6px; animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; margin: 0 auto; max-width: 520px;
  background: var(--card); border-radius: var(--radius) var(--radius) 0 0;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  box-shadow: 0 -6px 24px rgba(0,0,0,.15);
  transform: translateY(110%); transition: transform .38s cubic-bezier(.2,.8,.2,1);
}
.sheet.open { transform: translateY(0); }
/* 접힌 상태: 위쪽(손잡이·제목·열섬 지수)만 보인다 */
.sheet.open.peek { transform: translateY(calc(100% - var(--peek, 120px))); overflow: hidden; }
.sheet.dragging { transition: none; }
.sheet-top { cursor: pointer; touch-action: none; user-select: none; -webkit-user-select: none; }
.grabber { width: 42px; height: 5px; border-radius: 3px; background: #ced4da; margin: -6px auto 10px; }
.peek-hint { display: none; text-align: center; font-size: 13px; font-weight: 700; color: var(--brand); margin: -2px 0 6px; }
.sheet.peek .peek-hint { display: block; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.sheet h2 { font-size: 17px; margin: 0; }
.chip { background: #eef3ff; color: var(--brand); font-weight: 600; font-size: 13px; padding: 4px 10px; border-radius: 999px; white-space: nowrap; }

.types { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 10px; }
.type {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  border: 2px solid var(--line); background: #fafbfc; border-radius: 12px;
  padding: 10px 4px; font-size: 13px; color: var(--ink); cursor: pointer;
}
.type .ic { font-size: 22px; line-height: 1; }
.type.on { border-color: var(--brand); background: #eef3ff; font-weight: 700; }

textarea {
  width: 100%; border: 1.5px solid var(--line); border-radius: 12px; padding: 10px 12px;
  font: inherit; font-size: 16px; resize: none; outline: none;
}
textarea:focus { border-color: var(--brand); }

.actions { display: flex; gap: 8px; margin-top: 10px; align-items: center; }
.actions .primary { flex: 1; }
button { font: inherit; }
.primary, .ghost { border: 0; border-radius: 12px; padding: 12px 16px; font-size: 15px; font-weight: 700; cursor: pointer; }
.primary { background: var(--brand); color: var(--brand-ink); }
.primary:disabled { background: #c9d3e6; cursor: default; }
.ghost { background: #f1f3f6; color: var(--ink); }
.muted { color: var(--muted); margin-right: auto; }
.d-text { font-size: 16px; line-height: 1.5; margin: 0 0 4px; }

.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 24px);
  transform: translate(-50%, 20px); opacity: 0; transition: .25s;
  background: rgba(29,36,51,.92); color: #fff; padding: 10px 16px; border-radius: 12px;
  font-size: 14px; max-width: calc(100% - 32px); text-align: center; pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.sheet.open ~ .toast { bottom: calc(env(safe-area-inset-bottom) + 300px); }

.bar .right { display: flex; gap: 8px; align-items: center; }
.layer-btn {
  pointer-events: auto; border: 0; cursor: pointer; font: inherit; font-size: 14px; font-weight: 600;
  background: rgba(255,255,255,.92); color: var(--ink); border-radius: 999px; padding: 8px 14px;
  box-shadow: 0 2px 10px rgba(0,0,0,.08); white-space: nowrap;
}
.layer-btn[aria-pressed="true"] { background: #e03131; color: #fff; }
.legend {
  position: fixed; left: 12px; top: calc(env(safe-area-inset-top) + 64px); width: 230px;
  background: rgba(255,255,255,.95); border-radius: 14px; padding: 12px 14px; font-size: 13px;
  box-shadow: 0 2px 12px rgba(0,0,0,.12);
}
.legend-title { font-weight: 700; margin-bottom: 8px; }
.legend-title small { font-weight: 400; color: var(--muted); }
.legend-bar { height: 10px; border-radius: 5px; background: linear-gradient(90deg, #2f9e44 0%, #94d82d 35%, #fcd83c 55%, #fca01e 70%, #f05028 85%, #be192d 100%); }
.legend-scale { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; margin-top: 4px; }
.legend-note { margin: 8px 0 0; color: var(--muted); line-height: 1.5; }
.legend-note b { color: var(--ink); }
.heat-info { font-size: 13px; margin: -4px 0 10px; color: var(--muted); }
.heat-info:empty { display: none; }
.heat-info b { color: var(--ink); }
.heat-badge { display: inline-block; color: #fff; font-weight: 700; border-radius: 6px; padding: 1px 7px; margin-left: 4px; }
.env-now {
  position: fixed; top: calc(env(safe-area-inset-top) + 60px); right: 12px;
  background: rgba(255,255,255,.92); border-radius: 12px; padding: 6px 12px; font-size: 13px;
  box-shadow: 0 2px 10px rgba(0,0,0,.08); pointer-events: none; text-align: right; line-height: 1.5;
}
.env-now b { font-size: 15px; }
.env-now small { color: var(--muted); }
.env-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin: 0 3px 1px 6px; vertical-align: middle; }
@media (max-width: 480px) {
  .env-now { top: auto; bottom: calc(env(safe-area-inset-bottom) + 16px); right: 12px; }
  .sheet.open ~ .env-now, body.sheet-open .env-now { display: none; }
  .brand span { display: none; }
  .legend { top: calc(env(safe-area-inset-top) + 60px); left: 12px; right: 12px; width: auto; padding: 8px 12px; }
  .legend-note { display: none; }
}

/* ---- 도구 막대 */
.tools {
  position: fixed; right: 12px; top: 50%; transform: translateY(-50%);
  display: flex; flex-direction: column; gap: 6px; z-index: 5;
}
.tool {
  width: 62px; border: 0; cursor: pointer; font: inherit; color: var(--ink);
  background: rgba(255,255,255,.94); border-radius: 14px; padding: 7px 2px 6px;
  box-shadow: 0 2px 10px rgba(0,0,0,.12); display: flex; flex-direction: column; align-items: center; gap: 1px;
}
.tool span { font-size: 20px; line-height: 1.1; }
.tool small { font-size: 10.5px; font-weight: 600; white-space: nowrap; }
.tool[aria-pressed="true"] { background: var(--brand); color: #fff; }
#tool-heat[aria-pressed="true"] { background: #e03131; }
#tool-sim[aria-pressed="true"] { background: #2f9e44; }
#tool-labels[aria-pressed="true"] { background: rgba(255,255,255,.94); color: var(--ink); }
#tool-labels[aria-pressed="false"] { opacity: .55; }
body.sheet-open .tools { display: none; }
.env-now { right: 86px; }

/* ---- 리포트 패널 */
.report {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(360px, 100%); z-index: 20;
  background: #fff; box-shadow: -6px 0 24px rgba(0,0,0,.15); overflow-y: auto;
  padding: calc(env(safe-area-inset-top) + 14px) 18px calc(env(safe-area-inset-bottom) + 18px);
  transform: translateX(105%); transition: transform .25s ease;
}
.report.open { transform: none; }
.report { overflow-x: hidden; }
.report-head { display: flex; justify-content: space-between; align-items: center; }
.report h2 { font-size: 18px; margin: 0; }
.report h3 { font-size: 14px; margin: 18px 0 8px; }
.report h3 small { font-weight: 400; color: var(--muted); }
.report .x { border: 0; background: #f1f3f6; border-radius: 10px; width: 34px; height: 34px; font-size: 16px; cursor: pointer; }
.r-env { font-size: 14px; line-height: 1.7; }
.r-list { margin: 0; padding: 0; list-style: none; }
.r-list li {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px; cursor: pointer;
  background: #fff5f5; margin-bottom: 6px; font-size: 14px;
}
.r-list li:hover { background: #ffe3e3; }
.r-list .num { font-weight: 800; color: #e03131; width: 18px; }
.r-list .score { margin-left: auto; font-weight: 700; color: #fff; border-radius: 6px; padding: 1px 8px; }
.hint { color: var(--muted); font-size: 12px; margin: 4px 0 0; }
.r-sim { font-size: 14px; line-height: 1.6; }
.r-sim .big { font-size: 26px; font-weight: 800; color: #2f9e44; }
.r-types { display: flex; flex-direction: column; gap: 5px; }
.r-type {
  display: grid; grid-template-columns: 22px 92px 1fr 30px; align-items: center; gap: 8px;
  border: 0; background: none; padding: 3px 0; font: inherit; font-size: 13px; cursor: pointer; text-align: left;
}
.r-type .rbar { display: block; height: 10px; border-radius: 5px; background: #e9ecef; overflow: hidden; }
.r-type .rbar i { display: block; height: 100%; border-radius: 5px; }
.r-type.off { opacity: .35; }
.r-type b { text-align: right; }

/* ---- 제안 시트 */
.types-title { font-size: 12.5px; font-weight: 700; color: var(--muted); margin: 2px 0 6px; }
.types.small { grid-template-columns: repeat(4, 1fr); }
.types.small .type { padding: 7px 2px; font-size: 12px; }
.types.small .type .ic { font-size: 18px; }
.type small { font-size: 10.5px; color: var(--muted); line-height: 1.2; text-align: center; }
.sheet { max-height: 88vh; overflow-y: auto; }
.effect-info { font-size: 13.5px; background: #ebfbee; color: #2b8a3e; border-radius: 10px; padding: 8px 12px; margin-bottom: 10px; }
.effect-info:empty { display: none; }
.effect-info.warn { background: #fff4e6; color: #d9480f; }
.effect-info b { font-size: 16px; }

/* ---- 첫 방문 안내 */
.intro { position: fixed; inset: 0; z-index: 30; background: rgba(15,23,42,.45); display: grid; place-items: center; padding: 16px; }
.intro[hidden] { display: none; }
.intro-card { background: #fff; border-radius: 18px; padding: 22px 20px; max-width: 420px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.intro-card h2 { margin: 0 0 12px; font-size: 19px; }
.intro-card ol { margin: 0 0 16px; padding-left: 20px; line-height: 1.6; font-size: 14.5px; }
.intro-card li { margin-bottom: 8px; }
.intro-card .primary { width: 100%; }
.intro-card .method { margin: 0 0 14px; font-size: 13.5px; line-height: 1.55; background: #f1f5f9; border-radius: 10px; padding: 8px 12px; }
.intro-card .method summary { cursor: pointer; font-weight: 600; }
.intro-card .method p { margin: 6px 0; }
.intro-card .muted-note { color: #64748b; font-size: 12.5px; }

@media (max-width: 480px) {
  .tools { top: auto; left: 8px; right: 8px; bottom: calc(env(safe-area-inset-bottom) + 8px); transform: none;
           flex-direction: row; gap: 4px; }
  .tool { flex: 1; width: auto; padding: 5px 0 4px; border-radius: 12px; }
  .tool span { font-size: 17px; }
  .tool small { font-size: 9.5px; }
  .env-now { right: 8px; bottom: calc(env(safe-area-inset-bottom) + 66px); }
  .types { grid-template-columns: repeat(3, 1fr); }
}

/* ---- 실시간 열섬 지수 읽기 (마우스 위치 / 폰은 화면 가운데) */
.probe {
  position: fixed; z-index: 6; pointer-events: none; transform: translate(14px, 14px);
  background: rgba(255,255,255,.96); border-radius: 12px; padding: 7px 11px; font-size: 13px; line-height: 1.45;
  box-shadow: 0 3px 14px rgba(0,0,0,.18); border-left: 6px solid #ccc; white-space: nowrap;
}
.probe .v { font-size: 22px; font-weight: 800; vertical-align: -2px; margin-right: 4px; }
.probe .lv { font-weight: 700; }
.probe small { color: var(--muted); }
.crosshair {
  position: fixed; left: 50%; top: 50%; width: 26px; height: 26px; margin: -13px 0 0 -13px; z-index: 6; pointer-events: none;
  border: 2.5px solid #fff; border-radius: 50%; box-shadow: 0 0 0 1.5px rgba(0,0,0,.45), inset 0 0 0 1.5px rgba(0,0,0,.45);
}
.crosshair::after { content: ""; position: absolute; left: 50%; top: 50%; width: 4px; height: 4px; margin: -2px 0 0 -2px; background: #fff; border-radius: 50%; box-shadow: 0 0 0 1px rgba(0,0,0,.5); }
.probe.center { left: 50% !important; top: 50% !important; transform: translate(-50%, 22px); text-align: center; }
body.sheet-open .probe, body.sheet-open .crosshair { display: none; }

/* 처리 상태 배지 + 공무원 답변 */
.badge { display: inline-block; padding: 1px 9px; border-radius: 10px; font-size: 12px; font-weight: 700; margin-left: 6px; }
.badge.received { background: #fff3bf; color: #8a6d00; } .badge.working { background: #d0ebff; color: #1864ab; } .badge.done { background: #d3f9d8; color: #2b8a3e; }
.d-reply { margin: 6px 0 4px; padding: 8px 10px; border-radius: 10px; background: #e7f5ff; color: #1864ab; font-size: 14px; line-height: 1.45; }

@media (max-width: 480px) {
  /* 폰: 화면 가운데를 덜 가리게 조금 작게 */
  .probe.center { font-size: 12px; padding: 5px 9px; transform: translate(-50%, 20px); }
  .probe.center .v { font-size: 18px; }
}

/* ---- 지자체 대시보드 링크 (리포트 패널 아래, 도움말) */
.admin-link {
  display: grid; grid-template-columns: 28px 1fr 18px; align-items: center; gap: 10px;
  margin-top: 14px; padding: 12px 14px; border-radius: 12px; text-decoration: none; color: var(--ink);
  background: #eef3ff; border: 1.5px solid #d0dcff;
}
.admin-link:hover { background: #e2eaff; }
.admin-link span:first-child { font-size: 22px; }
.admin-link b { display: block; font-size: 14.5px; color: var(--brand); }
.admin-link small { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }
.admin-link span:last-child { color: var(--brand); font-weight: 700; }
.intro-admin { display: block; text-align: center; margin-top: 12px; font-size: 13.5px; color: var(--brand); text-decoration: none; font-weight: 600; }

/* 여러 칸에 놓기 (한 곳 / 줄 / 네모) */
.shape-box { margin: -2px 0 10px; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; background: #f1f3f5; border-radius: 12px; padding: 4px; }
.seg button { border: 0; background: transparent; border-radius: 9px; padding: 8px 2px; font-size: 12.5px; color: var(--ink); cursor: pointer; white-space: nowrap; }
.seg button.on { background: #fff; color: var(--brand); font-weight: 700; box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.shape-hint { font-size: 12.5px; color: #e8590c; background: #fff4e6; border-radius: 10px; padding: 7px 10px; margin-top: 6px; }

/* ---- 거리 QR 위치 모드 */
.spot-card {
  position: fixed; z-index: 8; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom) + 16px);
  width: min(440px, calc(100vw - 24px)); background: var(--card); border-radius: 16px; padding: 14px 14px 12px;
  box-shadow: 0 8px 28px rgba(0,0,0,.22); display: grid; gap: 8px;
}
.spot-card[hidden] { display: none; }
.spot-name { font-size: 16px; }
.spot-heat { font-size: 13.5px; color: var(--muted); line-height: 1.5; }
.spot-heat b { color: var(--ink); }
.spot-card .primary { font-size: 16px; padding: 14px; }
.spot-card .ghost { padding: 9px; font-size: 13.5px; }
body.spot-open .probe, body.spot-open .crosshair, body.sheet-open .spot-card { display: none; }
.here-pin {
  position: fixed; z-index: 6; pointer-events: none; transform: translate(-50%, -100%);
  font-size: 28px; line-height: 1; text-align: center; filter: drop-shadow(0 2px 3px rgba(0,0,0,.35));
}
.here-pin span { display: block; margin-top: 2px; font-size: 11.5px; font-weight: 700; background: #e03131; color: #fff; padding: 2px 7px; border-radius: 99px; }
.here-pin[hidden] { display: none; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 2px 0 8px; }
.chips:empty { display: none; }
.chip-q { border: 1px solid #d8dee9; background: #fff; border-radius: 99px; padding: 6px 11px; font: inherit; font-size: 13px; cursor: pointer; color: var(--ink); }
.chip-q.on { border-color: var(--brand); background: #eef4ff; }
@media (max-width: 480px) {
  .spot-card { bottom: calc(env(safe-area-inset-bottom) + 66px); }
  body.spot-open .env-now { display: none; }
}

.tool[hidden] { display: none; }
