:root {
  --bg: linear-gradient(135deg, #0f172a, #111827);
  --glass: rgba(255, 255, 255, 0.08);
  --glass-strong: rgba(255, 255, 255, 0.14);
  --border: rgba(255, 255, 255, 0.18);
  --text: #e5e7eb;
  --muted: #a1a1aa;
  --brand: #60a5fa;
  --brand-2: #a78bfa;
  --ok: #34d399;
  --warn: #fbbf24;
  --err: #f87171;
  --halo: radial-gradient(1200px 600px at 10% -20%, rgba(96,165,250,0.10), transparent 60%),
          radial-gradient(1000px 600px at 110% 10%, rgba(167,139,250,0.10), transparent 60%);

  /* Motion tokens */
  --ease-out: cubic-bezier(.22,.61,.36,1);
  --ease-in: cubic-bezier(.32,0,.67,0);
  --ease-spring: cubic-bezier(.15,.85,.25,1.25); /* 살짝 오버슈트 */
  --pop-duration: 560ms;
  --item-duration: 460ms;
  --overlay-duration: 360ms;
  --stagger-step: 70ms;
}

/* Light theme overrides */
body[data-theme="light"] {
  --bg: linear-gradient(135deg, #f5f7fb, #e9eef7);
  --glass: rgba(0, 0, 0, 0.06);
  --glass-strong: rgba(0, 0, 0, 0.10);
  --border: rgba(0, 0, 0, 0.15);
  --text: #0f172a;
  --muted: #4b5563;
  --halo: radial-gradient(1200px 600px at 10% -20%, rgba(96,165,250,0.12), transparent 60%),
          radial-gradient(1000px 600px at 110% 10%, rgba(167,139,250,0.10), transparent 60%);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, Inter, system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
  /* avoid jank when viewport units change on mobile scroll */
  background-attachment: scroll;
  overscroll-behavior-y: none;
}
html { scroll-behavior: smooth; }

.bg-grid::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image: radial-gradient(rgba(255,255,255,0.08) 1px, transparent 1px);
  background-size: 18px 18px;
  pointer-events: none;
  z-index: 0;
}

.bg-grid::after {
  content: "";
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background: var(--halo);
  filter: blur(40px) saturate(140%);
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px;
  animation: pagePopIn 520ms var(--ease-out) both;
}

/* Scroll reveal for all pages */
.reveal-on-scroll { opacity: 0; transform: translateY(18px); }
.reveal-on-scroll.is-visible { opacity: 1; transform: translateY(0); transition: opacity 900ms var(--ease-out), transform 900ms var(--ease-out); }

.glass {
  background: var(--glass);
  border: 1px solid var(--border);
  backdrop-filter: blur(22px) saturate(170%);
  -webkit-backdrop-filter: blur(22px) saturate(170%);
  border-radius: 16px;
  box-shadow: 0 26px 70px rgba(0,0,0,0.28), inset 0 1px 0 rgba(255,255,255,0.07);
}

/* Header / Nav */
.nav {
  position: sticky;
  top: 0;
  z-index: 50;
  margin: calc(16px + env(safe-area-inset-top, 0px)) 16px 16px 16px;
}
.nav-inner {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 14px;
  background: linear-gradient(180deg, rgba(255,255,255,0.10), rgba(255,255,255,0.06));
  border: 1px solid rgba(255,255,255,0.18);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  letter-spacing: 0.2px;
}
.brand-badge {
  width: 28px; height: 28px; border-radius: 8px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  box-shadow: 0 8px 22px rgba(96,165,250,0.38), 0 0 0 1px rgba(255,255,255,.10) inset;
  transition: transform 520ms var(--ease-spring), filter 420ms var(--ease-out);
}
.brand:hover .brand-badge{ transform: scale(1.06) rotate(1deg); filter: brightness(1.06) saturate(110%); }

.nav-links { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.menu-btn {
  display: none;
  margin-left: auto;
  width: 40px; height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--glass);
  color: var(--text);
  align-items: center; justify-content: center;
  cursor: pointer;
}
.menu-btn svg { width: 20px; height: 20px; }

.nav a, .btn, .submenu-trigger {
  color: var(--text); text-decoration: none; font-weight: 500;
  padding: 8px 12px; border-radius: 10px; border: 1px solid transparent;
  transition:
    transform 420ms var(--ease-spring),
    box-shadow 420ms var(--ease-out),
    background 420ms ease,
    border-color 420ms ease,
    filter 420ms var(--ease-out);
}
.nav a:hover, .submenu-trigger:hover { border-color: var(--border); background: var(--glass-strong); transform: translateY(-1px) scale(1.02); box-shadow: 0 16px 36px rgba(0,0,0,.22), 0 0 0 1px rgba(255,255,255,.06) inset; }
.nav a:active, .submenu-trigger:active, .menu-btn:active{ transform: translateY(1px) scale(.985); filter: saturate(110%); }

.nav a:focus-visible, .btn:focus-visible, .submenu-trigger:focus-visible, .pill:focus-visible,
input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 2px solid rgba(96,165,250,0.9);
  outline-offset: 2px;
  box-shadow: 0 0 0 6px rgba(96,165,250,0.12), 0 8px 24px rgba(96,165,250,0.18);
}

.btn {
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  border-color: transparent; color: #0b1020; font-weight: 700;
  box-shadow: 0 10px 28px rgba(96,165,250,0.35);
}
.btn:hover { filter: brightness(1.05); }
.btn:active { transform: translateY(1px); }

a, button { -webkit-tap-highlight-color: transparent; touch-action: manipulation; user-select: none; }
button { cursor: pointer; }

/* Responsive Nav — macOS-like pop/blur로 전환 */
@media (max-width: 860px) {
  .nav-inner { gap: 10px; }
  /* 기존 display:none → visibility/opacity/transform 전환 */
  .nav-links {
    display: flex;
    flex-direction: column;
    gap: 6px;
    position: fixed;
    left: 16px; right: 16px; top: 72px;
    z-index: 90;
    padding: 12px;
    border-radius: 14px;
    background: rgba(17, 24, 39, 0.72);
    border: 1px solid var(--border);
    box-shadow: 0 30px 60px rgba(0,0,0,0.45);
    visibility: hidden;
    opacity: 0;
    transform: translateY(10px) scale(.96);
    filter: blur(10px);
    pointer-events: none;
    transition:
      visibility 0s linear var(--pop-duration),
      opacity var(--pop-duration) var(--ease-out),
      transform var(--pop-duration) var(--ease-spring),
      filter calc(var(--pop-duration) - 80ms) var(--ease-out),
      box-shadow var(--pop-duration) var(--ease-out);
  }
  .nav.is-open .nav-links {
    visibility: visible;
    opacity: 1;
    transform: translateY(0) scale(1.02);
    filter: blur(0px);
    pointer-events: auto;
    animation: navPopIn var(--pop-duration) var(--ease-spring) both;
  }

  /* 촤라라라락: 아이템 스태거 */
  .nav.is-open .nav-links > *{
    opacity: 0; transform: translateY(12px) scale(.98);
    animation: itemUp var(--item-duration) var(--ease-spring) both;
  }
  .nav.is-open .nav-links > *:nth-child(1){ animation-delay: calc(0  * var(--stagger-step)); }
  .nav.is-open .nav-links > *:nth-child(2){ animation-delay: calc(1  * var(--stagger-step)); }
  .nav.is-open .nav-links > *:nth-child(3){ animation-delay: calc(2  * var(--stagger-step)); }
  .nav.is-open .nav-links > *:nth-child(4){ animation-delay: calc(3  * var(--stagger-step)); }
  .nav.is-open .nav-links > *:nth-child(5){ animation-delay: calc(4  * var(--stagger-step)); }
  .nav.is-open .nav-links > *:nth-child(6){ animation-delay: calc(5  * var(--stagger-step)); }
  .nav.is-open .nav-links > *:nth-child(7){ animation-delay: calc(6  * var(--stagger-step)); }
  .nav.is-open .nav-links > *:nth-child(8){ animation-delay: calc(7  * var(--stagger-step)); }

  .menu-btn { display: inline-flex; }
}

/* Nav overlay to block background interaction (blur + fade) */
.nav-overlay {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(0,0,0,0.35);
  backdrop-filter: blur(0px);
  -webkit-backdrop-filter: blur(0px);
  opacity: 0; pointer-events: none;
  transition: opacity var(--overlay-duration) var(--ease-out),
              backdrop-filter var(--overlay-duration) var(--ease-out);
}
.nav.is-open + .nav-overlay { opacity: 1; pointer-events: auto; backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }

/* Submenu */
.has-submenu { position: relative; z-index: 1000; }
.submenu-trigger { background: transparent; border-color: transparent; display: inline-flex; align-items: center; gap: 8px; }
.submenu-trigger.active { background: rgba(255,255,255,0.06); border: 1px solid var(--border); }

.submenu {
  position: absolute; top: calc(100% + 8px); left: 0;
  min-width: 220px; display: flex; flex-direction: column; gap: 6px;
  padding: 10px; border-radius: 12px; border: 1px solid var(--border);
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
  backdrop-filter: blur(18px) saturate(170%); -webkit-backdrop-filter: blur(18px) saturate(170%);
  background: rgba(17, 24, 39, 0.7); z-index: 1100;

  opacity: 0; transform: translateY(8px) scale(.98); filter: blur(8px);
  pointer-events: none;
  transition: opacity 280ms var(--ease-out), transform 320ms var(--ease-out), filter 320ms var(--ease-out);
}
.has-submenu.open .submenu { pointer-events: auto; opacity: 1; transform: translateY(0) scale(1.02); filter: blur(0px); animation: submenuOvershoot 420ms var(--ease-spring) both; }
.has-submenu:hover .submenu { pointer-events: auto; opacity: 1; transform: translateY(0) scale(1.02); filter: blur(0px); }

@keyframes submenuOvershoot{
  0%   { opacity:0; transform: translateY(8px) scale(.98); filter: blur(8px); }
  68%  { opacity:1; transform: translateY(0)   scale(1.02); filter: blur(0px); }
  100% { opacity:1; transform: translateY(0)   scale(1.00); filter: blur(0px); }
}

/* Stagger effect for mobile expanded menu (fallback) */
.nav.is-open .nav-links > * { animation: fadeInUp 760ms var(--ease-out) both; animation-delay: var(--stagger, 0ms); }

/* Hero */
.hero {
  margin-top: 18px;
  padding: 28px;
  position: relative; overflow: hidden;
  animation: cardIn 1100ms var(--ease-out) both;
}
.hero h1 { margin: 0; font-size: 34px; }
.hero p { margin: 8px 0 0; color: var(--muted); }

/* Grid */
.grid { display: grid; gap: 16px; }
@media (min-width: 720px) { .grid.cols-3 { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 720px) { .grid.cols-2 { grid-template-columns: repeat(2, 1fr); } }

.card {
  padding: 16px;
  display: flex; flex-direction: column; gap: 8px;
  transform: translateY(6px);
  transition: transform 640ms var(--ease-out), box-shadow 640ms ease, background 640ms ease;
}
.card h3 { margin: 0; font-size: 18px; }
.card p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.5; }
.card .actions { margin-top: 8px; display: flex; gap: 8px; flex-wrap: wrap; }
.card:hover { transform: translateY(0); box-shadow: 0 26px 60px rgba(0,0,0,0.28); background: rgba(255,255,255,0.10); }

/* Footer */
.footer { margin: 24px 16px 32px; padding: 14px; text-align: center; color: var(--muted); }

/* Widgets */
.input, .select, textarea {
  width: 100%;
  padding: 10px 12px;
  color: var(--text);
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: 12px;
  outline: none;
  transition: box-shadow 300ms ease, border-color 300ms ease, background 300ms ease;
}
.input:focus, .select:focus, textarea:focus { box-shadow: 0 0 0 6px rgba(96,165,250,0.12); border-color: rgba(255,255,255,0.35); background: rgba(255,255,255,0.08); }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1 1 200px; }
.label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.kbd { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: rgba(255,255,255,0.06); border: 1px solid var(--border); padding: 2px 6px; border-radius: 6px; }

.tag { font-size: 12px; padding: 4px 8px; border: 1px solid var(--border); border-radius: 999px; background: rgba(255,255,255,0.06); color: var(--muted); }

.muted { color: var(--muted); }
.center { text-align: center; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 12px; }
.mt-3 { margin-top: 16px; }
.mt-4 { margin-top: 24px; }
.mt-6 { margin-top: 36px; }
.hidden { display: none; }

/* Table */
table { width: 100%; border-collapse: collapse; }
td, th { padding: 10px; border-bottom: 1px solid var(--border); text-align: left; }
tr:hover td { background: rgba(255,255,255,0.04); }

/* Utility */
.pill { padding: 8px 12px; border-radius: 999px; background: rgba(255,255,255,0.06); border: 1px solid var(--border); }
.btn, .pill, a, button { min-height: 40px; }

/* Motion system: iOS-like bouncy and cancellable feeling */
@keyframes cardIn { from { opacity: 0; transform: translateY(24px) scale(0.985);} to { opacity: 1; transform: translateY(0) scale(1);} }
@keyframes floaty { 0%,100% { transform: translateY(0);} 50% { transform: translateY(-4px);} }
@keyframes shimmer { 0%{background-position:0% 50%} 50%{background-position:100% 50%} 100%{background-position:0% 50%} }

.reveal { opacity: 0; transform: translateY(20px); }
.reveal.show { opacity: 1; transform: translateY(0); transition: opacity 1000ms cubic-bezier(.22,.61,.36,1.12), transform 1000ms cubic-bezier(.22,.61,.36,1.12); }

/* Springy transitions (bouncy like iOS) */
.springy { transition: transform 620ms cubic-bezier(.22,.61,.36,1.12), box-shadow 620ms cubic-bezier(.22,.61,.36,1.12), background 420ms ease, border-color 420ms ease; will-change: transform; }
.springy:active { transform: scale(0.985); }

/* Press ripple (ink-like but subtle) */
.ripple { position: relative; overflow: hidden; }
.ripple::after { content: ""; position: absolute; inset: 0; border-radius: inherit; background: radial-gradient(120px 120px at var(--rx,50%) var(--ry,50%), rgba(255,255,255,0.18), transparent 70%); opacity: 0; transition: opacity 260ms ease; pointer-events: none; }
.ripple.is-press::after { opacity: 1; transition: opacity 560ms ease; }

/* Premium motions */
.fade-in { opacity: 0; animation: fadeInUp 1100ms var(--ease-out) forwards; }
@keyframes fadeInUp { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: translateY(0); } }

/* Hover float */
.hover-float { transition: transform 640ms var(--ease-out), box-shadow 640ms ease; }
.hover-float:hover { transform: translateY(-2px); box-shadow: 0 26px 60px rgba(0,0,0,0.28); }

/* Keyframes for macOS-like nav pop + items */
@keyframes navPopIn{
  0%   { opacity:0; transform: translateY(10px) scale(.96); filter: blur(10px); box-shadow: 0 30px 60px rgba(0,0,0,0.00); }
  66%  { opacity:1; transform: translateY(0)    scale(1.04); filter: blur(0px);  box-shadow: 0 30px 60px rgba(0,0,0,0.28); }
  100% { opacity:1; transform: translateY(0)    scale(1.00); filter: blur(0px);  box-shadow: 0 24px 48px rgba(0,0,0,0.22); }
}
@keyframes itemUp{
  0%   { opacity:0; transform: translateY(12px) scale(.98); filter: blur(6px); }
  68%  { opacity:1; transform: translateY(0)    scale(1.04); filter: blur(0px); }
  100% { opacity:1; transform: translateY(0)    scale(1.00); }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001s !important; animation-iteration-count: 1 !important; transition: none !important; }
}

/* Remove blue tap highlight on iOS/Safari Chrome */
input, textarea, select, button, a { -webkit-tap-highlight-color: rgba(0,0,0,0); }
/* Better touch-action defaults for interactive components */
.btn, .pill, a, button { touch-action: manipulation; }

/* Contrast fixes: ensure button text always readable */
.btn { color: #0b1020; }
.pill { color: var(--text); }

/* Mobile canvas container utility */
.canvas-wrap { width: 100%; display: flex; justify-content: center; }
canvas.responsive { width: 100%; height: auto; max-width: 520px; }

/* Hit target size for touch */
button, .pill, .btn { min-height: 40px; }

/* Selection and scrollbars */
::selection { background: rgba(147,112,219,0.35); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.18); border-radius: 8px; }
::-webkit-scrollbar-track { background: rgba(255,255,255,0.06); }

/* Print: simplify background and borders */
@media print {
  body { background: #fff; color: #111; }
  .bg-grid::before, .bg-grid::after, .nav, .footer { display: none !important; }
  .glass { background: transparent; border: 1px solid #ddd; box-shadow: none; }
}

/* High contrast users */
@media (prefers-contrast: more) {
  .glass { background: rgba(255,255,255,0.12); border-color: rgba(255,255,255,0.4); }
  .nav-links { background: rgba(17,24,39,0.85); }
}

/* Page and link polish */
@keyframes pagePopIn { from { opacity: 0; transform: translateY(10px) scale(0.985); } to { opacity: 1; transform: translateY(0) scale(1); } }
a { color: #93c5fd; }
a:hover { color: #bfdbfe; }

/* Command palette */
.cmdk-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 1400; display: none; align-items: flex-start; justify-content: center; padding: 10vh 16px 16px; }
.cmdk { width: 100%; max-width: 680px; background: rgba(17,24,39,0.78); border: 1px solid var(--border); border-radius: 12px; backdrop-filter: blur(16px) saturate(160%); -webkit-backdrop-filter: blur(16px) saturate(160%); box-shadow: 0 30px 80px rgba(0,0,0,0.4); }
.cmdk .head { padding: 10px; border-bottom: 1px solid var(--border); }
.cmdk input { width: 100%; background: transparent; border: none; color: var(--text); font-size: 16px; outline: none; }
.cmdk .list { max-height: 50vh; overflow:auto; }
.cmdk .item { display:flex; align-items:center; gap:10px; padding: 10px 12px; border-bottom: 1px solid rgba(255,255,255,0.06); cursor: pointer; }
.cmdk .item.active { background: rgba(255,255,255,0.08); }
.cmdk-overlay.is-open { display: flex; }

/* Back to top */
.back-to-top { position: fixed; right: 16px; bottom: 16px; z-index: 1300; opacity: 0; pointer-events: none; transition: opacity 320ms var(--ease-out), transform 320ms var(--ease-out); transform: translateY(8px); }
.back-to-top.show { opacity: 1; pointer-events: auto; transform: translateY(0); }

/* Manual reduce motion */
body.reduce-motion * { transition: none !important; animation: none !important; }

/* Optional: floating glow for nav if you add .glow */
.nav .nav-inner.glow{
  box-shadow: 0 20px 60px rgba(96,165,250,.20), 0 0 0 1px rgba(255,255,255,.08) inset;
  animation: subtleFloat 6s ease-in-out infinite;
}
@keyframes subtleFloat{
  0%,100% { transform: translateY(0) }
  50%     { transform: translateY(-2px) }
}

/* Hide theme toggle control (kept from original) */
[data-theme-toggle] { display: none !important; }