/* =========================================================
   CSS Development Lab 11
   Modal / Lightbox
   ========================================================= */

:root {
  --page-max: 1200px;
  --text: #171717;
  --muted: #686868;
  --line: #e5e5df;
  --surface: #ffffff;
  --soft: #f5f5f1;
  --dark: #171717;
  --radius: 20px;
  --shadow: 0 28px 80px rgba(0, 0, 0, .22);
}

*,
*::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.has-modal {
  overflow: hidden;
}

button,
input,
textarea {
  font: inherit;
}

button {
  color: inherit;
}

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

code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

.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);
}

/* ---------- Main 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-stack {
  display: grid;
  gap: 18px;
}

.demo-card {
  overflow: hidden;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 24px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.demo-card:has(.demo-thumb) {
  grid-template-columns: 150px minmax(0, 1fr) auto;
}

.demo-thumb {
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border-radius: 14px;
  background: #ddd;
}

.demo-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.demo-copy {
  min-width: 0;
}

.demo-copy span {
  color: #999;
  font-size: .76rem;
  font-weight: 800;
}

.demo-copy h3 {
  margin: 8px 0 6px;
  font-size: 1.28rem;
}

.demo-copy p {
  margin: 0;
  color: var(--muted);
  font-size: .92rem;
}

.demo-button,
.primary-button,
.secondary-button {
  min-height: 44px;
  padding: 0 17px;
  border-radius: 999px;
  font-weight: 750;
  cursor: pointer;
}

.demo-button,
.primary-button {
  border: 0;
  color: #fff;
  background: var(--dark);
}

.secondary-button {
  border: 1px solid var(--line);
  background: #fff;
}

/* ---------- Native modal ---------- */

.modal-dialog,
.lightbox-dialog {
  border: 0;
  padding: 0;
  background: transparent;
}

.modal-dialog {
  width: min(calc(100% - 32px), 680px);
  max-height: min(86dvh, 760px);
  border-radius: 22px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.modal-dialog::backdrop,
.lightbox-dialog::backdrop {
  background: rgba(0, 0, 0, .62);
  backdrop-filter: blur(3px);
}

.modal-shell {
  max-height: min(86dvh, 760px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: #fff;
}

.modal-head,
.modal-foot {
  padding: 20px 24px;
  display: flex;
  align-items: center;
  gap: 18px;
  background: #fff;
}

.modal-head {
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.modal-head h2 {
  margin: 0;
  font-size: clamp(1.55rem, 3vw, 2.2rem);
  line-height: 1.15;
  letter-spacing: -.035em;
}

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

.icon-button,
.lightbox-close {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  padding: 11px;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
}

.icon-button {
  background: var(--soft);
}

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

.modal-body {
  min-height: 0;
  padding: 24px;
  overflow-y: auto;
}

.modal-body > p {
  margin: 0;
  color: var(--muted);
}

.modal-body > p + * {
  margin-top: 24px;
}

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

.form-demo label {
  display: grid;
  gap: 7px;
}

.form-demo label > span {
  font-size: .86rem;
  font-weight: 750;
}

.form-demo input,
.form-demo textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  color: inherit;
  background: #fff;
  resize: vertical;
}

.modal-foot {
  justify-content: flex-end;
  border-top: 1px solid var(--line);
}

/* ---------- Lightbox ---------- */

.lightbox-dialog {
  width: min(calc(100% - 32px), 1200px);
  max-width: 1200px;
  max-height: 92dvh;
}

.lightbox-shell {
  position: relative;
  display: grid;
  place-items: center;
}

.lightbox-image {
  max-width: 100%;
  max-height: 90dvh;
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.lightbox-close {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 2;
  background: rgba(20,20,20,.82);
}

.lightbox-close img {
  width: 100%;
  height: 100%;
}

/* ---------- Explanation ---------- */

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

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

.compare-list {
  display: grid;
  gap: 12px;
}

.compare-list > div {
  padding: 18px 20px;
  display: grid;
  gap: 4px;
  border-radius: 14px;
  background: #fff;
}

.compare-list strong {
  font-size: .94rem;
}

.compare-list span {
  color: var(--muted);
  font-size: .88rem;
}

/* ---------- 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: 190px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 18px;
}

.usage-grid span {
  color: #999;
  font-size: .78rem;
  font-weight: 800;
}

.usage-grid h3 {
  margin: auto 0 8px;
  font-size: 1.15rem;
}

.usage-grid p {
  margin: 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: 680px) {
  .page-wrap {
    width: calc(100% - 28px);
  }

  .demo-card,
  .demo-card:has(.demo-thumb) {
    grid-template-columns: 1fr;
  }

  .demo-thumb {
    width: 100%;
  }

  .demo-button {
    width: 100%;
  }

  .modal-dialog {
    width: calc(100% - 20px);
    max-height: 92dvh;
  }

  .modal-shell {
    max-height: 92dvh;
  }

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

  .modal-foot {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .explain-grid {
    padding: 24px;
  }

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

  .usage-grid article {
    min-height: 160px;
  }
}

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

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