/* ============================================================
   숨 (breathe) — styles
   콘셉트: 깊은 밤, 숨에 맞춰 차오르고 빠지는 빛의 호수
   ============================================================ */

:root {
  --bg: #0a0f1c;
  --bg-2: #0f1626;
  --surface: #141d2e;
  --surface-hover: #1b2740;
  --ink: #e8eef7;
  --muted: #8597b3;
  --line: #22304a;
  --accent: #48d4c4;
  --accent-soft: #2a8f9e;
  --accent-warm: #7ce3d0;
  --accent-ink: #06121a;

  --r-pill: 999px;
  --r-card: 16px;
  --ease-soft: cubic-bezier(0.37, 0, 0.63, 1);
}
/* ===== 3-way theme (Light/Dark/System) — base :root above = native DARK. Opposite (light) WCAG-aware auto-generated (contrast-solving ink/accent vs worst-case surface). ===== */
:root[data-theme="light"]{
  --bg: #f4f4f6;
  --bg-2: #f5f5f7;
  --surface: #f6f6f8;
  --surface-hover: #f8f9f9;
  --ink: #2f5286;
  --muted: #596e8f;
  --line: rgba(0,0,0,0.10);
  --accent: #1c796e;
  --accent-soft: #237682;
  --accent-warm: #1a7968;
  --accent-ink: #ffffff;
}












* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: radial-gradient(120% 120% at 50% 30%, var(--bg-2) 0%, var(--bg) 62%);
  color: var(--ink);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo",
    "Malgun Gothic", "Segoe UI", sans-serif;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}

/* 아주 느린 배경 글로우 일렁임 */
#bg-glow {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(40% 35% at 50% 42%, rgba(72, 212, 196, 0.10), transparent 70%);
  opacity: 0.9;
  animation: bgDrift 24s ease-in-out infinite;
  z-index: 0;
}

@keyframes bgDrift {
  0%, 100% { transform: translateY(0) scale(1); opacity: 0.75; }
  50% { transform: translateY(-3%) scale(1.06); opacity: 1; }
}

/* ---------- Topbar ---------- */
.topbar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  padding-top: max(18px, env(safe-area-inset-top));
}

.brand {
  font-size: 1.3rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--ink);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.streak-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 13px;
  border-radius: var(--r-pill);
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: default;
  transition: background 0.2s ease, border-color 0.2s ease;
}
.streak-chip .streak-icon { color: var(--accent); font-size: 0.9rem; }
.streak-chip.is-up { border-color: var(--accent-soft); }
.streak-chip.is-up .streak-icon { animation: pop 0.5s ease; }

@keyframes pop {
  0% { transform: scale(1); }
  45% { transform: scale(1.4); }
  100% { transform: scale(1); }
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: var(--r-pill);
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}
.icon-btn:hover { background: var(--surface-hover); color: var(--ink); }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* 사운드 토글: 기본 off 표시, aria-pressed=true 면 on */
#soundToggle .sound-on { display: none; }
#soundToggle .sound-off { display: inline; }
#soundToggle[aria-pressed="true"] { color: var(--accent); border-color: var(--accent-soft); }
#soundToggle[aria-pressed="true"] .sound-on { display: inline; }
#soundToggle[aria-pressed="true"] .sound-off { display: none; }

/* 나가기 버튼: running/done 상태에서만 표시 */
.exit-btn { display: none; }
body[data-state="running"] .exit-btn,
body[data-state="done"] .exit-btn { display: inline-flex; }

/* running 상태에서 스트릭 칩은 잠시 숨겨 무대에 집중 */
body[data-state="running"] #streakChip { display: none; }

/* ---------- Main layout ---------- */
main {
  position: relative;
  z-index: 1;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 28px;
  padding: 8px 20px 24px;
  min-height: 0;
}

/* ---------- Breathing circle ---------- */
.stage {
  display: flex;
  align-items: center;
  justify-content: center;
}

.circle-wrap {
  position: relative;
  width: min(64vw, 300px);
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.circle-glow {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(72, 212, 196, 0.42), transparent 68%);
  filter: blur(18px);
  transform: scale(0.78);
  opacity: 0.7;
  z-index: 0;
}

.circle {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 38%, var(--accent), var(--accent-soft) 78%);
  box-shadow:
    0 0 60px 0 rgba(72, 212, 196, 0.35),
    inset 0 0 40px rgba(255, 255, 255, 0.08);
  transform: scale(0.78);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* idle: 아주 느린 미세 맥동 (원 + glow) */
body[data-state="idle"] .circle { animation: idlePulse 8s var(--ease-soft) infinite; }
body[data-state="idle"] .circle-glow { animation: idlePulseGlow 8s var(--ease-soft) infinite; }

@keyframes idlePulse {
  0%, 100% { transform: scale(0.72); }
  50% { transform: scale(0.84); }
}
@keyframes idlePulseGlow {
  0%, 100% { transform: scale(0.72); opacity: 0.55; }
  50% { transform: scale(0.9); opacity: 0.85; }
}

.circle-inner {
  text-align: center;
  color: var(--accent-ink);
  padding: 12px;
  user-select: none;
}

.phase-label {
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  opacity: 0.92;
}

.countdown {
  margin-top: 2px;
  font-size: clamp(2.5rem, 9vw, 4.5rem);
  font-weight: 300;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  min-height: 1px;
}

/* ---------- Panels ---------- */
.panel {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
  animation: fadeUp 0.32s ease-out;
}
.is-hidden { display: none !important; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.tagline {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  letter-spacing: 0.02em;
}

/* preset chips */
.chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.chip {
  padding: 9px 15px;
  border-radius: var(--r-pill);
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}
.chip:hover { background: var(--surface-hover); color: var(--ink); }
.chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.chip .chip-sub {
  margin-left: 6px;
  font-size: 0.74rem;
  font-weight: 400;
  opacity: 0.7;
  font-variant-numeric: tabular-nums;
}
.chip[aria-checked="true"] {
  background: rgba(72, 212, 196, 0.12);
  border-color: var(--accent-soft);
  color: var(--accent-warm);
}

.preset-desc {
  margin: 0;
  min-height: 2.6em;
  max-width: 30rem;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

/* ---------- Buttons ---------- */
.btn {
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 13px 26px;
  border-radius: var(--r-pill);
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn.primary {
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 0 26px rgba(72, 212, 196, 0.28);
}
.btn.primary:hover { background: var(--accent-warm); }

.btn.ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--ink);
}
.btn.ghost:hover { background: var(--surface); border-color: var(--surface-hover); }

/* ---------- Running panel ---------- */
.progress-row {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 0.92rem;
  font-variant-numeric: tabular-nums;
}
.progress-dot { opacity: 0.5; }

.controls {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

/* ---------- Done panel ---------- */
.done-title {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 600;
}
.done-summary {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  width: 100%;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  padding: 16px 8px;
}
.stat-num {
  font-size: 1.7rem;
  font-weight: 300;
  color: var(--accent-warm);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.stat-label {
  margin-top: 4px;
  font-size: 0.74rem;
  color: var(--muted);
}

/* ---------- Footer safety ---------- */
.safety {
  position: relative;
  z-index: 1;
  padding: 10px 24px max(14px, env(safe-area-inset-bottom));
  text-align: center;
  color: var(--muted);
  font-size: 0.74rem;
  line-height: 1.5;
  opacity: 0.72;
}
body[data-state="running"] .safety { opacity: 0.4; }

/* ---------- Responsive ---------- */
@media (min-width: 600px) {
  .circle-wrap { width: 320px; }
  main { gap: 34px; }
}

@media (max-height: 680px) {
  .circle-wrap { width: min(52vw, 240px); }
  main { gap: 18px; }
  .tagline { display: none; }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  #bg-glow { animation: none; }
  body[data-state="idle"] .circle,
  body[data-state="idle"] .circle-glow { animation: none; }
  .panel { animation: none; }
  .streak-chip.is-up .streak-icon { animation: none; }
  /* 호흡 가이드(원 크기 변화)는 본질이므로 JS transition은 유지 */
}

/* 언어 스위처 (다크 테마) */
.topbar-right { display: flex; align-items: center; gap: 8px; }
.i18n-switch {
  --i18n-switch-bg: rgba(255,255,255,.07);
  --i18n-switch-border: rgba(255,255,255,.16);
  --i18n-switch-fg: rgba(255,255,255,.9);
  --i18n-switch-active-bg: rgba(120,180,255,.22);
  --i18n-switch-active-fg: #bcd3ff;
  --i18n-switch-menu-bg: #121826;
  --i18n-switch-menu-border: rgba(255,255,255,.12);
}

/* 주간 호흡 통계 패널 */
.stats-panel{position:fixed;inset:0;z-index:80;display:flex;align-items:center;justify-content:center;padding:20px;
  background:rgba(3,6,14,.55);backdrop-filter:blur(4px);opacity:0;visibility:hidden;transition:opacity .2s,visibility .2s}
.stats-panel.open{opacity:1;visibility:visible}
.stats-panel[aria-hidden="false"],.stats-panel.open{opacity:1;visibility:visible}
.stats-card{width:min(360px,94vw);background:var(--surface);border:1px solid rgba(255,255,255,.08);border-radius:18px;
  padding:20px 18px 16px;box-shadow:0 16px 44px rgba(0,0,0,.5)}
.stats-head{display:flex;align-items:center;justify-content:space-between;margin-bottom:8px}
.stats-head h2{margin:0;font-size:17px;font-weight:700;color:var(--ink)}
.stats-close{border:none;background:none;font-size:20px;line-height:1;cursor:pointer;color:var(--muted);padding:2px 6px;border-radius:8px}
.stats-close:active{transform:scale(.92)}
.stats-week-total{margin:0 0 10px;text-align:center;font-size:13px;color:var(--muted)}
.stats-chart{display:flex;justify-content:center}
.stats-chart .stats-empty{color:var(--muted);font-size:13px;line-height:1.5;text-align:center;padding:26px 8px}
.week-svg{width:100%;max-width:300px;height:auto}
.week-svg .week-bar{fill:var(--accent)}
.week-svg .week-val{fill:var(--ink);font-size:9px;font-weight:700;text-anchor:middle}
.week-svg .week-day{fill:var(--muted);font-size:9px;text-anchor:middle}
