:root {
  color-scheme: light;
  --bg: #f6f1df;
  --surface: #fffdf6;
  --surface-strong: #fff8d7;
  --ink: #23261f;
  --muted: #74776e;
  --line: rgba(35, 38, 31, 0.12);
  --green: #44765b;
  --green-dark: #254d3b;
  --amber: #c79b28;
  --red: #c65a4a;
  --shadow: 0 18px 45px rgba(41, 45, 36, 0.12);
}

body.dark {
  color-scheme: dark;
  --bg: #000;
  --surface: #1a1a1a;
  --surface-strong: #242424;
  --ink: #f0f0f0;
  --muted: #999;
  --line: rgba(255, 255, 255, 0.08);
  --green: #f97316;
  --green-dark: #fb923c;
  --amber: #fbbf24;
  --red: #f87171;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.7);
  background: #000;
}

body.dark .progress-pill,
body.dark .segmented,
body.dark .icon-button,
body.dark .deck-chip,
body.dark .pager button,
body.dark .library-module,
body.dark .toggle-row,
body.dark .audio-button,
body.dark .quiz-option {
  background: rgba(255, 255, 255, 0.04);
}

body.dark .icon-button.active,
body.dark .audio-button.speaking {
  background: rgba(248, 113, 113, 0.15);
  color: var(--red);
}

body.dark .deck-chip.active,
body.dark .library-module.active,
body.dark .tab.active,
body.dark .pos,
body.dark .quiz-option.correct {
  background: rgba(249, 115, 22, 0.15);
}

body.dark .quiz-option.wrong {
  background: rgba(248, 113, 113, 0.15);
  color: #fca5a5;
}

body.dark .quiz-feedback.wrong {
  color: #fca5a5;
}

body.dark .youdao-meaning {
  background: rgba(249, 115, 22, 0.1);
}

body.dark .youdao-tags span {
  background: rgba(249, 115, 22, 0.1);
}

body.dark .tabbar {
  background: rgba(0, 0, 0, 0.95);
  border-top-color: rgba(255, 255, 255, 0.06);
}

body.dark .flashcard,
body.dark .quiz-card {
  border-right-color: rgba(255, 255, 255, 0.06);
  border-bottom-color: rgba(255, 255, 255, 0.06);
  border-left-color: rgba(255, 255, 255, 0.06);
}

body.dark .reset-button {
  background: #1a1a1a;
}

body.dark .stat-box:hover,
body.dark .stat-box.active {
  box-shadow: 0 8px 22px rgba(249, 115, 22, 0.15);
}

@media (min-width: 720px) {
  body.dark {
    background: #000;
  }
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
  background: var(--bg);
  overflow: hidden;
}

body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 245, 173, 0.42), rgba(255, 255, 255, 0) 260px),
    var(--bg);
}

button,
input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.1s;
}

button:active {
  transform: scale(0.97);
}

.app-shell {
  width: min(100%, 480px);
  height: 100dvh;
  min-height: 0;
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) 12px calc(68px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

body.lookup-focus-mode .app-shell {
  padding: max(6px, env(safe-area-inset-top)) 12px max(8px, env(safe-area-inset-bottom));
}

body.lookup-focus-mode .topbar,
body.lookup-focus-mode .tabbar,
body.lookup-focus-mode #view-lookup > .section-heading {
  display: none;
}

.topbar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}

.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  line-height: 1.1;
}

.progress-bar {
  position: relative;
  height: 6px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--green);
  transition: width 0.3s ease;
}

.progress-label {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-align: right;
}

main {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.view {
  display: none;
}

.view-active {
  display: flex;
  min-height: 0;
  height: 100%;
  flex-direction: column;
  overflow: hidden;
}

.control-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  flex: 0 0 auto;
  padding: 2px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(255, 253, 246, 0.7);
}

.segment {
  min-height: 30px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}

.segment.active {
  background: var(--green);
  color: white;
  box-shadow: 0 8px 16px rgba(68, 118, 91, 0.2);
}

.icon-button {
  display: grid;
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 246, 0.82);
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}



.icon-button svg,
.audio-button svg,
.tab svg,
.search-box svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-button#favoriteButton svg {
  fill: currentColor;
  stroke: none;
}

.icon-button.theme-toggle svg {
  fill: currentColor;
  stroke: none;
  transition: transform 0.4s ease;
}

body.dark .icon-button.theme-toggle svg {
  transform: rotate(180deg);
}

.icon-button.active,
.icon-button.speaking,
.audio-button.speaking {
  color: #d45847;
  background: #fff1ed;
}

.deck-chips {
  display: flex;
  flex: 1 1 auto;
  gap: 3px;
}

.deck-chip {
  flex: 1 1 0;
  min-width: 0;
  min-height: 30px;
  padding: 0 5px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 253, 246, 0.76);
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.deck-chip.active {
  border-color: var(--green);
  background: rgba(68, 118, 91, 0.15);
  color: var(--green-dark);
}

.flashcard {
  flex: 1;
  min-height: 0;
  max-height: 460px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid rgba(35, 38, 31, 0.1);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.card-header {
  padding: 20px 18px 18px;
  background: linear-gradient(135deg, var(--green-dark), var(--green));
  color: white;
}

.card-header .card-meta {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  color: rgba(255, 255, 255, 0.65);
  font-size: 13px;
  font-weight: 800;
}

.flashcard .card-header h2 {
  overflow-wrap: anywhere;
  margin-top: 14px;
  color: white;
  font-size: clamp(36px, 12vw, 50px);
  line-height: 1.05;
  letter-spacing: 0;
}

.card-header .ipa {
  margin-top: 6px;
  color: rgba(255, 255, 255, 0.7);
  font-size: 18px;
  font-style: italic;
  line-height: 1.3;
}

.card-header .ipa-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}

.card-header .ipa-row .ipa {
  margin-top: 0;
}

.card-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 16px 18px 18px;
}

.card-meta {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.ipa {
  margin-top: 8px;
  color: #74776e;
  font-size: 18px;
  font-style: italic;
  line-height: 1.3;
}

.ipa-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.ipa-row .ipa {
  margin-top: 0;
}

.audio-button {
  display: inline-grid;
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 253, 246, 0.9);
  color: var(--green-dark);
}

.audio-button.dark {
  border-color: rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.12);
  color: white;
}

.audio-button.small {
  width: 30px;
  height: 30px;
  vertical-align: middle;
}

.audio-button.small svg {
  width: 18px;
  height: 18px;
}

.meaning-line {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 14px;
  padding: 12px 0 12px 12px;
  border-left: 3px solid var(--green);
  background: linear-gradient(90deg, rgba(68,118,91,0.04), transparent 60%);
  border-radius: 0 6px 6px 0;
  font-size: 19px;
  line-height: 1.38;
  font-weight: 750;
}

.pos {
  flex: 0 0 auto;
  padding: 3px 8px;
  border-radius: 999px;
  background: #e8efdf;
  color: var(--green-dark);
  font-size: 15px;
  line-height: 1.4;
  font-weight: 900;
}

.pos:empty {
  display: none;
}

.derivatives {
  display: grid;
  gap: 7px;
  margin: 14px 0 0;
  padding: 12px 0 0 14px;
  border-top: 1px dashed var(--line);
  list-style: none;
}

.derivatives:empty {
  display: none;
}

.derivatives li {
  position: relative;
  padding-left: 18px;
  color: var(--ink);
  font-size: 15px;
  line-height: 1.35;
}

.derivatives li::before {
  position: absolute;
  left: 0;
  content: "•";
  color: var(--green);
  font-weight: 900;
}

.derivatives strong {
  color: var(--green-dark);
  font-weight: 900;
}

.derivatives em {
  color: var(--muted);
  font-style: italic;
}

.derived-ipa {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0 2px;
}

.speech-status {
  min-height: 24px;
  margin: 7px 2px 8px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
  line-height: 1.4;
}

.speech-status:empty {
  display: none;
}

.card-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  flex: 0 0 auto;
}

.rating,
.pager button,
.reset-button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  color: white;
  font-size: 16px;
  font-weight: 900;
}

.rating-known {
  background: var(--green);
}

.rating-fuzzy {
  background: var(--amber);
}

.rating-unknown {
  background: var(--red);
}

.rating:disabled,
.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
  flex: 0 0 auto;
}

.pager button {
  border: 1px solid var(--line);
  background: rgba(255, 253, 246, 0.74);
  color: var(--ink);
}

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  flex: 0 0 auto;
}

.section-heading h2 {
  font-size: 24px;
  line-height: 1.15;
}

.section-heading span {
  color: var(--muted);
  font-weight: 800;
}

.library-modules {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
  flex: 0 0 auto;
}

.library-module {
  display: flex;
  min-height: 50px;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 246, 0.76);
  color: var(--muted);
}

.library-module strong {
  color: inherit;
  font-size: 16px;
  font-weight: 900;
}

.library-module span {
  color: inherit;
  font-size: 15px;
  font-weight: 900;
}

.library-module.active {
  border-color: rgba(68, 118, 91, 0.3);
  background: #e8efdf;
  color: var(--green-dark);
}

.search-box {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.search-box svg {
  flex: 0 0 auto;
  color: var(--muted);
}

.search-box input {
  width: 100%;
  min-height: 44px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: 15px;
}

.list {
  display: grid;
  gap: 8px;
  min-height: 0;
  overflow: auto;
  padding-bottom: 2px;
}

.list-item {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 8px 22px rgba(41, 45, 36, 0.06);
}

.list-item-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.list-item h3 {
  margin: 0;
  overflow-wrap: anywhere;
  color: var(--green-dark);
  font-size: 20px;
  line-height: 1.2;
}

.list-item .status {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

.list-item p {
  margin-top: 8px;
  color: var(--ink);
  font-size: 16px;
  line-height: 1.45;
}

.toggle-row {
  display: inline-flex;
  width: fit-content;
  min-height: 36px;
  align-items: center;
  gap: 8px;
  margin: 0 0 8px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 246, 0.76);
  color: var(--green-dark);
  font-size: 14px;
  font-weight: 900;
}

.toggle-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--green);
}

.list-item .ipa {
  margin: 0;
  font-size: 16px;
}

.empty {
  padding: 38px 18px;
  border: 1px dashed rgba(35, 38, 31, 0.2);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.6;
}

.quiz-card {
  padding: 16px;
  border: 1px solid rgba(35, 38, 31, 0.1);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.quiz-card h2 {
  overflow-wrap: anywhere;
  margin-top: 14px;
  color: var(--green-dark);
  font-size: clamp(28px, 8vw, 36px);
  line-height: 1.08;
}

.quiz-prompt {
  margin-top: 12px;
  color: var(--muted);
  font-size: 16px;
  font-weight: 900;
}

.quiz-options {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.quiz-option {
  min-height: 50px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 246, 0.82);
  color: var(--ink);
  text-align: left;
  font-size: 15px;
  font-weight: 850;
  line-height: 1.45;
}

.quiz-option.correct {
  border-color: rgba(68, 118, 91, 0.42);
  background: #e8efdf;
  color: var(--green-dark);
}

.quiz-option.wrong {
  border-color: rgba(198, 90, 74, 0.34);
  background: #fff1ed;
  color: #9f3e32;
}

.quiz-feedback {
  min-height: 24px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 15px;
  font-weight: 900;
  line-height: 1.45;
}

.quiz-feedback.correct {
  color: var(--green-dark);
}

.quiz-feedback.wrong {
  color: #9f3e32;
}

.quiz-next {
  width: 100%;
  min-height: 44px;
  margin-top: 8px;
  border: 0;
  border-radius: 8px;
  background: var(--green);
  color: white;
  font-size: 17px;
  font-weight: 900;
}

.quiz-next:disabled {
  opacity: 0.45;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.stat-box {
  position: relative;
  min-height: 90px;
  padding: 14px 14px 14px 18px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--line);
  border-radius: 0 8px 8px 0;
  background: var(--surface);
  box-shadow: 0 8px 22px rgba(41, 45, 36, 0.06);
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.stat-box[data-stats-filter="known"] { border-left-color: var(--green); background: rgba(68,118,91,0.06); }
.stat-box[data-stats-filter="known"] strong { color: var(--green); }
.stat-box[data-stats-filter="fuzzy"] { border-left-color: var(--amber); background: rgba(199,155,40,0.06); }
.stat-box[data-stats-filter="fuzzy"] strong { color: var(--amber); }
.stat-box[data-stats-filter="unknown"] { border-left-color: var(--red); background: rgba(198,90,74,0.06); }
.stat-box[data-stats-filter="unknown"] strong { color: var(--red); }
.stat-box[data-stats-filter="favorite"] { border-left-color: #d45847; background: rgba(212,88,71,0.06); }
.stat-box[data-stats-filter="favorite"] strong { color: #d45847; }

.stat-box:hover {
  border-color: var(--green);
  box-shadow: 0 8px 22px rgba(68, 118, 91, 0.14);
  transform: translateY(-1px);
}

.stat-box.active {
  border-color: var(--green);
  box-shadow: 0 8px 22px rgba(68, 118, 91, 0.22);
  transform: translateY(-1px);
}

.stat-box strong {
  display: block;
  color: var(--green-dark);
  font-size: 34px;
  line-height: 1;
  margin-bottom: 14px;
}

.stat-box span {
  display: block;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

#statsOverview,
#statsDetail {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.stats-detail-heading {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.stats-detail-heading > span {
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

.back-button {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 36px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--green-dark);
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
}

.back-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.back-button:hover {
  background: rgba(68, 118, 91, 0.1);
}

.stats-detail-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: grid;
  gap: 8px;
  padding-bottom: 2px;
}

.reset-button {
  width: 100%;
  margin-top: 14px;
  background: #2f332b;
}

.lookup-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  flex: 0 0 auto;
  margin-bottom: 8px;
  position: sticky;
  top: 0;
  z-index: 2;
}

.lookup-form input {
  min-width: 0;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: 0;
  background: var(--surface);
  color: var(--ink);
  font-size: 16px;
}

.lookup-form button {
  min-height: 44px;
  padding: 0 14px;
  border: 0;
  border-radius: 8px;
  background: var(--green);
  color: white;
  font-size: 15px;
  font-weight: 900;
}

.lookup-panel {
  min-height: 0;
  margin-bottom: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 8px 22px rgba(41, 45, 36, 0.06);
  overflow: auto;
}

.lookup-panel:empty {
  display: none;
}

#lookupResult {
  flex: 1 1 auto;
}

.lookup-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.lookup-title-row h3,
.lookup-entry h3 {
  margin: 0;
  color: var(--green-dark);
  font-size: 19px;
  line-height: 1.2;
}

.lookup-entry + .lookup-entry {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.lookup-note {
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
}

.youdao-phone-list {
  display: grid;
  gap: 7px;
  margin: 8px 0 10px;
}

.youdao-phone {
  display: inline-flex;
  width: fit-content;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 16px;
  font-style: italic;
  font-weight: 800;
}

.youdao-meaning-list {
  display: grid;
  gap: 8px;
}

.youdao-meaning {
  padding: 10px 11px;
  border-radius: 8px;
  background: rgba(232, 239, 223, 0.58);
  color: var(--ink);
  font-size: 17px;
  font-weight: 850;
  line-height: 1.45;
}

.youdao-web {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.youdao-web h4 {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.2;
}

.youdao-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.youdao-tags span {
  padding: 6px 9px;
  border-radius: 999px;
  background: rgba(255, 248, 215, 0.86);
  color: var(--green-dark);
  font-size: 14px;
  font-weight: 900;
}

.tabbar {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  width: min(100%, 480px);
  margin: 0 auto;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  border-top: 1px solid rgba(35, 38, 31, 0.12);
  background: rgba(255, 253, 246, 0.92);
  backdrop-filter: blur(18px);
}

.tab {
  position: relative;
  display: grid;
  min-height: 50px;
  place-items: center;
  gap: 2px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 10px;
  font-weight: 900;
  cursor: pointer;
  transition: color 0.2s;
}

.tab::after {
  content: "";
  position: absolute;
  top: 4px;
  left: 50%;
  width: 18px;
  height: 3px;
  border-radius: 999px;
  background: transparent;
  transform: translateX(-50%);
  transition: background 0.2s;
}

.tab.active {
  background: transparent;
  color: var(--green-dark);
}

.tab.active::after {
  background: var(--green);
}

@media (min-width: 720px) {
  .app-shell {
    padding-top: 34px;
  }

  body {
    background:
      linear-gradient(180deg, rgba(255, 245, 173, 0.34), rgba(255, 255, 255, 0) 310px),
      #efe8d1;
  }
}
