:root {
  --ink: #132033;
  --ink-soft: #3a4a5c;
  --muted: #6b7a8c;
  --line: #d5dde8;
  --paper: #f3f6fa;
  --panel: #ffffff;
  --brand: #0e6b5c;
  --brand-deep: #0a4f44;
  --phonetic: #a83228;
  --phonetic-bg: #fff4f1;
  --shadow: 0 10px 28px rgba(19, 32, 51, 0.08);
  --radius: 16px;
  --font-cn: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-en: "Fraunces", "Noto Serif SC", Georgia, serif;
  --font-ui: "DM Sans", var(--font-cn);
  --topbar-h: 64px;
}

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

html { font-size: 19px; }
html, body {
  height: 100%;
  width: 100%;
  margin: 0;
  overflow: hidden; /* 整页永不出现滚动条 */
  overscroll-behavior: none;
  touch-action: manipulation;
}

/* 整页不滚动；仅内容容器允许出现滚动条 */
.app,
.topbar,
.shell,
.page {
  scrollbar-width: none;
}
.app::-webkit-scrollbar,
.topbar::-webkit-scrollbar,
.shell::-webkit-scrollbar {
  width: 0;
  height: 0;
  display: none;
}

body {
  color: var(--ink);
  font-family: var(--font-ui);
  background:
    radial-gradient(900px 480px at 8% -8%, #d9efe8 0%, transparent 55%),
    radial-gradient(720px 420px at 100% 0%, #dce7f7 0%, transparent 50%),
    var(--paper);
}

button { font: inherit; }

.app {
  height: 100dvh;
  height: 100vh;
  width: 100%;
  display: grid;
  grid-template-rows: var(--topbar-h) minmax(0, 1fr) auto;
  overflow: hidden;
}

/* Jobsoko 植入广告条 */
.ad-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 8px 16px;
  background: linear-gradient(90deg, #0a4f44 0%, #0e6b5c 55%, #1a5c4a 100%);
  color: #f3fffb;
  font-size: 0.92rem;
  letter-spacing: 0.01em;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}
.ad-bar strong {
  font-family: var(--font-en);
  font-size: 1rem;
  font-weight: 700;
}
.ad-bar span { opacity: 0.96; }
.ad-bar em {
  font-style: normal;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  font-size: 0.86rem;
}

/* ===== Top bar ===== */
.topbar {
  height: var(--topbar-h);
  z-index: 20;
  backdrop-filter: blur(14px);
  background: rgba(243, 246, 250, 0.92);
  border-bottom: 1px solid rgba(213, 221, 232, 0.9);
  overflow: hidden;
}

.topbar-inner {
  height: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  overflow: hidden;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
  overflow: hidden;
}
.brand strong {
  font-family: var(--font-en);
  font-size: 0.98rem;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: min(42vw, 420px);
}
.brand span {
  font-size: 0.84rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.controls {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
}

.toggle-slot {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  min-width: 7.5em; /* 占位，防止顶栏抖动 */
}
.toggle-slot.is-empty .toggle {
  visibility: hidden;
  pointer-events: none;
}
.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  cursor: pointer;
  user-select: none;
  transition: border-color .2s, box-shadow .2s, background .2s;
  white-space: nowrap;
  font-size: 0.95rem;
}
.toggle:hover { border-color: #b7c4d6; }
.toggle.active {
  background: var(--phonetic-bg);
  border-color: #efc2bc;
  box-shadow: inset 0 0 0 1px rgba(168, 50, 40, 0.08);
}
.toggle .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #c9d3e0;
  flex-shrink: 0;
}
.toggle.active .dot { background: var(--phonetic); }

.nav-btns { display: flex; gap: 6px; }
.btn {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: 10px;
  padding: 7px 11px;
  cursor: pointer;
  transition: transform .15s, background .15s, border-color .15s;
  white-space: nowrap;
}
.btn:hover { border-color: #adc0d8; }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}
.btn.primary:hover { background: var(--brand-deep); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ===== Layout ===== */
.shell {
  min-height: 0;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 12px 16px 14px;
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  gap: 12px;
  overflow: hidden;
}

.sidebar {
  min-height: 0;
  align-self: stretch;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sidebar h2 {
  margin: 2px 8px 8px;
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
  flex-shrink: 0;
}
#sideNav {
  min-height: 0;
  flex: 1;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 2px;
  scrollbar-width: thin;
  scrollbar-color: #b7c4d6 transparent;
}
#sideNav::-webkit-scrollbar { width: 8px; }
#sideNav::-webkit-scrollbar-thumb {
  background: #b7c4d6;
  border-radius: 999px;
}
.side-link {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.92rem;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 0 0 auto;
}
.side-link:hover { background: #eef3f8; }
.side-link.active {
  background: #e5f3ef;
  color: var(--brand-deep);
  font-weight: 600;
}
.side-link .idx {
  display: inline-block;
  width: 1.5em;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.page {
  min-height: 0;
  align-self: stretch;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: rise .22s ease;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.page-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.page-head h1 {
  margin: 0;
  font-family: var(--font-en);
  font-size: clamp(1.25rem, 1.8vw, 1.70rem);
  line-height: 1.2;
}
.page-head .meta {
  color: var(--muted);
  font-size: 0.87rem;
  margin-top: 3px;
}

.phonetic-chip {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 9px;
  border-radius: 999px;
  border: 1px dashed #efc2bc;
  background: var(--phonetic-bg);
  color: var(--phonetic);
  font-size: 0.86rem;
}
.phonetic-chip.hidden-state {
  background: #eef2f6;
  border-color: var(--line);
  color: var(--muted);
}

/* 场景/说明固定在滚动区外 */
.page-intro {
  flex-shrink: 0;
  margin: 0 0 8px;
  padding: 0 2px;
}

/* 内容容器：从列表顶部开始滚动；上下留 buffer */
.page-viewport {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px 6px 16px 2px; /* 上下 buffer，避免列表贴边重叠 */
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: #b7c4d6 transparent;
  border-top: 1px solid transparent; /* 视觉起点对齐列表区 */
}
.page-viewport::-webkit-scrollbar {
  width: 10px;
}
.page-viewport::-webkit-scrollbar-track {
  background: transparent;
  margin-block: 12px; /* 滚动条轨道也避开上下 buffer */
}
.page-viewport::-webkit-scrollbar-thumb {
  background: #b7c4d6;
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: content-box;
}
.page-viewport::-webkit-scrollbar-thumb:hover {
  background: #8fa0b5;
  background-clip: content-box;
}
.page-body {
  width: 100%;
  overflow: visible;
  padding-bottom: 4px;
}

/* content */
.lead { font-size: 1.07rem; color: var(--ink-soft); margin: 0 0 8px; }
.page-body p {
  margin: 0 0 10px;
  font-size: 1.02rem;
  line-height: 1.65;
  color: var(--ink-soft);
}
.page-body strong { color: var(--ink); font-weight: 650; }
.page-body h3 {
  margin: 10px 0 6px;
  font-size: 1.07rem;
  color: var(--brand-deep);
}
.page-body ul, .page-body ol {
  margin: 0 0 8px;
  padding-left: 1.2em;
}
.page-body li { margin: 2px 0; font-size: 1.02rem; }

blockquote {
  margin: 8px 0 12px;
  padding: 10px 12px;
  border-left: 4px solid var(--brand);
  background: #eef8f5;
  border-radius: 0 10px 10px 0;
  font-size: 1.07rem;
}
.note {
  margin-top: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  background: #fff7e8;
  color: #7a5a20;
  font-size: 0.94rem;
}
.schedule {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 8px 0;
}
.schedule div {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 10px;
  display: grid;
  gap: 2px;
  background: linear-gradient(180deg, #fff, #f7fafc);
}
.schedule strong { color: var(--brand-deep); font-size: 1.00rem; }
.schedule span { color: var(--muted); font-size: 0.87rem; }
.schedule em { font-style: normal; font-size: 0.96rem; }

.intro-line {
  color: var(--muted);
  margin: 0 0 10px;
  font-size: 0.98rem;
  line-height: 1.45;
}

.word-grid {
  display: grid;
  gap: 7px;
}
.word-grid.cols-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.word-grid.cols-7 { grid-template-columns: repeat(7, minmax(0, 1fr)); }

.word-card {
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 7px 5px 8px;
  text-align: center;
  background: #fff;
}

.speakable {
  position: relative;
  cursor: pointer;
  transition: border-color .18s, box-shadow .18s, background .18s;
}
.speakable:hover {
  border-color: #9ec4b8;
  box-shadow: 0 0 0 2px rgba(14, 107, 92, 0.12);
}
.speakable.is-speaking {
  border-color: var(--brand);
  background: #eef8f5;
  box-shadow: 0 0 0 2px rgba(14, 107, 92, 0.18);
}
.speak-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 8px;
  padding: 4px 10px;
  border: 1px solid #c5d7d1;
  border-radius: 999px;
  background: #f3faf7;
  color: var(--brand-deep);
  font-size: 0.82rem;
  cursor: pointer;
  line-height: 1.2;
}
.speakable:hover .speak-btn,
.speakable.is-speaking .speak-btn {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}
.word-card .speak-btn {
  margin-top: 6px;
  padding: 3px 8px;
  font-size: 0.75rem;
}

.ph-line {
  color: var(--phonetic);
  font-size: 0.86rem;
  line-height: 1.15;
  min-height: 1.05em;
  margin-bottom: 2px;
  transition: opacity .18s, max-height .2s, margin .2s, transform .18s;
  overflow: hidden;
}
.en-line {
  font-family: var(--font-en);
  font-weight: 650;
  font-size: 1.12rem;
  color: var(--ink);
  line-height: 1.2;
}
.zh-line {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.86rem;
}

.page.hide-phonetic .ph-line {
  opacity: 0;
  max-height: 0;
  margin-bottom: 0;
  transform: translateY(-3px);
  pointer-events: none;
}

.sentence-list, .dialogue-list { display: grid; gap: 7px; }
.sentence-item, .dialogue-item {
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 8px 10px;
  background: linear-gradient(180deg, #fff, #fafcfe);
}
.sentence-item .en-line { font-size: 1.17rem; }
.dialogue-item .who {
  display: inline-block;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--brand-deep);
  background: #e5f3ef;
  border-radius: 999px;
  padding: 1px 7px;
  margin-bottom: 4px;
}

.rules table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.94rem;
}
.rules th, .rules td {
  border-bottom: 1px solid var(--line);
  padding: 6px 6px;
  text-align: left;
  vertical-align: top;
}
.rules th { color: var(--muted); font-weight: 600; font-size: 0.84rem; }
.rules .fixed { color: var(--phonetic); font-weight: 600; }

@media (max-width: 880px) {
  :root { --topbar-h: 58px; }
  .shell {
    grid-template-columns: 140px minmax(0, 1fr);
    padding: 8px 10px 10px;
    gap: 8px;
  }
  .brand span { display: none; }
  .word-grid.cols-5 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .word-grid.cols-7 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .schedule { grid-template-columns: 1fr; }
  .page { padding: 10px 12px; }
  .side-link { font-size: 0.84rem; padding: 4px 6px; }
}

@media (max-width: 640px) {
  .shell {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 44px minmax(0, 1fr);
  }
  .sidebar {
    padding: 4px 6px;
  }
  .sidebar h2 { display: none; }
  #sideNav {
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 2px;
  }
  .side-link {
    flex: 1 1 0;
    padding: 4px 2px;
    font-size: 0.70rem;
    text-align: center;
  }
  .side-link .idx { display: none; }
  .word-grid.cols-5,
  .word-grid.cols-7 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .toggle .label { font-size: 0.90rem; }
}


.week-nav {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}
.week-btn {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink-soft);
  border-radius: 999px;
  padding: 7px 12px;
  cursor: pointer;
  font-size: 0.92rem;
  white-space: nowrap;
}
.week-btn:hover { border-color: #adc0d8; }
.week-btn.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
  font-weight: 600;
}
.en-line { font-size: 1.22rem; }
.ph-line { font-size: 0.95rem; }
.zh-line { font-size: 0.95rem; }
.side-link { font-size: 0.95rem; }
