:root {
  color-scheme: light;
  --bg-1: #f6e6bf;
  --bg-2: #f2c48d;
  --bg-3: #24425f;
  --card: rgba(255, 250, 238, 0.86);
  --card-strong: rgba(255, 247, 228, 0.96);
  --ink: #162534;
  --muted: #5d6771;
  --accent: #d1632b;
  --accent-soft: rgba(209, 99, 43, 0.12);
  --correct: #1f7a53;
  --correct-soft: rgba(31, 122, 83, 0.14);
  --wrong: #ad3c36;
  --wrong-soft: rgba(173, 60, 54, 0.14);
  --border: rgba(17, 33, 48, 0.1);
  --shadow: 0 24px 48px rgba(26, 36, 43, 0.18);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100svh;
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.45), transparent 32%),
    linear-gradient(160deg, var(--bg-1) 0%, var(--bg-2) 42%, var(--bg-3) 100%);
  color: var(--ink);
  font-family: "Avenir Next", "Trebuchet MS", sans-serif;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(120deg, rgba(255, 255, 255, 0.08) 0%, transparent 30%),
    radial-gradient(circle at bottom right, rgba(255, 239, 190, 0.18), transparent 24%);
}

#app {
  min-height: 100svh;
}

.app-shell {
  width: min(100%, 430px);
  margin: 0 auto;
  padding: 20px 16px 28px;
  display: grid;
  gap: 16px;
}

.app-titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 2px 0;
}

.app-title {
  margin: 0;
  font-size: 1.55rem;
  line-height: 1;
  letter-spacing: 0.01em;
  font-family: "Iowan Old Style", "Palatino Linotype", serif;
}

.title-action {
  min-height: 40px;
}

.hero-card,
.sentence-card,
.trainer-card,
.stats-card {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: var(--card);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.sentence-card,
.trainer-card,
.stats-card,
.trouble-card {
  padding: 18px;
}

.sentence-card::after,
.trainer-card::after,
.stats-card::after {
  content: "";
  position: absolute;
  inset: auto -24px -38px auto;
  width: 120px;
  height: 120px;
  border-radius: 999px;
  background: rgba(209, 99, 43, 0.08);
}

.eyebrow,
.section-label,
.translation-label,
.stat-label,
.letter-index {
  margin: 0;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--muted);
}

.hero-copy,
.sentence-translation,
.completion-copy,
.stats-copy,
.empty-copy,
.status-message {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.sentence-arabic,
.active-word-arabic,
.letter-glyph,
.word-chip,
.trouble-letter {
  font-family: "Geeza Pro", "Noto Naskh Arabic", serif;
}

.sentence-arabic {
  margin: 10px 0 8px;
  font-size: clamp(2rem, 7vw, 2.7rem);
  direction: rtl;
  text-align: right;
}

.sentence-translation {
  margin-bottom: 14px;
}

.word-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-start;
}

.word-chip {
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.52);
  border: 1px solid rgba(0, 0, 0, 0.04);
  font-size: 1.15rem;
  transition: transform 180ms ease, background-color 180ms ease, color 180ms ease;
}

.word-chip.is-active {
  background: linear-gradient(135deg, #f9f0cc 0%, #f5d89c 100%);
  color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 12px 24px rgba(209, 99, 43, 0.16);
}

.word-chip.is-read {
  background: rgba(31, 122, 83, 0.1);
  color: var(--correct);
}

.trainer-card {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.trainer-header,
.stats-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  min-width: 0;
}

.trainer-copy {
  min-width: 0;
  flex: 1 1 180px;
}

.active-word-arabic {
  margin: 8px 0 0;
  font-size: clamp(2.4rem, 8vw, 3.4rem);
  line-height: 1;
  direction: rtl;
  text-align: right;
  max-width: 100%;
}

.meaning-pill {
  display: grid;
  gap: 6px;
  min-width: 120px;
  max-width: 100%;
  margin-left: auto;
  flex: 0 0 auto;
  padding: 10px 12px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.72);
  text-align: right;
}

.meaning-pill strong {
  font-size: 1rem;
}

.letter-row-shell {
  position: relative;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}

.letter-row-shell::before,
.letter-row-shell::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 4px;
  width: 18px;
  pointer-events: none;
  z-index: 1;
}

.letter-row-shell::before {
  left: 0;
  background: linear-gradient(90deg, rgba(246, 231, 203, 0.92), rgba(246, 231, 203, 0));
}

.letter-row-shell::after {
  right: 0;
  background: linear-gradient(270deg, rgba(246, 231, 203, 0.92), rgba(246, 231, 203, 0));
}

.letter-row {
  display: flex;
  align-items: stretch;
  gap: 12px;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  padding: 0 0 4px;
  scroll-padding-inline: 12px;
  scroll-snap-type: x proximity;
  scrollbar-width: thin;
  scrollbar-color: rgba(36, 61, 88, 0.28) transparent;
}

.letter-row::-webkit-scrollbar {
  height: 6px;
}

.letter-row::-webkit-scrollbar-track {
  background: transparent;
}

.letter-row::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(36, 61, 88, 0.28);
}

.letter-card {
  flex: 0 0 112px;
  display: grid;
  align-content: start;
  gap: 10px;
  min-height: 100%;
  padding: 14px 12px;
  border-radius: 20px;
  border: 1px solid rgba(9, 27, 41, 0.08);
  background: var(--card-strong);
  scroll-snap-align: start;
  transition:
    flex-basis 180ms ease,
    padding 180ms ease,
    transform 180ms ease,
    border-color 180ms ease,
    background-color 180ms ease;
}

.letter-card.is-current {
  border-color: rgba(209, 99, 43, 0.28);
  box-shadow: 0 10px 20px rgba(209, 99, 43, 0.12);
}

.letter-card.is-correct {
  border-color: rgba(31, 122, 83, 0.22);
  background: linear-gradient(180deg, rgba(255, 247, 228, 0.96), rgba(31, 122, 83, 0.08));
}

.letter-card.is-wrong {
  border-color: rgba(173, 60, 54, 0.24);
  background: linear-gradient(180deg, rgba(255, 247, 228, 0.96), rgba(173, 60, 54, 0.08));
}

.letter-glyph {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 3.1rem;
  overflow: visible;
}

.letter-head {
  display: flex;
  align-items: center;
  justify-content: center;
}

.letter-head-button {
  width: 100%;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
}

.letter-head-button:disabled {
  cursor: default;
}

.letter-context-word {
  direction: rtl;
  unicode-bidi: isolate;
  font-size: 2.35rem;
  line-height: 1;
  white-space: nowrap;
}

.letter-context-char {
  transition: color 140ms ease;
}

.letter-context-char.is-target {
  color: var(--ink);
}

.letter-context-char.is-ghost {
  color: rgba(22, 37, 52, 0.2);
}

.option-stack {
  display: grid;
  gap: 8px;
}

.option-pill {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 42px;
  border-radius: 14px;
  border: 1px solid rgba(21, 36, 49, 0.12);
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
  font-weight: 700;
  cursor: pointer;
  transition: transform 140ms ease, background-color 140ms ease, border-color 140ms ease;
  gap: 8px;
}

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

.option-pill:active {
  transform: scale(0.98);
}

.option-pill.is-answer {
  border-color: rgba(31, 122, 83, 0.35);
  background: var(--correct-soft);
  color: var(--correct);
}

.option-pill.is-removed {
  border-color: rgba(22, 37, 52, 0.08);
  background: rgba(103, 113, 123, 0.12);
  color: rgba(22, 37, 52, 0.36);
}

.option-pill.is-locked-muted {
  opacity: 0.62;
}

.option-main {
  font-size: 1rem;
  font-weight: 800;
}

.option-sub {
  color: rgba(22, 37, 52, 0.46);
  font-size: 0.82rem;
  font-weight: 700;
}

.translation-panel {
  padding: 14px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.55);
}

.translation-text {
  margin: 6px 0 0;
  font-size: 1.15rem;
  font-weight: 700;
}

.letter-feedback {
  margin: 0;
  min-height: auto;
  font-size: 1rem;
  line-height: 1;
  color: var(--muted);
}

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

.letter-feedback.is-wrong,
.status-message.is-wrong {
  color: var(--wrong);
}

.status-message.is-correct {
  color: var(--correct);
}

.status-message.is-neutral {
  color: var(--muted);
}

.primary-button,
.ghost-button {
  appearance: none;
  border: none;
  border-radius: 18px;
  min-height: 52px;
  padding: 0 18px;
  font: inherit;
  font-weight: 800;
}

.primary-button {
  background: linear-gradient(135deg, #243d58 0%, #162534 100%);
  color: #fff9ee;
  box-shadow: 0 14px 24px rgba(22, 37, 52, 0.24);
}

.primary-button:disabled {
  opacity: 0.52;
  box-shadow: none;
}

.ghost-button {
  min-height: 40px;
  background: rgba(255, 255, 255, 0.62);
  color: var(--ink);
}

.stats-card {
  display: grid;
  gap: 14px;
}

.stats-view-switch {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.stats-view-button.is-active {
  background: linear-gradient(135deg, #243d58 0%, #162534 100%);
  color: #fff9ee;
}

.stats-table-shell,
.attempt-log,
.failure-row {
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.54);
  border: 1px solid rgba(14, 31, 46, 0.08);
}

.stats-table-shell {
  overflow-x: auto;
}

.stats-table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
}

.stats-table th,
.stats-table td {
  padding: 12px 10px;
  border-bottom: 1px solid rgba(14, 31, 46, 0.08);
  vertical-align: top;
}

.stats-table thead th {
  position: sticky;
  top: 0;
  background: rgba(255, 249, 238, 0.96);
  text-align: left;
  font-size: 0.76rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

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

.letter-table-label {
  min-width: 110px;
  text-align: left;
}

.letter-table-arabic,
.failure-arabic {
  display: block;
  font-family: "Geeza Pro", "Noto Naskh Arabic", serif;
  font-size: 1.7rem;
  line-height: 1;
  margin-bottom: 6px;
}

.letter-table-sound,
.failure-sound {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: baseline;
}

.stats-table-cell {
  min-width: 84px;
}

.stats-rate-line {
  display: block;
  font-size: 0.88rem;
  color: var(--ink);
  white-space: nowrap;
}

.stats-rate-line + .stats-rate-line {
  margin-top: 4px;
  color: var(--muted);
}

.failure-list {
  display: grid;
  gap: 10px;
}

.failure-row {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr);
  gap: 12px;
  padding: 12px 14px;
}

.failure-rank {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  background: rgba(22, 37, 52, 0.08);
  font-size: 0.85rem;
  font-weight: 800;
}

.failure-copy {
  min-width: 0;
  display: grid;
  gap: 10px;
}

.failure-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
}

.failure-form {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
}

.failure-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.failure-chip {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  background: rgba(255, 250, 238, 0.82);
  border: 1px solid rgba(14, 31, 46, 0.08);
  font-size: 0.86rem;
  color: var(--ink);
}

.attempt-log summary {
  cursor: pointer;
  padding: 16px 18px 0;
  font-weight: 800;
}

.attempt-log pre {
  margin: 0;
  padding: 14px 18px 18px;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.82rem;
  line-height: 1.45;
}

.trainer-complete {
  animation: lift-in 280ms ease;
}

@keyframes lift-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 380px) {
  .app-shell {
    padding-inline: 12px;
  }

  .letter-row {
    grid-auto-columns: minmax(98px, 1fr);
  }
}
