/* ==========================================================================
   填词补文 120 词闪卡 · 样式
   设计语言与「完形文库」一致：纸本、朱砂印、宋体标题
   ========================================================================== */

:root {
  --bg: #f4efe4;
  --panel: #fffdf8;
  --panel-2: #faf5e9;
  --ink: #211f1b;
  --ink-2: #4b463d;
  --muted: #847a6b;
  --line: #e3dac8;
  --line-2: #d2c5ad;
  --accent: #a8432c;
  --accent-2: #c05a3e;
  --accent-wash: #f8ece6;
  --accent-line: #ecd2c7;
  --green: #3c5f4d;
  --green-wash: #e7efe8;
  --amber: #9a6b1f;
  --amber-wash: #f6ecd9;
  --red: #a33a32;
  --red-wash: #f7e6e3;

  --en: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Georgia, "Times New Roman", serif;
  --sans: "Inter", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  --serif: "Noto Serif SC", "Source Han Serif SC", "Songti SC", "SimSun", serif;

  --radius: 22px;
  --shadow: 0 1px 2px rgba(60, 45, 25, .05), 0 24px 50px -34px rgba(60, 45, 25, .5);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

[data-theme="dark"] {
  --bg: #131519;
  --panel: #1b1e24;
  --panel-2: #171a1f;
  --ink: #ece6d9;
  --ink-2: #c3bcae;
  --muted: #988f80;
  --line: #2b2f36;
  --line-2: #3b404a;
  --accent: #e0795c;
  --accent-2: #ef9277;
  --accent-wash: #2a1c18;
  --accent-line: #4a2d25;
  --green: #9cc2ac;
  --green-wash: #1c2a23;
  --amber: #d9b06a;
  --amber-wash: #2a2318;
  --red: #e08d84;
  --red-wash: #2c1d1b;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 24px 50px -30px rgba(0, 0, 0, .75);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink);
  background:
    radial-gradient(1100px 560px at 8% -10%, rgba(255, 255, 255, .55), transparent 60%),
    radial-gradient(820px 480px at 104% 2%, rgba(168, 67, 44, .06), transparent 58%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

[data-theme="dark"] body {
  background:
    radial-gradient(1100px 560px at 8% -10%, rgba(255, 255, 255, .035), transparent 60%),
    radial-gradient(820px 480px at 104% 2%, rgba(224, 121, 92, .05), transparent 58%),
    var(--bg);
}

h1, h2, p { margin: 0; }

button { font: inherit; color: inherit; }

.skip {
  position: absolute; left: -999px; top: 8px; z-index: 50;
  background: var(--panel); border: 1px solid var(--line);
  padding: 8px 12px; border-radius: 10px;
}
.skip:focus { left: 12px; }

/* ---------- 顶栏 ---------- */

.app {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 0 18px calc(28px + var(--safe-bottom));
}

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 2px 12px;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.seal {
  flex: none;
  width: 42px; height: 42px;
  display: grid; place-items: center;
  font-family: var(--serif);
  font-size: 21px;
  color: #fff;
  background: var(--accent);
  border-radius: 12px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .18), 0 6px 14px -8px rgba(168, 67, 44, .7);
}

.brand-text { min-width: 0; }

.brand-text h1 {
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: .01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-text p {
  font-size: 11.5px;
  color: var(--muted);
  letter-spacing: .04em;
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar-tools { display: flex; gap: 8px; flex: none; }

.icon-btn {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 12px;
  cursor: pointer;
  transition: border-color .15s, transform .15s, background .15s;
}
.icon-btn svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
#themeBtn .i-sun { display: none; }
[data-theme="dark"] #themeBtn .i-sun { display: block; }
[data-theme="dark"] #themeBtn .i-moon { display: none; }
.icon-btn:hover { border-color: var(--line-2); transform: translateY(-1px); }
.icon-btn:active { transform: translateY(0); }

.progress {
  height: 3px;
  border-radius: 3px;
  background: var(--line);
  overflow: hidden;
  margin: 2px 2px 16px;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: 3px;
  transition: width .35s ease;
}

/* ---------- 工具栏 ---------- */

.toolbar { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }

.seg {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 13px;
  width: fit-content;
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: none;
}
.seg::-webkit-scrollbar { display: none; }

.seg button {
  flex: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  padding: 7px 13px;
  border-radius: 9px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, color .15s;
}
.seg button:hover { color: var(--ink); }
.seg button.is-on {
  background: var(--panel);
  color: var(--ink);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(60, 45, 25, .08), 0 0 0 1px var(--line) inset;
}

.toolbar-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.seg-sm { padding: 3px; }
.seg-sm button { font-size: 12.5px; padding: 5px 11px; }

.chip {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink-2);
  font-size: 12.5px;
  padding: 7px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: border-color .15s, color .15s, background .15s;
}
.chip:hover { border-color: var(--line-2); }
.chip[aria-pressed="true"] {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-wash);
  font-weight: 600;
}

/* 发音开关：低调一点，用绿点表示开启 */
#speakToggle { display: inline-flex; align-items: center; gap: 6px; }
#speakToggle::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--line-2);
  flex: none;
}
#speakToggle[aria-pressed="true"] {
  color: var(--ink-2);
  border-color: var(--line);
  background: var(--panel);
  font-weight: 500;
}
#speakToggle[aria-pressed="true"]::before { background: var(--green); }

/* ---------- 卡片 ---------- */

.card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 6px 8px;
}

.pos {
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .06em;
  color: var(--accent);
  background: var(--accent-wash);
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 2px 9px;
  opacity: .92;
}

.card-tools { display: flex; gap: 6px; }

.mini-btn {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 10px;
  color: var(--muted);
  cursor: pointer;
  transition: color .15s, border-color .15s;
}
.mini-btn svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.mini-btn:hover { color: var(--ink); border-color: var(--line-2); }
.mini-btn[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); }
.mini-btn[aria-pressed="true"] .star-path { fill: currentColor; }

.card {
  position: relative;
  height: clamp(320px, 46vh, 400px);
  perspective: 1600px;
  cursor: pointer;
  outline: none;
}
.card:focus-visible .card-inner { box-shadow: 0 0 0 3px var(--accent-wash), 0 0 0 4px var(--accent); }

.card-inner {
  position: relative;
  width: 100%; height: 100%;
  transform-style: preserve-3d;
  transition: transform .5s cubic-bezier(.22, .75, .2, 1);
  border-radius: var(--radius);
}
.card.is-flipped .card-inner { transform: rotateY(180deg); }

.face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px 26px 22px;
  overflow: hidden;
}

.face-front {
  justify-content: center;
  align-items: center;
  gap: 18px;
  background:
    radial-gradient(120% 100% at 50% 0%, rgba(255, 255, 255, .7), transparent 55%),
    var(--panel);
}
[data-theme="dark"] .face-front { background: var(--panel); }

.front-word {
  font-family: var(--en);
  font-size: clamp(2.6rem, 11vw, 4.4rem);
  line-height: 1.08;
  letter-spacing: -.015em;
  text-align: center;
  word-break: break-word;
  max-width: 100%;
}
.front-word.is-cn {
  font-family: var(--serif);
  font-size: clamp(1.9rem, 7.4vw, 2.9rem);
  line-height: 1.35;
  letter-spacing: .01em;
}

.flip-hint {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: .08em;
  display: flex;
  align-items: center;
  gap: 6px;
}
.flip-hint::before {
  content: "";
  width: 22px; height: 1px;
  background: var(--line-2);
  display: inline-block;
}

.face-back {
  transform: rotateY(180deg);
  justify-content: center;
  gap: 14px;
  overflow-y: auto;
}

.back-main {
  font-family: var(--serif);
  font-size: clamp(1.55rem, 5.6vw, 2.1rem);
  line-height: 1.4;
  color: var(--ink);
}
.back-main.is-en {
  font-family: var(--en);
  font-size: clamp(2.1rem, 8vw, 2.9rem);
  letter-spacing: -.01em;
}

.back-alt {
  font-family: var(--serif);
  font-size: 1.05rem;
  color: var(--muted);
  margin-top: -6px;
}

.tip {
  font-size: 13px;
  color: var(--accent);
  background: var(--accent-wash);
  border-radius: 8px;
  padding: 7px 11px;
  align-self: flex-start;
  max-width: 100%;
}

.example {
  border-left: 3px solid var(--line-2);
  padding-left: 12px;
  max-width: 100%;
}

.ex-text {
  font-family: var(--en);
  font-size: 15.5px;
  line-height: 1.65;
  color: var(--ink-2);
}
.ex-text mark {
  background: var(--accent-wash);
  color: var(--accent);
  font-weight: 600;
  padding: 0 3px;
  border-radius: 3px;
}

.ex-src { font-size: 11.5px; color: var(--muted); margin-top: 5px; }

/* ---------- 评分 ---------- */

.rate {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 16px;
}

.rate-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  height: 54px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s, transform .1s;
}
.rate-btn kbd {
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 0 5px;
  line-height: 16px;
}
.rate-btn:hover { transform: translateY(-1px); }
.rate-btn:active { transform: translateY(0); }

.rate-btn.again:hover { color: var(--red); border-color: var(--red); background: var(--red-wash); }
.rate-btn.fuzzy:hover { color: var(--amber); border-color: var(--amber); background: var(--amber-wash); }
.rate-btn.know:hover { color: var(--green); border-color: var(--green); background: var(--green-wash); }

.meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
  justify-content: center;
  margin-top: 14px;
  font-size: 12.5px;
  color: var(--muted);
}
.meta .dot { opacity: .6; }

.link-btn {
  border: 0; background: none; padding: 0 0 0 10px;
  border-left: 1px solid var(--line);
  color: var(--muted);
  font-size: 12.5px;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  margin-left: 3px;
}
.link-btn:hover { color: var(--accent); }

/* ---------- 完成页 ---------- */

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

.done-inner {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 34px 26px 30px;
  text-align: center;
}

.done-seal {
  width: 52px; height: 52px;
  margin: 0 auto 14px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--accent-wash);
  color: var(--accent);
  font-size: 24px;
  border: 1px solid var(--accent-line, var(--line));
}

.done-kicker {
  font-size: 11.5px;
  letter-spacing: .22em;
  color: var(--accent);
  text-transform: uppercase;
}

.done h2 {
  font-family: var(--serif);
  font-size: 26px;
  margin: 10px 0 8px;
}

.done-sub { color: var(--muted); font-size: 14px; }

.done-stats {
  margin-top: 6px;
  font-size: 12.5px;
  color: var(--muted);
}

.done-actions { display: flex; gap: 10px; justify-content: center; margin-top: 24px; flex-wrap: wrap; }

.btn-primary, .btn-ghost {
  border-radius: 12px;
  padding: 11px 22px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: transform .12s, background .15s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-2); transform: translateY(-1px); }
.btn-ghost { background: transparent; border-color: var(--line-2); color: var(--ink-2); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- 词表 ---------- */

.sheet { position: fixed; inset: 0; z-index: 40; display: grid; place-items: end center; }
.sheet[hidden] { display: none; }

.sheet-backdrop {
  position: absolute; inset: 0;
  background: rgba(25, 20, 12, .45);
  backdrop-filter: blur(2px);
  animation: fade .18s ease;
}

.sheet-panel {
  position: relative;
  width: min(720px, 100%);
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px 22px 0 0;
  box-shadow: 0 -20px 60px -30px rgba(0, 0, 0, .45);
  animation: rise .22s ease;
  padding: 18px 18px calc(14px + var(--safe-bottom));
  outline: none;
}

@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(18px); opacity: .6; } }

.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex: none; }
.sheet-head h2 { font-family: var(--serif); font-size: 18px; }
.sheet-head h2 span { font-family: var(--sans); font-size: 12px; color: var(--muted); font-weight: 400; margin-left: 6px; }

.sheet-hint { font-size: 12px; color: var(--muted); margin: 6px 0 12px; flex: none; }

.sheet-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(158px, 1fr));
  gap: 7px;
  padding-right: 4px;
  align-content: start;
}

.word-chip {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 12.5px;
  line-height: 1.4;
  text-align: left;
  cursor: pointer;
  min-width: 0;
}
.word-chip:hover { border-color: var(--accent); }
.word-chip i { margin-top: 5px; }
.word-chip .w { font-family: var(--en); font-size: 13.5px; font-weight: 600; word-break: break-word; }
.word-chip .c { color: var(--muted); font-size: 11.5px; }

.sheet-foot { display: flex; gap: 14px; padding-top: 12px; margin-top: 10px; border-top: 1px solid var(--line); font-size: 11.5px; color: var(--muted); flex-wrap: wrap; flex: none; }
.legend { display: inline-flex; align-items: center; gap: 5px; }

i[class^="dot-"], .word-chip i {
  width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none;
}
.dot-know, .word-chip[data-s="know"] i { background: var(--green); }
.dot-fuzzy, .word-chip[data-s="fuzzy"] i { background: var(--amber); }
.dot-again, .word-chip[data-s="again"] i { background: var(--red); }
.dot-new, .word-chip[data-s="new"] i { background: var(--line-2); }

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

@media (max-width: 520px) {
  body { font-size: 14.5px; }
  .app { padding: 0 12px calc(20px + var(--safe-bottom)); }
  .bar { padding: 12px 2px 10px; }
  .seal { width: 38px; height: 38px; font-size: 19px; }
  .brand-text h1 { font-size: 16px; }
  .brand-text p { font-size: 10.5px; }
  .icon-btn { width: 38px; height: 38px; }
  .card { height: clamp(300px, 46vh, 380px); }
  .face { padding: 20px 18px; }
  .rate-btn { height: 50px; font-size: 13.5px; gap: 6px; }
  .rate-btn kbd { display: none; }
  .meta { font-size: 11.5px; }
  .back-main { font-size: 1.45rem; }
  .ex-text { font-size: 14.5px; }
  .sheet-body { grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  .card-inner, .progress-fill, .sheet-panel, .sheet-backdrop { transition: none; animation: none; }
}

/* 键盘用户 */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* 保证 hidden 属性始终生效（覆盖组件自身的 display） */
[hidden] { display: none !important; }
