/* ==========================================================================
   知乐物 · base.css
   reset + CSS 变量 + 排版 + 工具类
   全站唯一允许出现 hex 色值、间距原始值的位置
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. 设计令牌
   -------------------------------------------------------------------------- */
:root {
  /* ========== 品牌主色：松墨绿 ========== */
  --color-primary:        #2D5A4E;
  --color-primary-dark:   #234A40;
  --color-primary-darker: #1B3A32;
  --color-primary-light:  #EAF1ED;
  --color-primary-mid:    #4F7C6E;

  /* ========== 强调色：蜜蜡金（仅底色/图标，不做文字） ========== */
  --color-accent:         #B8860B;
  --color-accent-strong:  #8A5D0F;
  --color-accent-light:   #F8EFDC;

  /* ========== 语义色 ========== */
  --color-price:          #C0392B;
  --color-price-dark:     #A32B1E;
  --color-success:        #1E7A4D;
  --color-success-bg:     #E7F3EC;
  --color-warning:        #96600F;
  --color-warning-bg:     #FBF0DE;
  --color-danger:         #B02A1E;
  --color-danger-bg:      #FBEAE7;
  --color-info:           #245E86;
  --color-info-bg:        #E9F1F7;

  /* ========== 中性色阶（暖灰） ========== */
  --color-white:          #FFFFFF;
  --color-paper:          #FBF9F5;
  --color-sand-50:        #F5F1EA;
  --color-sand-100:       #EDE7DC;
  --color-sand-200:       #E2DACD;
  --color-sand-300:       #CFC5B4;
  --color-ink-400:        #8C8375;
  --color-ink-450:        #7A7164;
  --color-ink-500:        #6E6558;
  --color-ink-600:        #5C5449;
  --color-ink-700:        #3E3831;
  --color-ink-800:        #262220;
  --color-ink-900:        #16130F;
  --color-ink-mute:       #B9B2A7;   /* 仅用于深色底合规行 */

  /* ========== 语义别名（组件只许用这一层） ========== */
  --text-strong:      var(--color-ink-900);
  --text-body:        var(--color-ink-700);
  --text-muted:       var(--color-ink-500);
  --text-faint:       var(--color-ink-400);
  --text-placeholder: var(--color-ink-450);
  --text-inverse:     var(--color-white);
  --text-link:        var(--color-primary);
  --text-price:       var(--color-price);

  --bg-page:    var(--color-paper);
  --bg-surface: var(--color-white);
  --bg-subtle:  var(--color-sand-50);
  --bg-inset:   var(--color-sand-100);
  --bg-inverse: var(--color-ink-800);
  --bg-overlay: rgba(22, 19, 15, 0.48);

  --border-subtle:  var(--color-sand-100);
  --border-default: var(--color-sand-200);
  --border-strong:  var(--color-sand-300);
  --border-inverse: rgba(255, 255, 255, 0.16);

  /* ========== 焦点 ========== */
  --focus-ring:        0 0 0 3px rgba(45, 90, 78, 0.30);
  --focus-ring-danger: 0 0 0 3px rgba(176, 42, 30, 0.26);

  /* ========== 字体 ========== */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", "Source Han Sans SC",
               "Noto Sans CJK SC", "WenQuanYi Micro Hei", sans-serif;
  --font-num: "Helvetica Neue", "Segoe UI", Arial, "PingFang SC", sans-serif;

  /* ========== 字号阶梯 ========== */
  --fs-display:   2.25rem;
  --fs-price-xl:  2.125rem;
  --fs-h1:        1.75rem;
  --fs-h2:        1.375rem;
  --fs-h3:        1.125rem;
  --fs-h4:        1rem;
  --fs-price-lg:  1.625rem;
  --fs-price:     1.25rem;
  --fs-body-lg:   1.0625rem;
  --fs-body:      0.9375rem;
  --fs-body-sm:   0.875rem;
  --fs-price-sm:  1rem;
  --fs-caption:   0.8125rem;
  --fs-micro:     0.75rem;
  --fs-overline:  0.75rem;

  /* ========== 间距（4px 基准） ========== */
  --sp-0:  0;
  --sp-1:  4px;
  --sp-2:  8px;
  --sp-3:  12px;
  --sp-4:  16px;
  --sp-5:  20px;
  --sp-6:  24px;
  --sp-7:  32px;
  --sp-8:  40px;
  --sp-9:  48px;
  --sp-10: 64px;
  --sp-11: 80px;
  --sp-12: 96px;

  /* ========== 容器与栅格 ========== */
  --container:        1200px;
  --container-narrow: 760px;
  --gutter:           16px;
  --grid-gap:         12px;
  --sidebar-w:        232px;
  --sidebar-gap:      32px;

  /* ========== 圆角 ========== */
  --radius-xs:   2px;
  --radius-sm:   4px;
  --radius-md:   6px;
  --radius-lg:   10px;
  --radius-xl:   16px;
  --radius-pill: 999px;

  /* ========== 阴影（暖褐，禁止纯黑） ========== */
  --shadow-1: 0 1px 2px rgba(38, 34, 32, 0.06), 0 1px 1px rgba(38, 34, 32, 0.04);
  --shadow-2: 0 2px 8px rgba(38, 34, 32, 0.08), 0 1px 2px rgba(38, 34, 32, 0.04);
  --shadow-3: 0 8px 24px rgba(38, 34, 32, 0.10), 0 2px 6px rgba(38, 34, 32, 0.05);
  --shadow-4: 0 16px 48px rgba(38, 34, 32, 0.14), 0 4px 12px rgba(38, 34, 32, 0.06);
  --shadow-up: 0 -2px 12px rgba(38, 34, 32, 0.07);

  /* ========== 动效 ========== */
  --ease-out:    cubic-bezier(.2, .7, .3, 1);
  --ease-in-out: cubic-bezier(.4, 0, .2, 1);
  --ease-linear: linear;
  --dur-fast:    150ms;
  --dur-base:    180ms;
  --dur-slow:    280ms;

  /* ========== 结构尺寸 ========== */
  --h-header:        52px;
  --h-tabbar:        56px;   /* Tab 栏内容高度（.tabbar__item 用这个值） */
  --h-tabbar-total:  57px;   /* Tab 栏实际占位 = 56 + 1px 上边框；body 留白必须用这个 */
  --h-bar:           64px;
}

@media (min-width: 768px) {
  :root {
    --gutter: 24px;
    --grid-gap: 20px;
    --h-header: 68px;
  }
}

@media (min-width: 1024px) {
  :root {
    --fs-display:  2.5rem;
    --fs-price-xl: 2.5rem;
    --fs-h1:       2.125rem;
    --fs-h2:       1.75rem;
    --fs-h3:       1.25rem;
    --fs-body-lg:  1.125rem;
    --fs-body:     1rem;
    --fs-price-lg: 1.625rem;
    --fs-price:    1.375rem;
    --gutter: 32px;
    --grid-gap: 24px;
    --h-header: 72px;
  }
}

@media (min-width: 1280px) {
  :root { --gutter: 40px; }
}

/* --------------------------------------------------------------------------
   2. 重置
   -------------------------------------------------------------------------- */
*,
*::before,
*::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: auto;
}

html,
body { margin: 0; padding: 0; }

body {
  min-height: 100%;
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  line-height: 1.72;
  font-weight: 400;
  letter-spacing: 0.01em;
  color: var(--text-body);
  background-color: var(--bg-page);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  padding-bottom: 0;
}

/* 底部 Tab 栏占位 —— 只在 Tab 栏真实存在的区间保留
   断点必须与 .tabbar 的 display 区间严格对齐（components.css：≥768 隐藏）。
   否则桌面端 <body> 会一直挂着 57px 的空白，页脚下方出现一条死白边。 */
@media (max-width: 767px) {
  body { padding-bottom: calc(var(--h-tabbar-total) + env(safe-area-inset-bottom, 0px)); }
  /* 流程页（cart / checkout / pay / pay-result）不渲染 Tab 栏，取消其占位 */
  body.is-flow { padding-bottom: 0; }
}

h1, h2, h3, h4, h5, h6, p, figure, blockquote, dl, dd, ol, ul {
  margin: 0;
  padding: 0;
}

ol, ul { list-style: none; }

h1 { font-size: var(--fs-h1); line-height: 1.28; font-weight: 700; color: var(--text-strong); letter-spacing: 0; }
h2 { font-size: var(--fs-h2); line-height: 1.36; font-weight: 700; color: var(--text-strong); letter-spacing: 0; }
h3 { font-size: var(--fs-h3); line-height: 1.44; font-weight: 600; color: var(--text-strong); letter-spacing: 0; }
h4 { font-size: var(--fs-h4); line-height: 1.50; font-weight: 600; color: var(--text-strong); letter-spacing: 0; }

/* H1 分档：流程页与长标题页 */
.page-flow h1    { font-size: 1.5rem; }
.page-product h1 { font-size: 1.375rem; }

@media (min-width: 1024px) {
  .page-flow h1    { font-size: var(--fs-h1); }
  .page-product h1 { font-size: 1.875rem; }
}

p { margin-bottom: var(--sp-4); }
p:last-child { margin-bottom: 0; }

a {
  color: var(--text-link);
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

a:hover { color: var(--color-primary-dark); }

img, svg, video { display: block; max-width: 100%; }
img { border: 0; }
svg { flex-shrink: 0; }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  margin: 0;
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

input, select, textarea {
  font: inherit;
  color: inherit;
  margin: 0;
}

input[type="search"]::-webkit-search-cancel-button { -webkit-appearance: none; }

table { border-collapse: collapse; border-spacing: 0; width: 100%; }

hr {
  border: 0;
  border-top: 1px solid var(--border-subtle);
  margin: var(--sp-6) 0;
}

strong, b { font-weight: 600; }
em, i { font-style: normal; }

/* 数字 & 金额统一等宽 */
.price,
.num,
table td.n,
.tabular {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
}

/* --------------------------------------------------------------------------
   3. 焦点可见（WCAG AA）
   -------------------------------------------------------------------------- */
/* hidden 属性优先于组件的 display:flex/grid，避免隐藏态仍占位 */
[hidden] { display: none !important; }

:focus-visible {
  outline: 2px solid transparent;
  outline-offset: 2px;
  box-shadow: var(--focus-ring);
  border-radius: inherit;
}

.on-dark :focus-visible { box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.55); }

/* 跳到主要内容 */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 1000;
  padding: var(--sp-3) var(--sp-4);
  background: var(--color-ink-900);
  color: var(--color-white);
  border-radius: var(--radius-md);
  font-size: var(--fs-body-sm);
  font-weight: 600;
  text-decoration: none;
}
.skip-link:focus {
  left: var(--sp-4);
  top: var(--sp-2);
  color: var(--color-white);
}

/* --------------------------------------------------------------------------
   4. 布局工具类
   -------------------------------------------------------------------------- */
.container {
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: var(--gutter);
  box-sizing: border-box;
}

.container--narrow {
  max-width: calc(var(--container-narrow) + var(--gutter) * 2);
}

.section { padding-block: var(--sp-7); }
@media (min-width: 1024px) { .section { padding-block: var(--sp-11); } }

.section--tight { padding-block: var(--sp-6); }
.section--subtle { background: var(--bg-subtle); }
.section--paper { background: var(--bg-page); }

.stack > * + * { margin-top: var(--sp-4); }
.stack-sm > * + * { margin-top: var(--sp-2); }
.stack-lg > * + * { margin-top: var(--sp-6); }

.flex { display: flex; }
.flex-center { display: flex; align-items: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
.gap-1 { gap: var(--sp-1); }
.gap-2 { gap: var(--sp-2); }
.gap-3 { gap: var(--sp-3); }
.gap-4 { gap: var(--sp-4); }
.gap-6 { gap: var(--sp-6); }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--grid-gap); }
.grid-3 { display: grid; grid-template-columns: repeat(1, minmax(0, 1fr)); gap: var(--grid-gap); }
.grid-4 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--grid-gap); }

@media (min-width: 768px) {
  .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid-4 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (min-width: 1024px) {
  .grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

.mt-0 { margin-top: 0; }
.mt-2 { margin-top: var(--sp-2); }
.mt-3 { margin-top: var(--sp-3); }
.mt-4 { margin-top: var(--sp-4); }
.mt-5 { margin-top: var(--sp-5); }
.mt-6 { margin-top: var(--sp-6); }
.mt-7 { margin-top: var(--sp-7); }
.mt-8 { margin-top: var(--sp-8); }
.mb-0 { margin-bottom: 0; }
.mb-2 { margin-bottom: var(--sp-2); }
.mb-3 { margin-bottom: var(--sp-3); }
.mb-4 { margin-bottom: var(--sp-4); }
.mb-6 { margin-bottom: var(--sp-6); }

.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.text-faint { color: var(--text-faint); }
.text-strong { color: var(--text-strong); }
.text-sm { font-size: var(--fs-body-sm); }
.text-caption { font-size: var(--fs-caption); }
.text-micro { font-size: var(--fs-micro); }
.text-lg { font-size: var(--fs-body-lg); }
.w-full { width: 100%; }
.nowrap { white-space: nowrap; }
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.prose { max-width: 34em; }
.prose-lg { max-width: 36em; }
.prose p { margin-bottom: var(--sp-4); }
.prose p:last-child { margin-bottom: 0; }

/* --------------------------------------------------------------------------
   5. 眉标 / 区块标题
   -------------------------------------------------------------------------- */
.overline {
  display: block;
  font-size: var(--fs-overline);
  line-height: 1.4;
  font-weight: 600;
  letter-spacing: 0.14em;
  color: var(--text-muted);
  margin-bottom: var(--sp-2);
}

.section-head { margin-bottom: var(--sp-6); }
@media (min-width: 1024px) { .section-head { margin-bottom: var(--sp-8); } }

.section-head__desc {
  font-size: var(--fs-body);
  line-height: 1.72;
  color: var(--text-muted);
  max-width: 34em;
  margin-top: var(--sp-2);
}

.section-head--row {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}
@media (min-width: 768px) {
  .section-head--row {
    flex-direction: row;
    align-items: flex-end;
    justify-content: space-between;
  }
}

/* --------------------------------------------------------------------------
   6. 动效降级
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .card:hover { transform: none; }
  .btn:active { transform: none; }
  .media > img { transform: none !important; }
  .skeleton { animation: none; background: var(--bg-inset); }
}

/* --------------------------------------------------------------------------
   7. 打印
   -------------------------------------------------------------------------- */
@media print {
  .site-header,
  .tabbar,
  .action-bar,
  .toast {
    display: none !important;
  }
  body { padding-bottom: 0; background: #fff; }
}
