/* ═══════════════════════════════════════════════════════════════
   Aurora Loom — styles.css
   DESIGN.md frontmatter 1:1 미러. 색 이원화 규율:
   라즈베리(accent)=UI 인지램프만 · 직물색=palettes(loom.js 소유, 여기 없음).
   base :root = LIGHT(웜 페이퍼, no-JS 폴백) · [data-theme="dark"] = 웜 차콜.
   ═══════════════════════════════════════════════════════════════ */

/* ── 구조 토큰(공유 — 색/장식만 모드별) ───────────────────────── */
:root {
  --font-heading: 'Cabinet Grotesk', 'Pretendard', system-ui, sans-serif;
  --font-body: 'Geist', 'Pretendard', system-ui, 'Apple SD Gothic Neo', sans-serif;
  --font-mono: 'Geist Mono', ui-monospace, 'SFMono-Regular', monospace;

  --fs-display: clamp(30px, 5vw, 44px); --lh-display: 1.06; --fw-display: 700;
  --fs-h1: 20px; --lh-h1: 1.2; --fw-h1: 700;
  --fs-h2: 14px; --lh-h2: 1.3; --fw-h2: 600;
  --fs-body: 14px; --lh-body: 1.62;
  --fs-micro: 11.5px; --lh-micro: 1.35;

  --sp-xs: 6px; --sp-sm: 10px; --sp-md: 16px; --sp-lg: 24px; --sp-xl: 40px;
  --r-base: 16px; --r-sm: 10px; --r-dial: 999px; --r-pill: 999px;

  --t-weave: 620ms; --t-base: 240ms; --t-fast: 140ms;
  --ease: cubic-bezier(.33, .66, .32, 1);
  --ease-settle: cubic-bezier(.4, .9, .3, 1);

  --dock-w: 300px;
  --dial-size: 72px;
  --bolt-h: 108px;
  --thumb-w: 84px;
  --png-scale: 3;
}

/* ── LIGHT (base, native — 아침 햇살 드는 공방) ──────────────── */
:root,
:root[data-theme="light"] {
  --bg: #f3ede2; --surface: #fbf6ec; --surface-2: #eee5d4;
  --ink: #2b2620; --muted: #6f6452; --faint: #a2957f;
  --line: #e0d5c1; --line-strong: #cabda3;
  --accent: #b23a5b; --accent-deep: #8f2c48;
  --accent-soft: rgba(178, 58, 91, .12); --accent-glow: rgba(178, 58, 91, .24);
  --accent-ink: #fffaf3;
  --selvedge: #d8c9ad; --loom-frame: #c9b48f;
  --warn: #a8641a; --danger: #b03b2e;

  --grad-bg-glow: radial-gradient(1100px 620px at 82% -12%, var(--accent-soft) 0%, transparent 58%), radial-gradient(760px 520px at 10% 112%, rgba(0, 0, 0, .04), transparent 60%);
  --grad-accent: linear-gradient(150deg, var(--accent), var(--accent-deep));
  --grad-paper: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="140" height="140"><filter id="n"><feTurbulence type="fractalNoise" baseFrequency="0.85" numOctaves="2"/></filter><rect width="140" height="140" filter="url(%23n)" opacity="0.035"/></svg>');

  --shadow-card: 0 1px 0 var(--line);
  --shadow-lift: 0 10px 30px -18px rgba(60, 40, 20, .35);
  --shadow-focus: 0 0 0 3px var(--accent-soft);
  --shadow-pin: 0 0 0 2px var(--accent), 0 0 20px -2px var(--accent-glow);

  color-scheme: light;
}

/* ── DARK (웜 차콜 — 잠들기 전의 암막 공방, 램프처럼 발광) ──── */
:root[data-theme="dark"] {
  --bg: #181410; --surface: #241d16; --surface-2: #120e0a;
  --ink: #efe6d7; --muted: #b0a189; --faint: #7c6f5b;
  --line: rgba(255, 255, 255, .10); --line-strong: rgba(255, 255, 255, .15);
  --accent: #e26a86; --accent-deep: #c44a67;
  --accent-soft: rgba(226, 106, 134, .16); --accent-glow: rgba(226, 106, 134, .30);
  --accent-ink: #1a0c11;
  --selvedge: #3a3025; --loom-frame: #2e2519;
  --warn: #d99441; --danger: #e2795f;

  --grad-bg-glow: radial-gradient(1100px 620px at 82% -12%, var(--accent-soft) 0%, transparent 58%), radial-gradient(760px 520px at 10% 112%, rgba(0, 0, 0, .22), transparent 60%);
  --grad-accent: linear-gradient(150deg, var(--accent), var(--accent-deep));
  --grad-paper: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="140" height="140"><filter id="n"><feTurbulence type="fractalNoise" baseFrequency="0.85" numOctaves="2"/></filter><rect width="140" height="140" filter="url(%23n)" opacity="0.05"/></svg>');

  --shadow-card: 0 1px 0 var(--line);
  --shadow-lift: 0 14px 34px -18px rgba(0, 0, 0, .7);
  --shadow-focus: 0 0 0 3px var(--accent-soft);
  --shadow-pin: 0 0 0 2px var(--accent), 0 0 24px -2px var(--accent-glow);

  color-scheme: dark;
}

/* ── 스위처 브릿지 (실제 변수명만) ───────────────────────────── */
:root .i18n-switch, :root .theme-switch {
  --i18n-switch-bg: var(--surface); --i18n-switch-border: var(--line); --i18n-switch-fg: var(--ink);
  --i18n-switch-active-bg: var(--accent-soft); --i18n-switch-active-fg: var(--accent);
  --i18n-switch-menu-bg: var(--surface); --i18n-switch-menu-border: var(--line);
  --i18n-switch-shadow: 0 12px 30px -8px rgba(40, 28, 14, .28);
  --theme-switch-bg: var(--surface); --theme-switch-border: var(--line); --theme-switch-fg: var(--muted);
  --theme-switch-active-bg: var(--accent); --theme-switch-active-fg: var(--accent-ink); --theme-switch-radius: 10px;
}

/* ── 리셋 ──────────────────────────────────────────────────── */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font-body);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  overscroll-behavior: none;
}
.font-heading { font-family: var(--font-heading); }
button { font: inherit; color: inherit; cursor: pointer; }
svg { display: block; }

/* ── 셸: 작업대 그리드 ─────────────────────────────────────── */
.site {
  height: 100dvh;
  display: grid;
  grid-template-rows: 1fr var(--bolt-h);
  position: relative;
}

/* ── 무대: 전체화면 직물 ───────────────────────────────────── */
.stage {
  position: relative;
  overflow: hidden;
  background: var(--bg);
  background-image: var(--grad-bg-glow), var(--grad-paper);
}
.canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* ── 헤더 ──────────────────────────────────────────────────── */
.topbar {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 20;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-md);
  padding: var(--sp-md) var(--sp-lg);
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.brand { display: flex; align-items: center; gap: var(--sp-sm); }
.brand-mark {
  display: grid; place-items: center;
  width: 34px; height: 34px;
  border-radius: var(--r-sm);
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--accent);
  box-shadow: var(--shadow-card);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.05; }
.brand-name {
  font-family: var(--font-heading);
  font-size: var(--fs-h1); font-weight: var(--fw-h1);
  color: var(--ink);
  letter-spacing: -0.01em;
}
.brand-tag { font-size: var(--fs-micro); color: var(--muted); margin-top: 2px; }
.topbar-right { display: flex; align-items: center; gap: var(--sp-sm); }

/* ── 시드 배지 ─────────────────────────────────────────────── */
.seed-badge {
  position: absolute;
  left: var(--sp-lg); bottom: var(--sp-lg);
  z-index: 15;
  display: flex; align-items: baseline; gap: var(--sp-sm);
  padding: var(--sp-xs) var(--sp-md);
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow-card);
}
.seed-name { font-size: var(--fs-body); font-weight: 500; color: var(--ink); }
.seed-num { font-family: var(--font-mono); font-size: var(--fs-micro); color: var(--muted); }

/* ── 다이얼독 ──────────────────────────────────────────────── */
.dock {
  position: absolute;
  top: 64px; right: var(--sp-lg); bottom: calc(var(--sp-lg) + 8px);
  z-index: 18;
  width: var(--dock-w);
  max-height: calc(100dvh - var(--bolt-h) - 84px);
  display: flex; flex-direction: column;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  border: 1px solid var(--line);
  border-radius: var(--r-base);
  box-shadow: var(--shadow-lift);
  backdrop-filter: blur(14px) saturate(1.1);
  overflow: hidden;
}
.dock-handle { display: none; }
.dock-body { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.dock-scroll {
  padding: var(--sp-md) var(--sp-md) var(--sp-sm);
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  scrollbar-width: thin;
}
.dock-heading {
  font-size: var(--fs-h1);
  color: var(--ink);
  margin: var(--sp-sm) 0 var(--sp-md);
  letter-spacing: -0.01em;
}
.dock-heading:first-child { margin-top: 2px; }

/* ── 다이얼(노브) ──────────────────────────────────────────── */
.dials { display: flex; flex-direction: column; gap: var(--sp-md); }
.dial {
  display: grid;
  grid-template-columns: var(--dial-size) 1fr;
  align-items: center;
  gap: var(--sp-md);
}
.dial-knob {
  position: relative;
  width: var(--dial-size); height: var(--dial-size);
  border-radius: var(--r-dial);
  background: var(--surface-2);
  border: 1px solid var(--line);
  cursor: grab;
  touch-action: none;
  outline: none;
  flex-shrink: 0;
}
.dial-knob:active { cursor: grabbing; }
.dial-knob:focus-visible { box-shadow: var(--shadow-focus); }
.dial-knob svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.dial-arc-track { stroke: var(--line-strong); }
.dial-arc-fill { stroke: var(--accent); transition: stroke-dashoffset var(--t-base) var(--ease); }
.dial-handle { fill: var(--ink); }
.dial-meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.dial-label { font-size: var(--fs-h2); font-weight: var(--fw-h2); color: var(--ink); }
.dial-value { font-family: var(--font-mono); font-size: var(--fs-micro); color: var(--muted); }
.dial-tip { font-size: var(--fs-micro); line-height: 1.35; color: var(--faint); }

/* ── 팔레트 칩 스트립 ──────────────────────────────────────── */
.palette-strip {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(78px, 1fr));
  gap: var(--sp-sm);
  margin-bottom: var(--sp-md);
}
.palette-chip {
  position: relative;
  display: flex; flex-direction: column;
  padding: 0;
  border: 2px solid transparent;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  overflow: hidden;
  text-align: left;
  transition: transform var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}
.palette-chip:hover { transform: translateY(-2px); }
.palette-chip:focus-visible { box-shadow: var(--shadow-focus); outline: none; }
.palette-chip.is-active { border-color: var(--accent); box-shadow: var(--shadow-focus); }
.palette-swatch { height: 34px; display: block; }
.palette-name { font-size: var(--fs-micro); color: var(--ink); padding: 4px 6px 5px; line-height: 1.2; }

/* ── 액션 버튼군 ───────────────────────────────────────────── */
.dock-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-sm);
  padding: var(--sp-md);
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 70%, transparent);
}
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: var(--sp-xs);
  min-height: 46px;
  padding: 0 var(--sp-md);
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  font-size: var(--fs-h2); font-weight: 600;
  transition: transform var(--t-fast) var(--ease), background var(--t-base) var(--ease), box-shadow var(--t-base) var(--ease);
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: var(--shadow-focus); }
.btn-pin {
  grid-column: 1 / 2;
  background: var(--grad-accent);
  color: var(--accent-ink);
  box-shadow: 0 2px 0 var(--accent-deep);
}
.btn-pin.pin-pulse { box-shadow: var(--shadow-pin); }
.btn-share {
  grid-column: 2 / 3;
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}
.btn-share:hover { background: var(--accent-glow); }
.btn-ghost {
  background: var(--surface-2);
  color: var(--ink);
  border-color: var(--line);
}
.btn-ghost:hover { border-color: var(--line-strong); }

/* ── 두루마리 필름스트립 ───────────────────────────────────── */
.bolt {
  position: relative;
  z-index: 16;
  height: var(--bolt-h);
  background: var(--surface);
  border-top: 1px solid var(--line);
  display: flex; flex-direction: column;
  padding: var(--sp-xs) var(--sp-lg) var(--sp-sm);
}
.bolt-head { display: flex; align-items: baseline; gap: var(--sp-sm); padding: 2px 0; }
.bolt-title { font-size: var(--fs-h2); color: var(--muted); letter-spacing: .02em; }
.bolt-count {
  font-size: var(--fs-micro);
  font-family: var(--font-mono);
  color: var(--accent);
  padding: 1px 8px;
  background: var(--accent-soft);
  border-radius: var(--r-pill);
}
.bolt-count.is-warn { color: var(--warn); background: color-mix(in srgb, var(--warn) 14%, transparent); }
.bolt-track {
  flex: 1;
  display: flex; align-items: center; gap: var(--sp-sm);
  overflow-x: auto; overflow-y: hidden;
  scrollbar-width: thin;
  padding-bottom: 2px;
}
.bolt-empty {
  color: var(--faint);
  font-size: var(--fs-body);
  padding: 0 var(--sp-md);
  border: 1px dashed var(--line-strong);
  border-radius: var(--r-sm);
  height: 60px; display: flex; align-items: center;
}
.bolt-thumb {
  position: relative;
  flex-shrink: 0;
  width: var(--thumb-w);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  overflow: hidden;
  transition: transform var(--t-base) var(--ease), box-shadow var(--t-base) var(--ease), border-color var(--t-base) var(--ease);
}
.bolt-thumb:hover { transform: translateY(-3px); box-shadow: var(--shadow-lift); border-color: var(--accent); }
.bolt-thumb:focus-visible { outline: none; box-shadow: var(--shadow-focus); border-color: var(--accent); }
.bolt-thumb.thumb-in { animation: thumbIn var(--t-weave) var(--ease-settle); }
.bolt-thumb canvas { display: block; width: var(--thumb-w); height: 63px; }
.bolt-thumb-label {
  display: flex; align-items: baseline; justify-content: space-between; gap: 4px;
  padding: 2px 5px 3px;
  background: color-mix(in srgb, var(--surface) 90%, transparent);
}
.bolt-thumb-name { font-size: 10px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bolt-thumb-num { font-family: var(--font-mono); font-size: 9px; color: var(--muted); }
.thumb-remove {
  position: absolute;
  top: 3px; right: 3px;
  width: 20px; height: 20px;
  display: grid; place-items: center;
  border-radius: var(--r-pill);
  background: color-mix(in srgb, var(--surface) 80%, transparent);
  border: 1px solid var(--line);
  color: var(--muted);
  opacity: 0; transition: opacity var(--t-fast) var(--ease);
  font-size: 13px; line-height: 1;
}
.bolt-thumb:hover .thumb-remove, .thumb-remove:focus-visible { opacity: 1; }
.thumb-remove:hover { color: var(--danger); border-color: var(--danger); }

@keyframes thumbIn {
  from { transform: translateY(-24px) scale(.7); opacity: 0; }
  to { transform: none; opacity: 1; }
}

/* ── 온보딩 ────────────────────────────────────────────────── */
.onboarding {
  position: absolute;
  inset: 0;
  z-index: 25;
  display: grid; place-items: center;
  padding: var(--sp-lg);
  pointer-events: none;
  animation: fadeIn var(--t-base) var(--ease);
}
.onboarding .coach { pointer-events: auto; }
.coach {
  max-width: 380px;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  border: 1px solid var(--line);
  border-radius: var(--r-base);
  box-shadow: var(--shadow-lift);
  backdrop-filter: blur(16px);
  padding: var(--sp-lg);
}
.coach-title { font-size: var(--fs-h1); color: var(--ink); margin-bottom: var(--sp-md); letter-spacing: -0.01em; }
.coach-steps { list-style: none; display: flex; flex-direction: column; gap: var(--sp-md); margin-bottom: var(--sp-lg); }
.coach-steps li { display: grid; grid-template-columns: 26px 1fr; gap: var(--sp-sm); align-items: start; color: var(--muted); font-size: var(--fs-body); line-height: 1.5; }
.coach-dot {
  display: grid; place-items: center;
  width: 24px; height: 24px;
  border-radius: var(--r-pill);
  background: var(--accent-soft); color: var(--accent);
  font-family: var(--font-mono); font-size: 12px; font-weight: 500;
}
.btn-coach {
  width: 100%;
  min-height: 46px;
  border-radius: var(--r-sm);
  background: var(--grad-accent);
  color: var(--accent-ink);
  font-weight: 600;
  box-shadow: 0 2px 0 var(--accent-deep);
  transition: transform var(--t-fast) var(--ease);
}
.btn-coach:active { transform: translateY(1px); }
.btn-coach:focus-visible { outline: none; box-shadow: var(--shadow-focus); }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ── 토스트 ────────────────────────────────────────────────── */
.toast {
  position: fixed;
  left: 50%; bottom: calc(var(--bolt-h) + 20px);
  transform: translateX(-50%) translateY(12px);
  z-index: 2147483001;
  max-width: min(90vw, 420px);
  padding: var(--sp-sm) var(--sp-md);
  background: var(--ink); color: var(--bg);
  border-radius: var(--r-pill);
  font-size: var(--fs-micro);
  box-shadow: var(--shadow-lift);
  opacity: 0; pointer-events: none;
  transition: opacity var(--t-base) var(--ease), transform var(--t-base) var(--ease);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── 모바일: 다이얼독 → 하단 시트 ──────────────────────────── */
@media (max-width: 900px) {
  .site { grid-template-rows: 1fr auto; }
  .dock {
    top: auto; right: 0; left: 0; bottom: var(--bolt-h);
    width: 100%;
    max-height: 62dvh;
    border-radius: var(--r-base) var(--r-base) 0 0;
    border-left: none; border-right: none; border-bottom: none;
    transform: translateY(calc(100% - 52px));
    transition: transform var(--t-base) var(--ease-settle);
  }
  .dock.open { transform: translateY(0); }
  .dock-handle {
    display: flex; align-items: center; justify-content: center;
    height: 44px; width: 100%;
    background: transparent; border: none;
    flex-shrink: 0;
  }
  .dock-grip { width: 44px; height: 5px; border-radius: 999px; background: var(--line-strong); }
  .dock-scroll { max-height: 42dvh; }
  .dock-actions { grid-template-columns: 1fr 1fr 1fr 1fr; }
  .btn span:not([aria-hidden]) { display: none; }
  .btn-pin span, .btn-share span { display: inline; }
  .seed-badge { bottom: calc(52px + var(--sp-md)); left: var(--sp-md); }
  .topbar { padding: var(--sp-sm) var(--sp-md); }
  .brand-tag { display: none; }
  .bolt { padding-left: var(--sp-md); padding-right: var(--sp-md); }
}

@media (max-width: 560px) {
  .dial { grid-template-columns: 60px 1fr; }
  .dial-knob { width: 60px; height: 60px; }
}

/* ── RTL (ar) ──────────────────────────────────────────────── */
:root[dir="rtl"] .topbar { flex-direction: row-reverse; }
:root[dir="rtl"] .seed-badge { left: auto; right: var(--sp-lg); }
:root[dir="rtl"] .dock { right: auto; left: var(--sp-lg); }
@media (max-width: 900px) { :root[dir="rtl"] .dock { left: 0; right: 0; } }

/* ── reduced motion ───────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
