/* ============================================================
   styles.css — Base Styles, Layout, Typography & Components
   
   Cupertino-inspired design system:
   - Native OS font stack (no webfont — the app is fully offline-capable)
   - Generous whitespace, max-width ~720px centered
   - Rounded corners, subtle shadows
   - Smooth micro-animations
   ============================================================ */

/* ── Reset & Base ─────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
}

body {
  /* Font fallback is resolved PER CHARACTER, so Latin text takes the first
     Latin font available while Hanzi fall through to the first CJK font:
       - 'Inter' / 'Segoe UI'          Latin, if installed
       - 'Microsoft YaHei UI'          Hanzi on Windows 10/11 (always present)
       - 'PingFang SC'                 Hanzi on macOS
       - 'Noto Sans SC'                Hanzi if installed locally
     No webfont is downloaded, so the app renders identically offline. */
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI Variable',
               'Segoe UI', 'Microsoft YaHei UI', 'Microsoft YaHei',
               'PingFang SC', 'Hiragino Sans GB', 'Noto Sans SC', SimSun,
               Roboto, Helvetica, Arial, sans-serif;
  font-size: 1rem;
  line-height: 1.6;
  color: var(--text-primary);
  background-color: var(--bg-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ── Screen Reader Utility ────────────────────────────────── */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* ── Accessible Skip Link ─────────────────────────────────── */
.skip-link {
  position: absolute;
  top: -60px;
  left: 1.5rem;
  background: var(--accent);
  color: var(--text-on-accent);
  padding: 0.625rem 1.25rem;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.9375rem;
  z-index: var(--z-toast);
  text-decoration: none;
  box-shadow: var(--shadow-lg);
  transition: top var(--transition-fast);
}

.skip-link:focus {
  top: 1rem;
  outline: 3px solid var(--border-focus);
  outline-offset: 3px;
}


/* ── Typography ───────────────────────────────────────────── */
h1, h2, h3, h4 {
  font-weight: 600;
  line-height: 1.25;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

h1 {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.025em;
}

h2 {
  font-size: 1.5rem;
}

h3 {
  font-size: 1.125rem;
}

p {
  color: var(--text-secondary);
  line-height: 1.7;
}

small {
  font-size: 0.8125rem;
  color: var(--text-tertiary);
}


/* ── Layout ───────────────────────────────────────────────── */
.app-container {
  width: 100%;
  max-width: 720px;
  padding: 0 1.5rem;
  margin: 0 auto;
}

.app-header {
  width: 100%;
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  background-color: var(--bg-primary);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.app-header::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 1.5rem;
  right: 1.5rem;
  height: 1px;
  background: var(--border-subtle);
}

.app-logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text-primary);
  text-decoration: none;
  user-select: none;
}

.header-center-flag {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.header-flag-img {
  height: 22px;
  width: auto;
  border-radius: 3px;
  box-shadow: 0 2px 6px rgba(170, 21, 32, 0.22), 0 1px 3px rgba(0, 0, 0, 0.12);
  display: block;
}

.app-main {
  width: 100%;
  max-width: 720px;
  padding: 2.5rem 1.5rem 4rem;
  min-height: calc(100vh - 4rem);
}


/* ── Screen Sections ──────────────────────────────────────── */
.screen {
  display: none;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity var(--transition-base),
              transform var(--transition-base);
}

.screen.active {
  display: block;
}

.screen.visible {
  opacity: 1;
  transform: translateY(0);
}


/* ── Cards ────────────────────────────────────────────────── */
.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition-fast),
              transform var(--transition-fast),
              border-color var(--transition-fast);
}

.card:hover {
  box-shadow: var(--shadow-md);
}

.card-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.card-header-icon {
  font-size: 1.5rem;
  line-height: 1;
}

.card-header-text h3 {
  margin-bottom: 0.125rem;
}

.card-header-text p {
  font-size: 0.8125rem;
  color: var(--text-tertiary);
  line-height: 1.4;
}


/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 500;
  line-height: 1;
  text-decoration: none;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  user-select: none;
  transition: all var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
  position: relative;
  overflow: hidden;
}

.btn:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* Primary button */
.btn-primary {
  background: var(--accent);
  color: var(--text-on-accent);
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  box-shadow: var(--shadow-md);
}

.btn-primary:active:not(:disabled) {
  background: var(--accent-active);
}

/* Secondary button */
.btn-secondary {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bg-hover);
  border-color: var(--border);
}

.btn-secondary:active:not(:disabled) {
  background: var(--bg-active);
}

/* Ghost button */
.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  padding: 0.5rem 0.75rem;
}

.btn-ghost:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* Icon-only button */
.btn-icon {
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--text-secondary);
  font-size: 1.25rem;
  border: none;
  cursor: pointer;
  transition: all var(--transition-fast);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-icon:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn-icon:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

/* Large button */
.btn-lg {
  padding: 1rem 2rem;
  font-size: 1.0625rem;
  font-weight: 600;
  border-radius: var(--radius-lg);
}

/* Full width */
.btn-full {
  width: 100%;
}

/* Button with ripple animation */
.btn .ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.25);
  transform: scale(0);
  animation: ripple-effect 500ms ease-out;
  pointer-events: none;
}

@keyframes ripple-effect {
  to {
    transform: scale(4);
    opacity: 0;
  }
}


/* ── Form Controls ────────────────────────────────────────── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.form-label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 0.01em;
  text-transform: uppercase;
}

.input,
.select {
  width: 100%;
  padding: 0.75rem 1rem;
  font-family: inherit;
  font-size: 1rem;
  color: var(--text-primary);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
  -webkit-appearance: none;
  appearance: none;
}

.input:hover,
.select:hover {
  border-color: var(--text-tertiary);
}

.input:focus,
.select:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(194, 59, 34, 0.12);
  background: var(--bg-elevated);
}

[data-theme="moon"] .input:focus,
[data-theme="moon"] .select:focus {
  box-shadow: 0 0 0 3px rgba(212, 168, 71, 0.15);
}

.input::placeholder {
  color: var(--text-tertiary);
}

/* Custom select arrow */
.select {
  padding-right: 2.5rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236B5D4D' d='M6 8.825L1.175 4 2.238 2.938 6 6.7 9.762 2.938 10.825 4z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 1rem center;
}

[data-theme="moon"] .select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23B8A994' d='M6 8.825L1.175 4 2.238 2.938 6 6.7 9.762 2.938 10.825 4z'/%3E%3C/svg%3E");
}


/* ── Segmented Control (Level Selector) ───────────────────── */
.segmented-control {
  display: flex;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 3px;
  gap: 2px;
  position: relative;
}

.segmented-btn {
  flex: 1;
  padding: 0.625rem 1rem;
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  border-radius: calc(var(--radius-md) - 2px);
  cursor: pointer;
  transition: all var(--transition-fast);
  position: relative;
  z-index: 1;
  text-align: center;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.segmented-btn:hover:not(.selected) {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.segmented-btn.selected {
  color: var(--text-primary);
  background: var(--bg-elevated);
  box-shadow: var(--shadow-sm);
  font-weight: 600;
}

.segmented-btn:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: -2px;
}

.segmented-label {
  display: block;
  font-size: 0.6875rem;
  color: var(--text-tertiary);
  margin-top: 2px;
  font-weight: 400;
  letter-spacing: 0.02em;
}

.segmented-btn.selected .segmented-label {
  color: var(--text-secondary);
}


/* ── Tags / Badges ────────────────────────────────────────── */
.tag {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem 0.625rem;
  font-size: 0.75rem;
  font-weight: 500;
  border-radius: var(--radius-full);
  background: var(--accent-subtle);
  color: var(--accent-text);
}

.tag-theme {
  padding: 0.25rem 0.5rem;
  font-size: 0.8125rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  transition: all var(--transition-fast);
}

.tag-theme:hover {
  border-color: var(--primary);
  transform: translateY(-1px);
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.375rem;
  height: 1.375rem;
  padding: 0 0.375rem;
  font-size: 0.6875rem;
  font-weight: 600;
  border-radius: var(--radius-full);
  background: var(--accent);
  color: var(--text-on-accent);
}


/* ── Theme Selector Grid & Pills ────────────────────────────── */
.section-header-flex {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.25rem;
}

.theme-badge-count {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--accent);
  margin-left: 0.375rem;
}

.theme-selected-status {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--accent-text);
  background: var(--accent-subtle);
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius-full);
}

.theme-help-text {
  font-size: 0.8125rem;
  color: var(--text-tertiary);
  margin-bottom: 0.75rem;
  line-height: 1.4;
}

.theme-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.5rem;
  max-height: 240px;
  overflow-y: auto;
  padding: 0.5rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
}

.theme-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  cursor: pointer;
  user-select: none;
  transition: all var(--transition-fast);
}

.theme-pill:hover {
  border-color: var(--accent-border);
  background: var(--bg-hover);
  color: var(--text-primary);
}

.theme-pill.selected {
  background: var(--accent-subtle);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  box-shadow: 0 0 0 1px var(--accent-border);
}

.theme-pill-icon {
  font-size: 0.9375rem;
  flex-shrink: 0;
}

.theme-pill-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}


/* ── Exercise Category Grid ───────────────────────────────── */
.category-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
}

.category-card {
  background: var(--bg-elevated);
  border: 2px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  cursor: pointer;
  transition: all var(--transition-fast);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.category-card:hover {
  border-color: var(--border);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.category-card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
  background: var(--accent-subtle);
}

.category-card:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

.category-card-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.category-card-icon {
  font-size: 1.5rem;
  line-height: 1;
  flex-shrink: 0;
}

.category-card-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.category-card-desc {
  font-size: 0.8125rem;
  color: var(--text-tertiary);
  line-height: 1.5;
  margin-left: 2.25rem;
}

.category-card-title-pinyin {
  font-size: 0.75rem;
  font-weight: 400;
  font-style: italic;
  color: var(--text-tertiary);
  line-height: 1.3;
}

.category-card-desc-pinyin {
  font-size: 0.75rem;
  font-style: italic;
  color: var(--text-tertiary);
  opacity: 0.85;
  line-height: 1.4;
  margin-left: 2.25rem;
  margin-top: 0.125rem;
}

.category-card.selected .category-card-title {
  color: var(--accent-text);
}


/* ── Progress Bar ─────────────────────────────────────────── */
.progress-bar-container {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.progress-bar {
  flex: 1;
  height: 4px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: var(--radius-full);
  transition: width var(--transition-slow);
}

.progress-text {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-tertiary);
  white-space: nowrap;
  min-width: 3.5rem;
  text-align: right;
}


/* ── Banner ───────────────────────────────────────────────── */
.banner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  line-height: 1.5;
}

.banner-info {
  background: var(--info-bg);
  color: var(--info);
  border: 1px solid rgba(74, 127, 165, 0.15);
}

.banner-warning {
  background: var(--warning-bg);
  color: var(--warning);
  border: 1px solid rgba(201, 139, 46, 0.15);
}

.banner-success {
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid rgba(61, 139, 94, 0.15);
}

.banner-error {
  background: var(--error-bg);
  color: var(--error);
  border: 1px solid rgba(194, 59, 34, 0.15);
}


/* ── Divider ──────────────────────────────────────────────── */
.divider {
  width: 100%;
  height: 1px;
  background: var(--border-subtle);
  margin: 1.5rem 0;
}


/* ── Utility Spacers ──────────────────────────────────────── */
.stack-sm  { display: flex; flex-direction: column; gap: 0.5rem; }
.stack-md  { display: flex; flex-direction: column; gap: 1rem; }
.stack-lg  { display: flex; flex-direction: column; gap: 1.5rem; }
.stack-xl  { display: flex; flex-direction: column; gap: 2rem; }

.row       { display: flex; align-items: center; gap: 0.75rem; }
.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
}


/* ── Welcome Section ──────────────────────────────────────── */
.welcome-section {
  text-align: center;
  padding: 2rem 0 1.5rem;
}

.welcome-icon {
  font-size: 3.5rem;
  margin-bottom: 1rem;
  display: block;
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.welcome-title {
  margin-bottom: 0.5rem;
}

.welcome-subtitle {
  font-size: 1.0625rem;
  max-width: 28rem;
  margin: 0 auto;
}


/* ── Start Screen Sections ────────────────────────────────── */
.start-section {
  margin-bottom: 2rem;
}

.section-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
  margin-bottom: 0.75rem;
}

.start-actions {
  padding-top: 0.5rem;
}


/* ── Screen-specific: Exercise ────────────────────────────── */
.exercise-question {
  font-size: 1.375rem;
  font-weight: 500;
  color: var(--text-primary);
  line-height: 1.5;
  margin-bottom: 1.5rem;
}

.exercise-question-pinyin {
  font-size: 0.9rem;
  font-weight: 400;
  font-style: italic;
  color: var(--text-tertiary);
  line-height: 1.4;
  margin-top: 0.25rem;
}

.exercise-input-group {
  margin-bottom: 1.5rem;
}

.exercise-actions {
  display: flex;
  gap: 0.75rem;
}

/* ── Hint Accordion Box ──────────────────────────────────── */
.hint-container {
  margin-top: 0.75rem;
  margin-bottom: 1.25rem;
}

.hint-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 0.75rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--warning);
  background: var(--warning-bg);
  border: 1px solid rgba(201, 139, 46, 0.25);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.hint-toggle-btn:hover {
  background: var(--bg-hover);
  border-color: var(--warning);
}

.hint-toggle-btn:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

.hint-box {
  display: none;
  margin-top: 0.625rem;
  padding: 0.875rem 1.125rem;
  background-color: var(--warning-bg);
  border: 1px solid rgba(201, 139, 46, 0.25);
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--text-primary);
}

.hint-box.visible {
  display: flex;
  align-items: flex-start;
  gap: 0.625rem;
  animation: slide-up var(--transition-fast) forwards;
}

.hint-box-icon {
  font-size: 1rem;
  line-height: 1;
  flex-shrink: 0;
  margin-top: 1px;
}



/* ── Screen-specific: Feedback ────────────────────────────── */
.feedback-status {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  border-radius: var(--radius-md);
  margin-bottom: 1.25rem;
}

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

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

.feedback-icon {
  font-size: 1.5rem;
  line-height: 1;
}

.feedback-label {
  font-weight: 600;
  font-size: 1.0625rem;
}

.feedback-detail {
  margin-bottom: 1.5rem;
}

.feedback-answer {
  font-size: 0.9375rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.feedback-answer strong {
  color: var(--text-primary);
  font-weight: 600;
}

.feedback-explanation {
  font-size: 0.9375rem;
  line-height: 1.7;
  color: var(--text-secondary);
  padding: 1rem;
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
}


/* ── Screen-specific: Summary ─────────────────────────────── */
.summary-score {
  text-align: center;
  padding: 2rem 0;
}

.score-circle {
  width: 7rem;
  height: 7rem;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1rem;
  border: 4px solid var(--accent);
  background: var(--accent-subtle);
}

.score-number {
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent-text);
  line-height: 1;
}

.score-label {
  font-size: 0.6875rem;
  color: var(--text-tertiary);
  margin-top: 2px;
}

.summary-actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 1.5rem;
}


/* ── Header Actions Group ─────────────────────────────────── */
.header-actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}


/* ── Connection Badge (Start Screen) ──────────────────────── */
.connection-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.375rem 0.875rem;
  border-radius: var(--radius-full);
  font-size: 0.8125rem;
  font-weight: 500;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  color: var(--text-tertiary);
  margin-bottom: 1.5rem;
  transition: all var(--transition-fast);
  cursor: default;
}

.connection-badge-connected {
  color: var(--success);
}

.connection-badge-disconnected {
  color: var(--error);
}


/* ── Status Dots ──────────────────────────────────────────── */
.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-dot-connected {
  background: var(--success);
  box-shadow: 0 0 6px rgba(61, 139, 94, 0.4);
  animation: pulse-dot 2s ease-in-out infinite;
}

.status-dot-disconnected {
  background: var(--error);
}

.status-dot-unknown {
  background: var(--text-tertiary);
}

.status-dot-pending {
  background: var(--warning);
  animation: pulse-dot 1s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}


/* ── Offline Exercise Banner ──────────────────────────────── */
.offline-banner {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.5rem 0.875rem;
  background-color: var(--warning-bg);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: var(--radius-md);
  font-size: 0.8125rem;
  font-weight: 500;
  margin-bottom: 1rem;
  box-shadow: var(--shadow-sm);
}

.offline-banner-icon {
  font-size: 0.9375rem;
  line-height: 1;
  flex-shrink: 0;
}


/* ── Screen-specific: Settings ────────────────────────────── */
.settings-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 2rem;
}

.settings-header h2 {
  margin: 0;
}

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

.settings-section-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
  margin-bottom: 1rem;
}

.settings-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.settings-row {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-subtle);
}

.settings-row:last-child {
  border-bottom: none;
}

.settings-row label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 0.25rem;
}

.settings-row .settings-helper {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  margin-bottom: 0.5rem;
  line-height: 1.4;
}

.settings-row .input {
  margin-top: 0.375rem;
}

/* Temperature slider row */
.settings-temp-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 0.375rem;
}

.settings-temp-row input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-full);
  outline: none;
  cursor: pointer;
}

.settings-temp-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition-fast);
}

.settings-temp-row input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

.settings-temp-row input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: none;
  box-shadow: var(--shadow-sm);
}

.settings-temp-value {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--accent-text);
  min-width: 2rem;
  text-align: center;
}


/* ── Connection Test Result ───────────────────────────────── */
.connection-result {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  font-size: 0.8125rem;
  line-height: 1.5;
  margin-top: 0.75rem;
  transition: all var(--transition-fast);
}

.connection-result-success {
  background: var(--success-bg);
  color: var(--success);
}

.connection-result-error {
  background: var(--error-bg);
  color: var(--error);
}

.connection-result-pending {
  background: var(--warning-bg);
  color: var(--warning);
}

.connection-result strong {
  font-weight: 600;
}


/* ── Connection Test Button ───────────────────────────────── */
.btn-connection-icon {
  font-size: 1rem;
  line-height: 1;
}


/* ── AI Provider Selector Pills ───────────────────────────── */
.provider-selector-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-top: 0.5rem;
}

.provider-pill {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.875rem 0.5rem;
  border-radius: var(--radius-md);
  border: 2px solid var(--border-subtle);
  background: var(--surface);
  transition: all var(--transition-fast);
  text-align: center;
  cursor: pointer;
  width: 100%;
}

.provider-pill:hover {
  border-color: var(--primary-light);
}

.provider-pill.selected {
  border-color: var(--primary);
  background: rgba(194, 59, 34, 0.08);
  box-shadow: 0 0 0 1px var(--primary);
}

.provider-icon {
  font-size: 1.5rem;
  margin-bottom: 0.25rem;
}

.provider-title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-primary);
}

.provider-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
}


/* ── Settings Actions ─────────────────────────────────────── */
.settings-actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 1rem;
}


/* ── Spinner ──────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 600ms linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}


/* ── Animations ───────────────────────────────────────────── */
@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes slide-up {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slide-in-right {
  from {
    opacity: 0;
    transform: translateX(16px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.animate-fade-in {
  animation: fade-in var(--transition-base) forwards;
}

.animate-slide-up {
  animation: slide-up var(--transition-slow) forwards;
}

.animate-slide-in {
  animation: slide-in-right var(--transition-slow) forwards;
}

/* Staggered children animation */
.stagger > * {
  opacity: 0;
  animation: slide-up var(--transition-slow) forwards;
}

.stagger > *:nth-child(1) { animation-delay: 0ms; }
.stagger > *:nth-child(2) { animation-delay: 60ms; }
.stagger > *:nth-child(3) { animation-delay: 120ms; }
.stagger > *:nth-child(4) { animation-delay: 180ms; }
.stagger > *:nth-child(5) { animation-delay: 240ms; }
.stagger > *:nth-child(6) { animation-delay: 300ms; }


/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 480px) {
  html {
    font-size: 15px;
  }

  .app-main {
    padding: 1.5rem 1rem 3rem;
  }

  .app-header {
    padding: 0.75rem 1rem;
  }

  .segmented-btn {
    padding: 0.5rem 0.5rem;
    font-size: 0.875rem;
  }

  .welcome-icon {
    font-size: 2.5rem;
  }

  h1 {
    font-size: 1.5rem;
  }

  .exercise-question {
    font-size: 1.125rem;
  }
}


/* ── Focus Visible Utilities ──────────────────────────────── */
:focus {
  outline: none;
}

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

.app-logo:focus-visible,
.btn-icon:focus-visible,
.btn:focus-visible,
.segmented-btn:focus-visible,
.category-card:focus-visible,
.option-card:focus-visible,
.connection-badge:focus-visible,
.hint-toggle-btn:focus-visible,
.input:focus-visible,
.select:focus-visible {
  outline: 3px solid var(--border-focus);
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(194, 59, 34, 0.18);
}

[data-theme="moon"] .app-logo:focus-visible,
[data-theme="moon"] .btn-icon:focus-visible,
[data-theme="moon"] .btn:focus-visible,
[data-theme="moon"] .segmented-btn:focus-visible,
[data-theme="moon"] .category-card:focus-visible,
[data-theme="moon"] .option-card:focus-visible,
[data-theme="moon"] .connection-badge:focus-visible,
[data-theme="moon"] .hint-toggle-btn:focus-visible,
[data-theme="moon"] .input:focus-visible,
[data-theme="moon"] .select:focus-visible {
  outline: 3px solid var(--border-focus);
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(224, 185, 79, 0.22);
}

/* Remove outline for mouse clicks, keep for keyboard */
.btn:focus:not(:focus-visible),
.btn-icon:focus:not(:focus-visible),
.segmented-btn:focus:not(:focus-visible),
.category-card:focus:not(:focus-visible),
.option-card:focus:not(:focus-visible),
.connection-badge:focus:not(:focus-visible) {
  outline: none;
  box-shadow: none;
}


/* ── Scrollbar (subtle, themed) ───────────────────────────── */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-tertiary);
}


/* ── Selection highlight ──────────────────────────────────── */
::selection {
  background: var(--accent-subtle);
  color: var(--accent-text);
}


/* ── Reading Passage Box ───────────────────────────────────── */
.reading-passage-box {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
  font-size: 1rem;
  line-height: 1.75;
  color: var(--text-primary);
}

.reading-passage-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-tertiary);
  margin-bottom: 0.5rem;
}


/* ── Multiple Choice Options Grid ─────────────────────────── */
.options-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.option-card {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  padding: 1rem 1.25rem;
  background: var(--bg-elevated);
  border: 2px solid var(--border-subtle);
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-primary);
  cursor: pointer;
  transition: all var(--transition-fast);
  user-select: none;
}

.option-card:hover {
  border-color: var(--border);
  background: var(--bg-hover);
}

.option-card.selected {
  border-color: var(--accent);
  background: var(--accent-subtle);
  color: var(--accent-text);
}

.option-card:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

.option-key {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
  flex-shrink: 0;
  transition: all var(--transition-fast);
}

.option-card.selected .option-key {
  background: var(--accent);
  color: var(--text-on-accent);
  border-color: var(--accent);
}


/* ── Skeleton Loading UI ──────────────────────────────────── */
.skeleton-container {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.skeleton-bar {
  background: linear-gradient(
    90deg,
    var(--bg-secondary) 25%,
    var(--bg-hover) 50%,
    var(--bg-secondary) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.loading-indicator {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1.5rem;
  text-align: center;
}

.loading-spinner-large {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border-subtle);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 1.25rem;
}

.loading-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.375rem;
}

.loading-subtitle {
  font-size: 0.875rem;
  color: var(--text-tertiary);
}


/* ── Summary Stats & Breakdown ────────────────────────────── */
.summary-stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.summary-stat-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1rem 0.75rem;
  text-align: center;
}

.summary-stat-val {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
}

.summary-stat-lbl {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  margin-top: 0.125rem;
}

.summary-breakdown-list {
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  max-height: 280px;
  overflow-y: auto;
  padding-right: 0.25rem;
}

.summary-breakdown-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  font-size: 0.875rem;
}

.summary-breakdown-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  overflow: hidden;
}

.summary-breakdown-icon {
  font-size: 1.125rem;
  flex-shrink: 0;
}

.summary-breakdown-q {
  color: var(--text-primary);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 320px;
}

.summary-breakdown-ans {
  font-size: 0.8125rem;
  color: var(--text-tertiary);
  flex-shrink: 0;
  text-align: right;
  margin-left: 0.5rem;
}


/* ── Word Tiles UI (Sentence Reordering) ──────────────────── */
.tiles-container {
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
  margin: 1.25rem 0;
}

.tiles-label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.tiles-dropzone {
  min-height: 3.5rem;
  padding: 0.75rem 1rem;
  background-color: var(--bg-tertiary, var(--bg-secondary));
  border: 2px dashed var(--border-subtle);
  border-radius: var(--radius-md);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  transition: all var(--transition-fast);
}

.tiles-dropzone:hover {
  border-color: var(--accent);
}

.tiles-placeholder {
  font-size: 0.84375rem;
  color: var(--text-tertiary);
  font-style: italic;
  pointer-events: none;
  user-select: none;
}

.tiles-pool {
  min-height: 3.25rem;
  padding: 0.75rem 0.5rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.tile-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 0.875rem;
  background-color: var(--card-bg, var(--bg-secondary));
  color: var(--text-primary);
  border: 1px solid var(--border-color, var(--border-subtle));
  border-radius: var(--radius-md);
  font-size: 0.9375rem;
  font-weight: 500;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.06);
  transition: all 0.15s ease-in-out;
  user-select: none;
}

.tile-btn:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.12);
  background-color: var(--bg-hover, var(--card-bg));
}

.tile-btn:active {
  transform: translateY(0);
}

.tiles-dropzone .tile-btn {
  background-color: var(--accent-subtle, rgba(234, 88, 12, 0.12));
  border-color: var(--accent);
  color: var(--accent-text, var(--primary));
}


/* ── 🔊 TTS Speaker Audio Button ───────────────────────────── */
.btn-speaker {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: var(--radius-full);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--primary);
  cursor: pointer;
  transition: all var(--transition-fast);
  flex-shrink: 0;
  padding: 0;
}

.btn-speaker:hover {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
  transform: scale(1.06);
}

.btn-speaker-sm {
  width: 1.75rem;
  height: 1.75rem;
}

.btn-speaker-sm svg {
  width: 14px;
  height: 14px;
}

.btn-speaker-lg {
  width: 2.75rem;
  height: 2.75rem;
}

.btn-speaker.playing {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
  animation: pulse-speaker 1.2s infinite ease-in-out;
}

@keyframes pulse-speaker {
  0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(194, 59, 34, 0.4); }
  50% { transform: scale(1.08); box-shadow: 0 0 0 8px rgba(194, 59, 34, 0); }
  100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(194, 59, 34, 0); }
}


/* ── 📘 Verb Conjugation Memorizing Assistant ─────────────── */
.conjugation-assistant-card {
  margin-top: 1rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
}

.conjugation-toggle-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0.875rem 1rem;
  background: var(--bg-secondary);
  border: none;
  cursor: pointer;
  font-size: 0.9375rem;
  color: var(--text-primary);
  text-align: left;
  transition: background var(--transition-fast);
}

.conjugation-toggle-btn:hover {
  background: var(--bg-hover);
}

.conj-btn-left {
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

.conj-btn-icon {
  font-size: 1.25rem;
}

.conj-btn-title {
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.conj-verb-tag {
  color: var(--text-primary);
  font-size: 0.9375rem;
  font-weight: 600;
  margin-left: 0.375rem;
  background: transparent;
  padding: 0;
  border-radius: 0;
  box-shadow: none;
  display: inline;
}

.conj-btn-right {
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

.conj-badge {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
  background: rgba(194, 59, 34, 0.1);
  color: var(--primary);
}

.conj-arrow-icon {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.conjugation-panel {
  padding: 1rem;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-primary);
}

.conj-header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.875rem;
}

.conj-tense-name {
  font-size: 0.84375rem;
  font-weight: 700;
  color: var(--text-primary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.conj-meaning {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-left: 0.375rem;
  font-style: italic;
}

.btn-peek-mode {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.3125rem 0.625rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  font-size: 0.78125rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-peek-mode:hover, .btn-peek-mode.active {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}

.conj-grid {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: 100%;
}

.conj-item {
  padding: 0.625rem 0.875rem;
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  width: 100%;
  transition: all var(--transition-fast);
}

.conj-item.target-highlight {
  border-color: var(--accent, #e0b94f);
  background: rgba(224, 185, 79, 0.12);
  box-shadow: 0 0 0 1px var(--accent, #e0b94f);
}

.conj-pronoun-label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
  flex: 1;
}

.conj-form-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.625rem;
  flex-shrink: 0;
}

.conj-form-text {
  font-size: 1.0625rem;
  font-weight: 700;
  color: var(--text-primary);
}

/* Modo Memoria (Peek Mode) hiding endings */
.peek-hidden .conj-form-text {
  filter: blur(5px);
  user-select: none;
  opacity: 0.5;
}

.peek-hidden .conj-item:hover .conj-form-text {
  filter: none;
  opacity: 1;
}


/* ── 🗂️ SRS Flashcard Hub & 3D Flip Card ──────────────────── */
.srs-stats-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.srs-stat-box {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.875rem;
  text-align: center;
}

.srs-stat-num {
  font-size: 1.375rem;
  font-weight: 700;
  color: var(--primary);
}

.srs-stat-lbl {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.125rem;
}

.flashcard-wrapper {
  perspective: 1000px;
  margin: 1rem 0 1.5rem;
  width: 100%;
  min-height: 260px;
}

.flashcard-inner {
  position: relative;
  width: 100%;
  min-height: 260px;
  text-align: center;
  transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  transform-style: preserve-3d;
  cursor: pointer;
}

.flashcard-inner.flipped {
  transform: rotateY(180deg);
}

.flashcard-front, .flashcard-back {
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  border-radius: var(--radius-lg);
  padding: 1.75rem 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--border);
  background: var(--bg-elevated);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
}

.flashcard-front {
  background: var(--bg-elevated);
}

.flashcard-back {
  transform: rotateY(180deg);
  background: var(--bg-secondary);
  border-color: var(--primary-light);
}

.flashcard-level-badge {
  position: absolute;
  top: 1rem;
  left: 1rem;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.25rem 0.625rem;
  border-radius: var(--radius-full);
  background: var(--primary);
  color: #ffffff;
}

.flashcard-audio-top {
  position: absolute;
  top: 1rem;
  right: 1rem;
}

.flashcard-target-text {
  font-size: 1.625rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.75rem;
  line-height: 1.3;
}

.flashcard-hint-text {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.flashcard-flip-prompt {
  position: absolute;
  bottom: 1rem;
  font-size: 0.78125rem;
  color: var(--text-muted);
}

.flashcard-quality-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  margin-top: 1rem;
}

.btn-quality {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.875rem 0.5rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-quality-again { color: #dc2626; border-color: rgba(220, 38, 38, 0.3); }
.btn-quality-again:hover { background: #fee2e2; border-color: #dc2626; }

.btn-quality-good { color: #d97706; border-color: rgba(217, 119, 6, 0.3); }
.btn-quality-good:hover { background: #fef3c7; border-color: #d97706; }

.btn-quality-easy { color: #16a34a; border-color: rgba(22, 163, 74, 0.3); }
.btn-quality-easy:hover { background: #dcfce7; border-color: #16a34a; }


/* ── Word Tiles & Drag & Drop Styles ─────────────────────────── */
.tiles-container {
  margin-bottom: 1.5rem;
}

.tiles-label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.625rem;
}

.tiles-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.625rem;
}

.tiles-label-row .tiles-label {
  margin-bottom: 0;
}

.tiles-dropzone {
  position: relative;
  min-height: 4.25rem;
  padding: 0.75rem 1rem;
  background: var(--bg-surface);
  border: 2px dashed var(--border-medium);
  border-radius: var(--radius-lg);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
  transition: border-color var(--transition-fast), background-color var(--transition-fast);
}

.tiles-dropzone.drag-over {
  border-color: var(--primary);
  background: var(--accent-subtle);
}

.tiles-placeholder {
  font-size: 0.875rem;
  color: var(--text-tertiary);
  font-style: italic;
  user-select: none;
  pointer-events: none;
}

.tiles-pool {
  position: relative;
  min-height: 5rem;
  padding: 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.625rem;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.03);
  transition: border-color var(--transition-fast);
}

.tiles-pool.drag-over {
  border-color: var(--primary);
}

.tile-btn {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.4375rem 0.875rem;
  font-size: 0.9375rem;
  font-weight: 600;
  font-family: inherit;
  color: var(--text-primary);
  background: var(--bg-surface);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  cursor: grab;
  user-select: none;
  touch-action: manipulation;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}

.tile-hanzi {
  line-height: 1.3;
}

.tile-pinyin {
  display: none;
  font-size: 0.6875rem;
  font-weight: 500;
  font-style: italic;
  color: var(--text-tertiary);
  line-height: 1.3;
  margin-top: 0.125rem;
}

.tiles-container.pinyin-visible .tile-pinyin {
  display: block;
}

.tiles-container.pinyin-visible .tile-btn {
  padding-top: 0.375rem;
  padding-bottom: 0.375rem;
}

.tile-btn:hover {
  transform: translateY(-2px);
  border-color: var(--primary);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  background: var(--accent-subtle);
  color: var(--primary);
}

.tile-btn:active {
  cursor: grabbing;
  transform: translateY(0);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.tile-btn.dragging {
  opacity: 0.4;
  cursor: grabbing;
  transform: scale(0.96);
  border-style: dashed;
}

.tiles-dropzone .tile-btn {
  background: var(--accent-subtle);
  border-color: var(--primary);
  color: var(--primary-dark, var(--text-primary));
}

.tile-drop-indicator {
  width: 4px;
  height: 2.25rem;
  background: var(--primary);
  border-radius: 2px;
  margin: 0 -2px;
  pointer-events: none;
  box-shadow: 0 0 6px var(--primary);
  animation: pulse-indicator 1s infinite alternate;
}

@keyframes pulse-indicator {
  from { opacity: 0.7; }
  to { opacity: 1; }
}





