/* ═══════════════════════════════════════════════════════════════════════════
   Cairn v2 — Base Design Tokens & Reset
   Warm archival paper aesthetic with ink-inspired typography.
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Design Tokens: Warm Paper (default) ────────────────────────────────── */
:root {
  /* Paper surfaces — warm ivory/cream */
  --paper:      #f4efe5;
  --paper-2:    #efe8da;
  --card:       #fbf8f1;
  --card-2:     #f6f1e7;

  /* Ink — sepia/charcoal text */
  --ink:        #2c2620;
  --ink-soft:   #6e6557;
  --ink-faint:  #a79d8b;

  /* Lines & borders — subtle warm greys */
  --line:       #e4dccb;
  --line-soft:  #ede6d6;

  /* Accent — golden amber (generated from oklch(0.63 0.09 52)) */
  --accent:      oklch(0.63 0.09 52);
  --accent-edge: oklch(0.53 0.10 52);
  --accent-tint: oklch(0.93 0.03 52);
  --accent-hover:oklch(0.68 0.10 52);
  --accent-soft: oklch(0.93 0.02 52 / 0.6);

  /* Success & error */
  --success:     oklch(0.55 0.15 160);
  --success-soft:oklch(0.92 0.04 160);
  --error:       oklch(0.50 0.18 20);
  --error-soft:  oklch(0.92 0.03 20);

  /* Nudge & alert tokens */
  --warn:        oklch(0.55 0.16 50);   /* warm amber for resume nudges */
  --warn-soft:   oklch(0.92 0.05 50);
  --pos:         oklch(0.52 0.14 145);  /* green for milestone nudges */
  --pos-soft:    oklch(0.92 0.04 145);

  /* Typography */
  --serif: "Newsreader", "Nanum Myeongjo", "Noto Serif KR", Georgia, serif;
  --sans:  "Pretendard", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --mono:  "JetBrains Mono", "D2Coding", "SF Mono", "Cascadia Code", monospace;

  /* Radii */
  --radius-card:   16px;
  --radius-input:  10px;
  --radius-btn:    12px;
  --radius-chip:   999px;
  --radius-sm:     8px;
  --radius-xs:     6px;

  /* Shadows — gentle, paper-like */
  --shadow-card:   0 1px 3px rgba(44, 38, 32, 0.06), 0 1px 2px rgba(44, 38, 32, 0.04);
  --shadow-raised: 0 4px 12px rgba(44, 38, 32, 0.08), 0 2px 4px rgba(44, 38, 32, 0.04);
  --shadow-overlay: 0 8px 32px rgba(44, 38, 32, 0.12);

  /* Transitions */
  --ease-out: 0.2s ease;
  --ease-spring: 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);

  /* Spacing scale */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;
}

/* ── Design Tokens: Linen Theme Variant ─────────────────────────────────── */
.linen-theme {
  --paper:      #eceee9;
  --paper-2:    #e5e8e0;
  --card:       #f4f5f0;
  --card-2:     #eff1ea;
  --ink:        #2c2e27;
  --ink-soft:   #6b6e62;
  --ink-faint:  #a2a698;
  --line:       #dde0d5;
  --line-soft:  #e8eadf;
  --accent:      oklch(0.55 0.08 140);
  --accent-edge: oklch(0.45 0.08 140);
  --accent-tint: oklch(0.92 0.03 140);
  --accent-hover:oklch(0.60 0.09 140);
  --accent-soft: oklch(0.92 0.02 140 / 0.6);
}

/* ── Reset ──────────────────────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--sans);
  background: var(--paper);
  color: var(--ink);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
}

/* ── Typography ─────────────────────────────────────────────────────────── */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--serif);
  font-weight: 400;
  line-height: 1.25;
  color: var(--ink);
}

h1 { font-size: 2rem;      letter-spacing: -0.02em; }
h2 { font-size: 1.5rem;    letter-spacing: -0.01em; }
h3 { font-size: 1.25rem; }
h4 { font-size: 1.0625rem; }
h5 { font-size: 0.9375rem; }
h6 { font-size: 0.8125rem; font-family: var(--sans); text-transform: uppercase; letter-spacing: 0.06em; }

p { margin-bottom: 0.75rem; }

a {
  color: var(--accent-edge);
  text-decoration: none;
  transition: color var(--ease-out);
}
a:hover { color: var(--accent); }

::selection {
  background: var(--accent-tint);
  color: var(--ink);
}

/* ── Scrollbar ──────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--ink-faint); }

/* ── Base Components ────────────────────────────────────────────────────── */

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 10px 20px;
  border-radius: var(--radius-btn);
  border: 1px solid transparent;
  font-family: var(--sans);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--ease-out);
  text-decoration: none;
  white-space: nowrap;
  user-select: none;
  line-height: 1.4;
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.btn-primary {
  background: var(--accent);
  color: var(--paper);
  border-color: var(--accent-edge);
}
.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-secondary {
  background: transparent;
  color: var(--ink-soft);
  border-color: var(--line);
}
.btn-secondary:hover:not(:disabled) {
  color: var(--ink);
  border-color: var(--ink-faint);
  background: var(--card);
}

.btn-ghost {
  background: transparent;
  color: var(--ink-faint);
  border-color: transparent;
}
.btn-ghost:hover:not(:disabled) {
  color: var(--ink);
  background: var(--card);
}

.btn-sm { padding: 6px 14px; font-size: 0.8125rem; border-radius: var(--radius-xs); }
.btn-lg { padding: 14px 28px; font-size: 1rem; border-radius: var(--radius-input); }

/* Inputs */
.input,
textarea.input {
  width: 100%;
  padding: 11px 15px;
  border-radius: var(--radius-input);
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 0.9375rem;
  line-height: 1.5;
  outline: none;
  transition: border-color var(--ease-out), box-shadow var(--ease-out);
}
.input::placeholder,
textarea.input::placeholder {
  color: var(--ink-faint);
}
.input:focus,
textarea.input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-tint);
}
textarea.input {
  resize: vertical;
  min-height: 100px;
}

/* Cards */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  padding: var(--space-5);
  box-shadow: var(--shadow-card);
}

.card-raised {
  background: var(--card-2);
  box-shadow: var(--shadow-raised);
}

/* Chip / Pill */
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 4px 14px;
  border-radius: var(--radius-chip);
  border: 1px solid var(--line);
  background: var(--card);
  font-family: var(--sans);
  font-size: 0.75rem;
  color: var(--ink-soft);
  transition: all var(--ease-out);
}

.chip.active {
  border-color: var(--accent);
  color: var(--ink);
  background: var(--accent-tint);
}

/* Toast */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column-reverse;
  gap: var(--space-2);
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  padding: 12px 18px;
  border-radius: var(--radius-input);
  font-size: 0.875rem;
  font-weight: 500;
  max-width: 380px;
  animation: toastIn 0.3s ease, toastOut 0.3s ease 3.8s forwards;
  box-shadow: var(--shadow-overlay);
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--line);
}

.toast-success { border-color: var(--success); background: var(--success-soft); color: var(--success); }
.toast-error   { border-color: var(--error);   background: var(--error-soft);   color: var(--error); }
.toast-info    { border-color: var(--accent);   background: var(--accent-tint);  color: var(--ink); }
.toast-celebrate {
  border-color: var(--accent);
  background: var(--accent-tint);
  font-family: var(--serif);
  font-size: 1rem;
  text-align: center;
}

@keyframes toastIn  { from { opacity: 0; transform: translateX(40px); } to { opacity: 1; transform: translateX(0); } }
@keyframes toastOut { from { opacity: 1; transform: translateX(0); }    to { opacity: 0; transform: translateX(40px); } }

/* Spinner */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
.spinner-sm { width: 14px; height: 14px; border-width: 1.5px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Typing dots */
.typing-dots {
  display: flex;
  gap: 4px;
  padding: 8px 12px;
}
.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ink-faint);
  animation: dotPulse 1.4s infinite both;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes dotPulse {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40%           { opacity: 1;   transform: scale(1); }
}

/* ── Animations ─────────────────────────────────────────────────────────── */

/* Blink — subtle attention pulse */
@keyframes blink {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.4; }
}
.blink { animation: blink 1.2s ease-in-out infinite; }

/* Bob — gentle up-down hover */
@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-3px); }
}
.bob { animation: bob 2s ease-in-out infinite; }

/* Settle — element settles into place */
@keyframes settle {
  0%   { opacity: 0; transform: translateY(8px) scale(0.98); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}
.settle { animation: settle 0.4s ease-out; }

/* bindSettle — staggered settle for bound items */
@keyframes bindSettle {
  0%   { opacity: 0; transform: translateY(6px); }
  100% { opacity: 1; transform: translateY(0); }
}
.bind-settle > * {
  opacity: 0;
  animation: bindSettle 0.35s ease-out forwards;
}
.bind-settle > *:nth-child(1)  { animation-delay: 0.05s; }
.bind-settle > *:nth-child(2)  { animation-delay: 0.10s; }
.bind-settle > *:nth-child(3)  { animation-delay: 0.15s; }
.bind-settle > *:nth-child(4)  { animation-delay: 0.20s; }
.bind-settle > *:nth-child(5)  { animation-delay: 0.25s; }
.bind-settle > *:nth-child(6)  { animation-delay: 0.30s; }
.bind-settle > *:nth-child(7)  { animation-delay: 0.35s; }
.bind-settle > *:nth-child(8)  { animation-delay: 0.40s; }
.bind-settle > *:nth-child(9)  { animation-delay: 0.45s; }
.bind-settle > *:nth-child(10) { animation-delay: 0.50s; }

/* fadeInUp */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}
.fade-in-up { animation: fadeInUp 0.4s ease; }

/* warmGlow */
@keyframes warmGlow {
  0%   { box-shadow: 0 0 0 0 var(--accent-tint); }
  50%  { box-shadow: 0 0 24px var(--accent-tint), 0 0 48px var(--accent-soft); }
  100% { box-shadow: 0 0 0 0 var(--accent-tint); }
}
.warm-glow { animation: warmGlow 1.5s ease; }

/* celebratePulse */
@keyframes celebratePulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.05); }
}
.celebrate-pulse { animation: celebratePulse 0.6s ease 2; }

/* ── Responsive Breakpoints ─────────────────────────────────────────────── */

/* Tablet & below (≤920px) */
@media (max-width: 920px) {
  :root {
    --radius-card: 12px;
    --radius-input: 10px;
  }
  h1 { font-size: 1.75rem; }
  h2 { font-size: 1.375rem; }
  .card { padding: var(--space-4); }
}

/* Mobile (≤560px) */
@media (max-width: 560px) {
  :root {
    --radius-card: 10px;
    --radius-btn: 10px;
    --radius-input: 8px;
  }
  html { font-size: 15px; }
  h1 { font-size: 1.5rem; }
  h2 { font-size: 1.25rem; }
  .btn-lg { padding: 12px 20px; font-size: 0.9375rem; }
  .card { padding: var(--space-3); }
  .toast-container {
    left: 12px;
    right: 12px;
    bottom: 12px;
  }
  .toast { max-width: 100%; }
}

/* ── Reduced Motion ─────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
