@font-face { font-family: 'Paperlogy'; src: url('/fonts/Paperlogy-4Regular.woff2') format('woff2'); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: 'Paperlogy'; src: url('/fonts/Paperlogy-5Medium.woff2') format('woff2'); font-weight: 500; font-style: normal; font-display: swap; }
@font-face { font-family: 'Paperlogy'; src: url('/fonts/Paperlogy-6SemiBold.woff2') format('woff2'); font-weight: 600; font-style: normal; font-display: swap; }
@font-face { font-family: 'Paperlogy'; src: url('/fonts/Paperlogy-8ExtraBold.woff2') format('woff2'); font-weight: 700 800; font-style: normal; font-display: swap; }

:root {
  --paper: #fbfaf7;
  --ink: #17171f;
  --ink-2: #44444f;
  --muted: #8a8a98;
  --line: rgb(var(--ink-rgb) / 0.09);
  --accent: #5b4bff;
  --accent-2: #ff5fa2;
  --accent-soft: rgba(91, 75, 255, 0.1);
  --danger: #e5484d;
  --ok: #18a058;
  --glass: rgba(255, 255, 255, 0.78);
  --glass-border: rgba(255, 255, 255, 0.7);
  --surface: #ffffff;
  --surface-soft: rgba(255, 255, 255, 0.85);
  --ink-rgb: 23 23 40;
  --paper-rgb: 251 250 247;
  --crayon: #ffffff;
  --crayon-edge: rgba(23, 23, 40, 0.92);
  color-scheme: light;
  --shadow-sm: 0 1px 2px rgba(20, 20, 40, 0.06), 0 2px 8px rgba(20, 20, 40, 0.05);
  --shadow-md: 0 4px 12px rgba(20, 20, 40, 0.07), 0 12px 32px rgba(20, 20, 40, 0.08);
  --shadow-lg: 0 8px 24px rgba(20, 20, 40, 0.1), 0 28px 64px rgba(20, 20, 40, 0.14);
  --r-sm: 10px;
  --r-md: 16px;
  --r-lg: 24px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --font: 'Paperlogy', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Apple SD Gothic Neo', 'Noto Sans KR', 'Malgun Gothic', system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  line-height: 1.5;
  animation: page-in 0.55s var(--ease) both;
}
body.leaving { animation: page-out 0.2s ease-in both; pointer-events: none; }

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- 키프레임 ---------- */
@keyframes page-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes page-out { to { opacity: 0; transform: translateY(-6px) scale(0.99); } }
@keyframes rise { from { opacity: 0; transform: translateY(18px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes pop { from { opacity: 0; transform: scale(0.9); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes float-a { 0%, 100% { transform: translate(0, 0) scale(1); } 50% { transform: translate(40px, -30px) scale(1.08); } }
@keyframes float-b { 0%, 100% { transform: translate(0, 0) scale(1); } 50% { transform: translate(-50px, 30px) scale(0.94); } }
@keyframes draw { to { stroke-dashoffset: 0; } }

.stagger > * { animation: rise 0.6s var(--ease) both; animation-delay: calc(var(--i, 0) * 70ms + 80ms); }

/* ---------- 공통 컴포넌트 ---------- */
.logo { display: inline-flex; align-items: center; gap: 10px; font-weight: 800; font-size: 22px; letter-spacing: -0.03em; }
.logo svg { width: 38px; height: 38px; overflow: visible; }
.logo .mark-path { stroke-dasharray: 120; stroke-dashoffset: 120; animation: draw 1.1s 0.25s var(--ease) forwards; }
.logo .mark-path.second { animation-delay: 0.75s; }

.btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 44px; padding: 0 20px; border-radius: 999px; font-weight: 600; font-size: 15px;
  transition: transform 0.25s var(--spring), box-shadow 0.25s var(--ease), background 0.2s, opacity 0.2s;
  user-select: none; white-space: nowrap;
}
.btn:active { transform: scale(0.96); }
.btn:disabled { opacity: 0.5; pointer-events: none; }
.btn-primary { color: #fff; background: linear-gradient(135deg, var(--accent), #8a4bff 60%, var(--accent-2)); background-size: 140% 140%; background-position: 0% 50%; box-shadow: 0 6px 18px rgba(91, 75, 255, 0.35); }
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 10px 26px rgba(91, 75, 255, 0.45); background-position: 100% 50%; }
.btn-ghost { background: rgb(var(--ink-rgb) / 0.05); }
.btn-ghost:hover { background: rgb(var(--ink-rgb) / 0.09); }
.btn-danger { color: #fff; background: var(--danger); }
.btn-sm { height: 36px; padding: 0 14px; font-size: 14px; }
.btn.loading { color: transparent; pointer-events: none; }
.btn.loading::after { content: ''; position: absolute; width: 18px; height: 18px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.4); border-top-color: #fff; animation: spin 0.7s linear infinite; }
.btn-ghost.loading::after { border-color: rgba(0, 0, 0, 0.15); border-top-color: var(--ink); }

.icon-btn { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; color: var(--ink-2); transition: background 0.2s, transform 0.25s var(--spring), color 0.2s; }
.icon-btn:hover { background: rgb(var(--ink-rgb) / 0.07); color: var(--ink); }
.icon-btn:active { transform: scale(0.9); }
.icon-btn svg, .tool svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.field { position: relative; margin-bottom: 14px; }
.field input {
  width: 100%; height: 56px; padding: 22px 16px 6px; border-radius: 14px; border: 1.5px solid var(--line);
  background: var(--surface-soft); outline: none; font-size: 16px;
  transition: border-color 0.2s, box-shadow 0.25s var(--ease), background 0.2s;
}
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); background: var(--surface); }
.field label { position: absolute; left: 17px; top: 17px; color: var(--muted); font-size: 16px; pointer-events: none; transform-origin: 0 0; transition: transform 0.25s var(--ease), color 0.2s; }
.field input:focus + label, .field input:not(:placeholder-shown) + label { transform: translateY(-9px) scale(0.76); }
.field input:focus + label { color: var(--accent); }
.field.invalid input { border-color: var(--danger); animation: shake 0.4s; }

.toast-host { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; z-index: 100; pointer-events: none; }
.toast { padding: 11px 18px; border-radius: 999px; background: rgba(23, 23, 31, 0.92); color: #fff; font-size: 14px; font-weight: 500; box-shadow: var(--shadow-md); backdrop-filter: blur(10px); animation: rise 0.45s var(--spring) both; max-width: 90vw; }
.toast.error { background: rgba(229, 72, 77, 0.95); }
.toast.out { animation: page-out 0.25s ease-in forwards; }

.backdrop { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: 20px; background: rgba(20, 20, 35, 0.35); backdrop-filter: blur(6px); animation: fade 0.25s both; }
.backdrop.out { animation: fade 0.2s reverse forwards; }
.dialog { width: min(420px, 100%); padding: 26px; border-radius: var(--r-lg); background: var(--surface); box-shadow: var(--shadow-lg); animation: pop 0.4s var(--spring) both; }
.dialog h2 { margin: 0 0 6px; font-size: 20px; letter-spacing: -0.02em; }
.dialog p { margin: 0 0 18px; color: var(--ink-2); font-size: 15px; }
.dialog .field { margin-bottom: 18px; }
.dialog .actions { display: flex; justify-content: flex-end; gap: 8px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-delay: 0ms !important; transition-duration: 0.01ms !important; }
}

.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 14px; background: var(--c, var(--accent)); box-shadow: 0 0 0 2px #fff, var(--shadow-sm); }

/* ---------- 다크(블랙) 테마 ---------- */
:root[data-theme='dark'] {
  --paper: #0c0c10;
  --ink: #f3f3f6;
  --ink-2: #c4c4cd;
  --muted: #8d8d99;
  --accent-soft: rgba(139, 124, 255, 0.18);
  --accent: #8b7cff;
  --glass: rgba(26, 26, 33, 0.78);
  --glass-border: rgba(255, 255, 255, 0.09);
  --surface: #17171d;
  --surface-soft: rgba(255, 255, 255, 0.05);
  --ink-rgb: 255 255 255;
  --paper-rgb: 12 12 16;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4), 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4), 0 12px 32px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5), 0 28px 64px rgba(0, 0, 0, 0.55);
  --crayon-edge: rgba(0, 0, 0, 0);
  color-scheme: dark;
}
:root[data-theme='dark'] .toast { background: rgba(48, 48, 58, 0.95); }

/* ---------- 테마 전환 버튼 ---------- */
.theme-toggle { position: relative; overflow: hidden; }
.theme-toggle svg { position: absolute; transition: transform 0.55s var(--spring), opacity 0.3s; }
.theme-toggle .sun { transform: rotate(0) scale(1); }
.theme-toggle .moon { transform: rotate(-90deg) scale(0.3); opacity: 0; }
:root[data-theme='dark'] .theme-toggle .sun { transform: rotate(90deg) scale(0.3); opacity: 0; }
:root[data-theme='dark'] .theme-toggle .moon { transform: none; opacity: 1; }
html.theme-anim, html.theme-anim *, html.theme-anim *::before, html.theme-anim *::after { transition: background-color 0.4s, color 0.4s, border-color 0.4s, box-shadow 0.4s !important; }

/* ---------- 크레파스 로고 ---------- */
.logo { color: var(--crayon); }
.logo .word { font-weight: 800; font-size: 26px; letter-spacing: -0.02em; color: var(--crayon); filter: url(#crayon-rough); text-shadow: -1px 0 0 var(--crayon-edge), 1px 0 0 var(--crayon-edge), 0 -1px 0 var(--crayon-edge), 0 1px 0 var(--crayon-edge), 1.5px 2px 0 var(--crayon-edge); }
.logo svg { filter: url(#crayon-rough) drop-shadow(-1px 0 0 var(--crayon-edge)) drop-shadow(1px 0 0 var(--crayon-edge)) drop-shadow(0 1px 0 var(--crayon-edge)) drop-shadow(1.5px 2px 0 var(--crayon-edge)); }

/* 버튼 안 아이콘 */
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
button, a, summary { touch-action: manipulation; }
