:root {
  color-scheme: light;
  --brand: #b3261e;
  --bg: #faf7f2;
  --card-bg: #ffffff;
  --border: #ddd4c8;
  --correct: #2e7d32;
  --incorrect: #c62828;
  --text: #1f1a17;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--card-bg);
}

.topbar .brand {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--brand);
  text-decoration: none;
}

.topbar nav {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.inline-form {
  display: inline;
}

.inline-form button {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  font: inherit;
  padding: 0;
}

.content {
  max-width: 640px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: 320px;
}

.auth-form input,
.auth-form textarea {
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  resize: vertical;
}

.auth-form button {
  margin-top: 0.5rem;
  padding: 0.6rem;
  border: none;
  border-radius: 6px;
  background: var(--brand);
  color: white;
  cursor: pointer;
}

.form-error {
  color: var(--incorrect);
}

#sentence-app {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
}

#sentence-app[hidden] {
  display: none;
}

.session-info {
  margin: 0;
  color: #6b5f52;
  font-size: 0.9rem;
  text-transform: capitalize;
}

.progress-bar {
  width: 100%;
  height: 8px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--correct);
  border-radius: 999px;
  transition: width 0.25s ease;
}

.sentence {
  font-size: 2.3rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  line-height: 1.4;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.15em;
}

.token {
  display: inline-block;
}

.token-box {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  min-width: 2.1rem;
  margin: 0 0.06em;
}

.token-char,
.token-pinyin {
  display: block;
  text-align: center;
}

.token-char {
  font-size: 2.2rem;
  line-height: 1.1;
}

.token-pinyin {
  font-size: 0.9rem;
  color: #6b5f52;
  line-height: 1.2;
  margin-top: 0.2rem;
}

.token-target .token-char {
  color: var(--brand);
  text-decoration: underline;
  text-underline-offset: 6px;
}

.token-target .token-pinyin {
  color: var(--brand);
  text-decoration: underline;
  text-underline-offset: 4px;
}

.token-done .token-char,
.token-done .token-pinyin {
  color: var(--correct);
}

.token-hint {
  display: block;
  text-align: center;
  font-size: 0.8rem;
  color: #6b5f52;
  margin-top: 0.2rem;
  font-style: italic;
}

.card {
  width: 100%;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2rem;
  text-align: center;
}

#replay-audio {
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 999px;
  padding: 0.4rem 1rem;
  cursor: pointer;
}

.audio-controls {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
}

#speed-control {
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 999px;
  padding: 0.4rem 1rem;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
  min-width: 3.5rem;
}

#help-hint {
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 999px;
  padding: 0.4rem 1rem;
  cursor: pointer;
}

#help-hint.active {
  border-color: var(--brand);
  background: var(--brand);
  color: white;
}

#speed-control:hover,
#replay-audio:hover,
#help-hint:hover {
  border-color: var(--brand);
}

.options {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.option {
  padding: 0.9rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
  cursor: pointer;
  font-size: 1rem;
  text-align: left;
}

.option:hover:not(:disabled) {
  border-color: var(--brand);
}

.option:disabled {
  cursor: default;
}

.option.correct {
  border-color: var(--correct);
  background: #e8f5e9;
}

.option.incorrect {
  border-color: var(--incorrect);
  background: #fdecea;
}

.feedback {
  min-height: 1.5rem;
  font-weight: 600;
}

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

.feedback-incorrect {
  color: var(--incorrect);
}

.feedback small {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.9rem;
  opacity: 0.9;
}

.next-button {
  align-self: center;
  padding: 0.75rem 2rem;
  border: none;
  border-radius: 999px;
  background: var(--brand);
  color: white;
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(179, 38, 30, 0.3);
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.2s ease;
  animation: next-button-in 0.25s ease;
}

.next-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(179, 38, 30, 0.4);
}

.next-button:active {
  transform: translateY(0);
  box-shadow: 0 2px 8px rgba(179, 38, 30, 0.3);
}

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

@keyframes next-button-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(31, 26, 23, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  z-index: 10;
}

.modal-overlay[hidden] {
  display: none;
}

.modal-card {
  background: var(--card-bg);
  border-radius: 16px;
  padding: 2.5rem 2rem;
  max-width: 360px;
  width: 100%;
  text-align: center;
  box-shadow: 0 12px 40px rgba(31, 26, 23, 0.25);
  animation: modal-in 0.2s ease;
}

.modal-title {
  font-size: 1.4rem;
  font-weight: 700;
  margin: 0 0 0.5rem;
}

.modal-subtitle {
  margin: 0 0 1.5rem;
  color: #6b5f52;
}

.modal-card .next-button {
  width: 100%;
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.profile-section {
  margin-bottom: 2rem;
}

.profile-section h3 {
  margin-bottom: 0.5rem;
}

.profile-summary {
  color: #6b5f52;
}

.profile-empty {
  color: #6b5f52;
  font-style: italic;
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 1.5rem;
}

.stats-table th,
.stats-table td {
  padding: 0.6rem 0.8rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.stats-table th {
  background: var(--bg);
  font-weight: 600;
}

.stats-table tr:last-child td {
  border-bottom: none;
}

.improvement-positive {
  color: var(--correct);
  font-weight: 600;
}

.improvement-negative {
  color: var(--incorrect);
  font-weight: 600;
}

.improvement-neutral {
  color: #6b5f52;
}

.accuracy-neutral {
  color: #6b5f52;
}

.theme-progress-list {
  margin-bottom: 1.5rem;
}

.theme-progress-item {
  margin-bottom: 0.9rem;
}

.theme-progress-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: #6b5f52;
  text-transform: capitalize;
  margin-bottom: 0.3rem;
}

