:root {
  --bg: #f6f4ef;
  --sidebar: #ebe6dc;
  --ink: #1a1a1a;
  --muted: #5c5c5c;
  --line: #cfc8bb;
  --accent: #2f5d50;
  --warn: #8a4b1f;
  --card: #fffcf7;
  --fill: rgba(26, 26, 26, 0.05);
  --radius: 12px;
  --radius-lg: 16px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --shadow: 0 1px 2px rgba(26, 26, 26, 0.05), 0 8px 24px rgba(26, 26, 26, 0.06);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
    "Apple SD Gothic Neo", "Noto Sans KR", "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
button, input, select { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
.app {
  display: grid;
  grid-template-columns: 360px 1fr;
  height: 100vh;
  height: 100dvh;
}
.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--sidebar);
  border-right: 0.5px solid var(--line);
  overflow: hidden;
  padding: 14px 14px 10px;
}
.sidebar-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 8px;
}
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  background: var(--bg);
}
.map-stage {
  flex: 1;
  position: relative;
  min-height: 0;
}
.map-pair {
  position: absolute;
  inset: 0;
}
.map-stage.is-split .map-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
  background: var(--line);
}
.map-stage.is-split .map-chrome {
  width: min(360px, calc(50% - 20px));
}
.map-chrome {
  position: absolute;
  top: 12px;
  left: 12px;
  width: min(440px, calc(100% - 24px));
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.main-header {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.2rem;
  padding: 14px 16px 13px;
  border: 0.5px solid rgba(207, 200, 187, 0.7);
  border-radius: var(--radius-lg);
  background: rgba(250, 248, 243, 0.78);
  -webkit-backdrop-filter: saturate(180%) blur(22px);
  backdrop-filter: saturate(180%) blur(22px);
  box-shadow: var(--shadow);
  pointer-events: auto;
}
.main-header h1 {
  margin: 0;
  font-size: 1.22rem;
  font-weight: 700;
  letter-spacing: -0.035em;
  line-height: 1.15;
}
.byline {
  margin: 0;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 400;
  line-height: 1.4;
  letter-spacing: -0.01em;
}
.byline em { font-style: italic; font-weight: 400; margin: 0 0.12em; }
@keyframes spin { to { transform: rotate(360deg); } }
.spin {
  display: inline-block;
  width: 0.85rem;
  height: 0.85rem;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex: 0 0 auto;
}
.map-wrap {
  position: absolute;
  inset: 0;
}
.map-stage.is-split .map-wrap {
  position: relative;
  inset: auto;
  min-width: 0;
  min-height: 0;
  height: 100%;
}
.map-caption {
  position: absolute;
  left: 10px;
  bottom: 12px;
  z-index: 4;
  max-width: calc(100% - 64px);
  padding: 6px 10px;
  border-radius: 10px;
  background: rgba(250, 248, 243, 0.88);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  font-size: 0.75rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  pointer-events: none;
  box-shadow: var(--shadow);
}
#mapB .maplibregl-ctrl-bottom-right { display: none; }
.map-wrap.is-loading::before {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(47, 93, 80, 0.14);
  z-index: 2;
  pointer-events: none;
}
.map-wrap.is-loading::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 36px;
  height: 36px;
  margin: -18px 0 0 -18px;
  border: 3px solid rgba(47, 93, 80, 0.22);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
  z-index: 3;
  pointer-events: none;
}
.map-wrap .maplibregl-map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.map-popup { font-size: 0.88rem; letter-spacing: -0.01em; }
.maplibregl-popup-content {
  border-radius: 14px !important;
  padding: 12px 14px !important;
  background: rgba(255, 252, 247, 0.94) !important;
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow) !important;
  color: var(--ink);
  font: inherit;
}
.maplibregl-popup-tip {
  border-top-color: rgba(255, 252, 247, 0.94) !important;
}
.maplibregl-ctrl-group {
  border: 0.5px solid rgba(207, 200, 187, 0.8) !important;
  border-radius: 14px !important;
  overflow: hidden;
  box-shadow: var(--shadow);
  background: rgba(255, 252, 247, 0.9) !important;
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
}
.maplibregl-ctrl-group button {
  width: 40px !important;
  height: 40px !important;
}
.maplibregl-ctrl-bottom-right {
  right: 12px !important;
  bottom: 12px !important;
}
.map-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.95rem;
  font-size: 0.82rem;
  letter-spacing: -0.015em;
  min-height: 2.2rem;
  border-radius: 14px;
  line-height: 1.35;
  box-shadow: var(--shadow);
  pointer-events: auto;
  transition: background 0.22s var(--ease), color 0.22s var(--ease);
}
.map-meta.is-wait { background: rgba(243, 238, 228, 0.92); color: var(--muted); }
.map-meta.is-loading { background: var(--accent); color: #fff; }
.map-meta.is-ok { background: rgba(231, 239, 233, 0.94); color: var(--ink); }
.map-meta.is-error { background: var(--warn); color: #fff; }
.map-meta.is-error a { color: #fff; }
.map-meta b, .map-meta code { font-weight: 650; }
.map-meta code {
  font-family: inherit;
  font-size: 0.92em;
}
.msi-panel {
  flex: 0 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  z-index: 6;
  border-top: 0.5px solid var(--line);
  background: rgba(255, 252, 247, 0.94);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  backdrop-filter: saturate(180%) blur(18px);
  padding: 0 16px 12px;
}
.msi-panel.has-result:not(.is-collapsed) {
  min-height: 132px;
}
.msi-panel.is-collapsed {
  min-height: 0;
  padding-bottom: 6px;
}
.result-toggle {
  display: flex;
  flex-direction: column;
  width: calc(100% + 32px);
  margin: 0 -16px 2px;
  padding: 0 16px 6px;
  border: none;
  background: transparent;
  color: inherit;
  cursor: pointer;
  text-align: left;
}
.result-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.result-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.result-toggle-label {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}
.result-chevron {
  width: 7px;
  height: 7px;
  margin-right: 4px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg);
  transition: transform 0.2s var(--ease);
}
.msi-panel.is-collapsed .result-chevron {
  transform: rotate(-45deg);
}
#resultBody {
  min-height: 0;
  overflow: auto;
  max-height: min(42vh, 420px);
  -webkit-overflow-scrolling: touch;
}
.msi-panel.is-collapsed #resultBody {
  display: none;
}
.sheet-handle {
  width: 36px;
  height: 5px;
  border-radius: 99px;
  background: var(--line);
  margin: 6px auto 10px;
}
.msi-panel h2 {
  margin: 0 2px 0.35rem;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}
#msiOut.hint { margin: 0 2px; }
.msi-panel pre {
  font-size: 0.72rem;
  background: var(--bg);
  border-radius: 12px;
  padding: 10px 12px;
  overflow: auto;
  margin: 0.6rem 0 0;
}
.msi-metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0;
  margin-top: 0.55rem;
  background: var(--bg);
  border-radius: var(--radius);
  overflow: hidden;
}
.metric {
  background: transparent;
  padding: 0.7rem 0.8rem;
  border-right: 0.5px solid var(--line);
}
.metric:last-child { border-right: none; }
.metric .label { font-size: 0.7rem; color: var(--muted); font-weight: 600; letter-spacing: -0.01em; }
.metric .value { font-size: 1.18rem; font-weight: 700; letter-spacing: -0.03em; margin-top: 0.1rem; }
.pane-kicker {
  margin: 2px 6px 0;
  font-size: 0.7rem;
  font-weight: 650;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.pane-title {
  margin: 2px 6px 10px;
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.038em;
  line-height: 1.15;
}
.field {
  display: block;
  font-size: 0.9rem;
  margin: 0;
  padding: 10px 14px;
}
.field + .field { border-top: 0.5px solid var(--line); }
.ios-group .field.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
}
.sidebar select, .sidebar input[type="number"], .sidebar input[type="text"] {
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.55rem 0.65rem;
  border: none;
  border-radius: 10px;
  background: var(--fill);
  font: inherit;
  color: var(--ink);
  outline: none;
}
.field.row input {
  width: 9.2rem;
  margin: 0;
  text-align: right;
  background: transparent;
  color: var(--muted);
  padding: 0.2rem 0;
  -moz-appearance: textfield;
}
.field.row input::-webkit-outer-spin-button,
.field.row input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.sidebar select:focus, .sidebar input:focus {
  box-shadow: 0 0 0 3px rgba(47, 93, 80, 0.18);
}
#mapCol, #msiFactor, #msiRate { font-size: 0.82rem; }
.factor-box {
  max-height: 220px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 2px 0 8px;
}
.opt-kicker {
  font-size: 0.68rem;
  font-weight: 650;
  letter-spacing: -0.01em;
  color: var(--muted);
  padding: 8px 14px 2px;
}
.msi-pairs { margin-top: 10px; overflow-x: auto; }
.msi-pairs table { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
.msi-pairs th, .msi-pairs td { text-align: left; padding: 5px 6px; border-bottom: 0.5px solid var(--line); }
.msi-a-box {
  background: var(--card);
  border-radius: var(--radius);
  padding: 10px 12px 8px;
  margin: 8px 0 10px;
}
.msi-a-box.is-compact { padding: 8px 10px 6px; }
.msi-a-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.78rem;
  font-weight: 650;
  margin-bottom: 6px;
}
.msi-a-val { font-variant-numeric: tabular-nums; color: var(--accent); font-size: 0.95rem; }
.msi-a-range { width: 100%; accent-color: var(--accent); }
.msi-a-formula { margin: 6px 0 0; font-size: 0.72rem; color: var(--muted); }
.msi-a-chart { width: 100%; height: 78px; display: block; margin-top: 6px; }
.msi-a-ends { margin: 2px 0 0; }
.msi-nxn { overflow: auto; margin-top: 10px; }
.msi-nxn table { border-collapse: collapse; font-size: 0.68rem; font-variant-numeric: tabular-nums; margin: 0 auto; }
.msi-nxn td {
  width: 2.4rem;
  height: 2.4rem;
  text-align: center;
  border: 0.5px solid var(--line);
  background: var(--card);
}
.msi-nxn td.is-center { background: var(--accent); color: #fff; font-weight: 700; font-size: 0.62rem; }
.msi-nxn td.is-miss { color: #c5c0b4; background: transparent; border-color: transparent; }
select[size] {
  margin-top: 0.2rem;
  min-height: 240px;
  background: transparent;
  border-radius: 0;
  padding: 4px;
}
select[size] option { padding: 7px 8px; border-radius: 8px; }
.radio-row, .check-row { display: flex; gap: 0.4rem; margin: 0.25rem 0; font-size: 0.82rem; }
.expander { border: 1px solid var(--line); margin: 0.35rem 0; background: rgba(255,255,255,0.4); border-radius: var(--radius); }
.expander summary { cursor: pointer; padding: 0.4rem 0.55rem; font-size: 0.85rem; font-weight: 600; }
.expander .body { padding: 0.25rem 0.55rem 0.55rem; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  margin-top: 0.55rem;
  margin-right: 0;
  width: 100%;
  padding: 0.72rem 0.9rem;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 650;
  letter-spacing: -0.02em;
  cursor: pointer;
  transition: transform 0.14s var(--ease), opacity 0.14s var(--ease), filter 0.14s var(--ease);
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: scale(0.98); opacity: 0.9; }
.btn-secondary {
  background: rgba(47, 93, 80, 0.12);
  color: var(--accent);
}
.btn-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 0.55rem;
}
.btn-row .btn { margin-top: 0; }
.hint {
  font-size: 0.76rem;
  color: var(--muted);
  margin: 8px 8px 10px;
  line-height: 1.45;
  letter-spacing: -0.01em;
}
.warn {
  color: var(--warn);
  font-size: 0.78rem;
  margin: 8px 8px 10px;
  line-height: 1.45;
}
.multi {
  max-height: min(320px, 36vh);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--card);
  border-radius: var(--radius);
  padding: 0;
}
.ios-group {
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 1px 0 rgba(26, 26, 26, 0.03);
}
.stepper {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
  margin: 0 0 14px;
}
.step-tab {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  column-gap: 0.7rem;
  text-align: left;
  width: 100%;
  border: none;
  background: transparent;
  color: var(--ink);
  font: inherit;
  padding: 0.62rem 0.85rem;
  cursor: pointer;
  transition: background 0.16s var(--ease);
}
.step-tab + .step-tab { border-top: 0.5px solid var(--line); }
.step-tab:hover:not(:disabled) { background: var(--fill); }
.step-tab:active:not(:disabled) { background: rgba(26, 26, 26, 0.07); }
.step-badge {
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1;
  color: var(--accent);
  background: rgba(47, 93, 80, 0.12);
  flex-shrink: 0;
}
.step-tab.is-active .step-badge {
  background: var(--accent);
  color: #fff;
}
.step-text { min-width: 0; display: flex; flex-direction: column; gap: 0.08rem; }
.step-name { font-size: 0.95rem; font-weight: 650; letter-spacing: -0.02em; }
.step-sum {
  font-size: 0.72rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.step-chev {
  width: 0.42rem;
  height: 0.42rem;
  border-right: 2px solid #b3aa9c;
  border-top: 2px solid #b3aa9c;
  transform: rotate(45deg);
  margin-right: 0.15rem;
}
.step-tab.is-active { background: var(--card); }
.step-tab.is-disabled { opacity: 0.38; cursor: not-allowed; }
.step-pane { animation: iosIn 0.28s var(--ease); }
@keyframes iosIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}
.choice-list {
  display: flex;
  flex-direction: column;
  max-height: 48vh;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.choice-row, .check-row {
  position: relative;
  display: flex;
  gap: 0.55rem;
  align-items: center;
  padding: 0.72rem 2.1rem 0.72rem 0.9rem;
  border: none;
  background: var(--card);
  font-size: 0.9rem;
  cursor: pointer;
  letter-spacing: -0.015em;
  word-break: keep-all;
}
.choice-row + .choice-row, .check-row + .check-row { border-top: 0.5px solid var(--line); }
.choice-row input, .check-row input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.choice-row span { display: flex; flex-direction: column; min-width: 0; }
.choice-row b { font-weight: 650; }
.choice-row small { color: var(--muted); font-size: 0.72rem; margin-top: 0.12rem; }
.choice-row.is-on, .check-row:has(input:checked), .choice-row:has(input:checked) {
  background: #f7fbf9;
}
.choice-row.is-on::after,
.choice-row:has(input:checked)::after,
.check-row:has(input:checked)::after {
  content: "";
  position: absolute;
  right: 16px;
  top: 50%;
  width: 6px;
  height: 12px;
  border: solid var(--accent);
  border-width: 0 2px 2px 0;
  transform: translateY(-62%) rotate(45deg);
}
.choice-row.is-off { opacity: 0.42; cursor: not-allowed; }
.sidebar-footer {
  position: sticky;
  bottom: 0;
  padding: 10px 0 4px;
  background: linear-gradient(transparent, var(--sidebar) 32%);
}
.btn-next { width: 100%; margin: 0; }
.btn-next small {
  font-weight: 500;
  opacity: 0.82;
  font-size: 0.82em;
}
hr.sep { border: none; height: 8px; margin: 0; background: transparent; }
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; grid-template-rows: minmax(280px, 42vh) 1fr; }
  .sidebar { border-right: none; border-bottom: 0.5px solid var(--line); }
  .main-header { gap: 0.15rem; }
  .msi-metrics { grid-template-columns: repeat(2, 1fr); }
  .metric:nth-child(2) { border-right: none; }
  .metric:nth-child(1), .metric:nth-child(2) { border-bottom: 0.5px solid var(--line); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}
