:root {
  --bg: #f3efe4;
  --ink: #1c2430;
  --muted: #5d675f;
  --card: #fffdf8;
  --pine: #1e3d34;
  --moss: #2f5d4e;
  --line: #e4d9c4;
  --seal: #b6402c;
  --ok: #1f7a45;
  --badbg: #fdeeea;
  --sel-bg: #e7f0ea;
  --sel-border: #2f5d4e;
  --key-bg: #f4eed8;
  --key-border: #d9cba8;
  --radius: 1.5rem;
  --tap: 52px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "PingFang SC", "Noto Sans SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  font-size: 18px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  min-height: 100%;
  min-height: 100dvh;
  overscroll-behavior: none;
}

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

button {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

body.dic-open {
  overflow: hidden;
  position: fixed;
  width: 100%;
}

.app {
  max-width: 72rem;
  margin: 0 auto;
  padding: calc(16px + var(--safe-t)) calc(20px + var(--safe-r)) calc(24px + var(--safe-b)) calc(20px + var(--safe-l));
}

.top {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 0 4px;
}

.top-inner { min-width: 0; flex: 1; }

.top h1 {
  margin: 0;
  font-size: 1.875rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--ink);
}

.unit-line {
  margin: 6px 0 0;
  font-size: 15px;
  font-weight: 500;
  color: var(--muted);
}

.top-tools { display: flex; gap: 8px; flex-shrink: 0; }

.top-chip {
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--ink);
  font-size: 15px;
  font-weight: 600;
}

.pager {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 18px 0 10px;
}

.unit-pager {
  margin: 18px 0 0;
}

.unit-pills {
  justify-content: flex-start;
}

.unit-pill {
  font-size: 15px;
  padding: 0 12px;
  min-width: auto;
}

.unit-pill[aria-current="true"] {
  background: var(--pine);
  border-color: var(--pine);
  color: #fff;
}

.page-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  flex: 1;
  justify-content: center;
}

.pill, .nav-btn {
  min-height: var(--tap);
  min-width: var(--tap);
  border-radius: 14px;
  border: 1px solid var(--line);
  padding: 0 16px;
  font-weight: 600;
  background: var(--card);
  color: var(--ink);
}

.nav-btn { white-space: nowrap; }

.pill { font-size: 20px; }

.pill[aria-current="page"] {
  background: var(--pine);
  border-color: var(--pine);
  color: #fff;
}

.hint {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 16px;
}

.layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

@media (min-width: 768px) {
  .layout {
    grid-template-columns: minmax(0, 1fr) 20rem;
    align-items: start;
  }
  .list-panel {
    position: sticky;
    top: 12px;
    max-height: calc(100dvh - var(--safe-t) - 24px);
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }
}

.page-card, .list-panel {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  padding: 20px 20px 24px;
}

.page-title {
  margin: 0 0 16px;
  font-size: 20px;
  font-weight: 600;
  color: var(--muted);
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.block { margin: 0 0 18px; }

.block-label {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 0 0 8px;
  font-size: 14px;
  color: var(--muted);
  font-weight: 700;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: #eee8dc;
  color: var(--pine);
  font-size: 13px;
}

.badge.sec { background: #f3e6e3; color: var(--seal); }
.badge.pic { background: #f4eed8; color: #7a5a20; }
.badge.gram { background: #e7f0ea; color: var(--moss); }
.badge.poster { background: #eee8dc; color: var(--pine); }

.unit-banner, .section-banner {
  font-size: 26px;
  font-weight: 700;
  color: var(--pine);
  margin-bottom: 6px;
}

.section-banner { font-size: 22px; }

.en {
  font-family: "Trebuchet MS", "Segoe UI", "Nunito", "PingFang SC", sans-serif;
  font-size: 22px;
  line-height: 1.75;
}

.instruction .en, .note, .picture-note, .grammar { font-size: 18px; }

.note, .picture-note {
  background: #faf7f0;
  border: 1px dashed #e4d9c4;
  border-radius: 14px;
  padding: 12px 14px;
  color: var(--muted);
}

.grammar {
  background: #f3f7f5;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
}

.dialogue .en, .chant .en, .prompt .en, .exercise .en, .puzzle .en, .poster .en {
  font-size: 22px;
}

.speaker {
  font-weight: 700;
  color: var(--pine);
  margin-right: 8px;
}

.word, .phrase-chip {
  display: inline;
  border-radius: 8px;
  padding: 0.12em 0.2em;
  margin: 0 0.04em;
  border: 1.5px solid transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.word.key {
  background: var(--key-bg);
  border-color: var(--key-border);
  font-weight: 700;
}

.word.stressed::before {
  content: "•";
  color: var(--moss);
  font-weight: 800;
  margin-right: 1px;
}

.word:active, .phrase-chip:active { transform: scale(0.98); }

.word.in-list, .phrase-chip.in-list {
  background: var(--sel-bg);
  border-color: var(--sel-border);
}

.phrases {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.phrase-chip {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 12px;
  background: #f3f7f5;
  border: 2px solid #c5d6cf;
  border-radius: 999px;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  font-size: 18px;
  font-weight: 700;
  color: var(--pine);
}

.vocab {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

@media (min-width: 640px) {
  .vocab { grid-template-columns: 1fr 1fr; }
}

.vocab-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 56px;
  padding: 8px 12px;
  background: #faf7f0;
  border: 1px solid var(--line);
  border-radius: 14px;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  font-size: 20px;
}

.vocab-n {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #e7f0ea;
  color: var(--pine);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  flex: 0 0 auto;
}

.arrow { color: var(--muted); }

.list-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.list-head h2 { margin: 0; font-size: 22px; font-weight: 600; }
.count { color: var(--muted); font-weight: 700; }

.list-empty { color: var(--muted); margin: 10px 0; }

.chip-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 42vh;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

@media (min-width: 768px) {
  .chip-list { max-height: none; }
}

.chip-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: #faf7f0;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 8px 8px 8px 14px;
  min-height: 52px;
}

.chip-text {
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  font-weight: 700;
  font-size: 20px;
}

.btn-remove {
  min-width: 44px;
  min-height: 44px;
  border: none;
  background: var(--badbg);
  color: var(--seal);
  border-radius: 12px;
  font-size: 20px;
  font-weight: 800;
}

.list-actions {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.sr-file {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.overlay.hidden, .hidden, .list-empty.hidden { display: none; }

.overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: #f3efe4;
  color: #1c2430;
  display: flex;
}
.overlay.hidden { display: none; }

.dic-shell {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  height: 100dvh;
}

.dic-main {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: calc(8px + var(--safe-t)) 16px 24px;
}

.dic-main-inner {
  max-width: 48rem;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

.dic-top-space { height: 1.75rem; flex-shrink: 0; }

.dic-back {
  width: fit-content;
  text-align: left;
  font-size: 20px;
  font-weight: 600;
  line-height: 1;
  color: #1e3d34;
  background: none;
  border: none;
  padding: 0;
  min-height: 44px;
}

.dic-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.dic-meta {
  margin: 0;
  font-size: 14px;
  color: #5d675f;
}

.dic-bar {
  margin-top: 12px;
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #e4d9c4;
}

.dic-bar > span {
  display: block;
  height: 100%;
  background: #2f5d4e;
  border-radius: inherit;
}

.dic-title {
  margin: 8px 0 0;
  font-size: 30px;
  font-weight: 600;
}

.dic-lead {
  margin: 16px 0 0;
  font-size: 16px;
  line-height: 1.7;
  color: #5d675f;
}

.dic-score {
  margin: 16px 0 0;
  font-size: 48px;
  font-weight: 600;
  color: #1e3d34;
}

.dic-score small { font-size: 24px; font-weight: 600; }

.dic-foot {
  flex-shrink: 0;
  border-top: 1px solid #e4d9c4;
  background: rgba(243, 239, 228, 0.95);
  padding: 12px 16px calc(12px + var(--safe-b));
}

.dic-foot-inner {
  max-width: 48rem;
  margin: 0 auto;
  display: grid;
  gap: 16px;
}

.dic-row3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

.btn-thick,
.btn-pine,
.btn-ghost-thick {
  width: 100%;
  min-height: 5.25rem;
  padding: 0 16px;
  border-radius: 16px;
  font-size: 20px;
  font-weight: 600;
  border: 1px solid transparent;
}

.btn-pine { background: #1e3d34; color: #fff; border-color: #1e3d34; }
.btn-ghost-thick { background: #fffdf8; color: #1c2430; border-color: #e4d9c4; }
.btn-thick:disabled,
.btn-pine:disabled,
.btn-ghost-thick:disabled,
.btn-ghost-dock:disabled { opacity: 0.4; }

.btn-ghost-dock {
  width: 100%;
  min-height: 44px;
  padding: 0 16px;
  border: none;
  background: none;
  color: var(--pine);
  font-size: 18px;
  font-weight: 600;
}

.grade-list, .record-list, .miss-list { list-style: none; margin: 16px 0 0; padding: 0; }
.grade-list li,
.record-list li,
.miss-list li {
  border: 1px solid #e4d9c4;
  background: #fffdf8;
  border-radius: 16px;
  padding: 12px 16px;
  margin: 0 0 12px;
}
.miss-list li { background: #fdeeea; border: none; }

.grade-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.grade-word {
  flex: 1 1 8em;
  margin: 0;
  font-size: 26px;
  font-weight: 600;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
}

.grade-recognized {
  margin: 4px 0 0;
  font-size: 14px;
  color: #5d675f;
  flex: 1 1 100%;
  order: 3;
}

.grade-btns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  flex: 1 1 16em;
}

.btn-mark {
  min-height: 3.5rem;
  min-width: 7.5rem;
  border-radius: 16px;
  padding: 0 16px;
  font-size: 18px;
  font-weight: 600;
  border: 1px solid #e4d9c4;
  background: #f3efe4;
  color: #1c2430;
  white-space: nowrap;
}

.btn-mark.on-ok { background: #1f7a45; color: #fff; border-color: #1f7a45; }
.btn-mark.on-bad { background: #b6402c; color: #fff; border-color: #b6402c; }

.btn-photo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid #e4d9c4;
  background: #fffdf8;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}

.btn-photo.is-busy { opacity: 0.5; pointer-events: none; }

.record-when, .error-sub { margin: 0; font-size: 14px; color: #5d675f; }
.record-title { margin: 4px 0 0; font-size: 20px; font-weight: 600; }
.record-score { margin: 4px 0 0; }
.ok-note { margin: 8px 0 0; font-size: 14px; color: #1f7a45; }
.btn-mini {
  margin-top: 12px;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 12px;
  background: #1e3d34;
  color: #fff;
  border: none;
  font-size: 16px;
  font-weight: 600;
}
.error-word, .miss-word {
  margin: 0;
  font-size: 24px;
  font-weight: 600;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
}

.blank {
  display: inline-block;
  min-width: 6em;
  border-bottom: 2px solid #c0b6a8;
  margin: 0 4px;
}

@media (max-width: 640px) {
  .top h1 { font-size: 26px; }
  .en, .dialogue .en, .chant .en { font-size: 20px; }
  .nav-btn { padding: 0 10px; font-size: 16px; }
}

.simple-page .section-mark {
  font-size: 32px;
  font-weight: 700;
  color: var(--pine);
  margin: 0 0 20px;
  letter-spacing: 0.02em;
}
.simple-page .en {
  font-size: 24px;
  line-height: 2;
  margin: 0 0 16px;
}
.simple-page .word {
  padding: 0.15em 0.18em;
  margin: 0 0.02em;
  border: none;
  border-radius: 4px;
  background: transparent;
  font-weight: inherit;
}
.simple-page .word.key,
.simple-page .word.stressed::before {
  background: none;
  border: none;
  font-weight: inherit;
  content: none;
}
.simple-page .word.in-list {
  background: var(--sel-bg);
  border-radius: 4px;
  padding: 0.15em 0.18em;
}
.simple-page .vocab-plain .en { margin-bottom: 8px; }
.simple-page .page-title {
  font-size: 20px;
  color: var(--muted);
  font-weight: 600;
}

.simple-page .backup-box {
  margin-top: 28px;
  padding: 16px 16px 10px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #faf7f0;
}
.simple-page .backup-box h3 {
  margin: 0 0 4px;
  font-size: 16px;
  font-weight: 700;
  color: var(--muted);
}
.simple-page .backup-hint {
  margin: 0 0 14px;
  font-size: 13px;
  color: var(--muted);
}
.simple-page .backup-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 8px;
  margin: 0 0 8px;
}
.simple-page .backup-label {
  font-size: 12px;
  color: var(--muted);
  flex: 0 0 auto;
}
.simple-page .backup-box .en {
  font-size: 18px;
  line-height: 1.75;
  margin: 0;
  flex: 1 1 12em;
}

.grade-word-wrap { flex: 1 1 8em; min-width: 0; }
.grade-word-wrap .grade-word { margin: 0; }
.grade-word-wrap .grade-recognized { margin: 4px 0 0; flex: none; order: 0; }

