:root {
  color-scheme: light;
  --page: #eef3f0;
  --surface: #ffffff;
  --surface-soft: #f6f8f7;
  --ink: #20312c;
  --muted: #61706b;
  --line: #cfd9d4;
  --green: #28734a;
  --green-dark: #1f593a;
  --blue: #3c6f8d;
  --gold: #d79b24;
  --red: #a7473d;
  --shadow: 0 10px 28px rgba(29, 53, 43, 0.1);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html { min-width: 320px; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--page);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.5;
  letter-spacing: 0;
}

button, input { font: inherit; letter-spacing: 0; }

button { cursor: pointer; }

[hidden] { display: none !important; }

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

a:hover { color: #284f66; }

:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 3px;
}

.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.header-inner {
  width: min(100% - 32px, 960px);
  min-height: 72px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.brand {
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--ink);
  text-decoration: none;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  background: #e5f1e8;
  border: 1px solid #b6ceb9;
  border-radius: 8px;
}

.brand-mark img {
  width: 32px;
  height: 32px;
  image-rendering: pixelated;
}

.brand strong, .brand small { display: block; }
.brand strong { font-size: 18px; }
.brand small { color: var(--muted); font-size: 12px; }

.view-tabs {
  align-self: stretch;
  display: flex;
  align-items: end;
  gap: 4px;
}

.view-tabs button {
  min-height: 48px;
  padding: 0 16px;
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--muted);
}

.view-tabs button[aria-selected="true"] {
  border-bottom-color: var(--green);
  color: var(--green-dark);
  font-weight: 700;
}

.app-main {
  width: min(100% - 32px, 960px);
  min-height: calc(100vh - 260px);
  margin: 0 auto;
  padding: 38px 0 56px;
}

.app-error {
  margin: 0 0 20px;
  padding: 12px 14px;
  border-left: 4px solid var(--red);
  background: #fff0ee;
  color: #772f29;
}

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

.eyebrow {
  margin: 0 0 4px;
  color: var(--green);
  font-size: 13px;
  font-weight: 800;
}

h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.25;
}

.progress {
  margin: 0;
  padding-bottom: 3px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.study-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 0 0 20px;
}

.mode-control {
  display: inline-grid;
  grid-template-columns: repeat(2, minmax(130px, 1fr));
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #dfe7e3;
}

.mode-control button {
  min-height: 40px;
  padding: 0 14px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: #4d5f58;
}

.mode-control button[aria-selected="true"] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(29, 53, 43, 0.14);
  font-weight: 700;
}

.reset-button {
  min-height: 44px;
  padding: 0 10px;
  border: 0;
  background: transparent;
  color: var(--blue);
  text-decoration: underline;
  text-underline-offset: 4px;
}

.study-card {
  height: 390px;
  min-height: 390px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
}

.card-loading, .prompt-hint { color: var(--muted); }
.card-loading { margin: auto; }
.card-prompt { display: grid; justify-items: center; gap: 16px; }
.prompt-hint { margin: 0; font-size: 15px; }

.crop-image-frame {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  overflow: hidden;
  border: 1px solid #bfcfc6;
  border-radius: 8px;
  background: #edf4ef;
}

.crop-image-frame img {
  image-rendering: pixelated;
  object-fit: contain;
}

.crop-image-large { width: 128px; height: 128px; }
.crop-image-large img { width: 96px; height: 96px; }
.crop-image-small { width: 76px; height: 76px; }
.crop-image-small img { width: 56px; height: 56px; }
.image-fallback { color: var(--muted); font-size: 13px; }

.prompt-english, .answer-english, .answer-chinese { margin: 0; }
.prompt-chinese { margin: 0; color: var(--ink); font-size: 24px; font-weight: 750; }
.prompt-english { font-size: 34px; font-weight: 800; }
.answer-english { font-size: 28px; font-weight: 800; }
.answer-chinese { color: #364b44; font-size: 20px; font-weight: 650; }

.answer-divider {
  width: min(100%, 340px);
  height: 1px;
  margin: 24px 0 20px;
  background: var(--line);
}

.card-answer { display: grid; justify-items: center; gap: 6px; }

.choice-grid {
  width: min(100%, 560px);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 20px;
}

.choice-option {
  min-width: 0;
  min-height: 52px;
  padding: 8px 12px;
  overflow-wrap: anywhere;
  border: 1px solid #9fb9aa;
  border-radius: 6px;
  background: #f7fbf8;
  color: var(--green-dark);
  font-size: 17px;
  font-weight: 750;
}

.choice-option:hover { border-color: var(--green); background: #e7f2ea; }

.answer-with-image {
  grid-template-columns: auto auto;
  align-items: center;
  justify-content: center;
  text-align: left;
  gap: 14px;
}

.study-actions { min-height: 72px; padding-top: 16px; }

.primary-action,
.grade-actions button {
  min-height: 48px;
  border-radius: 6px;
  font-weight: 750;
}

.primary-action {
  width: 100%;
  border: 1px solid var(--green-dark);
  background: var(--green);
  color: white;
}

.primary-action:hover { background: var(--green-dark); }

.grade-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.grade-actions button { border: 1px solid currentColor; background: var(--surface); }
.grade-again { color: var(--red); }
.grade-unsure { color: #876219; }
.grade-know { color: var(--green); }
.grade-actions button:hover { background: var(--surface-soft); }

.dictionary-heading { align-items: center; }

.search-field {
  width: min(100%, 320px);
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 13px;
}

.search-field input {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
}

.dictionary-count { margin: 0 0 16px; color: var(--muted); }

.crop-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.crop-item {
  min-width: 0;
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.dictionary-image { width: 72px; height: 72px; }
.dictionary-image img { width: 52px; height: 52px; }
.crop-item h2 { margin: 0; overflow-wrap: anywhere; font-size: 17px; line-height: 1.25; }
.crop-item p { margin: 3px 0 0; color: var(--muted); font-size: 14px; }
.dictionary-empty { grid-column: 1 / -1; padding: 48px 0; color: var(--muted); text-align: center; }

.detail-view { max-width: 680px; margin: 0 auto; }

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

.detail-topline .eyebrow { margin: 0; }

.text-button {
  min-height: 40px;
  padding: 0 10px;
  border: 0;
  background: transparent;
  color: var(--blue);
  text-decoration: underline;
  text-underline-offset: 4px;
}

.detail-card {
  min-height: 390px;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 14px;
  margin-top: 24px;
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
}

.detail-image { width: 128px; height: 128px; }
.detail-image img { width: 96px; height: 96px; }
.detail-card > div:nth-child(2) { display: grid; justify-items: center; gap: 3px; }
.detail-english { margin: 0; font-size: 32px; overflow-wrap: anywhere; }
.detail-chinese { margin: 0; color: #364b44; font-size: 21px; font-weight: 650; }

.detail-pronunciation {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}

.detail-ipa {
  margin: 0;
  color: var(--muted);
  font-family: "Segoe UI", "Arial Unicode MS", sans-serif;
  font-size: 18px;
}

.pronunciation-button {
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  display: grid;
  place-items: center;
  padding: 0 0 0 2px;
  border: 1px solid var(--blue);
  border-radius: 50%;
  background: var(--surface);
  color: var(--blue);
  font-size: 15px;
  line-height: 1;
}

.pronunciation-button:hover { background: #edf5f8; }
.pronunciation-button:disabled { border-color: var(--line); background: var(--surface-soft); color: #97a39e; cursor: not-allowed; }

.detail-result {
  width: min(100%, 500px);
  margin: 6px 0 0;
  padding: 10px 14px;
  border-left: 4px solid var(--gold);
  background: #fff9e5;
  color: #745b12;
}

.detail-correct { border-left-color: var(--green); background: #edf7ef; color: var(--green-dark); }
.detail-wrong { border-left-color: var(--red); background: #fff0ee; color: #772f29; }

.detail-actions {
  margin-top: 16px;
}

.audio-status {
  min-height: 24px;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.audio-status a { margin: 0 2px; }

.app-footer {
  border-top: 1px solid var(--line);
  background: #253a33;
  color: #dbe6e1;
}

.app-footer > div {
  width: min(100% - 32px, 960px);
  margin: 0 auto;
  padding: 26px 0 30px;
}

.app-footer p { margin: 4px 0; font-size: 13px; }
.app-footer a { color: #a9d5ea; }

@media (max-width: 760px) {
  .header-inner { width: min(100% - 24px, 960px); min-height: 64px; gap: 10px; }
  .brand-mark { width: 38px; height: 38px; }
  .brand-mark img { width: 28px; height: 28px; }
  .brand strong { font-size: 16px; }
  .brand small { display: none; }
  .view-tabs button { min-height: 44px; padding: 0 9px; font-size: 14px; }
  .app-main { width: min(100% - 24px, 960px); padding: 28px 0 44px; }
  .section-heading { align-items: start; flex-direction: column; gap: 10px; margin-bottom: 20px; }
  h1 { font-size: 24px; }
  .progress { white-space: normal; }
  .study-toolbar { align-items: stretch; flex-direction: column; margin-top: 8px; }
  .mode-control { width: 100%; }
  .mode-control button { padding: 0 7px; font-size: 13px; }
  .reset-button { align-self: end; }
  .study-card { padding: 24px 18px; }
  .prompt-english { font-size: 30px; overflow-wrap: anywhere; }
  .prompt-chinese { font-size: 22px; }
  .grade-actions { gap: 6px; }
  .grade-actions button { padding: 0 8px; }
  .choice-grid { gap: 8px; margin-top: 16px; }
  .choice-option { min-height: 50px; padding: 7px 8px; font-size: 15px; }
  .dictionary-heading { align-items: stretch; }
  .search-field { width: 100%; }
  .crop-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .crop-item { grid-template-columns: 56px minmax(0, 1fr); gap: 9px; padding: 10px; }
  .dictionary-image { width: 56px; height: 56px; }
  .dictionary-image img { width: 42px; height: 42px; }
  .crop-item h2 { font-size: 15px; }
  .detail-card { min-height: 390px; padding: 24px 18px; }
  .detail-english { font-size: 28px; }
  .app-footer > div { width: min(100% - 24px, 960px); }
}

@media (max-width: 390px) {
  .brand-mark { display: none; }
  .brand { gap: 0; }
  .crop-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
