:root {
  color-scheme: light;
  --bg: #f6f8f4;
  --bg-band: #edf4ef;
  --surface: #ffffff;
  --surface-soft: #f2f7f4;
  --ink: #172326;
  --muted: #5d6b70;
  --line: #d7e0dc;
  --primary: #245b72;
  --primary-strong: #153f55;
  --accent: #2f7d57;
  --accent-soft: #e7f3ec;
  --study: #fff2bd;
  --study-line: #d59a2d;
  --danger: #9f4636;
  --shadow: 0 16px 38px rgba(28, 57, 63, 0.1);
  --radius: 8px;
  font-family: "Avenir Next", "Atkinson Hyperlegible", "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, #f7faf8 0%, var(--bg) 44%, var(--bg-band) 100%);
  color: var(--ink);
  line-height: 1.68;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--primary);
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.18em;
}

button {
  font: inherit;
  touch-action: manipulation;
}

.skip-link {
  position: absolute;
  left: 16px;
  top: 12px;
  z-index: 10;
  transform: translateY(-160%);
  min-height: 44px;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--primary-strong);
  color: #fff;
  font-weight: 800;
  text-decoration: none;
  transition: transform 160ms ease;
}

.skip-link:focus {
  transform: translateY(0);
}

.page-shell,
.index-shell {
  flex: 1 0 auto;
  width: min(100%, 1120px);
  margin: 0 auto;
  padding: 28px 20px 48px;
}

.icp-footer {
  flex: 0 0 auto;
  width: 100%;
  margin: 0 auto;
  padding: 0 20px 28px;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.5;
  text-align: center;
}

.icp-footer a {
  color: inherit;
  text-decoration: none;
}

.icp-footer a:hover {
  text-decoration: underline;
}

.top-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
  font-size: 0.94rem;
}

.top-nav a {
  text-decoration: none;
  font-weight: 800;
}

.top-nav a:hover {
  text-decoration: underline;
}

.topic-pill {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 5px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.86);
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 750;
}

.article-header,
.index-hero {
  display: grid;
  gap: 12px;
  padding: 18px 0 24px;
}

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: 0.86rem;
  font-weight: 850;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  max-width: 880px;
  font-family: "Iowan Old Style", Georgia, "Times New Roman", serif;
  font-size: clamp(2.1rem, 4vw, 4.1rem);
  line-height: 1.08;
  letter-spacing: 0;
  color: #102b37;
}

.subtitle,
.summary,
.article-meta,
.source-line {
  max-width: 760px;
  margin: 0;
  color: var(--muted);
  font-size: 1.02rem;
}

.article-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  font-size: 0.94rem;
}

.hero-figure {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: #eaf1ed;
  box-shadow: var(--shadow);
}

.image-placeholder {
  display: grid;
  min-height: 220px;
  place-items: center;
  padding: 28px;
  background:
    linear-gradient(135deg, rgba(231, 243, 236, 0.94), rgba(247, 241, 220, 0.94)),
    repeating-linear-gradient(135deg, rgba(36, 91, 114, 0.08) 0, rgba(36, 91, 114, 0.08) 1px, transparent 1px, transparent 14px);
  color: var(--primary-strong);
  text-align: center;
  font-weight: 800;
}

.content-layout {
  display: block;
  margin-top: 24px;
}

article,
.study-panel,
.status-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

article {
  padding: clamp(20px, 3vw, 34px);
}

.paragraph-block {
  margin: 0 0 1.8rem;
}

.sentence-row {
  max-width: 72ch;
  margin: 0 0 1.2rem;
}

.sentence-text {
  margin: 0;
  font-family: "Iowan Old Style", Georgia, "Times New Roman", serif;
  font-size: 1.2rem;
  line-height: 1.84;
}

.sentence-translation {
  margin: 0.22rem 0 0;
  padding-left: 0.85rem;
  border-left: 3px solid rgba(36, 91, 114, 0.18);
  color: #4f5f68;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 0.98rem;
  line-height: 1.78;
}

.sentence {
  border-radius: 5px;
  transition: background 160ms ease, box-shadow 160ms ease;
}

.sentence.is-reading {
  background: linear-gradient(180deg, rgba(255, 242, 189, 0.98), rgba(255, 242, 189, 0.54));
  box-shadow: 0 0 0 4px rgba(213, 154, 45, 0.18);
}

.learning-word {
  display: inline-block;
  position: relative;
  border-bottom: 2px solid rgba(36, 91, 114, 0.34);
  background: linear-gradient(180deg, transparent 58%, rgba(226, 245, 236, 0.92) 58%);
  border-radius: 4px;
  cursor: pointer;
  font-weight: 800;
  text-decoration: none;
}

.learning-word--level {
  color: var(--primary);
}

.learning-phrase {
  display: inline-block;
  position: relative;
  border-bottom: 2px solid rgba(47, 125, 87, 0.4);
  background: linear-gradient(180deg, transparent 58%, rgba(226, 245, 236, 0.72) 58%);
  border-radius: 4px;
  color: #246047;
  cursor: pointer;
  font-weight: 850;
  text-decoration: none;
}

.learning-word:hover,
.learning-word:focus,
.learning-word.is-active,
.learning-phrase:hover,
.learning-phrase:focus,
.learning-phrase.is-active {
  color: var(--accent);
  outline: none;
  background: var(--accent-soft);
  z-index: 20;
}

.inline-word-tip {
  position: absolute;
  left: 50%;
  top: calc(100% + 8px);
  transform: translateX(-50%);
  z-index: 30;
  width: max-content;
  max-width: min(300px, 78vw);
  display: grid;
  gap: 4px;
  padding: 10px 12px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 14px 34px rgba(34, 51, 46, 0.18);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1.35;
  white-space: normal;
  text-align: left;
}

.inline-word-tip--mobile {
  position: fixed;
  left: 50%;
  right: auto;
  top: auto;
  bottom: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 10000;
  width: calc(100vw - 28px);
  max-width: 420px;
  max-height: 42vh;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 14px;
  text-align: center;
}

.inline-word-tip--mobile::before {
  display: none;
}

.inline-word-tip::before {
  content: "";
  position: absolute;
  left: 50%;
  top: -6px;
  width: 10px;
  height: 10px;
  transform: translateX(-50%) rotate(45deg);
  background: rgba(255, 255, 255, 0.98);
  border-left: 1px solid var(--line);
  border-top: 1px solid var(--line);
}

.tip-ipa {
  color: var(--muted);
  font-weight: 800;
}

.tip-meaning {
  color: var(--ink);
}

.learning-word:focus-visible,
.learning-phrase:focus-visible,
.speaker-button:focus-visible,
.note-audio-button:focus-visible,
.ipa-audio-button:focus-visible,
.read-button:focus-visible,
.topic-link:focus-visible {
  outline: 3px solid rgba(213, 154, 45, 0.48);
  outline-offset: 3px;
}

.speaker-button,
.note-audio-button,
.ipa-audio-button {
  min-width: 44px;
  min-height: 44px;
  margin-left: 6px;
  border: 1px solid #bfd1c8;
  border-radius: 999px;
  background: #f9fffb;
  color: var(--accent);
  cursor: pointer;
  line-height: 1;
  vertical-align: middle;
  transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}

.speaker-button:hover,
.note-audio-button:hover,
.ipa-audio-button:hover {
  background: var(--accent-soft);
  border-color: #8fb79f;
}

.ipa-audio-button {
  min-width: 30px;
  min-height: 30px;
  font-size: 0.78rem;
}

.article-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.read-button {
  min-height: 44px;
  padding: 0 18px;
  border: 0;
  border-radius: var(--radius);
  background: var(--primary);
  color: white;
  font-weight: 800;
  cursor: pointer;
  transition: background 160ms ease, transform 160ms ease;
}

.read-button:hover {
  background: var(--primary-strong);
}

.read-button.is-active {
  background: var(--danger);
}

.tts-state {
  color: var(--muted);
  font-size: 0.92rem;
}

.study-panel {
  display: none;
  position: sticky;
  top: 18px;
  padding: 18px;
}

.study-panel h2 {
  margin: 0 0 10px;
  color: #18323a;
  font-size: 1.02rem;
  letter-spacing: 0;
}

.word-card {
  min-height: 160px;
  border-radius: var(--radius);
  background: linear-gradient(180deg, #f8fffb, #fffdf6);
  border: 1px solid var(--line);
  padding: 16px;
}

.word-card [data-field="word"] {
  margin: 0;
  color: #14313c;
  font-size: 1.45rem;
  line-height: 1.2;
  font-weight: 850;
}

.word-meta {
  margin: 8px 0 0;
  color: var(--muted);
}

.word-meaning {
  margin: 12px 0 0;
  font-size: 1rem;
  color: #284a3d;
}

.word-details {
  display: grid;
  gap: 10px;
  margin: 14px 0 0;
}

.word-card [hidden],
.word-details [hidden] {
  display: none !important;
}

.word-details div {
  display: grid;
  gap: 2px;
}

.word-details dt {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.word-details dd {
  margin: 0;
  color: var(--ink);
  font-size: 0.95rem;
  line-height: 1.45;
}

.phrase-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.phrase-list li {
  display: grid;
  gap: 3px;
  padding: 8px;
  border: 1px solid rgba(217, 229, 223, 0.9);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.68);
}

.phrase-list strong {
  color: #14313c;
}

.phrase-list em {
  color: var(--muted);
  font-style: normal;
}

.example-zh,
.phrase-list .phrase-example-zh {
  display: block;
  margin-top: 3px;
  color: #52685f;
  font-size: 0.92rem;
}

.legend {
  display: grid;
  gap: 8px;
  margin-top: 18px;
  color: var(--muted);
  font-size: 0.9rem;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.legend span::before {
  content: "";
  width: 12px;
  height: 12px;
  border-radius: 2px;
  background: var(--primary);
}

.source-footer {
  margin-top: 24px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.92rem;
}

.index-hero {
  margin-bottom: 28px;
  border-bottom: 1px solid var(--line);
}

.meta-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 4px 0 0;
  padding: 0;
  list-style: none;
}

.meta-strip li {
  min-height: 36px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 750;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 14px;
}

.topic-link {
  display: grid;
  align-content: start;
  gap: 10px;
  min-height: 150px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.92);
  color: inherit;
  text-decoration: none;
  box-shadow: var(--shadow);
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.topic-link:hover {
  border-color: #92b6a2;
  box-shadow: 0 18px 42px rgba(28, 57, 63, 0.13);
  transform: translateY(-1px);
}

.topic-link span,
.topic-link small {
  color: var(--muted);
}

.topic-link span {
  font-size: 0.82rem;
  font-weight: 850;
  text-transform: uppercase;
}

.topic-link strong {
  color: #14313c;
  font-family: "Iowan Old Style", Georgia, "Times New Roman", serif;
  font-size: 1.24rem;
  line-height: 1.25;
}

.topic-link small {
  margin-top: auto;
  padding-top: 8px;
  border-top: 1px solid rgba(215, 224, 220, 0.72);
}

.status-panel {
  display: grid;
  gap: 10px;
  margin-top: 18px;
  padding: 18px;
}

.status-panel ul {
  margin: 0;
  padding-left: 18px;
}

@media (max-width: 900px) {
  .page-shell,
  .index-shell {
    padding: 18px 14px 34px;
  }

  .top-nav {
    align-items: flex-start;
    flex-direction: column;
  }

  .content-layout {
    display: block;
  }

  .study-panel {
    position: static;
  }

  .sentence-text {
    font-size: 1.12rem;
  }

  .sentence-translation {
    font-size: 0.94rem;
  }
}

@media (max-width: 560px) {
  .topic-pill {
    align-self: stretch;
    justify-content: center;
    text-align: center;
  }

  .article-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .read-button {
    width: 100%;
  }
}

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

  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.001ms !important;
  }
}
