/* ==========================================================================
   Java 面试题库 · 样式表
   结构：01 变量 / 02 基础 / 03 顶栏 / 04 布局与侧栏 / 05 通用组件
        06 首页 / 07 章节列表 / 08 题目详情 / 09 搜索 / 10 浮层 / 11 响应式 / 12 打印
   要点：手机端 16px 正文 + 1.75 行高、44px 点击区、代码块横向滚动不撑破页面。
   ========================================================================== */

/* --------------------------------------------------------------------------
   01 变量与主题
   -------------------------------------------------------------------------- */
:root {
  --bg: #f8fafc;
  --bg-soft: #f1f5f9;
  --card: #ffffff;
  --text: #1f2937;
  --text-strong: #0f172a;
  --muted: #6b7280;
  --line: #e5e7eb;

  --brand: #4f46e5;
  --brand-ink: #4338ca;
  --brand-soft: #eef2ff;

  --green: #16a34a;
  --green-soft: #dcfce7;
  --orange: #f59e0b;

  --topbar-bg: rgba(255, 255, 255, 0.88);
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 4px 14px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 14px 40px rgba(15, 23, 42, 0.16);

  --radius: 12px;
  --radius-sm: 8px;
  --topbar-h: 56px;
  --sidebar-w: 240px;

  --mono: "JetBrains Mono", Consolas, "Courier New", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei",
    "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  color-scheme: light;
}

html[data-theme="dark"] {
  --bg: #0f172a;
  --bg-soft: #16213a;
  --card: #1e293b;
  --text: #e2e8f0;
  --text-strong: #f1f5f9;
  --muted: #94a3b8;
  --line: #334155;

  --brand: #818cf8;
  --brand-ink: #a5b4fc;
  --brand-soft: #1e2a4a;

  --green: #4ade80;
  --green-soft: #14532d;

  --topbar-bg: rgba(15, 23, 42, 0.9);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 14px rgba(0, 0, 0, 0.24);
  --shadow-lg: 0 14px 40px rgba(0, 0, 0, 0.5);

  color-scheme: dark;
}

/* --------------------------------------------------------------------------
   02 基础重置
   -------------------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow-wrap: break-word;
}

[hidden] {
  display: none !important;
}

a {
  color: var(--brand);
  text-decoration: none;
}

a:hover {
  text-decoration: none;
}

h1, h2, h3, p, ul, ol, figure {
  margin: 0;
}

ul, ol {
  list-style: none;
  padding: 0;
}

img {
  max-width: 100%;
}

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: 4px;
}

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

.skip-link {
  position: absolute;
  left: 8px;
  top: -60px;
  z-index: 200;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  background: var(--brand);
  color: #fff;
}

.skip-link:focus {
  top: 8px;
}

.skeleton {
  padding: 48px 0;
  text-align: center;
  color: var(--muted);
}

.noscript,
.nosecript {
  margin: 24px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
}

/* --------------------------------------------------------------------------
   03 顶栏
   -------------------------------------------------------------------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 8px;
  height: var(--topbar-h);
  padding: 0 10px;
  padding-top: var(--safe-top);
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--line);
  -webkit-backdrop-filter: saturate(180%) blur(10px);
  backdrop-filter: saturate(180%) blur(10px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 1 auto;
  min-width: 0;
  color: var(--text-strong);
  font-weight: 600;
}

.brand-dot {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
}

.brand-name {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 15px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 0 0 auto;
  margin-left: auto;
}

/* 搜索框 */
.search {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  max-width: 520px;
}

.search-ico {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 13px;
  opacity: 0.55;
  pointer-events: none;
}

.search-input {
  width: 100%;
  height: 38px;
  padding: 0 34px 0 32px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-soft);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  -webkit-appearance: none;
  appearance: none;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}

.search-input::placeholder {
  color: var(--muted);
}

.search-input:focus {
  outline: none;
  border-color: var(--brand);
  background: var(--card);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

/* 去掉 Safari/Chrome 自带的清除按钮，用自定义的 */
.search-input::-webkit-search-cancel-button,
.search-input::-webkit-search-decoration {
  -webkit-appearance: none;
  appearance: none;
}

.search-clear {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
}

.search-clear:hover {
  background: var(--bg-soft);
  color: var(--text);
}

/* 搜索建议下拉 */
.suggest {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 60;
  max-height: min(60vh, 420px);
  overflow-y: auto;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow-lg);
}

.sg-item {
  display: block;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text);
}

.sg-item:hover,
.sg-item:focus {
  background: var(--bg-soft);
}

.sg-title {
  display: block;
  font-size: 14px;
  line-height: 1.45;
}

.sg-meta {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
}

.sg-empty {
  padding: 10px;
  font-size: 13px;
  color: var(--muted);
}

.sg-foot {
  margin-top: 4px;
  padding: 8px 10px 4px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
}

/* --------------------------------------------------------------------------
   04 布局与侧栏
   -------------------------------------------------------------------------- */
.layout {
  display: block;
}

.sidebar {
  background: var(--card);
  border-right: 1px solid var(--line);
  padding: 10px 8px 24px;
}

.sidebar-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px 10px;
}

.sidebar-title {
  font-size: 12px;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.drawer-close {
  display: none;
  margin-left: auto;
}

.ch-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.ch-link {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 44px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  transition: background 0.15s, color 0.15s;
}

.ch-link:hover {
  background: var(--bg-soft);
}

.ch-link.is-active {
  background: var(--brand-soft);
  color: var(--brand-ink);
  font-weight: 600;
}

.ch-link.is-active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 9px;
  bottom: 9px;
  width: 3px;
  border-radius: 2px;
  background: var(--brand);
}

.ch-link-name {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.ch-link-num {
  flex: 0 0 auto;
  min-width: 26px;
  text-align: right;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.ch-link.is-active .ch-link-num {
  color: var(--brand-ink);
}

.sidebar-foot {
  margin-top: 16px;
  padding: 12px 10px 0;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
}

.foot-title {
  margin-bottom: 6px;
}

.foot-text {
  margin-top: 6px;
}

.main {
  min-width: 0;
  padding: 20px 16px calc(72px + var(--safe-bottom));
}

/* 遮罩（手机抽屉） */
.scrim {
  position: fixed;
  inset: 0;
  z-index: 75;
  background: rgba(15, 23, 42, 0.45);
  border: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body.drawer-open {
  overflow: hidden;
}

body.no-scroll {
  overflow: hidden;
}

/* --------------------------------------------------------------------------
   05 通用组件
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.2;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.15s;
}

.btn:hover {
  background: var(--bg-soft);
}

.btn:active {
  transform: translateY(1px);
}

.btn.ghost {
  background: transparent;
  border-color: transparent;
}

.btn.ghost:hover {
  background: var(--bg-soft);
}

.btn.primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.btn.is-on {
  border-color: var(--green);
  background: var(--green-soft);
  color: var(--green);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s;
}

.icon-btn:hover {
  background: var(--bg-soft);
}

.random-btn {
  min-height: 40px;
  padding: 0 12px;
}

.random-lbl {
  font-size: 13px;
}

.search-toggle {
  display: none;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--bg-soft);
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.bar {
  height: 6px;
  border-radius: 999px;
  background: var(--bg-soft);
  overflow: hidden;
}

.bar > i {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: var(--brand);
  transition: width 0.25s ease;
}

.bar-wide {
  max-width: 320px;
  margin-top: 12px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--muted);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.chip[aria-pressed="true"] {
  border-color: var(--brand);
  background: var(--brand-soft);
  color: var(--brand-ink);
}

.crumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--muted);
}

.crumbs a {
  color: var(--muted);
}

.crumbs a:hover {
  color: var(--brand);
}

.crumb-sep {
  opacity: 0.6;
}

.crumb-cur {
  color: var(--text);
}

.page-head {
  margin-bottom: 18px;
}

.page-title {
  font-size: 24px;
  line-height: 1.35;
  font-weight: 700;
  color: var(--text-strong);
  overflow-wrap: break-word;
}

.page-sub {
  margin-top: 6px;
  font-size: 13px;
  color: var(--muted);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.empty {
  padding: 48px 16px;
  text-align: center;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: var(--card);
}

.empty-ico {
  font-size: 30px;
  line-height: 1;
  margin-bottom: 12px;
}

.empty-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-strong);
}

.empty-hint {
  margin: 8px auto 0;
  max-width: 460px;
  font-size: 14px;
  line-height: 1.7;
  color: var(--muted);
}

.empty-code {
  display: inline-block;
  margin-top: 14px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
  word-break: break-all;
}

.empty .btn {
  margin-top: 16px;
}

/* --------------------------------------------------------------------------
   06 首页：章节总览
   -------------------------------------------------------------------------- */
.hero {
  margin: 8px 0 20px;
}

.hero-title {
  font-size: 26px;
  font-weight: 700;
  line-height: 1.3;
  color: var(--text-strong);
}

.hero-sub {
  margin-top: 8px;
  font-size: 14px;
  color: var(--muted);
}

.hero-sub b {
  color: var(--text);
}

.hero-meta {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
  opacity: 0.85;
}

.ch-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 12px;
}

.ch-card {
  display: block;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
  box-shadow: var(--shadow);
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}

.ch-card:hover {
  border-color: var(--brand);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.ch-card-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.ch-idx {
  flex: 0 0 auto;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--brand);
  font-weight: 600;
}

.ch-name {
  min-width: 0;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.45;
  color: var(--text-strong);
  overflow-wrap: break-word;
}

.ch-card-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin: 10px 0 8px;
  font-size: 12px;
  color: var(--muted);
}

.ch-card-meta .is-done {
  color: var(--green);
}

/* --------------------------------------------------------------------------
   07 章节题目列表
   -------------------------------------------------------------------------- */
.q-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.q-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--text);
  transition: border-color 0.15s, background 0.15s, transform 0.15s;
}

.q-row:hover {
  border-color: var(--brand);
  background: var(--brand-soft);
}

.q-no {
  flex: 0 0 auto;
  min-width: 30px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.q-title {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 15px;
  line-height: 1.6;
  overflow-wrap: break-word;
}

.q-fav {
  margin-left: 6px;
  color: var(--orange);
  font-size: 12px;
}

.q-state {
  flex: 0 0 auto;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--line);
  transition: background 0.15s;
}

.q-row.is-mastered .q-state {
  background: var(--green);
  box-shadow: 0 0 0 3px var(--green-soft);
}

.q-row.is-mastered .q-no {
  color: var(--green);
}

/* --------------------------------------------------------------------------
   08 题目详情
   -------------------------------------------------------------------------- */
.q-nav-top {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.q-nav-top .crumbs {
  margin-bottom: 0;
}

.back-btn {
  flex: 0 0 auto;
  padding: 0 8px;
}

.q-kicker {
  font-size: 13px;
  color: var(--muted);
}

.q-title-main {
  margin-top: 6px;
  font-size: 24px;
}

.q-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.q-body {
  margin-top: 22px;
  font-size: 16px;
  line-height: 1.75;
}

.q-body > *:first-child {
  margin-top: 0;
}

.para {
  margin: 14px 0;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

.q-body ul,
.q-body ol {
  margin: 14px 0;
  padding-left: 22px;
  list-style: disc;
}

/* 代码块：深色底 + 工具条 + 横向滚动 */
.code {
  margin: 18px 0;
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: var(--radius);
  background: #0b1220;
  overflow: hidden;
}

.code-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 12px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.16);
  background: rgba(148, 163, 184, 0.09);
  color: #94a3b8;
  font-size: 12px;
  line-height: 1.6;
}

.code-lang {
  font-family: var(--mono);
  letter-spacing: 0.02em;
}

.code-copy {
  min-height: 28px;
  padding: 2px 10px;
  border: 1px solid rgba(148, 163, 184, 0.28);
  border-radius: 6px;
  background: transparent;
  color: #cbd5e1;
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.code-copy:hover {
  background: rgba(148, 163, 184, 0.16);
  color: #fff;
}

.code pre {
  margin: 0;
  padding: 14px 16px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.code code {
  display: block;
  white-space: pre;
  color: #e2e8f0;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.65;
  tab-size: 4;
}

/* 表格：容器内横向滚动 */
.table-wrap {
  margin: 18px 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  line-height: 1.65;
}

.tbl th,
.tbl td {
  padding: 8px 10px;
  border: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  overflow-wrap: break-word;
}

.tbl th {
  background: var(--bg-soft);
  font-weight: 600;
  color: var(--text-strong);
  white-space: nowrap;
}

/* 图片块 */
.fig {
  margin: 18px 0;
  text-align: center;
}

.fig img {
  max-width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  cursor: zoom-in;
}

/* 上一题 / 下一题 */
.pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 32px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.pager-btn {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  min-height: 62px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
  transition: border-color 0.15s, background 0.15s;
}

.pager-btn.next {
  text-align: right;
}

.pager-btn:not(.is-disabled):hover {
  border-color: var(--brand);
  background: var(--brand-soft);
}

.pager-btn.is-disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.pager-label {
  font-size: 12px;
  color: var(--muted);
}

.pager-title {
  font-size: 14px;
  line-height: 1.5;
  overflow-wrap: break-word;
}

/* --------------------------------------------------------------------------
   09 搜索结果
   -------------------------------------------------------------------------- */
.sr-group {
  margin-bottom: 22px;
}

.sr-group-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
}

.sr-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sr-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--text);
  transition: border-color 0.15s, background 0.15s;
}

.sr-row:hover {
  border-color: var(--brand);
  background: var(--brand-soft);
}

.sr-main {
  flex: 1 1 auto;
  min-width: 0;
}

.sr-title {
  display: block;
  font-size: 15px;
  line-height: 1.6;
  overflow-wrap: break-word;
}

.sr-snip {
  display: block;
  margin-top: 2px;
  font-size: 13px;
  line-height: 1.65;
  color: var(--muted);
  overflow-wrap: break-word;
}

mark {
  padding: 0 1px;
  border-radius: 3px;
  background: #fde68a;
  color: #78350f;
}

html[data-theme="dark"] mark {
  background: #a16207;
  color: #fef3c7;
}

/* --------------------------------------------------------------------------
   10 浮层：回到顶部 / 灯箱
   -------------------------------------------------------------------------- */
.to-top {
  position: fixed;
  right: 16px;
  bottom: calc(16px + var(--safe-bottom));
  z-index: 40;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--card);
  color: var(--text);
  font-size: 18px;
  box-shadow: var(--shadow-lg);
  cursor: pointer;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(2, 6, 23, 0.92);
  cursor: zoom-out;
}

.lightbox img {
  max-width: 100%;
  max-height: calc(100vh - 32px);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
}

/* --------------------------------------------------------------------------
   11 响应式
   -------------------------------------------------------------------------- */

/* 平板及以上：固定侧栏 + 居中内容 */
@media (min-width: 900px) {
  .layout {
    display: grid;
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
    align-items: start;
  }

  .sidebar {
    position: sticky;
    top: calc(var(--topbar-h) + var(--safe-top));
    height: calc(100vh - var(--topbar-h) - var(--safe-top));
    overflow-y: auto;
    padding: 14px 10px 32px;
    border-right: 1px solid var(--line);
  }

  .main {
    max-width: 860px;
    margin: 0 auto;
    padding: 24px 32px 80px;
  }

  .menu-btn,
  .search-toggle,
  .drawer-close,
  .scrim {
    display: none !important;
  }

  .page-title,
  .q-title-main {
    font-size: 26px;
  }

  .hero-title {
    font-size: 30px;
  }
}

/* 手机：抽屉导航 + 单列 + 全宽搜索 */
@media (max-width: 899px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 80;
    width: 82vw;
    max-width: 320px;
    height: auto;
    padding-top: calc(10px + var(--safe-top));
    padding-bottom: calc(24px + var(--safe-bottom));
    overflow-y: auto;
    border-right: 1px solid var(--line);
    box-shadow: var(--shadow-lg);
    transform: translateX(-102%);
    transition: transform 0.22s ease;
    will-change: transform;
  }

  body.drawer-open .sidebar {
    transform: translateX(0);
  }

  .search {
    display: none;
  }

  .topbar.search-open .search {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    display: block;
    max-width: none;
    padding: 8px 12px;
    background: var(--topbar-bg);
    border-bottom: 1px solid var(--line);
    box-shadow: var(--shadow);
    -webkit-backdrop-filter: saturate(180%) blur(10px);
    backdrop-filter: saturate(180%) blur(10px);
  }

  .search-toggle {
    display: inline-flex;
  }

  .random-btn {
    padding: 0 8px;
  }

  .random-lbl {
    display: none;
  }

  .main {
    padding: 16px 16px calc(88px + var(--safe-bottom));
  }

  .hero-title {
    font-size: 22px;
  }

  .page-title,
  .q-title-main {
    font-size: 20px;
    line-height: 1.45;
  }

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

  .q-body {
    font-size: 16px;
    line-height: 1.75;
  }

  .code code {
    font-size: 12.5px;
  }

  .code pre {
    padding: 12px;
  }

  .pager {
    gap: 8px;
  }

  .pager-btn {
    min-height: 56px;
    padding: 8px 10px;
  }

  .pager-title {
    font-size: 13px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .back-btn {
    min-height: 40px;
  }

  /* 手机端统一放大点击区，不只依赖 pointer:coarse */
  .btn,
  .chip {
    min-height: 44px;
  }

  .icon-btn {
    width: 44px;
    height: 44px;
  }
}

/* 极窄屏（≤360px）：进一步压缩 */
@media (max-width: 360px) {
  .brand-name {
    display: none;
  }

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

  .page-title,
  .q-title-main {
    font-size: 19px;
  }
}

/* 触屏设备：保证 44px 点击区 */
@media (pointer: coarse) {
  .icon-btn,
  .btn,
  .chip,
  .search-clear {
    min-height: 44px;
  }

  .icon-btn {
    width: 44px;
    height: 44px;
  }

  .code-copy {
    min-height: 34px;
  }

  .sg-item {
    padding: 11px 10px;
  }
}

/* --------------------------------------------------------------------------
   12 打印 / 动效
   -------------------------------------------------------------------------- */
@media print {
  .topbar,
  .sidebar,
  .scrim,
  .to-top,
  .pager,
  .q-actions,
  .back-btn,
  .search,
  .skip-link {
    display: none !important;
  }

  .main {
    max-width: none;
    padding: 0;
  }

  .code {
    break-inside: avoid;
  }

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

  body {
    background: #fff;
    color: #000;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
