/* 기본 = 다크 모드, [data-theme="light"] = 라이트 모드 */
:root {
  color-scheme: dark;
  --bg: #0f1420;
  --card: #182033;
  --ink: #ffffff;
  --ink-soft: #b6bfd0;
  --ink-faint: #7a849a;
  --line: #2b3550;
  --brand: #7398ff;
  --brand-soft: rgba(115, 152, 255, .16);
  --chip: #212a40;
  --chip-hover: #29334c;
  --logo: #ffffff;
  --knob: #ffffff;
  --tip-bg: #f2f5fb;
  --tip-ink: #1d2433;
  --hint-bg: rgba(255, 196, 72, .16);
  --hint-ink: #ffe3a3;
  --ph-a: #1a2236;
  --ph-b: #222c44;
  --shadow: 0 12px 32px rgba(0, 0, 0, .35), 0 2px 6px rgba(0, 0, 0, .2);

  --radius-xl: 28px;
  --radius-lg: 20px;
  --thumb: 26px;

  /* 애니메이션 공통값 */
  --ease-out: cubic-bezier(.2, .8, .2, 1);
  --ease-spring: cubic-bezier(.34, 1.56, .64, 1);
  --fill-ms: 320ms;
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f6fb;
  --card: #ffffff;
  --ink: #1d2433;
  --ink-soft: #6b7487;
  --ink-faint: #a9b0be;
  --line: #e6e9f0;
  --brand: #3d6cf2;
  --brand-soft: #e8eefe;
  --chip: #f4f6fb;
  --chip-hover: #eceff6;
  --logo: #3d6cf2;
  --knob: #ffffff;
  --tip-bg: #1d2433;
  --tip-ink: #ffffff;
  --hint-bg: #fff4d6;
  --hint-ink: #1d2433;
  --ph-a: #eef1f7;
  --ph-b: #f7f8fc;
  --shadow: 0 10px 30px rgba(29, 36, 51, 0.06), 0 2px 6px rgba(29, 36, 51, 0.04);
}

/* 테마 전환 순간에만 색이 부드럽게 바뀜 (app.js가 잠깐 붙였다 뗌) */
html.theme-switching *,
html.theme-switching *::before {
  transition: background-color .45s ease, color .45s ease, border-color .45s ease, box-shadow .45s ease,
              opacity .3s ease, transform .5s var(--ease-spring) !important;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  font-family: "Pretendard", -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* =========================================================
   등장 애니메이션 (공통)
   data-animate 를 붙인 요소는 화면에 들어오면 떠오르며 나타남.
   나중에 추가되는 요소도 app.js가 자동으로 감지해 적용.
   ========================================================= */
[data-animate] {
  opacity: 0;
  transform: translateY(14px) scale(.985);
  transition:
    opacity .6s var(--ease-out) var(--delay, 0ms),
    transform .6s var(--ease-out) var(--delay, 0ms);
}
[data-animate].is-in {
  opacity: 1;
  transform: none;
}

/* ---------- 상단 ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px 18px 28px;
}
.logo {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: "Jua", "Pretendard", sans-serif;
  font-size: 30px;
  color: var(--logo);
  text-decoration: none;
  letter-spacing: -0.5px;
}
.logo-egg {
  width: 26px;
  height: auto;
  display: block;
  filter: drop-shadow(0 3px 6px rgba(224, 103, 12, .35));
  transform-origin: 50% 90%;
  transition: transform .35s var(--ease-spring);
}
.logo-word { line-height: 1; padding-top: 3px; }
.logo.is-in { transition: opacity .6s var(--ease-out), transform .25s var(--ease-spring); }
.logo:hover { transform: scale(1.04); }
.logo:hover .logo-egg { animation: wobble .6s var(--ease-out); }
@keyframes wobble {
  0%, 100% { transform: rotate(0); }
  25% { transform: rotate(-10deg); }
  55% { transform: rotate(8deg); }
  80% { transform: rotate(-3deg); }
}

/* ---------- 다크/라이트 전환 버튼 (해·달 아이콘: 직접 그린 SVG) ---------- */
.theme-btn {
  position: relative;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 0;
  padding: 0;
  cursor: pointer;
  background: var(--card);
  color: var(--ink);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: transform .3s var(--ease-spring), background-color .45s, color .45s;
}
.theme-btn:hover { transform: scale(1.08) rotate(-8deg); }
.theme-btn:active { transform: scale(.92); }
.theme-btn:focus-visible { outline: 3px solid rgba(115,152,255,.45); outline-offset: 3px; }
.theme-btn svg {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 22px;
  height: 22px;
  transition: transform .5s var(--ease-spring), opacity .3s ease;
}
/* 다크 모드일 땐 해(→라이트로 전환)를, 라이트 모드일 땐 달(→다크로 전환)을 보여줌 */
.theme-btn .icon-sun { color: #ffc24a; }
.theme-btn .icon-moon { color: #6b7cff; opacity: 0; transform: translateY(30px) rotate(-90deg); }
[data-theme="light"] .theme-btn .icon-sun { opacity: 0; transform: translateY(-30px) rotate(90deg); }
[data-theme="light"] .theme-btn .icon-moon { opacity: 1; transform: none; }

.page {
  flex: 1;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 8px 20px 48px;
}

/* ---------- 필터 카드 ---------- */
.filter-card {
  background: var(--card);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
  padding: 32px 32px 18px;
}

.field { padding-bottom: 28px; }
.field + .field { padding-top: 26px; border-top: 1px solid var(--line); }

.field-title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
}

.field-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

/* ---------- 통신사 ---------- */
.carriers {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.carrier {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
}

.chip {
  cursor: pointer;
  user-select: none;
}
.chip input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.chip span {
  display: inline-block;
  min-width: 84px;
  text-align: center;
  padding: 12px 22px;
  border-radius: 999px;
  background: var(--chip);
  border: 2px solid transparent;
  font-weight: 700;
  font-size: 15px;
  color: var(--ink-soft);
  transition: background .25s, color .25s, border-color .25s, transform .25s var(--ease-spring), box-shadow .25s;
}
.chip:hover span { background: var(--chip-hover); transform: translateY(-2px); }
.chip input:checked + span {
  background: var(--brand-soft);
  border-color: var(--brand);
  color: var(--brand);
  box-shadow: 0 6px 16px rgba(61, 108, 242, .18);
  animation: pop .35s var(--ease-spring);
}
.chip input:focus-visible + span { outline: 3px solid rgba(61,108,242,.35); outline-offset: 2px; }
.chip:active span { transform: scale(0.95); }

/* 해제할 수 없는 선택(납부 방식 마지막 하나)을 누르면 살짝 흔들림 */
.chip input:checked + span.nope { animation: nope .4s var(--ease-out); }
@keyframes nope {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-5px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}

@keyframes pop {
  0% { transform: scale(.92); }
  60% { transform: scale(1.06); }
  100% { transform: scale(1); }
}

.info-btn {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1.5px solid var(--ink-faint);
  background: var(--card);
  color: var(--ink-soft);
  font: italic 700 12px/1 Georgia, "Times New Roman", serif;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
  transition: border-color .2s, color .2s, background .2s, transform .25s var(--ease-spring);
}
.info-btn:hover,
.info-btn[aria-expanded="true"] {
  border-color: var(--brand);
  color: var(--brand);
  background: var(--brand-soft);
  transform: scale(1.12);
}

.tip {
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  z-index: 10;
  width: max-content;
  max-width: 260px;
  padding: 12px 16px;
  border-radius: 16px;
  background: var(--tip-bg);
  color: var(--tip-ink);
  font-size: 13.5px;
  line-height: 1.5;
  word-break: keep-all;
  box-shadow: 0 8px 24px rgba(29, 36, 51, 0.18);
  opacity: 0;
  transform: translateY(-6px) scale(.96);
  transform-origin: 12px 0;
  pointer-events: none;
  transition: opacity .22s var(--ease-out), transform .3s var(--ease-spring);
}
.tip.open { opacity: 1; transform: none; pointer-events: auto; }

/* ---------- 데이터 용도 문구 ---------- */
.readout {
  display: grid;
  justify-items: end;
  min-height: 34px;
}
.readout-hint {
  font-size: 14px;
  font-weight: 600;
  color: var(--hint-ink);
  background: var(--hint-bg);
  padding: 7px 16px;
  border-radius: 999px;
  white-space: nowrap;
  /* 사라질 때: 천천히 점점 투명해짐 */
  opacity: 0;
  transform: translateY(0);
  transition: opacity 1.2s ease-in-out, transform 1.2s ease-in-out;
}
.readout.show-hint .readout-hint {
  /* 나타날 때: 빠르게 */
  opacity: 1;
  transform: none;
  transition: opacity .25s var(--ease-out), transform .3s var(--ease-spring);
  animation: hint-in .3s var(--ease-spring);
}
@keyframes hint-in {
  from { transform: translateY(6px) scale(.96); }
  to { transform: none; }
}

/* ---------- 슬라이더 (직접 그린 게이지 + 투명한 range 입력) ---------- */
.slider {
  position: relative;
  padding: 0 6px;
  --r: 0; /* 0~1, app.js가 설정 → 게이지/손잡이가 이 값으로 차오름 */
}

.rail {
  position: relative;
  height: var(--thumb);
}
.track {
  position: absolute;
  left: calc(var(--thumb) / 2);
  right: calc(var(--thumb) / 2);
  top: 50%;
  height: 10px;
  margin-top: -5px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}
.fill {
  height: 100%;
  width: calc(var(--r) * 100%);
  border-radius: 999px;
  background: linear-gradient(90deg, #6f93ff, var(--brand));
  transition: width var(--fill-ms) var(--ease-out);
}
.knob {
  position: absolute;
  top: 0;
  left: calc(var(--thumb) / 2 + (100% - var(--thumb)) * var(--r));
  width: var(--thumb);
  height: var(--thumb);
  margin-left: calc(var(--thumb) / -2);
  border-radius: 50%;
  background: var(--knob);
  border: 3px solid var(--brand);
  box-shadow: 0 3px 10px rgba(61, 108, 242, 0.3);
  transition:
    left var(--fill-ms) var(--ease-out),
    transform .2s var(--ease-spring),
    box-shadow .2s;
}
.slider:hover .knob { transform: scale(1.08); }
.slider:active .knob { transform: scale(1.18); box-shadow: 0 4px 14px rgba(61, 108, 242, 0.4); }
.slider:has(input:focus-visible) .knob { box-shadow: 0 0 0 6px rgba(61,108,242,.2); }

/* 실제 입력은 투명하게 위에 겹쳐 드래그/키보드만 담당 */
.slider input[type="range"] {
  position: absolute;
  top: -9px; /* 손가락으로 잡기 쉽게 위아래로 넓힘 (눈금 글자와는 겹치지 않게) */
  left: 6px;
  width: calc(100% - 12px);
  height: calc(var(--thumb) + 14px);
  margin: 0;
  opacity: 0;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}
.slider input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: var(--thumb);
  height: var(--thumb);
}
.slider input[type="range"]::-moz-range-thumb {
  width: var(--thumb);
  height: var(--thumb);
  border: 0;
}

/* 눈금 + 라벨: 손잡이 중심이 지나는 구간에 맞춰 정렬 */
.ticks {
  list-style: none;
  position: relative;
  height: 40px;
  margin: 6px calc(var(--thumb) / 2) 0;
  padding: 0;
}
.ticks li {
  position: absolute;
  top: 0;
  left: calc(var(--i) / var(--n) * 100%);
  /* 잘못 누르지 않도록: 각 눈금의 클릭 범위 = 이웃 눈금과의 중간까지 (칸 전체) */
  width: calc(100% / var(--n));
  height: 100%;
  text-align: center;
  transform: translateX(-50%);
  padding-top: 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-faint);
  white-space: nowrap;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: color .25s, transform .3s var(--ease-spring);
}
.ticks li:hover { color: var(--ink-soft); }
.ticks li::before {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  width: 4px;
  height: 7px;
  margin-left: -2px;
  border-radius: 2px;
  background: var(--line);
  transition: background .25s, height .3s var(--ease-spring);
}
.ticks li .up { margin-left: 1px; font-weight: 800; }
/* 두 줄 눈금 (예: 1Mbps / 속도제한) */
.ticks-two { height: 52px; }
.ticks-two li { line-height: 1.25; }
.ticks-two li small { display: block; font-size: 11px; font-weight: 600; opacity: .85; }
.ticks-dense li { font-size: 12.5px; letter-spacing: -0.3px; }
.ticks li.active { color: var(--brand); transform: translateX(-50%) scale(1.1); }
.ticks li.active::before { background: var(--brand); height: 9px; }

/* ---------- 결과 자리 ---------- */
.results { margin-top: 28px; }
.results-summary {
  margin: 0 6px 14px;
  font-size: 14px;
  color: var(--ink-soft);
}
.results-summary.changed { animation: text-swap .4s var(--ease-out); }
@keyframes text-swap {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}
.placeholder { display: grid; gap: 12px; }
.ph-card {
  height: 86px;
  border-radius: var(--radius-lg);
  background: linear-gradient(90deg, var(--ph-a) 0%, var(--ph-b) 50%, var(--ph-a) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.6s infinite linear;
}
.ph-text {
  text-align: center;
  color: var(--ink-faint);
  font-size: 14px;
  margin: 8px 0 0;
}
@keyframes shimmer { to { background-position: -200% 0; } }

.footer {
  text-align: center;
  color: var(--ink-faint);
  font-size: 12px;
  padding: 24px;
}

/* ---------- 모바일 ---------- */
@media (max-width: 520px) {
  .topbar { padding: 18px 20px; }
  .filter-card { padding: 26px 20px 12px; border-radius: 24px; }
  .chip span { min-width: 72px; padding: 11px 18px; }
  .ticks li { font-size: 12px; }
  /* 좁은 화면: 눈금 글자를 위/아래 두 줄로 번갈아 배치해 겹치지 않게 */
  .ticks-dense { height: 60px; }
  .ticks-dense li { font-size: 11.5px; letter-spacing: -0.3px; }
  .ticks-dense li:nth-child(even) { padding-top: 30px; }
  .ticks-dense li:nth-child(even)::before { height: 25px; width: 2px; margin-left: -1px; opacity: .6; }
  .ticks-dense li.active:nth-child(even)::before { height: 27px; opacity: 1; }
  .ticks-dense li.active { transform: translateX(-50%) scale(1.12); }
  /* 통신사 세 개가 한 줄에 들어가도록 */
  .carriers { gap: 8px; flex-wrap: nowrap; }
  .carrier { gap: 4px; }
  .chip span { min-width: 0; padding: 10px 15px; font-size: 14px; }
  .readout-hint { white-space: normal; text-align: right; max-width: 200px; }
}

/* 동작 줄이기 설정 사용자: 떠오름/튕김 같은 움직임만 빼고, 페이드와 게이지 채움은 유지 */
@media (prefers-reduced-motion: reduce) {
  [data-animate] { transform: none; }
  .chip input:checked + span,
  .readout.show-hint .readout-hint,
  .results-summary.changed { animation: none; }
  .chip:hover span, .chip:active span,
  .logo:hover, .info-btn:hover,
  .slider:hover .knob, .slider:active .knob { transform: none; }
}
