:root {
  color-scheme: light;
  --bg: #f3f6fb;
  --surface: #ffffff;
  --surface-2: #eef3f8;
  --text: #101827;
  --muted: #667085;
  --line: #d9e2ec;
  --primary: #2481cc;
  --primary-text: #ffffff;
  --success: #168a55;
  --danger: #c33d3d;
  --shadow: 0 14px 34px rgba(16, 24, 39, 0.10);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f141b;
  --surface: #171e27;
  --surface-2: #202a36;
  --text: #eef3f8;
  --muted: #a6b0bf;
  --line: #303b49;
  --primary: #4aa3ff;
  --primary-text: #06101d;
  --success: #48d18d;
  --danger: #ff7b7b;
  --shadow: 0 14px 34px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Vazirmatn, Tahoma, Arial, sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  padding: 12px 13px;
  outline: 0;
}

textarea {
  resize: vertical;
  line-height: 1.7;
}

input::placeholder,
textarea::placeholder {
  color: color-mix(in srgb, var(--muted), transparent 20%);
}

input:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary), transparent 82%);
}

.app-shell {
  width: min(100%, 540px);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 14px max(20px, env(safe-area-inset-bottom));
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 11px;
}

.brand-mark {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--primary);
  color: var(--primary-text);
  font-weight: 900;
  font-size: 1.25rem;
}

.brand p,
.brand h1 {
  margin: 0;
}

.brand p {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.brand h1 {
  font-size: 1.25rem;
  line-height: 1.35;
}

.icon-button {
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font-size: 1.15rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1.15fr 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.stat,
.panel,
.review-card,
.empty-state,
.deck-item,
.box-pill {
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.stat {
  min-width: 0;
  border-radius: 14px;
  padding: 12px 10px;
}

.stat.strong {
  background: var(--primary);
  color: var(--primary-text);
  border-color: transparent;
}

.stat small {
  display: block;
  margin-bottom: 6px;
  color: inherit;
  opacity: 0.72;
  font-size: 0.72rem;
  white-space: nowrap;
}

.stat span {
  display: block;
  font-size: 1.35rem;
  font-weight: 900;
  line-height: 1;
}

.tabs {
  position: sticky;
  top: max(8px, env(safe-area-inset-top));
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: color-mix(in srgb, var(--surface), transparent 8%);
  backdrop-filter: blur(12px);
  margin-bottom: 14px;
}

.tab {
  min-height: 40px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
  font-size: 0.86rem;
}

.tab.active {
  background: var(--text);
  color: var(--bg);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.review-card,
.panel,
.empty-state {
  border-radius: 16px;
}

.review-card {
  min-height: 455px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.card-meta span {
  padding: 7px 10px;
  border-radius: 999px;
  background: var(--surface-2);
}

.box-progress {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 5px;
}

.box-progress i {
  height: 7px;
  border-radius: 999px;
  background: var(--surface-2);
}

.box-progress i.active {
  background: var(--primary);
}

.flash-face {
  min-height: 205px;
  display: grid;
  align-content: center;
  gap: 10px;
  padding: 16px;
  border-radius: 14px;
  background: var(--surface-2);
}

.flash-face small,
.answer-panel small,
.panel-title span,
.card-form label span,
.settings-form label span {
  color: var(--muted);
}

.flash-face small,
.answer-panel small {
  font-weight: 800;
}

.prompt {
  direction: ltr;
  text-align: left;
  min-height: 84px;
  display: grid;
  align-items: center;
  font-size: clamp(2rem, 11vw, 3.65rem);
  font-weight: 900;
  line-height: 1.06;
  overflow-wrap: anywhere;
}

.example {
  direction: ltr;
  text-align: left;
  min-height: 42px;
  margin: 0;
  color: var(--muted);
  line-height: 1.75;
}

.primary-button,
.secondary-button {
  min-height: 48px;
  border-radius: 12px;
  border: 0;
  font-weight: 900;
}

.primary-button {
  width: 100%;
  background: var(--primary);
  color: var(--primary-text);
}

.primary-button.compact {
  width: auto;
  min-width: 92px;
  padding-inline: 16px;
}

.secondary-button {
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
}

.secondary-button.success {
  color: var(--success);
}

.secondary-button.danger {
  color: var(--danger);
}

.answer-panel {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
}

.answer-panel p {
  margin: 0;
  line-height: 1.8;
}

#backText {
  font-size: 1.08rem;
  font-weight: 900;
}

#qaText {
  color: var(--muted);
}

.review-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.panel {
  display: grid;
  gap: 13px;
  padding: 14px;
  margin-bottom: 12px;
}

.panel-title {
  display: grid;
  gap: 4px;
}

.panel-title strong {
  font-size: 1rem;
}

.panel-title span {
  font-size: 0.8rem;
  line-height: 1.7;
}

.ai-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 5px;
  border-radius: 13px;
  background: var(--surface-2);
}

.segmented label {
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  border-radius: 10px;
  color: var(--muted);
  font-weight: 900;
}

.segmented label:has(input:checked) {
  background: var(--surface);
  color: var(--text);
}

.card-form label,
.settings-form label {
  display: grid;
  gap: 6px;
  font-weight: 800;
  font-size: 0.85rem;
}

.boxes {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 7px;
  margin-bottom: 12px;
}

.box-pill {
  min-height: 58px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  font-weight: 900;
}

.box-pill small {
  color: var(--muted);
  font-size: 0.68rem;
}

.deck-list {
  display: grid;
  gap: 9px;
}

.deck-item {
  border-radius: 14px;
  padding: 13px;
}

.deck-item h3 {
  direction: ltr;
  text-align: left;
  margin: 0 0 7px;
  font-size: 1rem;
  font-weight: 900;
}

.deck-item p {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.deck-item footer {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
}

.empty-state {
  padding: 24px 16px;
  text-align: center;
  line-height: 1.9;
}

.empty-state strong,
.empty-state span {
  display: block;
}

.empty-state span {
  color: var(--muted);
}

.toast {
  position: fixed;
  right: 14px;
  left: 14px;
  bottom: 16px;
  max-width: 512px;
  margin: 0 auto;
  padding: 12px 14px;
  border-radius: 13px;
  background: var(--text);
  color: var(--bg);
  text-align: center;
  box-shadow: var(--shadow);
  transform: translateY(90px);
  opacity: 0;
  transition: 180ms ease;
  pointer-events: none;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

@media (max-width: 390px) {
  .app-shell {
    padding-inline: 10px;
  }

  .stats-grid {
    gap: 6px;
  }

  .stat {
    padding-inline: 7px;
  }

  .stat small,
  .tab {
    font-size: 0.7rem;
  }

  .ai-row,
  .segmented {
    grid-template-columns: 1fr;
  }
}
