@font-face {
  font-family: "HMC Han SC";
  src: url("../fonts/hmc-zh.woff2") format("woff2");
  font-display: block;
}

@font-face {
  font-family: "HMC Nom";
  src: url("../fonts/hmc-nom.woff2") format("woff2");
  font-display: block;
}

:root {
  color-scheme: light;
  --paper: #ece2cd;
  --card: #fbf6ea;
  --card-edge: #d9cbb0;
  --rule: #e6dcc6;
  --ink: #2a2520;
  --ink-soft: #655a4e;
  --right: #235c38;
  --right-bg: #e3eedd;
  --wrong: #96301f;
  --wrong-bg: #f7e3dc;
  --focus: #1b5aa6;
  --han-font: "HMC Han SC";
  --ui-font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

:root[data-deck="chu-nom"] {
  --han-font: "HMC Nom";
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 17px/1.5 var(--ui-font);
}

.page {
  max-width: 34rem;
  margin: 0 auto;
  padding: 12px 12px 20px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

button {
  font: inherit;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}

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

[tabindex="-1"]:focus {
  outline: none;
}

.han,
.glyph {
  font-family: var(--han-font), "Songti SC", "Noto Serif CJK SC", "Source Han Serif SC", serif;
  font-weight: 400;
}

/* Deck selector, progress, script and language switchers */

.top {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.bar-settings {
  justify-content: flex-end;
}

.bar-settings #scripts {
  margin-right: auto;
}

.pill {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--card-edge);
  border-radius: 999px;
  background: var(--card);
}

.pill[hidden] {
  display: none;
}

.pill button {
  min-height: 40px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  white-space: nowrap;
}

.pill.small button {
  min-height: 34px;
  padding: 0 9px;
  font-size: 0.86rem;
}

.pill button[aria-pressed="true"] {
  background: var(--ink);
  color: var(--card);
  font-weight: 600;
}

.progress {
  margin: 0;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

html[lang="vi"] [data-lang="en"],
html[lang="en"] [data-lang="vi"] {
  display: none;
}

/* The study card */

.card {
  background: var(--card);
  border: 1px solid var(--card-edge);
  border-radius: 14px;
  padding: 16px;
  box-shadow: 0 1px 0 #fff inset, 0 10px 28px rgba(70, 50, 20, 0.1);
}

.round-tag {
  margin: 0 0 4px;
  text-align: center;
  color: var(--ink-soft);
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.glyph-area {
  display: grid;
  place-items: center;
  padding: 4px 0 12px;
  border-bottom: 1px solid var(--rule);
}

.glyph-area.is-pair {
  grid-auto-flow: column;
  justify-content: center;
  gap: clamp(8px, 4vw, 28px);
}

.glyph-fig {
  margin: 0;
  text-align: center;
}

.glyph-fig figcaption {
  margin-top: -2px;
  color: var(--ink-soft);
  font-size: 0.8rem;
}

.glyph {
  display: block;
  font-size: clamp(7rem, 36vw, 11rem);
  line-height: 1.15;
}

.is-pair .glyph {
  font-size: clamp(5.6rem, 30vw, 9rem);
}

.prompt {
  margin: 12px 0;
  font-size: 1.05rem;
  font-weight: 600;
  text-align: center;
}

.options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.option {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  min-height: 64px;
  padding: 6px 8px;
  border: 1.5px solid var(--card-edge);
  border-radius: 10px;
  background: #fffdf6;
  cursor: pointer;
  text-align: center;
  overflow-wrap: anywhere;
}

.option-text {
  font-size: 1.1rem;
  line-height: 1.25;
}

.option:not([aria-disabled="true"]):hover {
  border-color: var(--ink);
}

.option:not([aria-disabled="true"]):active {
  background: var(--rule);
}

.option[aria-disabled="true"] {
  cursor: default;
}

.option.is-correct {
  border: 2px solid var(--right);
  background: var(--right-bg);
  color: var(--right);
  font-weight: 600;
}

.option.is-wrong {
  border: 2px dashed var(--wrong);
  background: var(--wrong-bg);
  color: var(--wrong);
}

.option.is-muted {
  color: var(--ink-soft);
  background: transparent;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1.2;
}

.icon {
  flex: none;
  width: 1.15em;
  height: 1.15em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Feedback */

.feedback {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--rule);
  scroll-margin-bottom: 12px;
}

.verdict {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  margin: 0 0 10px;
  font-weight: 600;
}

.verdict .icon {
  margin-top: 0.18em;
}

.verdict.is-right {
  color: var(--right);
}

.verdict.is-wrong {
  color: var(--wrong);
}

.answer {
  display: flex;
  align-items: center;
  gap: 14px;
}

.answer-glyph {
  flex: none;
  display: inline-flex;
  gap: 4px;
  font-size: 3.4rem;
  line-height: 1.1;
}

.answer-glyph.is-pair {
  font-size: 2.6rem;
}

.facts {
  margin: 0;
  min-width: 0;
}

.facts div {
  display: flex;
  gap: 8px;
  align-items: baseline;
}

.facts dt {
  flex: none;
  min-width: 4.6em;
  color: var(--ink-soft);
  font-size: 0.85rem;
}

.facts dd {
  margin: 0;
  font-weight: 600;
}

.facts .han {
  font-size: 1.25rem;
  font-weight: 400;
}

.note {
  margin: 10px 0 8px;
}

.note .han,
.lookup .han {
  font-size: 1.12em;
}

.lookup {
  margin: 0 0 12px;
  font-size: 0.9rem;
  color: var(--ink-soft);
}

a {
  color: var(--ink);
  text-underline-offset: 2px;
}

.primary,
.secondary {
  display: block;
  width: 100%;
  min-height: 48px;
  padding: 8px 16px;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
}

.primary {
  border: 1.5px solid var(--ink);
  background: var(--ink);
  color: var(--card);
}

.secondary {
  border: 1.5px solid var(--ink);
  background: transparent;
}

/* Results */

.result-title {
  margin: 4px 0 6px;
  font-size: 2rem;
  line-height: 1.2;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.result-lead {
  margin: 0 0 12px;
  text-align: center;
  color: var(--ink-soft);
}

.missed {
  list-style: none;
  margin: 0 0 14px;
  padding: 0;
  border-top: 1px solid var(--rule);
}

.missed li {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 0;
  border-bottom: 1px solid var(--rule);
}

.missed-glyph {
  flex: none;
  display: inline-flex;
  justify-content: center;
  gap: 2px;
  min-width: 1.2em;
  font-size: 2.6rem;
  line-height: 1.1;
}

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

.missed-text p {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  margin: 0;
}

.missed-text .icon {
  margin-top: 0.2em;
}

.missed-wrong {
  color: var(--wrong);
}

.missed-right {
  color: var(--right);
}

.actions {
  display: grid;
  gap: 10px;
}

.loading,
.load-error {
  margin: 24px 0;
  text-align: center;
}

/* Footer and sources */

.bottom {
  margin-top: 12px;
  text-align: center;
}

.link {
  min-height: 40px;
  padding: 6px 10px;
  border: 0;
  background: none;
  color: var(--ink-soft);
  font-size: 0.9rem;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

dialog {
  width: min(34rem, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  padding: 18px;
  border: 1px solid var(--card-edge);
  border-radius: 14px;
  background: var(--card);
  color: var(--ink);
  font-size: 0.95rem;
}

dialog::backdrop {
  background: rgba(42, 37, 32, 0.45);
}

dialog h2 {
  margin: 0 0 8px;
  font-size: 1.2rem;
}

dialog h3 {
  margin: 14px 0 4px;
  font-size: 1rem;
}

dialog p {
  margin: 0 0 8px;
}

dialog form {
  margin-top: 14px;
}

.noscript {
  margin: 16px;
  text-align: center;
}

@media (min-width: 520px) {
  .page {
    padding-top: 28px;
  }

  .card {
    padding: 24px 28px;
  }

  .glyph-area {
    padding: 12px 0 20px;
  }

  .actions {
    grid-template-columns: 1fr 1fr;
  }

  .actions > :only-child {
    grid-column: 1 / -1;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .option {
    transition: border-color 0.12s, background-color 0.12s;
  }
}
