/* =========================================================
   CSS Development Lab 12
   Drawer / Offcanvas
   ========================================================= */

:root {
  --page-max: 1200px;
  --text: #171717;
  --muted: #686868;
  --line: #e5e5df;
  --surface: #ffffff;
  --soft: #f5f5f1;
  --dark: #171717;
  --radius: 20px;
  --drawer-width: min(88vw, 430px);
  --shadow: -26px 0 70px rgba(0, 0, 0, .18);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  color: var(--text);
  background: var(--surface);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  line-height: 1.65;
}

body.drawer-open {
  overflow: hidden;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

img {
  display: block;
  max-width: 100%;
}

a {
  color: inherit;
  text-decoration: none;
}

.page-wrap {
  width: min(calc(100% - 40px), var(--page-max));
  margin-inline: auto;
}

.eyebrow {
  margin: 0 0 14px;
  color: #858585;
  font-size: .78rem;
  font-weight: 800;
  letter-spacing: .15em;
}

.intro {
  padding: clamp(72px, 10vw, 130px) 0 clamp(58px, 8vw, 90px);
  background:
    radial-gradient(circle at 86% 14%, rgba(0,0,0,.05), transparent 27%),
    linear-gradient(180deg, #fafaf8 0%, #f3f3ef 100%);
}

.intro-inner {
  max-width: 980px;
}

.intro h1,
.lab-copy h2,
.explain h2,
.usage-head h2 {
  margin: 0;
  line-height: 1.04;
  letter-spacing: -.045em;
}

.intro h1 {
  font-size: clamp(2.8rem, 7vw, 6rem);
}

.intro-desc {
  max-width: 820px;
  margin: 24px 0 0;
  color: var(--muted);
  font-size: clamp(1rem, 1.7vw, 1.18rem);
}

/* ---------- Demo ---------- */

.lab {
  padding: clamp(80px, 10vw, 130px) 0;
}

.lab-grid {
  display: grid;
  grid-template-columns: minmax(0, .72fr) minmax(420px, 1.28fr);
  align-items: start;
  gap: clamp(40px, 8vw, 110px);
}

.lab-copy {
  position: sticky;
  top: 32px;
}

.lab-copy h2,
.explain h2,
.usage-head h2 {
  font-size: clamp(2rem, 4.5vw, 4.5rem);
}

.lab-copy > p,
.explain-grid > div:first-child > p:last-child {
  margin: 22px 0 0;
  color: var(--muted);
}

.tips {
  margin-top: 30px;
  display: grid;
  gap: 10px;
}

.tips > div {
  padding: 16px 18px;
  display: grid;
  gap: 3px;
  border-radius: 14px;
  background: var(--soft);
}

.tips strong {
  font-size: .88rem;
}

.tips span {
  color: var(--muted);
  font-size: .84rem;
}

.demo-grid {
  display: grid;
  gap: 16px;
}

.demo-card {
  min-height: 180px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.demo-card > span {
  color: #999;
  font-size: .78rem;
  font-weight: 800;
}

.demo-card h3 {
  margin: 24px 0 8px;
  font-size: 1.3rem;
}

.demo-card p {
  margin: 0;
  color: var(--muted);
}

.demo-card button {
  margin-top: auto;
  align-self: flex-start;
  min-height: 44px;
  padding: 0 17px;
  border: 0;
  border-radius: 999px;
  color: #fff;
  background: var(--dark);
  font-weight: 750;
  cursor: pointer;
}

/* ---------- Drawer backdrop ---------- */

.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 190;
  background: rgba(0, 0, 0, .48);
  opacity: 0;
  transition: opacity 260ms ease;
}

.drawer-backdrop.is-visible {
  opacity: 1;
}

/* ---------- Drawer ---------- */

.drawer {
  position: fixed;
  inset-block: 0;
  right: 0;
  z-index: 200;
  width: var(--drawer-width);
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: #fff;
  box-shadow: var(--shadow);
  transform: translateX(100%);
  visibility: hidden;
  transition:
    transform 300ms cubic-bezier(.2,.8,.2,1),
    visibility 300ms;
}

.drawer.is-open {
  transform: translateX(0);
  visibility: visible;
}

.drawer-head,
.drawer-foot {
  padding: 20px 22px;
  background: #fff;
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid var(--line);
}

.drawer-head .eyebrow {
  margin-bottom: 7px;
}

.drawer-head h2 {
  margin: 0;
  font-size: clamp(1.45rem, 3vw, 2rem);
  line-height: 1.1;
  letter-spacing: -.03em;
}

.icon-button {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  padding: 11px;
  border: 0;
  border-radius: 50%;
  background: var(--soft);
  cursor: pointer;
}

.icon-button img {
  width: 100%;
  height: 100%;
}

.drawer-body {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 20px 22px;
}

.drawer-foot {
  border-top: 1px solid var(--line);
}

.drawer-foot:empty {
  display: none;
}

/* ---------- Drawer content: nav ---------- */

.drawer-nav {
  display: grid;
}

.drawer-nav a {
  min-height: 56px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--line);
  font-size: 1rem;
  font-weight: 720;
}

.drawer-nav a:last-child {
  border-bottom: 0;
}

/* ---------- Drawer content: filter ---------- */

.filter-form {
  display: grid;
  gap: 28px;
}

.filter-form fieldset {
  margin: 0;
  padding: 0 0 22px;
  display: grid;
  gap: 12px;
  border: 0;
  border-bottom: 1px solid var(--line);
}

.filter-form legend {
  margin-bottom: 12px;
  padding: 0;
  font-weight: 800;
}

.filter-form label {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #505050;
}

.filter-form input {
  width: 18px;
  height: 18px;
}

/* ---------- Drawer content: cart ---------- */

.cart-list {
  display: grid;
  gap: 0;
}

.cart-item {
  padding: 16px 0;
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr);
  gap: 16px;
  border-bottom: 1px solid var(--line);
}

.cart-item:first-child {
  padding-top: 0;
}

.cart-thumb {
  aspect-ratio: 1;
  border-radius: 12px;
  background: linear-gradient(135deg, #ddd9d1, #aaa398);
}

.cart-thumb.alt {
  background: linear-gradient(135deg, #d4d9d5, #9fac9f);
}

.cart-thumb.dark {
  background: linear-gradient(135deg, #c9cbd0, #858a93);
}

.cart-item h3 {
  margin: 4px 0 6px;
  font-size: .96rem;
  line-height: 1.35;
}

.cart-item p {
  margin: 0;
  color: var(--muted);
  font-size: .84rem;
}

.drawer-action {
  width: 100%;
  min-height: 48px;
  border: 0;
  border-radius: 999px;
  color: #fff;
  background: var(--dark);
  font-weight: 760;
  cursor: pointer;
}

/* ---------- Explain ---------- */

.explain {
  padding: 0 0 clamp(90px, 11vw, 140px);
}

.explain-grid {
  padding: clamp(30px, 6vw, 64px);
  display: grid;
  grid-template-columns: minmax(0, .8fr) minmax(360px, 1.2fr);
  align-items: center;
  gap: clamp(36px, 7vw, 90px);
  border-radius: 28px;
  background: var(--soft);
}

.code-card {
  min-width: 0;
  overflow-x: auto;
  border-radius: 18px;
  background: #181818;
}

.code-card pre {
  margin: 0;
  padding: clamp(22px, 4vw, 34px);
}

.code-card code {
  color: #f2f2f2;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: clamp(.82rem, 1.5vw, .96rem);
  line-height: 1.75;
}

/* ---------- Use cases ---------- */

.usage {
  padding: 0 0 clamp(90px, 12vw, 150px);
}

.usage-head {
  max-width: 780px;
}

.usage-grid {
  margin-top: 38px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.usage-grid article {
  min-height: 180px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 18px;
}

.usage-grid span {
  font-size: .78rem;
  font-weight: 800;
  letter-spacing: .08em;
}

.usage-grid p {
  margin: auto 0 0;
  color: var(--muted);
  font-size: .9rem;
}

/* ---------- Responsive ---------- */

@media (max-width: 920px) {
  .lab-grid,
  .explain-grid {
    grid-template-columns: 1fr;
  }

  .lab-copy {
    position: static;
  }

  .usage-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  :root {
    --drawer-width: min(92vw, 430px);
  }

  .page-wrap {
    width: calc(100% - 28px);
  }

  .demo-card button {
    width: 100%;
  }

  .drawer-head,
  .drawer-body,
  .drawer-foot {
    padding-left: 18px;
    padding-right: 18px;
  }

  .explain-grid {
    padding: 24px;
  }

  .usage-grid {
    grid-template-columns: 1fr;
  }
}

:focus-visible {
  outline: 2px solid #171717;
  outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}
