@font-face {
  font-family: 'AmiriQuran';
  src: url('../assets/fonts/AmiriQuran.ttf') format('truetype');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg-outer: #ebe5d8;
  --bg-app: #faf7f0;
  --bg-surface: #ffffff;
  --bg-surface-alt: #f3eee2;
  --bg-header: rgba(250, 247, 240, 0.94);
  --primary: #0f5132;
  --primary-hover: #0b3f27;
  --primary-soft: #e7f3ec;
  --primary-contrast: #ffffff;
  --gold: #b8892d;
  --gold-soft: #fdf6e6;
  --gold-border: rgba(184, 137, 45, 0.35);
  --text-main: #1b2a24;
  --text-muted: #5b6d65;
  --border: #e3dccb;
  --success: #15803d;
  --success-soft: #e8f7ee;
  --danger: #c53030;
  --danger-soft: #fdecec;
  --shadow-shell: 0 20px 50px rgba(15, 45, 30, 0.14);
  --shadow-card: 0 2px 6px rgba(27, 42, 36, 0.05);
  --pattern-color: rgba(15, 81, 50, 0.055);
  --font-ui: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-arabic: 'AmiriQuran', 'Amiri', 'Traditional Arabic', serif;
}

[data-theme="dark"] {
  --bg-outer: #05100d;
  --bg-app: #0a1d18;
  --bg-surface: #112b24;
  --bg-surface-alt: #16362d;
  --bg-header: rgba(10, 29, 24, 0.94);
  --primary: #34d399;
  --primary-hover: #10b981;
  --primary-soft: rgba(52, 211, 153, 0.14);
  --primary-contrast: #062118;
  --gold: #e2b95b;
  --gold-soft: rgba(226, 185, 91, 0.14);
  --gold-border: rgba(226, 185, 91, 0.32);
  --text-main: #f1f5f2;
  --text-muted: #9ab0a7;
  --border: #1e4237;
  --success: #34d399;
  --success-soft: rgba(52, 211, 153, 0.16);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.16);
  --shadow-shell: 0 24px 60px rgba(0, 0, 0, 0.55);
  --shadow-card: 0 2px 8px rgba(0, 0, 0, 0.25);
  --pattern-color: rgba(226, 185, 91, 0.05);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: var(--font-ui);
  color: var(--text-main);
  background-color: var(--bg-outer);
  overflow: hidden;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='64' height='64' viewBox='0 0 64 64'%3E%3Cg fill='none' stroke='%23998b6c' stroke-opacity='0.14' stroke-width='1'%3E%3Cpath d='M32 4 L60 32 L32 60 L4 32 Z'/%3E%3Crect x='14' y='14' width='36' height='36'/%3E%3Ccircle cx='32' cy='32' r='6'/%3E%3C/g%3E%3C/svg%3E");
}

.app-shell {
  width: 100%;
  max-width: min(480px, 100%);
  min-width: 0;
  height: 100dvh;
  background: var(--bg-app);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

@media (min-width: 520px) {
  .app-shell {
    height: min(96dvh, 860px);
    border-radius: 22px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-shell);
  }
}

.app-shell.is-title-screen .app-header {
  display: none;
}

.app-shell.is-title-screen {
  background: #062519;
}

@media (min-width: 520px) {
  .app-shell.is-title-screen {
    border-color: rgba(212, 160, 23, 0.38);
    box-shadow: 0 24px 60px rgba(4, 22, 14, 0.34), 0 0 0 1px rgba(212, 160, 23, 0.14);
  }
}

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

.is-hidden {
  display: none !important;
}

/* Header */
.app-header {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 9px 12px;
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  overflow: hidden;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--gold-border);
  box-shadow: 0 2px 6px rgba(15, 81, 50, 0.16);
  background: #0f5132;
}

.brand-mark-btn {
  padding: 0;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.15s ease;
}

.brand-mark-btn:hover {
  border-color: var(--gold);
  transform: scale(1.03);
}

.brand-logo-img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.header-titles {
  min-width: 0;
}

.brand-title {
  font-size: 0.98rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-title .accent {
  color: var(--primary);
}

.badge-basic {
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--gold-soft);
  color: var(--gold);
  border: 1px solid var(--gold-border);
}

.header-subtitle {
  font-size: 0.69rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

.icon-btn {
  position: relative;
  height: 32px;
  min-width: 32px;
  padding: 0 7px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.icon-btn:hover {
  border-color: var(--primary);
  color: var(--text-main);
}

.icon-btn.is-active {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary);
}

.icon-btn-mistakes .btn-svg-icon {
  display: block;
}

.icon-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--danger);
  color: #ffffff;
  font-size: 0.6rem;
  font-weight: 800;
  line-height: 16px;
  text-align: center;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

@media (max-width: 390px) {
  .brand-mark {
    width: 34px;
    height: 34px;
  }

  .icon-btn {
    height: 30px;
    min-width: 30px;
    padding: 0 5px;
  }

  .header-actions {
    gap: 4px;
  }

  .header-subtitle {
    font-size: 0.64rem;
  }
}

/* Views */
.view {
  display: none;
  flex: 1;
  min-height: 0;
  min-width: 0;
  flex-direction: column;
}

.view.is-active {
  display: flex;
}

/* Title Screen */
.title-screen {
  flex: 1;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
  background: linear-gradient(180deg, #052015 0%, #07291c 65%, #041a11 100%);
}

.title-cover-wrap {
  position: relative;
  flex: 1 1 0;
  min-height: 0;
  min-width: 0;
  width: 100%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #062519;
}

.title-cover-wrap::before {
  content: "";
  position: absolute;
  inset: -18px;
  background-image: url("../assets/title-cover.jpg");
  background-size: cover;
  background-position: center;
  filter: blur(22px) brightness(0.42) saturate(1.15);
  transform: scale(1.08);
  z-index: 0;
  pointer-events: none;
}

.title-cover-wrap::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 16px;
  background: linear-gradient(180deg, rgba(6, 37, 25, 0) 0%, rgba(5, 31, 20, 0.78) 100%);
  z-index: 2;
  pointer-events: none;
}

.title-cover-img {
  position: relative;
  z-index: 1;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  min-width: 0;
  min-height: 0;
  object-fit: contain;
  display: block;
  box-shadow: 0 0 32px rgba(2, 14, 9, 0.55);
}

.title-top-bar {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
}

.title-top-bar > * {
  pointer-events: auto;
}

.title-pill {
  font-size: 0.69rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(5, 29, 19, 0.72);
  color: #f6df98;
  border: 1px solid rgba(226, 185, 91, 0.44);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.28);
}

.title-top-bar .title-theme-btn {
  background: rgba(5, 29, 19, 0.72);
  color: #f6df98;
  border: 1px solid rgba(226, 185, 91, 0.44);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.28);
}

.title-top-bar .title-theme-btn:hover {
  border-color: #f3ca52;
  color: #fff6cf;
  background: rgba(9, 46, 30, 0.86);
}

.title-footer-panel {
  flex-shrink: 0;
  background: linear-gradient(180deg, #062619 0%, #041b12 100%);
  border-top: 1px solid rgba(212, 160, 23, 0.3);
  padding: 10px 14px 9px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  z-index: 3;
}

.title-footer-panel .title-status-msg {
  background: rgba(16, 68, 45, 0.88);
  border: 1px solid rgba(110, 231, 183, 0.38);
  color: #d1fae5;
}

.title-footer-panel .title-status-msg.is-error {
  background: rgba(95, 22, 22, 0.88);
  border-color: rgba(248, 113, 113, 0.45);
  color: #fecaca;
}

.title-actions {
  display: grid;
  grid-template-columns: minmax(0, 1.48fr) minmax(0, 1fr);
  gap: 8px;
  align-items: stretch;
  flex-shrink: 0;
}

.title-actions .title-btn-start {
  height: 42px;
  padding: 0 14px;
  border-radius: 11px;
  background: linear-gradient(180deg, #f6d879 0%, #d4a017 62%, #bc8713 100%);
  color: #062317;
  font-size: 0.92rem;
  font-weight: 800;
  letter-spacing: 0.01em;
  border: 1px solid rgba(255, 240, 184, 0.65);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.36), inset 0 1px 0 rgba(255, 250, 220, 0.6);
  white-space: nowrap;
}

.title-actions .title-btn-start:hover {
  background: linear-gradient(180deg, #fae293 0%, #e1ae24 62%, #c99217 100%);
}

.title-actions .title-btn-import {
  height: 42px;
  padding: 0 10px;
  border-radius: 11px;
  background: rgba(11, 52, 35, 0.78);
  color: #f6e4ad;
  border: 1px solid rgba(212, 160, 23, 0.48);
  font-size: 0.82rem;
  font-weight: 700;
  white-space: nowrap;
}

.title-actions .title-btn-import:hover {
  border-color: #f3ca52;
  background: rgba(16, 70, 48, 0.92);
  color: #fff6d4;
}

.title-credit {
  flex-shrink: 0;
  text-align: center;
  font-size: 0.71rem;
  font-weight: 600;
  color: rgba(225, 237, 230, 0.74);
  padding-top: 5px;
  border-top: 1px dashed rgba(212, 160, 23, 0.24);
}

.title-credit strong {
  color: #f1cf6f;
}

/* Home View */
.home-layout {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  padding: 10px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.panel-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  box-shadow: var(--shadow-card);
}

.surah-panel {
  flex: 1;
  min-height: 120px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 10px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.surah-panel .panel-header {
  flex-shrink: 0;
  margin-bottom: 7px;
}

.panel-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
}

.sort-switch {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg-surface-alt);
}

.sort-switch button {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.68rem;
  font-weight: 600;
  padding: 4px 8px;
  cursor: pointer;
}

.sort-switch button.is-active {
  background: var(--primary);
  color: var(--primary-contrast);
}

.search-input {
  width: 100%;
  padding: 7px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-surface-alt);
  color: var(--text-main);
  font-size: 0.84rem;
  outline: none;
  margin-bottom: 7px;
  flex-shrink: 0;
}

.search-input:focus {
  border-color: var(--primary);
  background: var(--bg-surface);
}

.surah-list {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
  padding-right: 3px;
}

.surah-item {
  width: 100%;
  text-align: left;
  border: 1px solid var(--border);
  background: var(--bg-surface-alt);
  color: var(--text-main);
  border-radius: 10px;
  padding: 7px 9px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.surah-item:hover {
  border-color: var(--primary);
}

.surah-item.is-selected {
  background: var(--primary-soft);
  border-color: var(--primary);
}

.surah-item-left {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.surah-num {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--primary);
  font-size: 0.74rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.surah-item.is-selected .surah-num {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-contrast);
}

.surah-name {
  font-size: 0.86rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.surah-meta {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.surah-badge {
  font-size: 0.68rem;
  font-weight: 700;
  padding: 3px 7px;
  border-radius: 999px;
  white-space: nowrap;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.surah-badge.is-done {
  background: var(--success-soft);
  border-color: rgba(21, 128, 61, 0.35);
  color: var(--success);
}

.surah-badge.is-gold {
  background: var(--gold-soft);
  border-color: var(--gold-border);
  color: var(--gold);
  font-weight: 800;
}

.home-dock {
  flex-shrink: 0;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 9px 11px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  box-shadow: var(--shadow-card);
}

.dock-controls-row {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
  gap: 8px;
  align-items: center;
}

.dock-select-col {
  min-width: 0;
}

.part-select {
  width: 100%;
  min-width: 0;
  height: 36px;
  padding: 0 28px 0 10px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background-color: var(--bg-surface-alt);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%235b6d65'%3E%3Cpath fill-rule='evenodd' d='M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z' clip-rule='evenodd'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 9px center;
  background-size: 13px;
  color: var(--text-main);
  font-family: var(--font-ui);
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}

[data-theme="dark"] .part-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%239ab0a7'%3E%3Cpath fill-rule='evenodd' d='M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z' clip-rule='evenodd'/%3E%3C/svg%3E");
}

.part-select:focus {
  outline: none;
  border-color: var(--primary);
  background-color: var(--bg-surface);
}

.part-select:disabled {
  opacity: 0.85;
  cursor: default;
  background-image: none;
  padding-right: 10px;
  text-align: center;
}

.btn-primary {
  width: 100%;
  border: none;
  border-radius: 12px;
  padding: 11px 16px;
  background: var(--primary);
  color: var(--primary-contrast);
  font-size: 0.94rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(15, 81, 50, 0.22);
  transition: transform 0.12s ease, background-color 0.15s ease;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-primary:active {
  transform: scale(0.99);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-secondary {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  background: var(--bg-surface);
  color: var(--text-main);
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-secondary:hover {
  border-color: var(--primary);
}

.inline-error {
  flex-shrink: 0;
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid rgba(197, 48, 48, 0.3);
  border-radius: 10px;
  padding: 7px 10px;
  font-size: 0.78rem;
}

/* Game View */
.game-hud {
  padding: 10px 14px 8px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
  flex-shrink: 0;
}

.hud-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 7px;
}

.wave-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-main);
}

.hud-pills {
  display: flex;
  align-items: center;
  gap: 6px;
}

.hud-pill {
  font-size: 0.74rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-surface-alt);
}

.hud-pill-score {
  color: var(--primary);
  background: var(--primary-soft);
  border-color: rgba(15, 81, 50, 0.28);
}

.hud-pill-wrong {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: rgba(197, 48, 48, 0.25);
}

.wave-progress-track {
  width: 100%;
  height: 5px;
  border-radius: 999px;
  background: var(--bg-surface-alt);
  overflow: hidden;
}

.wave-progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--primary), var(--gold));
  transition: width 0.25s ease;
}

.board-wrap {
  flex: 1;
  min-height: 0;
  padding: 10px 12px 14px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.board-col {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.col-heading {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  text-align: center;
  margin: 0 0 7px;
  flex-shrink: 0;
}

.cards-stack {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-rows: repeat(var(--wave-rows, 6), minmax(0, 1fr));
  gap: 8px;
}

.word-card {
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 1.5px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-main);
  border-radius: 12px;
  padding: 5px 7px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  cursor: pointer;
  user-select: none;
  box-shadow: var(--shadow-card);
  transition: border-color 0.14s ease, background-color 0.14s ease, transform 0.12s ease;
  overflow: hidden;
}

.word-card:hover:not(.is-matched) {
  border-color: var(--gold);
}

.word-card:active:not(.is-matched) {
  transform: scale(0.985);
}

.word-card.is-selected {
  border-color: var(--primary);
  background: var(--primary-soft);
  box-shadow: 0 0 0 2px rgba(15, 81, 50, 0.14);
}

[data-theme="dark"] .word-card.is-selected {
  box-shadow: 0 0 0 2px rgba(52, 211, 153, 0.22);
}

.word-card.is-wrong {
  border-color: var(--danger);
  background: var(--danger-soft);
  animation: cardShake 0.34s ease;
}

.word-card.is-matching {
  border-color: var(--success);
  background: var(--success-soft);
  pointer-events: none;
  animation: cardMatchOut 0.26s ease forwards;
}

.word-card.is-matched {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

.arabic-text {
  font-family: var(--font-arabic);
  direction: rtl;
  unicode-bidi: isolate;
  font-size: clamp(1.14rem, 4.5vw, 1.48rem);
  line-height: 1.48;
  padding: 2px 2px 0;
  color: var(--text-main);
  max-width: 100%;
  overflow-wrap: anywhere;
}

.mastery-dots {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  margin-top: 3px;
  flex-shrink: 0;
}

.mastery-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: transparent;
  transition: background-color 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
}

.mastery-dot.is-done {
  background: var(--gold);
  border-color: var(--gold);
  transform: scale(1.1);
}

.mastery-dots.is-review .mastery-dot.is-done {
  background: var(--success);
  border-color: var(--success);
  opacity: 0.65;
}

.latin-text {
  font-size: 0.7rem;
  line-height: 1.2;
  color: var(--text-muted);
  margin-top: 1px;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.translation-text {
  font-size: clamp(0.76rem, 3.1vw, 0.88rem);
  line-height: 1.28;
  font-weight: 600;
  color: var(--text-main);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

@keyframes cardShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-5px); }
  45% { transform: translateX(5px); }
  70% { transform: translateX(-4px); }
}

@keyframes cardMatchOut {
  0% { opacity: 1; transform: scale(1); }
  40% { opacity: 0.95; transform: scale(1.03); }
  100% { opacity: 0; transform: scale(0.86); }
}

/* Summary View */
.summary-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 14px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.summary-hero {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px 14px;
  text-align: center;
  box-shadow: var(--shadow-card);
}

.summary-stars {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 4px;
}

.star-icon {
  font-size: 2rem;
  line-height: 1;
  color: var(--border);
  transition: transform 0.2s ease, color 0.2s ease;
}

.star-icon.is-earned {
  color: #d9a326;
  text-shadow: 0 2px 10px rgba(217, 163, 38, 0.35);
}

[data-theme="dark"] .star-icon.is-earned {
  color: #f4c95d;
}

.summary-star-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--gold);
  margin-bottom: 6px;
}

.star-hint-box {
  margin-top: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--bg-surface-alt);
  border: 1px solid var(--border);
  font-size: 0.74rem;
  line-height: 1.4;
  color: var(--text-muted);
}

.summary-title {
  margin: 0 0 2px;
  font-size: 1.12rem;
  font-weight: 800;
  color: var(--primary);
}

.summary-subtitle {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.new-best-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--gold-soft);
  color: var(--gold);
  border: 1px solid var(--gold-border);
  margin-bottom: 10px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  margin-top: 8px;
}

.stat-tile {
  background: var(--bg-surface-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 4px;
}

.stat-val {
  font-size: 1.05rem;
  font-weight: 800;
  line-height: 1.15;
}

.stat-lbl {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-top: 2px;
}

.mistake-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.mistake-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--bg-surface-alt);
  border: 1px solid var(--border);
}

.mistake-row-main {
  min-width: 0;
  flex: 1;
}

.mistake-row-ar {
  font-family: var(--font-arabic);
  font-size: 1.2rem;
  line-height: 1.45;
  direction: rtl;
  display: inline-block;
}

.mistake-row-tr {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-main);
}

.mistake-row-meta {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.mistake-count-pill {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--danger-soft);
  color: var(--danger);
  white-space: nowrap;
}

.perfect-box {
  text-align: center;
  padding: 12px;
  border-radius: 12px;
  background: var(--success-soft);
  border: 1px solid rgba(21, 128, 61, 0.25);
  color: var(--success);
  font-size: 0.82rem;
  font-weight: 600;
}

.summary-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Modal */
.modal-backdrop {
  position: absolute;
  inset: 0;
  z-index: 20;
  background: rgba(10, 20, 15, 0.56);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
}

.modal-card {
  width: 100%;
  max-height: 86dvh;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.modal-title {
  margin: 0;
  font-size: 0.96rem;
  font-weight: 800;
}

.modal-body {
  padding: 12px 14px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.modal-footer {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
}

.filter-select {
  width: 100%;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-surface-alt);
  color: var(--text-main);
  font-size: 0.82rem;
}

.btn-remove-mistake {
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--success);
  width: 28px;
  height: 28px;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
}

.btn-remove-mistake:hover {
  background: var(--success-soft);
  border-color: var(--success);
}

.btn-danger-outline {
  border: 1px solid rgba(197, 48, 48, 0.35);
  background: var(--danger-soft);
  color: var(--danger);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  flex: 1;
}

.empty-state {
  text-align: center;
  padding: 20px 10px;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.modal-progress-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 11px;
  border-radius: 10px;
  background: var(--bg-surface-alt);
  border: 1px solid var(--border);
}

.modal-progress-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 0.82rem;
  color: var(--text-main);
}

.modal-progress-label {
  font-size: 0.66rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.btn-reset-mini {
  border: 1px solid rgba(197, 48, 48, 0.35);
  background: var(--danger-soft);
  color: var(--danger);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.74rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}

.btn-reset-mini:hover {
  filter: brightness(0.96);
}

#modal-reset {
  z-index: 25;
}

#modal-import {
  z-index: 26;
}

.modal-backup-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.btn-backup {
  border: 1px solid var(--border);
  background: var(--bg-surface-alt);
  color: var(--text-main);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.77rem;
  font-weight: 700;
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.btn-backup:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
}

.backup-status {
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.4;
  background: var(--success-soft);
  border: 1px solid rgba(21, 128, 61, 0.25);
  color: var(--success);
}

.backup-status.is-error {
  background: var(--danger-soft);
  border-color: rgba(197, 48, 48, 0.3);
  color: var(--danger);
}

.import-preview-box {
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--bg-surface-alt);
  border: 1px solid var(--border);
  font-size: 0.78rem;
  line-height: 1.5;
  color: var(--text-main);
}

.import-actions-col {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

