:root {
  color-scheme: light;
  --bg: #f6f3ee;
  --surface: #ffffff;
  --ink: #24302f;
  --muted: #65706d;
  --line: #d9ded5;
  --teal: #167f7a;
  --teal-dark: #0f5f5b;
  --coral: #c8553d;
  --gold: #d7a72f;
  --green-soft: #e2f4ef;
  --red-soft: #f9e5df;
  --shadow: 0 18px 45px rgba(36, 48, 47, 0.13);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(22, 127, 122, 0.06) 1px, transparent 1px),
    linear-gradient(rgba(200, 85, 61, 0.05) 1px, transparent 1px),
    var(--bg);
  background-size: 36px 36px;
  font-family:
    "Noto Sans Thai", Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", "Noto Sans SC", Arial, sans-serif;
}

button {
  font: inherit;
}

.app-shell {
  width: min(960px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0;
  display: grid;
  gap: 18px;
}

.login-shell {
  min-height: 100vh;
  width: min(820px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0;
  display: grid;
  align-items: center;
}

.hero-panel,
.account-panel,
.level-panel,
.login-panel,
.learning-panel,
.stats-panel,
.quiz-panel {
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.login-panel {
  position: relative;
  overflow: hidden;
  padding: 30px;
  display: grid;
  gap: 24px;
  align-items: center;
}

.login-panel::before {
  content: "HSK";
  position: absolute;
  right: 24px;
  top: 10px;
  color: rgba(22, 127, 122, 0.08);
  font-size: clamp(5rem, 18vw, 9rem);
  font-weight: 900;
  line-height: 1;
  pointer-events: none;
}

.auth-hero {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 102px minmax(0, 1fr);
  gap: 22px;
  align-items: center;
}

.login-copy {
  min-width: 0;
}

.login-copy h1 {
  margin-bottom: 8px;
  font-size: clamp(2rem, 7vw, 4rem);
  line-height: 1.08;
}

.login-panel .auth-form {
  position: relative;
  z-index: 1;
  grid-column: 1 / -1;
}

.auth-gateway {
  min-height: 430px;
}

.auth-choice-grid {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.auth-choice {
  min-height: 150px;
  padding: 18px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #fbfaf7;
  color: var(--ink);
  display: grid;
  align-content: center;
  gap: 8px;
  text-decoration: none;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    background-color 160ms ease;
}

.auth-choice:hover,
.auth-choice:focus-visible {
  border-color: var(--teal);
  background: #eef8f5;
  outline: none;
  transform: translateY(-2px);
}

.auth-choice.primary-choice {
  border-color: rgba(22, 127, 122, 0.62);
  background: #edf8f5;
}

.choice-kicker {
  color: var(--coral);
  font-size: 0.82rem;
  font-weight: 900;
  text-transform: uppercase;
}

.auth-choice strong {
  color: var(--teal-dark);
  font-size: clamp(1.45rem, 4vw, 2rem);
  line-height: 1.05;
}

.auth-choice span:last-child,
.auth-switch {
  color: var(--muted);
  font-weight: 800;
  line-height: 1.45;
}

.single-auth-form {
  grid-template-columns: 1fr;
}

.auth-switch {
  position: relative;
  z-index: 1;
  margin: -6px 0 0;
  text-align: right;
}

.auth-switch a,
.text-link {
  color: var(--teal-dark);
  font-weight: 900;
  text-decoration: none;
}

.auth-switch a:hover,
.auth-switch a:focus-visible,
.text-link:hover,
.text-link:focus-visible {
  color: var(--coral);
  outline: none;
}

.account-panel {
  min-height: 58px;
  padding: 14px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  color: var(--muted);
  font-weight: 900;
}

.account-panel strong {
  color: var(--ink);
  overflow-wrap: anywhere;
}

.account-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
}

.level-panel {
  padding: 18px;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
}

.level-card {
  min-height: 168px;
  padding: 16px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #fbfaf7;
  color: var(--ink);
  display: grid;
  align-content: center;
  gap: 8px;
  text-decoration: none;
  text-align: left;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    background-color 160ms ease;
}

button.level-card {
  width: 100%;
  font: inherit;
  cursor: pointer;
}

.level-card:hover,
.level-card:focus-visible {
  border-color: var(--teal);
  background: #eef8f5;
  outline: none;
  transform: translateY(-2px);
}

.level-card span {
  color: var(--coral);
  font-size: 0.82rem;
  font-weight: 900;
  text-transform: uppercase;
}

.level-card strong {
  color: var(--teal-dark);
  font-size: clamp(1.2rem, 3vw, 1.7rem);
  line-height: 1.1;
}

.level-card small {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
  line-height: 1.35;
}

.featured-level {
  border-color: rgba(22, 127, 122, 0.62);
  background: #edf8f5;
}

.unlocked-level {
  border-color: rgba(22, 127, 122, 0.72);
  background: #eef8f5;
}

.payment-notice {
  padding: 14px 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfaf7;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  align-items: center;
  font-weight: 800;
  box-shadow: var(--shadow);
}

.payment-notice strong {
  color: var(--teal-dark);
}

.payment-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  padding: 18px;
  background: rgba(25, 38, 42, 0.58);
  display: grid;
  place-items: center;
}

.payment-dialog {
  width: min(520px, 100%);
  max-height: calc(100vh - 36px);
  overflow: auto;
  position: relative;
  padding: 24px;
  border-radius: 8px;
  background: #fffdf8;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  display: grid;
  gap: 18px;
}

.payment-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #fbfaf7;
  color: var(--muted);
  cursor: pointer;
  font-size: 1.4rem;
  font-weight: 900;
  line-height: 1;
}

.payment-copy {
  margin: 8px 0 0;
  color: var(--muted);
  font-weight: 800;
  line-height: 1.5;
}

.qr-frame {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.qr-frame img {
  width: 100%;
  max-height: 520px;
  object-fit: contain;
  display: block;
}

.auth-status {
  margin: 0;
  color: var(--muted);
  font-size: 0.98rem;
  font-weight: 800;
  line-height: 1.5;
}

.auth-status.success {
  color: var(--teal-dark);
}

.auth-status.error {
  color: #8f321f;
}

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

.auth-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 900;
}

.auth-form label:first-child {
  grid-column: 1 / -1;
}

.auth-form input {
  min-height: 46px;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfaf7;
  color: var(--ink);
  font: inherit;
  font-size: 1rem;
}

.auth-form input:focus {
  border-color: var(--teal);
  outline: 3px solid rgba(22, 127, 122, 0.18);
}

.verify-form {
  grid-template-columns: 1fr;
}

.verify-form label:first-child {
  grid-column: auto;
}

.verify-form input {
  text-align: center;
  font-size: 1.25rem;
  font-weight: 900;
  letter-spacing: 0;
}

.auth-actions {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.resend-panel {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfaf7;
}

.resend-panel[hidden] {
  display: none;
}

.resend-panel p {
  margin: 0;
  color: var(--muted);
  font-weight: 800;
}

.hero-panel {
  min-height: 178px;
  padding: 26px;
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 22px;
  align-items: center;
}

.brand-mark {
  width: 102px;
  height: 102px;
}

.brand-mark svg {
  display: block;
  width: 100%;
  height: 100%;
}

.sheet {
  stroke-width: 4;
}

.sheet-back {
  fill: #f4d487;
  stroke: #a67618;
}

.sheet-front {
  fill: #e7f4f2;
  stroke: var(--teal);
}

.mark-text {
  fill: var(--teal-dark);
  font-size: 28px;
  font-weight: 800;
}

.mark-small {
  fill: var(--coral);
  font-size: 15px;
  font-weight: 800;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--coral);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 8px;
  font-size: clamp(2rem, 7vw, 4.6rem);
  line-height: 0.96;
  letter-spacing: 0;
}

.subtitle {
  max-width: 660px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 1.04rem;
  line-height: 1.6;
}

.stats-panel {
  padding: 18px;
  display: grid;
  grid-template-columns: repeat(3, minmax(110px, 0.32fr)) 1fr;
  gap: 14px;
  align-items: center;
}

.stat {
  min-height: 64px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  align-content: center;
  gap: 2px;
}

.stat-label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

.stat strong {
  font-size: 1.35rem;
}

.progress-track {
  height: 18px;
  border-radius: 999px;
  overflow: hidden;
  background: #ece8de;
  border: 1px solid #d6cdbc;
}

.progress-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--teal), var(--gold));
  transition: width 240ms ease;
}

.learning-panel {
  padding: 14px;
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
}

.mode-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.mode-button {
  min-height: 42px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfaf7;
  color: var(--muted);
  cursor: pointer;
  font-weight: 900;
}

.mode-button:hover,
.mode-button:focus-visible,
.mode-button.active {
  border-color: var(--teal);
  background: #eef8f5;
  color: var(--teal-dark);
  outline: none;
}

.learning-counters {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  color: var(--muted);
  font-weight: 900;
}

.learning-counters span {
  min-height: 42px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #fbfaf7;
}

.quiz-panel {
  padding: 28px;
}

.question-topline {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 800;
}

.level-return {
  margin-top: 14px;
  display: flex;
  justify-content: flex-end;
}

.link-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

#word {
  margin: 12px auto 8px;
  max-width: 760px;
  text-align: center;
  font-size: clamp(2rem, 8vw, 4.1rem);
  line-height: 1.12;
  letter-spacing: 0;
}

.question-label {
  margin: 20px 0 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.98rem;
  font-weight: 900;
}

.pinyin {
  margin-bottom: 24px;
  text-align: center;
  color: var(--teal-dark);
  font-size: clamp(1rem, 3.5vw, 1.25rem);
  font-weight: 800;
}

.word-tools {
  margin: -8px 0 20px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
}

.compact-action {
  min-height: 40px;
  padding: 9px 14px;
}

.icon-action {
  width: 42px;
  height: 42px;
  border: 1px solid var(--teal);
  border-radius: 50%;
  background: #eef8f5;
  color: var(--teal-dark);
  cursor: pointer;
  display: inline-grid;
  place-items: center;
  font-size: 1rem;
  font-weight: 900;
}

.icon-action:hover,
.icon-action:focus-visible {
  background: var(--teal);
  color: white;
  outline: 3px solid rgba(22, 127, 122, 0.2);
}

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

.study-card {
  margin: 8px auto 0;
  max-width: 720px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfaf7;
  display: grid;
  gap: 14px;
  justify-items: center;
}

.example-panel {
  margin-top: 16px;
  padding: 16px;
  border: 1px solid #d5e5df;
  border-radius: 8px;
  background: #f2faf7;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42px;
  gap: 14px;
  align-items: center;
}

.example-label {
  display: block;
  margin-bottom: 8px;
  color: var(--coral);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.example-zh,
.example-pinyin,
.example-thai {
  margin: 0;
  line-height: 1.45;
}

.example-zh {
  color: var(--ink);
  font-family: "Noto Sans SC", "Noto Sans Thai", sans-serif;
  font-size: clamp(1.25rem, 4vw, 1.8rem);
  font-weight: 900;
}

.example-pinyin {
  margin-top: 5px;
  color: var(--teal-dark);
  font-weight: 900;
}

.example-thai {
  margin-top: 5px;
  color: var(--muted);
  font-weight: 800;
}

.card-answer {
  margin: 0;
  color: var(--teal-dark);
  font-size: clamp(1.2rem, 4vw, 1.8rem);
  font-weight: 900;
  line-height: 1.35;
  text-align: center;
}

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

.option-button {
  min-height: 72px;
  padding: 14px 16px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #fbfaf7;
  color: var(--ink);
  cursor: pointer;
  font-size: 1.05rem;
  font-weight: 800;
  line-height: 1.35;
  text-align: left;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    background-color 160ms ease;
  overflow-wrap: anywhere;
}

.option-word {
  display: block;
  font-family: "Noto Sans SC", "Noto Sans Thai", sans-serif;
  font-size: clamp(1.55rem, 5vw, 2.25rem);
  line-height: 1.05;
}

.option-pinyin {
  display: block;
  margin-top: 6px;
  color: var(--teal-dark);
  font-size: 1rem;
  font-weight: 900;
  letter-spacing: 0.02em;
}

.option-button:hover:not(:disabled),
.option-button:focus-visible {
  border-color: var(--teal);
  background: #eef8f5;
  transform: translateY(-1px);
  outline: none;
}

.option-button.correct {
  border-color: var(--teal);
  background: var(--green-soft);
}

.option-button.wrong {
  border-color: var(--coral);
  background: var(--red-soft);
}

.option-button:disabled {
  cursor: default;
}

.feedback {
  min-height: 56px;
  margin-top: 20px;
  padding: 14px 16px;
  border-radius: 8px;
  border: 1px solid var(--line);
  color: var(--muted);
  font-weight: 800;
  line-height: 1.4;
}

.feedback.correct {
  border-color: #9acdc0;
  background: var(--green-soft);
  color: var(--teal-dark);
}

.feedback.wrong {
  border-color: #e5ad9e;
  background: var(--red-soft);
  color: #8f321f;
}

.actions {
  margin-top: 18px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.primary-action {
  min-width: 140px;
  min-height: 48px;
  padding: 12px 20px;
  border: 0;
  border-radius: 8px;
  background: var(--teal);
  color: white;
  cursor: pointer;
  font-weight: 900;
}

.secondary-action,
.ghost-action {
  min-height: 48px;
  padding: 12px 18px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 900;
}

.secondary-action {
  border: 1px solid var(--teal);
  background: #eef8f5;
  color: var(--teal-dark);
}

.secondary-action:hover,
.secondary-action:focus-visible {
  background: #dff0ec;
  outline: 3px solid rgba(22, 127, 122, 0.18);
}

.ghost-action {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
}

.ghost-action:hover,
.ghost-action:focus-visible {
  border-color: var(--coral);
  color: var(--coral);
  outline: 3px solid rgba(200, 85, 61, 0.16);
}

.primary-action:hover:not(:disabled),
.primary-action:focus-visible {
  background: var(--teal-dark);
  outline: 3px solid rgba(22, 127, 122, 0.25);
}

.primary-action:disabled {
  background: #b7c4bf;
  cursor: default;
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100% - 22px, 520px);
    padding: 14px 0;
    gap: 12px;
  }

  .hero-panel {
    min-height: 150px;
    grid-template-columns: 76px 1fr;
    gap: 14px;
    padding: 18px;
  }

  .login-shell {
    width: min(100% - 22px, 520px);
    padding: 14px 0;
  }

  .login-panel {
    grid-template-columns: 1fr;
    padding: 18px;
  }

  .auth-hero,
  .auth-choice-grid {
    grid-template-columns: 1fr;
  }

  .login-panel .brand-mark {
    width: 72px;
    height: 72px;
  }

  .account-panel {
    align-items: stretch;
    flex-direction: column;
  }

  .account-actions {
    justify-content: stretch;
  }

  .account-actions .text-link,
  .account-actions button {
    flex: 1 1 140px;
    text-align: center;
  }

  .level-panel {
    grid-template-columns: 1fr;
    padding: 14px;
  }

  .level-card {
    min-height: 118px;
  }

  .auth-form {
    grid-template-columns: 1fr;
  }

  .auth-actions {
    justify-content: stretch;
  }

  .auth-actions .text-link {
    width: 100%;
    text-align: center;
  }

  .auth-actions button {
    flex: 1 1 130px;
  }

  .auth-switch {
    text-align: center;
  }

  .brand-mark {
    width: 72px;
    height: 72px;
  }

  .subtitle {
    font-size: 0.96rem;
  }

  .stats-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    padding: 14px;
  }

  .progress-track {
    grid-column: 1 / -1;
  }

  .learning-panel {
    align-items: stretch;
    flex-direction: column;
  }

  .mode-tabs,
  .learning-counters {
    justify-content: stretch;
  }

  .mode-button,
  .learning-counters span {
    flex: 1 1 140px;
    justify-content: center;
  }

  .quiz-panel {
    padding: 18px;
  }

  .level-return {
    justify-content: stretch;
  }

  .link-action {
    width: 100%;
  }

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

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

  .example-panel {
    grid-template-columns: 1fr;
  }

  .option-button {
    min-height: 62px;
    font-size: 1rem;
  }

  .actions {
    justify-content: stretch;
    flex-direction: column;
  }

  .actions button,
  .primary-action {
    width: 100%;
  }
}
