@layer base, layout, parts;

@layer base {
  :root {
    color-scheme: light;
    --bg: oklch(98.5% 0.006 280);
    --surface: oklch(100% 0 0);
    --text: oklch(22% 0.02 280);
    --muted: oklch(52% 0.02 280);
    --line: oklch(91% 0.01 280);
    --brand: oklch(62% 0.21 285);
    --brand-2: oklch(72% 0.18 350);
    --radius: 18px;
    --shadow: 0 1px 2px oklch(0% 0 0 / .06), 0 8px 24px oklch(30% 0.05 280 / .08);
  }
  :root[data-theme="dark"] {
    color-scheme: dark;
    --bg: oklch(17% 0.015 280);
    --surface: oklch(22% 0.018 280);
    --text: oklch(95% 0.01 280);
    --muted: oklch(70% 0.02 280);
    --line: oklch(30% 0.02 280);
    --shadow: 0 1px 2px oklch(0% 0 0 / .4), 0 8px 24px oklch(0% 0 0 / .35);
  }
  * { box-sizing: border-box; }
  html { overflow-x: clip; scroll-behavior: smooth; scroll-padding-top: 72px; }
  body {
    margin: 0; background: var(--bg); color: var(--text);
    font: 16px/1.6 "Pretendard Variable", Pretendard, system-ui, sans-serif;
    word-break: keep-all; -webkit-font-smoothing: antialiased;
  }
  body:has(dialog[open]) { overflow: hidden; }
  a { color: inherit; }
  button { font: inherit; color: inherit; cursor: pointer; }
  h1, h2, h3 { line-height: 1.25; letter-spacing: -0.02em; }
  ::view-transition-old(root), ::view-transition-new(root) { animation-duration: .35s; }
}

@layer layout {
  .top {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; gap: 24px; padding: 12px clamp(16px, 4vw, 48px);
    background: color-mix(in oklch, var(--bg) 78%, transparent);
    backdrop-filter: blur(14px) saturate(1.6);
    border-bottom: 1px solid var(--line);
    & nav { display: flex; gap: 20px; margin-left: auto; font-size: 15px; color: var(--muted); }
    & nav a { text-decoration: none; &:hover { color: var(--text); } }
    @media (width < 720px) { & nav { display: none; } & #theme { margin-left: auto; } }
  }
  .brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 18px; text-decoration: none; }

  .hero {
    position: relative; overflow: hidden; padding: clamp(56px, 9vw, 120px) clamp(16px, 4vw, 48px) 72px;
    background:
      radial-gradient(60% 80% at 15% 10%, oklch(80% 0.12 285 / .45), transparent 70%),
      radial-gradient(50% 70% at 90% 20%, oklch(85% 0.12 350 / .45), transparent 70%),
      radial-gradient(60% 60% at 60% 100%, oklch(88% 0.1 200 / .4), transparent 70%);
    & .hero-in { position: relative; z-index: 1; max-width: 760px; margin: 0 auto; text-align: center; }
    & h1 { font-size: clamp(27px, 6vw, 60px); font-weight: 850; margin: 10px 0 16px; }
    & em {
      font-style: normal;
      background: linear-gradient(90deg, var(--brand), var(--brand-2)); -webkit-background-clip: text; background-clip: text; color: transparent;
    }
    & .lead { color: var(--muted); font-size: clamp(16px, 2vw, 19px); margin: 0 auto 32px; max-width: 560px; }
  }
  :root[data-theme="dark"] .hero { background:
      radial-gradient(60% 80% at 15% 10%, oklch(40% 0.15 285 / .5), transparent 70%),
      radial-gradient(50% 70% at 90% 20%, oklch(40% 0.14 350 / .45), transparent 70%); }
  .nw { white-space: nowrap; }
  .eyebrow {
    display: inline-block; margin: 0; padding: 6px 14px; border-radius: 99px; font-size: 14px; font-weight: 600;
    background: color-mix(in oklch, var(--surface) 70%, transparent); border: 1px solid var(--line);
  }

  .gallery { max-width: 1280px; margin: 0 auto; padding: 0 clamp(16px, 4vw, 48px) 80px; }
  .how, .faq { max-width: 1080px; margin: 0 auto; padding: 72px clamp(16px, 4vw, 48px); }
  .how h2, .faq h2 { text-align: center; font-size: clamp(26px, 4vw, 36px); margin: 0 0 36px; }
  footer { padding: 32px; text-align: center; color: var(--muted); font-size: 14px; border-top: 1px solid var(--line); }
}

@layer parts {
  .search {
    display: flex; align-items: center; gap: 12px; padding: 8px 10px 8px 20px; border-radius: 99px;
    background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow);
    transition: box-shadow .2s, border-color .2s;
    &:focus-within { border-color: var(--brand); box-shadow: 0 0 0 4px color-mix(in oklch, var(--brand) 22%, transparent), var(--shadow); }
    & input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; font: inherit; font-size: 18px; padding: 12px 0; color: var(--text); }
    @media (width < 720px) { & kbd { display: none; } }
    & kbd { font: 600 13px/1 inherit; padding: 6px 9px; border-radius: 8px; border: 1px solid var(--line); color: var(--muted); }
  }
  .popular {
    display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 18px; align-items: center;
    & span { color: var(--muted); font-size: 14px; margin-right: 4px; }
    & button {
      border: 1px solid var(--line); background: color-mix(in oklch, var(--surface) 75%, transparent);
      padding: 5px 13px; border-radius: 99px; font-size: 14px;
      &:hover { border-color: var(--brand); color: var(--brand); }
    }
  }
  .hero-float {
    position: absolute; inset: 0; pointer-events: none;
    & span {
      position: absolute; width: clamp(44px, 6vw, 76px); opacity: .9;
      filter: drop-shadow(0 10px 18px oklch(30% 0.1 280 / .25));
      animation: bob 6s ease-in-out infinite alternate; animation-delay: calc(var(--n) * -0.7s);
      rotate: calc((var(--n) - 4) * 4deg);
    }
    @media (width < 900px) { display: none; }
  }
  @keyframes bob { to { translate: 0 -16px; } }

  .toolbar {
    position: sticky; top: 61px; z-index: 10; margin: -28px 0 24px;
    display: flex; flex-wrap: wrap; align-items: center; gap: 14px 24px; padding: 14px 20px;
    background: color-mix(in oklch, var(--surface) 88%, transparent); backdrop-filter: blur(14px);
    border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
    & .group { display: flex; align-items: center; gap: 10px; min-width: 0; max-width: 100%; }
    & .seg { overflow-x: auto; max-width: 100%; scrollbar-width: none; }
    & .label { font-size: 13px; font-weight: 700; color: var(--muted); }
    & .sliders { gap: 16px; font-size: 13px; color: var(--muted); & label { display: flex; align-items: center; gap: 8px; } }
    & input[type=range] { width: 96px; accent-color: var(--brand); }
    & #reset { margin-left: auto; }
    @media (width < 720px) { position: static; padding: 14px; & .sliders { flex-wrap: wrap; } & #reset { margin-left: 0; } }
  }
  .seg {
    display: inline-flex; padding: 3px; border-radius: 12px; background: color-mix(in oklch, var(--line) 60%, transparent);
    & button { border: 0; background: none; padding: 6px 11px; border-radius: 9px; font-size: 13.5px; color: var(--muted); white-space: nowrap; }
    & button.on { background: var(--surface); color: var(--text); font-weight: 700; box-shadow: 0 1px 3px oklch(0% 0 0 / .12); }
    &.mini { margin-top: 14px; }
  }
  .swatches {
    display: flex; flex-wrap: wrap; gap: 6px;
    & button {
      width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--surface); padding: 0;
      background: linear-gradient(135deg, var(--a), var(--b)); box-shadow: 0 0 0 1px var(--line);
      transition: scale .15s;
      &:hover { scale: 1.15; }
      &.on { box-shadow: 0 0 0 2px var(--text); }
      &.auto { background: conic-gradient(#ff8787, #ffd43b, #69db7c, #4dabf7, #b197fc, #ff8787); font-size: 0; }
    }
  }

  .cats {
    display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; scrollbar-width: none;
    & button {
      flex: none; display: flex; align-items: center; gap: 6px; padding: 9px 16px; border-radius: 99px;
      border: 1px solid var(--line); background: var(--surface); font-size: 15px; font-weight: 600;
      & small { font-size: 12px; color: var(--muted); font-weight: 500; }
      &[aria-selected="true"] { background: var(--text); color: var(--bg); border-color: var(--text); & small { color: inherit; opacity: .7; } }
    }
  }
  .result { color: var(--muted); font-size: 14px; margin: 14px 2px; }

  .grid {
    list-style: none; margin: 0; padding: 0;
    display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 14px;
  }
  .card {
    container-type: inline-size;
    position: relative; width: 100%; display: flex; flex-direction: column; align-items: center; gap: 10px;
    padding: 20px 10px 14px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface);
    transition: translate .2s, box-shadow .2s, border-color .2s;
    & .art { width: 62%; aspect-ratio: 1; filter: drop-shadow(0 6px 10px oklch(30% 0.05 280 / .18)); transition: scale .25s cubic-bezier(.3, 1.6, .5, 1); }
    & .name { font-size: 14px; font-weight: 600; }
    & .quick {
      position: absolute; top: 8px; right: 8px; display: flex; gap: 4px; opacity: 0; translate: 0 -4px; transition: .2s;
      & span { font-size: 11px; font-weight: 700; padding: 3px 7px; border-radius: 7px; background: var(--text); color: var(--bg); }
      & span:hover { background: var(--brand); color: #fff; }
    }
    &:hover, &:focus-visible {
      translate: 0 -3px; box-shadow: var(--shadow); border-color: color-mix(in oklch, var(--brand) 40%, var(--line));
      & .art { scale: 1.08; }
      & .quick { opacity: 1; translate: 0; }
    }
    @container (width < 120px) { & .quick { display: none; } }
  }
  .empty { text-align: center; padding: 60px 0; color: var(--muted); font-size: 17px; }
  .link { border: 0; background: none; color: var(--brand); text-decoration: underline; padding: 0; }

  .how ol {
    list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 20px;
    & li { padding: 28px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); }
    & span {
      display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; font-weight: 800; color: #fff;
      background: linear-gradient(135deg, var(--brand), var(--brand-2));
    }
    & h3 { margin: 16px 0 6px; }
    & p { margin: 0; color: var(--muted); }
  }
  .faq details {
    background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 4px 22px; margin-bottom: 10px;
    & summary { cursor: pointer; font-weight: 700; padding: 14px 0; list-style: none; display: flex; justify-content: space-between; gap: 12px; }
    & summary::after { content: "+"; font-size: 22px; line-height: 1; color: var(--muted); transition: rotate .2s; }
    &[open] summary::after { rotate: 45deg; }
    & p { margin: 0 0 16px; color: var(--muted); }
  }

  button.ghost, .actions button {
    border: 1px solid var(--line); background: var(--surface); padding: 9px 16px; border-radius: 12px; font-weight: 600;
    &:hover { border-color: var(--brand); }
    &.small { padding: 6px 12px; font-size: 13px; }
  }
  #theme { padding: 6px 10px; }

  dialog {
    width: min(1040px, 94vw); max-height: 92vh; padding: 0; border: 0; border-radius: 26px;
    background: var(--surface); color: var(--text); box-shadow: 0 30px 80px oklch(0% 0 0 / .35);
    opacity: 1; translate: 0; transition: opacity .25s, translate .25s, overlay .25s allow-discrete, display .25s allow-discrete;
    @starting-style { &[open] { opacity: 0; translate: 0 24px; } }
    &::backdrop { background: oklch(15% 0.02 280 / .55); backdrop-filter: blur(4px); }
    & .close { position: absolute; top: 14px; right: 14px; z-index: 2; & button { border: 0; background: var(--bg); width: 38px; height: 38px; border-radius: 50%; font-size: 16px; } }
  }
  .d-body { display: grid; grid-template-columns: 1fr 1fr; max-height: 92vh; overflow: auto; @media (width < 820px) { grid-template-columns: 1fr; } }
  .d-preview {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px; padding: 36px 24px;
    background: color-mix(in oklch, var(--line) 45%, var(--bg));
  }
  .d-big { width: 168px; filter: drop-shadow(0 16px 26px oklch(25% 0.05 280 / .3)); }
  .phone {
    width: 250px; padding: 9px; border-radius: 38px; background: #0d0e12; box-shadow: 0 20px 40px oklch(0% 0 0 / .3);
    --wall: linear-gradient(160deg, #e9e4ff, #ffe3ef 60%, #e0f7ff);
    &[data-wall="dark"] { --wall: linear-gradient(160deg, #1d1b3a, #0f1420); --app-text: #fff; }
    &[data-wall="photo"] { --wall: linear-gradient(180deg, #7fb2e5 0%, #f5c38b 55%, #3d6b4f 56%, #24452f); --app-text: #fff; }
  }
  .phone-screen { border-radius: 30px; padding: 12px 14px 12px; background: var(--wall); color: var(--app-text, #1a1a1a); }
  .phone-time { font-size: 12px; font-weight: 700; margin: 0 0 14px 8px; }
  .phone-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px 8px; }
  .phone-grid .app { display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 9px; text-align: center; line-height: 1.2; }
  .phone-grid .app svg { width: 44px; height: 44px; }
  .phone-grid .app.me svg { animation: pop 1.6s ease-in-out infinite; }
  @keyframes pop { 50% { scale: 1.12; } }
  .phone-dock {
    display: grid; grid-template-columns: repeat(4, 1fr); justify-items: center; margin-top: 18px; padding: 9px 4px; border-radius: 22px;
    background: oklch(100% 0 0 / .35); backdrop-filter: blur(6px);
    & svg { width: 40px; height: 40px; }
  }
  .d-side { padding: 40px 36px 32px; & h2 { font-size: 32px; margin: 2px 0 6px; } & h3 { font-size: 16px; margin: 28px 0 10px; } }
  .d-cat { margin: 0; color: var(--brand); font-weight: 700; font-size: 14px; }
  .d-tags { margin: 0 0 20px; color: var(--muted); font-size: 13.5px; }
  .field {
    display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 16px;
    & input { font: inherit; font-size: 15px; font-weight: 500; color: var(--text); padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); }
    & .seg { align-self: flex-start; }
  }
  .actions {
    display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
    & button { padding: 12px; }
    & .primary { background: var(--text); color: var(--bg); border-color: var(--text); }
    & .accent { grid-column: 1 / -1; color: #fff; border: 0; background: linear-gradient(90deg, var(--brand), var(--brand-2)); }
    & .ghost { grid-column: 1 / -1; }
  }
  .hint { font-size: 13px; color: var(--muted); }
  .related {
    list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px;
    & button { border: 0; background: none; padding: 4px; border-radius: 12px; &:hover { background: var(--bg); } }
  }

  .toast {
    position: fixed; left: 50%; bottom: 28px; z-index: 100; translate: -50% 20px; opacity: 0; pointer-events: none;
    padding: 12px 20px; border-radius: 14px; background: var(--text); color: var(--bg); font-weight: 600; transition: .25s;
    &.show { opacity: 1; translate: -50% 0; }
  }
}
