:root {
  --bg: #eef7ff;
  --bg2: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --card: rgba(255, 255, 255, 0.88);
  --soft: rgba(248, 250, 252, 0.94);
  --line: rgba(148, 163, 184, 0.34);
  --brand: #0f766e;
  --brand-dark: #134e4a;
  --shadow: rgba(15, 23, 42, 0.1);
  --header1: #0f172a;
  --header2: #2f6b42;
  --button-text: #ffffff;
}

html[data-theme="dark"] {
  --bg: #08111f;
  --bg2: #101827;
  --ink: #e5eefb;
  --muted: #a8b4c7;
  --card: rgba(15, 23, 42, 0.86);
  --soft: rgba(30, 41, 59, 0.86);
  --line: rgba(148, 163, 184, 0.22);
  --brand: #5eead4;
  --brand-dark: #99f6e4;
  --shadow: rgba(0, 0, 0, 0.38);
  --header1: #020617;
  --header2: #064e3b;
  --button-text: #ffffff;
}

@media (prefers-color-scheme: dark) {
  html[data-theme="auto"] {
    --bg: #08111f;
    --bg2: #101827;
    --ink: #e5eefb;
    --muted: #a8b4c7;
    --card: rgba(15, 23, 42, 0.86);
    --soft: rgba(30, 41, 59, 0.86);
    --line: rgba(148, 163, 184, 0.22);
    --brand: #5eead4;
    --brand-dark: #99f6e4;
    --shadow: rgba(0, 0, 0, 0.38);
    --header1: #020617;
    --header2: #064e3b;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(56, 189, 248, 0.22), transparent 36%),
    linear-gradient(145deg, var(--bg), var(--bg2));
  padding: env(safe-area-inset-top) 14px env(safe-area-inset-bottom);
}
button, select { font: inherit; }
.app-shell { width: min(980px, 100%); margin: 0 auto; padding: 18px 0 10px; }

.app-header {
  display: flex; justify-content: space-between; gap: 14px; align-items: flex-start;
  padding: 22px 18px; border-radius: 26px; color: white;
  background: linear-gradient(135deg, var(--header1), var(--header2));
  box-shadow: 0 18px 50px var(--shadow);
}
.eyebrow { margin: 0 0 5px; font-size: 12px; font-weight: 900; letter-spacing: 0.1em; text-transform: uppercase; opacity: 0.78; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: clamp(24px, 4.5vw, 38px); line-height: 1.12; letter-spacing: -0.05em; }
.subtitle { margin: 0; max-width: 680px; font-size: 14px; line-height: 1.6; color: rgba(255, 255, 255, 0.84); }
.header-actions { display: flex; align-items: center; gap: 8px; }
.theme-toggle {
  width: 38px; height: 38px; border: 1px solid rgba(255,255,255,.22); border-radius: 999px;
  color: white; background: rgba(255,255,255,.12); cursor: pointer;
}
.status-pill {
  flex: 0 0 auto; padding: 7px 11px; border-radius: 999px; font-size: 12px; font-weight: 900;
  color: #dcfce7; background: rgba(22,163,74,.16); border: 1px solid rgba(187,247,208,.25); white-space: nowrap;
}
.status-pill.bad { color: #fee2e2; background: rgba(239,68,68,.18); }

.main-grid { display: grid; grid-template-columns: .9fr 1.1fr; gap: 14px; margin-top: 14px; }
.panel, .fog-risk-card {
  padding: 16px; border-radius: 22px; background: var(--card); border: 1px solid var(--line);
  box-shadow: 0 12px 34px var(--shadow); backdrop-filter: blur(18px);
}
.panel.wide { grid-column: 1 / -1; }
.section-title, .fog-risk-head, .donate-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.section-title h2, .donate-head h2 { margin: 0; font-size: 18px; letter-spacing: -0.03em; }
.section-title span {
  padding: 5px 10px; border-radius: 999px; font-size: 12px; color: #064e3b; background: #ccfbf1; font-weight: 900; white-space: nowrap;
}
html[data-theme="dark"] .section-title span { color: #99f6e4; background: rgba(20,184,166,.16); }
.field-label { display: block; margin: 18px 0 7px; font-size: 13px; font-weight: 900; color: var(--ink); }
.select-box {
  width: 100%; min-height: 46px; padding: 0 13px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--soft); color: var(--ink); outline: none;
}
.help-text { margin: 10px 0 0; color: var(--muted); font-size: 13px; line-height: 1.55; }

.action-buttons { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; width: 100%; margin: 14px 0 0; }
.action-buttons button {
  width: 100%; min-width: 0; padding: 10px 4px; border: 0; border-radius: 13px;
  background: #0f172a; color: var(--button-text); font-size: 13px; font-weight: 900; line-height: 1.1;
  white-space: nowrap; cursor: pointer; box-shadow: 0 10px 22px var(--shadow);
}
.action-buttons button:nth-child(2) { background: #0f766e; }
.action-buttons button:nth-child(3) { background: #7c3aed; }
.action-buttons button:nth-child(4) { background: #ea580c; }

.fog-risk-head span { font-size: 14px; color: var(--ink); font-weight: 900; }
.fog-risk-head strong { padding: 5px 11px; border-radius: 999px; background: var(--soft); color: var(--ink); font-size: 13px; }
.fog-risk-head strong.level-low { background: #dcfce7; color: #166534; }
.fog-risk-head strong.level-mid { background: #fef9c3; color: #854d0e; }
.fog-risk-head strong.level-high { background: #ffedd5; color: #9a3412; }
.fog-risk-head strong.level-very-high { background: #fee2e2; color: #991b1b; }

.fog-risk-score { margin: 10px 0 2px; font-size: clamp(50px, 11vw, 76px); font-weight: 950; letter-spacing: -0.07em; color: var(--ink); }
.fog-risk-score small { margin-left: 4px; font-size: 24px; color: var(--muted); letter-spacing: 0; }
#fogRiskMessage { margin: 0; min-height: 44px; font-size: 14px; line-height: 1.55; color: var(--muted); }
.fog-risk-detail { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 13px; }
.fog-risk-detail span { padding: 9px 7px; border-radius: 13px; background: var(--soft); font-size: 12px; text-align: center; color: var(--muted); }
.fog-risk-detail b { color: var(--ink); }
.risk-bar { height: 10px; margin-top: 14px; border-radius: 999px; background: var(--soft); overflow: hidden; }
#riskBarFill { width: 0%; height: 100%; border-radius: inherit; background: linear-gradient(90deg,#22c55e,#facc15,#f97316,#ef4444); transition: width .45s ease; }
.last-update { margin-top: 9px; color: var(--muted); font-size: 12px; text-align: right; }

.debug-box { display: none; margin-top: 12px; padding: 10px; border-radius: 14px; background: var(--soft); color: var(--muted); font-size: 12px; }
.debug-box.show { display: block; }
.debug-box pre { white-space: pre-wrap; word-break: break-word; margin: 8px 0 0; }

.guide-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.guide-grid article { padding: 13px; border-radius: 17px; background: var(--soft); border: 1px solid var(--line); }
.guide-grid b { display: block; margin-bottom: 6px; font-size: 15px; }
.guide-grid p { margin: 0; font-size: 13px; color: var(--muted); line-height: 1.55; }

.app-footer { margin: 18px auto 12px; padding: 16px 10px; text-align: center; font-size: 13px; color: var(--muted); }
.donate-button {
  display: inline-flex; align-items: center; justify-content: center; margin-bottom: 8px; padding: 9px 16px;
  border-radius: 999px; border: 1px solid #fde68a; background: #fef3c7; color: #0f172a; font-weight: 900; cursor: pointer;
}
.app-footer span { display: block; }

.donate-modal { position: fixed; inset: 0; display: none; z-index: 1000; }
.donate-modal.open { display: block; }
.donate-backdrop { position: absolute; inset: 0; background: rgba(15,23,42,.48); backdrop-filter: blur(4px); }
.donate-sheet {
  position: absolute; left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); width: min(430px, calc(100% - 28px));
  height: min(620px, 82vh); transform: translateX(-50%); padding: 14px; border-radius: 24px;
  background: var(--bg2); color: var(--ink); box-shadow: 0 28px 70px rgba(0,0,0,.34); overflow: hidden;
}
.icon-button { width: 38px; height: 38px; border-radius: 999px; border: 0; background: var(--soft); font-size: 24px; color: var(--ink); cursor: pointer; }
.donate-sheet iframe { width: 100%; height: calc(100% - 64px); margin-top: 12px; border: 1px solid var(--line); border-radius: 18px; background: white; }

@media (max-width: 740px) {
  body { padding-left: 10px; padding-right: 10px; }
  .app-header { flex-direction: column; border-radius: 22px; }
  .header-actions { width: 100%; justify-content: space-between; }
  .main-grid { grid-template-columns: 1fr; }
  .guide-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 430px) {
  .action-buttons { gap: 5px; }
  .action-buttons button { padding: 9px 2px; border-radius: 11px; font-size: 11px; letter-spacing: -0.04em; }
  .fog-risk-detail { grid-template-columns: repeat(2, 1fr); }
  .guide-grid { grid-template-columns: 1fr; }
  .donate-sheet { height: 78vh; }
}
