/* =========================================================
   CSS Development Lab 20
   Dark Mode + Design Tokens
   ========================================================= */

:root {
  /* Primitive tokens */
  --white: #ffffff;
  --black: #171717;

  /* Semantic color tokens - Light */
  --bg: #f7f7f4;
  --surface: #ffffff;
  --surface-2: #efefea;
  --text: #171717;
  --muted: #676863;
  --border: #dfdfd8;
  --accent: #171717;
  --accent-text: #ffffff;
  --shadow: 0 18px 44px rgba(0, 0, 0, .08);

  /* Layout tokens */
  --page-max: 1200px;
  --space-section: clamp(72px, 10vw, 132px);

  /* Shape tokens */
  --radius-sm: 14px;
  --radius-md: 20px;
  --radius-lg: 28px;

  color-scheme: light;
}

/*
 * 默认跟随系统。
 * 只在用户没有手动设置 data-theme 时生效。
 */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #101112;
    --surface: #181a1c;
    --surface-2: #222427;
    --text: #f4f4f2;
    --muted: #a8aaa5;
    --border: #303236;
    --accent: #f2f2ef;
    --accent-text: #151617;
    --shadow: 0 20px 50px rgba(0, 0, 0, .28);

    color-scheme: dark;
  }
}

/* 手动浅色 */
:root[data-theme="light"] {
  --bg: #f7f7f4;
  --surface: #ffffff;
  --surface-2: #efefea;
  --text: #171717;
  --muted: #676863;
  --border: #dfdfd8;
  --accent: #171717;
  --accent-text: #ffffff;
  --shadow: 0 18px 44px rgba(0, 0, 0, .08);

  color-scheme: light;
}

/* 手动深色 */
:root[data-theme="dark"] {
  --bg: #101112;
  --surface: #181a1c;
  --surface-2: #222427;
  --text: #f4f4f2;
  --muted: #a8aaa5;
  --border: #303236;
  --accent: #f2f2ef;
  --accent-text: #151617;
  --shadow: 0 20px 50px rgba(0, 0, 0, .28);

  color-scheme: dark;
}

/* ---------- Reset ---------- */

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

html {
  scroll-behavior: smooth;
}

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

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

button {
  font: inherit;
  color: inherit;
}

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

code,
pre {
  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: var(--muted);
  font-size: .78rem;
  font-weight: 800;
  letter-spacing: .15em;
}

/* ---------- Header ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(14px);
}

.header-inner {
  min-height: 70px;
  display: flex;
  align-items: center;
  gap: 20px;
}

.brand {
  font-weight: 850;
  letter-spacing: -.025em;
}

.theme-toggle {
  margin-left: auto;
  min-height: 42px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  cursor: pointer;
}

.theme-icon {
  width: 16px;
  height: 16px;
}

.icon-moon {
  display: none;
}

:root[data-theme="dark"] .icon-sun {
  display: none;
}

:root[data-theme="dark"] .icon-moon {
  display: block;
}

/* 系统暗色且还没有手动主题 */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .icon-sun {
    display: none;
  }

  :root:not([data-theme]) .icon-moon {
    display: block;
  }
}

.theme-toggle span {
  font-size: .82rem;
  font-weight: 760;
}

/* ---------- Hero ---------- */

.hero {
  padding-block:
    clamp(76px, 11vw, 145px)
    clamp(72px, 9vw, 112px);
}

.hero-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, .85fr);
  align-items: center;
  gap: clamp(42px, 8vw, 110px);
}

.hero-copy h1,
.section-head h2,
.strategy-copy h2,
.code-grid h2,
.rules-head h2 {
  margin: 0;
  line-height: 1.03;
  letter-spacing: -.05em;
}

.hero-copy h1 {
  max-width: 11ch;
  font-size: clamp(2.8rem, 7vw, 6rem);
}

.hero-desc {
  max-width: 760px;
  margin: 24px 0 0;
  color: var(--muted);
  font-size: clamp(1rem, 1.5vw, 1.16rem);
}

.hero-actions {
  margin-top: 30px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.button {
  min-height: 44px;
  padding: 0 17px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  font-size: .88rem;
  font-weight: 760;
}

.button-primary {
  border: 1px solid var(--accent);
  color: var(--accent-text);
  background: var(--accent);
}

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

/* ---------- Theme preview ---------- */

.theme-preview {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.preview-toolbar {
  min-height: 54px;
  padding: 0 18px;
  display: flex;
  align-items: center;
  gap: 7px;
  border-bottom: 1px solid var(--border);
}

.preview-toolbar span {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted);
  opacity: .35;
}

.preview-body {
  padding: clamp(24px, 5vw, 48px);
  display: grid;
  gap: 14px;
}

.preview-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.preview-block {
  min-height: 92px;
  border-radius: var(--radius-sm);
  background:
    linear-gradient(135deg, var(--surface-2), color-mix(in srgb, var(--surface-2) 65%, var(--muted)));
}

.preview-block.large {
  min-height: 210px;
}

/* ---------- Common sections ---------- */

.tokens-section,
.component-section {
  padding-block: var(--space-section);
}

.tokens-section {
  border-top: 1px solid var(--border);
}

.component-section {
  background: var(--surface-2);
}

.section-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, .78fr);
  align-items: end;
  gap: clamp(28px, 6vw, 80px);
}

.section-head h2,
.strategy-copy h2,
.code-grid h2,
.rules-head h2 {
  font-size: clamp(2rem, 4.5vw, 4.5rem);
}

.section-head > p,
.strategy-copy > p {
  margin: 0;
  color: var(--muted);
}

/* ---------- Token cards ---------- */

.token-grid {
  margin-top: 40px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.token-card {
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.token-dot {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--border);
}

.dot-bg { background: var(--bg); }
.dot-surface { background: var(--surface); }
.dot-text { background: var(--text); }
.dot-muted { background: var(--muted); }
.dot-border { background: var(--border); }
.dot-accent { background: var(--accent); }

.token-card strong {
  display: block;
  font-size: .9rem;
}

.token-card p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: .82rem;
}

/* ---------- Component demo ---------- */

.component-grid {
  margin-top: 42px;
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(300px, .85fr);
  gap: 18px;
}

.product-card,
.info-panel {
  border: 1px solid var(--border);
  background: var(--surface);
}

.product-card {
  overflow: hidden;
  display: grid;
  grid-template-columns: minmax(220px, 42%) minmax(0, 1fr);
  border-radius: var(--radius-lg);
}

.product-media {
  min-height: 360px;
}

.product-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.product-body {
  padding: clamp(26px, 4vw, 44px);
  display: flex;
  flex-direction: column;
}

.tag {
  align-self: flex-start;
  padding: 5px 9px;
  border-radius: 999px;
  color: var(--muted);
  background: var(--surface-2);
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .08em;
}

.product-body h3 {
  margin: 18px 0 0;
  font-size: clamp(1.6rem, 3vw, 2.7rem);
  line-height: 1.1;
  letter-spacing: -.035em;
}

.product-body p {
  margin: 14px 0 0;
  color: var(--muted);
}

.product-actions {
  margin-top: auto;
  padding-top: 28px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.panel-stack {
  display: grid;
  gap: 12px;
}

.info-panel {
  min-height: 130px;
  padding: 22px;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
  border-radius: var(--radius-md);
}

.info-panel > span {
  color: var(--muted);
  font-size: .76rem;
  font-weight: 800;
}

.info-panel h3 {
  margin: 0;
  font-size: 1rem;
}

.info-panel p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: .86rem;
}

/* ---------- Strategy ---------- */

.strategy-section {
  padding-block: var(--space-section);
}

.strategy-grid {
  padding: clamp(28px, 6vw, 62px);
  display: grid;
  grid-template-columns: minmax(0, .85fr) minmax(320px, 1.15fr);
  align-items: center;
  gap: clamp(36px, 7vw, 90px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.strategy-copy > p {
  margin-top: 22px;
}

.strategy-list {
  display: grid;
  gap: 10px;
}

.strategy-list > div {
  padding: 17px 18px;
  display: grid;
  gap: 4px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.strategy-list strong {
  font-size: .9rem;
}

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

/* ---------- Code ---------- */

.code-section {
  padding-bottom: var(--space-section);
}

.code-grid {
  display: grid;
  grid-template-columns: minmax(0, .8fr) minmax(360px, 1.2fr);
  align-items: center;
  gap: clamp(36px, 7vw, 90px);
}

.code-card {
  min-width: 0;
  overflow-x: auto;
  border-radius: var(--radius-md);
  background: #111315;
}

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

.code-card code {
  color: #f4f4f2;
  font-size: clamp(.8rem, 1.4vw, .94rem);
  line-height: 1.75;
}

/* ---------- Rules ---------- */

.rules-section {
  padding-bottom: clamp(90px, 12vw, 150px);
}

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

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

.rules-grid article {
  min-height: 220px;
  padding: 22px;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.rules-grid span {
  color: var(--muted);
  font-size: .76rem;
  font-weight: 800;
}

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

.rules-grid p {
  margin: 0;
  color: var(--muted);
  font-size: .88rem;
}

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

@media (max-width: 920px) {
  .hero-grid,
  .section-head,
  .component-grid,
  .strategy-grid,
  .code-grid {
    grid-template-columns: 1fr;
  }

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

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

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

  .theme-toggle span {
    display: none;
  }

  .theme-toggle {
    width: 42px;
    padding: 0;
    justify-content: center;
  }

  .product-card {
    grid-template-columns: 1fr;
  }

  .product-media {
    min-height: 0;
    aspect-ratio: 4 / 3;
  }

  .token-grid,
  .rules-grid {
    grid-template-columns: 1fr;
  }

  .hero-actions,
  .product-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .button {
    width: 100%;
  }

  .strategy-grid {
    padding: 24px;
  }
}

:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    transition-duration: .01ms !important;
  }
}
