/* ============================================================
   词根词缀记忆工坊 · 墨纸朱砂学术风
   体系：纸(paper) 墨(ink) 朱砂(accent) 三 token，双主题自动切换
   字体：EB Garamond(拉丁词根) + 系统中文无衬线 + IBM Plex Mono(数据)
   圆角制度：全局 3px，唯一取值
   ============================================================ */

@font-face {
  font-family: "EB Garamond";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("./fonts/eb-garamond-latin-400-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+2000-206F;
}

@font-face {
  font-family: "EB Garamond";
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  src: url("./fonts/eb-garamond-latin-400-italic.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+2000-206F;
}

@font-face {
  font-family: "EB Garamond";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("./fonts/eb-garamond-latin-600-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+2000-206F;
}

@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("./fonts/ibm-plex-mono-latin-400-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+2000-206F;
}

@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("./fonts/ibm-plex-mono-latin-500-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+2000-206F;
}

:root {
  --paper: #f8f6f1;
  --raised: #fffdf9;
  --ink: #211e1a;
  --ink-soft: #55504a;
  --muted: #6e685e;
  --line: rgba(33, 30, 26, 0.14);
  --line-strong: rgba(33, 30, 26, 0.36);
  --accent: #b23a26;
  --accent-ink: #8f2e1e;
  --accent-wash: rgba(178, 58, 38, 0.07);
  --on-accent: #f8f6f1;
  --ok: #3f6b50;
  --ok-wash: rgba(63, 107, 80, 0.09);
  --btn-primary-bg: #b23a26;
  --btn-primary-fg: #f8f6f1;
  --btn-primary-border: #b23a26;
  --btn-primary-hover: #8f2e1e;
  --btn-ok-bg: #3f6b50;
  --btn-ok-fg: #f8f6f1;
  --serif-latin: "EB Garamond", Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "PingFang SC", "HarmonyOS Sans SC",
    "MiSans", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
  --r: 3px;
  --grain-opacity: 0.05;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #171411;
    --raised: #201c18;
    --ink: #ece5d8;
    --ink-soft: #c4bbab;
    --muted: #a09887;
    --line: rgba(236, 229, 216, 0.13);
    --line-strong: rgba(236, 229, 216, 0.38);
    --accent: #d0553c;
    --accent-ink: #e06a50;
    --accent-wash: rgba(208, 85, 60, 0.13);
    --on-accent: #171411;
    --ok: #7aa889;
    --ok-wash: rgba(122, 168, 137, 0.12);
    --btn-primary-bg: #ece5d8;
    --btn-primary-fg: #1a1512;
    --btn-primary-border: #ece5d8;
    --btn-primary-hover: #f8f3e9;
    --btn-ok-bg: #7aa889;
    --btn-ok-fg: #10160f;
    --grain-opacity: 0.08;
  }
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: light dark;
}

body {
  margin: 0;
  min-height: 100dvh;
  color: var(--ink);
  background: var(--paper);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

/* 顶部朱砂书签线 */
body::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--accent);
  z-index: 90;
}

/* 纸张颗粒 */
.grain {
  position: fixed;
  inset: 0;
  z-index: 80;
  pointer-events: none;
  opacity: var(--grain-opacity);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.55'/%3E%3C/svg%3E");
}

::selection {
  background: var(--accent);
  color: var(--on-accent);
}

a {
  color: var(--accent);
}

:focus {
  outline: none;
}

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

/* ============ 报头 ============ */

.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 16px;
}

.masthead {
  padding-top: 34px;
}

.masthead-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 16px;
}

.eyebrow {
  margin: 0 0 6px;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--accent);
}

h1 {
  margin: 0 0 10px;
  font-size: clamp(1.8rem, 3.4vw, 2.5rem);
  font-weight: 700;
  letter-spacing: 0.01em;
  line-height: 1.2;
}

h2 {
  margin: 0 0 10px;
  font-size: 1.2rem;
  font-weight: 700;
}

.sub {
  margin: 0 0 20px;
  max-width: 40em;
  color: var(--muted);
  font-size: 0.95rem;
}

/* 拉丁词根水印 */
.masthead-ghost {
  font-family: var(--serif-latin);
  font-style: italic;
  font-weight: 600;
  font-size: clamp(4.5rem, 10vw, 7.5rem);
  line-height: 0.8;
  color: transparent;
  -webkit-text-stroke: 1.5px var(--line-strong);
  user-select: none;
  white-space: nowrap;
}

@supports not (-webkit-text-stroke: 1px black) {
  .masthead-ghost {
    color: var(--line);
    -webkit-text-stroke: 0;
  }
}

/* 报头横线：统计 + 模式切换 */
.masthead-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 8px;
  padding: 10px 0;
  border-top: 1px solid var(--line-strong);
  border-bottom: 1px solid var(--line);
}

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.stats > span:only-child {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  animation: pulse 1.2s ease-in-out infinite;
}

.chip {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-soft);
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 4px 10px;
  white-space: nowrap;
}

.chip-mastered {
  color: var(--on-accent);
  background: var(--accent);
  border-color: var(--accent);
}

/* 墨块式选项卡 */
.tabs {
  display: inline-flex;
  border: 1px solid var(--line-strong);
  border-radius: var(--r);
  overflow: hidden;
  background: var(--raised);
}

.tab {
  border: none;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--ink-soft);
  font: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  padding: 9px 18px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.tab:last-child {
  border-right: none;
}

.tab:hover {
  background: var(--accent-wash);
  color: var(--ink);
}

.tab.active {
  background: var(--ink);
  color: var(--paper);
}

/* ============ 面板 ============ */

.app {
  padding: 20px 0 8px;
}

.panel {
  display: none;
}

.panel.active {
  display: block;
  animation: rise 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.45;
  }
}

/* ============ 通用控件 ============ */

input,
button {
  font: inherit;
}

input[type="search"] {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--r);
  background: var(--raised);
  color: var(--ink);
  padding: 10px 14px;
  font-size: 0.95rem;
}

input[type="search"]::placeholder {
  color: var(--muted);
}

input[type="search"]:focus-visible {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-wash);
}

.btn {
  border: 1px solid var(--line-strong);
  border-radius: var(--r);
  background: var(--raised);
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 600;
  padding: 10px 14px;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s ease, background 0.15s ease,
    transform 0.1s ease;
}

.btn:hover:not(:disabled) {
  border-color: var(--ink);
}

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

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--btn-primary-bg);
  border-color: var(--btn-primary-border);
  color: var(--btn-primary-fg);
}

.btn-primary:hover:not(:disabled) {
  background: var(--btn-primary-hover);
  border-color: var(--btn-primary-hover);
}

.btn-ok {
  background: var(--btn-ok-bg);
  border-color: var(--btn-ok-bg);
  color: var(--btn-ok-fg);
}

.btn-ok:hover:not(:disabled) {
  border-color: var(--btn-ok-bg);
  opacity: 0.9;
}

/* ============ 学习地图 ============ */

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

.map-layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 20px;
  align-items: start;
  min-height: 56vh;
}

.root-list {
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--raised);
  overflow: auto;
  max-height: 68vh;
  padding: 4px 0;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.root-list::-webkit-scrollbar {
  width: 10px;
}

.root-list::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border-radius: 5px;
}

.root-item {
  padding: 9px 14px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  transition: background 0.15s ease;
}

.root-item:last-child {
  border-bottom: none;
}

.root-item:hover {
  background: var(--accent-wash);
}

.root-item.active {
  background: var(--accent-wash);
  box-shadow: inset 3px 0 0 var(--accent);
}

.root-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.root-key {
  font-family: var(--serif-latin);
  font-size: 1.08rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.root-head > span:not(.root-key) {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
}

.root-gloss {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.86rem;
}

.root-list > div:not(.root-item) {
  padding: 18px 14px;
  color: var(--muted);
  font-size: 0.9rem;
}

/* 详情区：无框，直接呈现在纸上 */
.root-detail {
  padding: 4px 0;
}

.root-detail h2 {
  font-size: 1.15rem;
}

.root-detail p {
  color: var(--muted);
  font-size: 0.92rem;
}

.detail-head {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: baseline;
}

.detail-root {
  font-family: var(--serif-latin);
  font-size: clamp(2.2rem, 5vw, 2.8rem);
  font-weight: 600;
  line-height: 1;
}

.root-detail > p {
  margin: 14px 0 10px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.examples {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
}

.example-card {
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--raised);
  padding: 10px 12px;
  transition: border-color 0.15s ease;
}

.example-card:hover {
  border-color: var(--line-strong);
}

.example-word {
  font-family: var(--serif-latin);
  font-size: 1.12rem;
  font-weight: 600;
  line-height: 1.3;
}

.example-meaning {
  margin-top: 2px;
  font-size: 0.88rem;
  color: var(--ink-soft);
}

.example-decomp {
  margin-top: 5px;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--muted);
  letter-spacing: 0.01em;
  overflow-wrap: anywhere;
}

/* ============ 闪卡 ============ */

.flash-wrap {
  max-width: 680px;
  margin: 0 auto;
}

.flash-meta,
.quiz-score {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 12px;
}

.flash-card {
  position: relative;
  min-height: 340px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r);
  background: var(--raised);
  box-shadow: 0 16px 40px rgba(33, 30, 26, 0.07);
  padding: 34px 32px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 14px;
  text-align: center;
}

/* 左上朱砂印 */
.flash-card::before {
  content: "";
  position: absolute;
  top: 16px;
  left: 16px;
  width: 8px;
  height: 8px;
  background: var(--accent);
}

.flash-prompt {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.flash-root {
  font-family: var(--serif-latin);
  font-size: clamp(2.6rem, 8vw, 3.8rem);
  font-weight: 600;
  line-height: 1.1;
}

.flash-gloss,
.flash-words,
.flash-breakdown {
  font-size: 0.95rem;
  color: var(--ink-soft);
  max-width: 34em;
}

.is-revealed .flash-gloss,
.is-revealed .flash-words,
.is-revealed .flash-breakdown {
  animation: rise 0.35s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.is-revealed .flash-words {
  animation-delay: 0.07s;
}

.is-revealed .flash-breakdown {
  animation-delay: 0.14s;
}

.flash-actions {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 14px;
}

/* ============ 选择题 ============ */

.quiz-wrap {
  max-width: 680px;
  margin: 0 auto;
}

.quiz-question {
  font-size: 1.22rem;
  font-weight: 700;
  line-height: 1.5;
  margin-bottom: 16px;
}

.quiz-options {
  counter-reset: opt;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.quiz-option {
  display: flex;
  align-items: baseline;
  gap: 12px;
  text-align: left;
  border: 1px solid var(--line-strong);
  border-radius: var(--r);
  background: var(--raised);
  color: var(--ink);
  padding: 13px 16px;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.quiz-option::before {
  counter-increment: opt;
  content: counter(opt, upper-alpha);
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  min-width: 1.1em;
}

.quiz-option:hover:not(:disabled) {
  border-color: var(--ink);
}

.quiz-option:disabled {
  cursor: default;
}

.quiz-option:not(.correct):not(.wrong):disabled {
  opacity: 0.55;
}

.quiz-option > span,
.quiz-option {
  font-family: var(--serif-latin);
  font-size: 1.05rem;
  font-weight: 600;
}

.quiz-option.correct {
  border-color: var(--ok);
  background: var(--ok-wash);
}

.quiz-option.correct::before {
  color: var(--ok);
  font-weight: 500;
}

.quiz-option.wrong {
  border-color: var(--accent);
  background: var(--accent-wash);
}

.quiz-option.wrong::before {
  color: var(--accent);
  font-weight: 500;
}

.quiz-feedback {
  min-height: 44px;
  color: var(--ink-soft);
  font-size: 0.92rem;
}

.quiz-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 6px;
}

/* ============ 页脚 ============ */

.credits {
  max-width: 1100px;
  margin: 0 auto;
  padding: 18px 16px 30px;
  border-top: 1px solid var(--line);
  margin-top: 18px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  text-align: center;
}

.credits a {
  color: var(--ink-soft);
}

/* ============ 点读 ============ */

.say {
  cursor: pointer;
}

.say:hover {
  color: var(--accent);
}

.say.playing {
  color: var(--accent);
  animation: sayPulse 0.3s ease 3;
}

@keyframes sayPulse {
  50% {
    opacity: 0.45;
  }
}

.example-word-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.say-btn {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--r);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.say-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.say-btn.playing {
  border-color: var(--accent);
  color: var(--accent);
  animation: sayPulse 0.3s ease 3;
}

.say-btn svg {
  display: block;
}

.example-word.say {
  display: inline-block;
  transition: color 0.15s ease;
}

.example-ipa {
  display: inline;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--muted);
  font-weight: 400;
}

.flash-words .say,
.quiz-feedback .say {
  border-bottom: 1px dashed var(--line-strong);
  transition: color 0.15s ease, border-color 0.15s ease;
}

.flash-words .say:hover,
.quiz-feedback .say:hover {
  border-bottom-color: var(--accent);
}

/* ============ 响应式 ============ */

@media (max-width: 900px) {
  .map-layout {
    grid-template-columns: 1fr;
    min-height: 0;
  }

  .root-list {
    max-height: 38vh;
  }

  .masthead-ghost {
    font-size: 4rem;
  }
}

@media (max-width: 640px) {
  .masthead {
    padding-top: 26px;
  }

  .masthead-row {
    grid-template-columns: 1fr;
  }

  .masthead-ghost {
    display: none;
  }

  .masthead-bar {
    align-items: stretch;
    flex-direction: column;
  }

  .tabs {
    display: flex;
    width: 100%;
  }

  .tab {
    flex: 1;
    padding: 10px 8px;
    font-size: 0.88rem;
  }

  .toolbar {
    flex-direction: column;
  }

  .flash-card {
    min-height: 280px;
    padding: 26px 20px;
  }

  .flash-actions {
    grid-template-columns: repeat(2, 1fr);
  }

  .quiz-options {
    grid-template-columns: 1fr;
  }
}

/* ============ 动效克制 ============ */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
