/* ── Local fonts ─────────────────────────────────────────────────────────── */
@font-face {
  font-family: 'Google Sans';
  src: url('fonts/GoogleSans.woff2') format('woff2');
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

/* ── Reset ───────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { user-select: none; }

/* ── Theme variables ─────────────────────────────────────────────────────── */
:root {
  --bg:          #E8E5E0;
  --surface:     #F0EDE8;
  --border:      #CDC9C3;
  --title-text:  #2A2520;
  --subtle-text: rgba(42, 37, 32, 0.5);
  --accent:      #7A3F2E;
  --glass-bg:    rgba(240, 237, 232, 0.65);
}

html.dark {
  --bg:          #0F1117;
  --surface:     #171B26;
  --border:      #232840;
  --title-text:  #E8EBF5;
  --subtle-text: rgba(232, 235, 245, 0.5);
  --accent:      #D4896A;
  --glass-bg:    rgba(23, 27, 38, 0.65);
}

/* ── Layout ──────────────────────────────────────────────────────────────── */
html, body { height: 100%; overflow: hidden; }
html { background-color: var(--surface); }

body {
  background-color: var(--bg);
  color: var(--title-text);
  font-family: 'DM Sans', sans-serif;
  display: flex;
  flex-direction: column;
  transition: background-color 0.4s ease;
}

/* ── App bar ─────────────────────────────────────────────────────────────── */
.app-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  height: 60px;
  background-color: var(--glass-bg);
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.4s ease, border-color 0.4s ease;
}

.app-title {
  font-family: 'Google Sans', sans-serif;
  font-size: 2.375rem;
  font-weight: 600;
  letter-spacing: -0.5px;
  color: var(--title-text);
  transition: color 0.4s ease;
}

/* ── Main ────────────────────────────────────────────────────────────────── */
#main { flex: 1; overflow: hidden; position: relative; }

.cards-view {
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.cards-list {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 84px 0 calc(64px + env(safe-area-inset-bottom, 0px) + 40px);
  gap: 40px;
}

.hidden { display: none !important; }

/* ── Flip card ───────────────────────────────────────────────────────────── */
.flip-card {
  width: min(300px, 90vw);
  height: 190px;
  perspective: 800px;
  cursor: pointer;
  position: relative;
}

.flip-card-front,
.flip-card-back {
  position: absolute;
  inset: 0;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(0, 0, 0, 0.08);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  background-color: var(--card-light-bg);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.10);
}

html.dark .flip-card-front,
html.dark .flip-card-back {
  background-color: var(--card-dark-bg);
  border-color: rgba(255, 255, 255, 0.18);
}

/* Front: visible → folds away top-backward on flip */
.flip-card-front {
  transition: background-color 0.4s ease, border-color 0.4s ease, transform 0.1s ease-in 0s;
}
.flip-card.flipped .flip-card-front {
  transform: rotateX(90deg);
  transition: background-color 0.4s ease, border-color 0.4s ease, transform 0.1s ease-in 0s;
}

/* Back: hidden (edge-on) → unfolds forward after front hides */
.flip-card-back {
  transform: rotateX(-90deg);
  flex-direction: column;
  gap: 4px;
  transition: background-color 0.4s ease, border-color 0.4s ease, transform 0.1s ease-out 0s;
}
.flip-card.flipped .flip-card-back {
  transform: rotateX(0deg);
  transition: background-color 0.4s ease, border-color 0.4s ease, transform 0.1s ease-out 0.1s;
}

/* Un-flip: back folds away, front unfolds after */
.flip-card-front {
  transition: background-color 0.4s ease, border-color 0.4s ease, transform 0.1s ease-out 0.1s;
}
.flip-card-back {
  transition: background-color 0.4s ease, border-color 0.4s ease, transform 0.1s ease-in 0s;
}

.card-arabic {
  font-family: 'Scheherazade New', serif;
  font-size: 4rem;
  font-weight: 400;
  line-height: 1.2;
  color: var(--card-light-text);
  transition: color 0.4s ease;
}

html.dark .card-arabic {
  color: var(--card-dark-text);
}

.card-phonetic {
  font-family: 'Source Serif 4', serif;
  font-size: 1.625rem;
  font-weight: 600;
  color: var(--card-light-text);
  transition: color 0.4s ease;
}

html.dark .card-phonetic {
  color: var(--card-dark-text);
}

.card-meaning {
  font-family: 'Source Serif 4', serif;
  font-size: 0.9375rem;
  font-weight: 400;
  font-style: italic;
  color: var(--card-meaning-color);
}

/* ── Bottom nav ──────────────────────────────────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10;
  height: calc(64px + env(safe-area-inset-bottom, 0px));
  background-color: var(--glass-bg);
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: stretch;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  transition: background-color 0.4s ease, border-color 0.4s ease;
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--subtle-text);
  transition: color 0.4s ease;
  -webkit-tap-highlight-color: transparent;
}

.nav-item.active { color: var(--accent); }

.nav-icon {
  font-size: 22px;
  font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 20;
}

.nav-item.active .nav-icon {
  font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 20;
}

.nav-label {
  font-family: 'DM Sans', sans-serif;
  font-size: 0.75rem;
  font-weight: 400;
}

.nav-item.active .nav-label { font-weight: 600; }

/* ── Settings ────────────────────────────────────────────────────────────── */
.settings-view {
  height: 100%;
  overflow-y: auto;
  padding: 92px 24px calc(64px + env(safe-area-inset-bottom, 0px) + 32px);
  background-color: var(--bg);
  transition: background-color 0.4s ease;
}

.settings-usage-motivation {
  font-family: 'DM Sans', sans-serif;
  font-size: 2rem;
  font-weight: 700;
  color: var(--title-text);
  text-align: center;
  margin-bottom: 16px;
  transition: color 0.4s ease;
}

.settings-usage-welcome {
  font-family: 'DM Sans', sans-serif;
  font-size: 2rem;
  font-weight: 700;
  color: var(--title-text);
  text-align: center;
  margin-bottom: 40px;
  transition: color 0.4s ease;
}

.settings-usage-stats {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 0 auto 48px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px 48px 24px;
  width: fit-content;
  transition: background 0.4s ease, border-color 0.4s ease;
}

.settings-usage-fraction {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  line-height: 1;
  margin-bottom: 16px;
}

.settings-usage-numerator {
  font-family: 'DM Sans', sans-serif;
  font-size: 5rem;
  font-weight: 700;
  color: var(--title-text);
  transition: color 0.4s ease;
  line-height: 1;
}

.settings-usage-denominator {
  font-family: 'DM Sans', sans-serif;
  font-size: 1.5rem;
  font-weight: 400;
  color: var(--subtle-text);
  transition: color 0.4s ease;
  padding-bottom: 10px;
}

.settings-usage-label {
  font-family: 'DM Sans', sans-serif;
  font-size: 1rem;
  font-weight: 500;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--subtle-text);
  transition: color 0.4s ease;
  margin-top: 4px;
}

.settings-section-label {
  font-family: 'DM Sans', sans-serif;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 1.2px;
  color: var(--subtle-text);
  text-transform: uppercase;
  margin-bottom: 12px;
  transition: color 0.4s ease;
}

.settings-gap { height: 40px; }

.settings-option {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  border-top: 1px solid transparent;
  transition: border-color 0.4s ease;
}

.settings-option + .settings-option {
  border-top-color: var(--border);
}

.settings-option .material-symbols-outlined {
  font-size: 20px;
  color: var(--subtle-text);
  flex-shrink: 0;
  font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 20;
  transition: color 0.4s ease;
}

.settings-option.selected .material-symbols-outlined {
  color: var(--title-text);
}

.settings-option-label {
  flex: 1;
  font-family: 'DM Sans', sans-serif;
  font-size: 1rem;
  font-weight: 400;
  color: var(--subtle-text);
  transition: color 0.4s ease;
}

.settings-option.selected .settings-option-label {
  font-weight: 600;
  color: var(--title-text);
}

.settings-check {
  font-size: 18px;
  color: var(--title-text);
  font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 20;
  transition: color 0.4s ease;
}

/* Toggle row */
.settings-toggle-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 0;
}

.settings-toggle-row .material-symbols-outlined {
  font-size: 20px;
  color: var(--title-text);
  flex-shrink: 0;
  font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 20;
  transition: color 0.4s ease;
}

.settings-toggle-text { flex: 1; }

.settings-toggle-title {
  font-family: 'DM Sans', sans-serif;
  font-size: 1rem;
  color: var(--title-text);
  transition: color 0.4s ease;
}

.settings-toggle-subtitle {
  font-family: 'DM Sans', sans-serif;
  font-size: 0.8125rem;
  color: var(--subtle-text);
  transition: color 0.4s ease;
}

/* iOS-style toggle */
.toggle-switch {
  position: relative;
  width: 51px;
  height: 31px;
  flex-shrink: 0;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle-track {
  position: absolute;
  inset: 0;
  border-radius: 15.5px;
  background-color: #E5E5EA;
  cursor: pointer;
  transition: background-color 0.3s;
}

html.dark .toggle-track { background-color: #3A3A3C; }

.toggle-switch input:checked + .toggle-track { background-color: #34C759; }

.toggle-track::after {
  content: '';
  position: absolute;
  left: 2px;
  top: 2px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
  transition: transform 0.3s;
}

.toggle-switch input:checked + .toggle-track::after {
  transform: translateX(20px);
}

/* ── Desktop footer (desktop only) ───────────────────────────────────────── */
.app-footer {
  display: none;
}

/* ── Responsive: 2-column card grid (560px+) ─────────────────────────────── */
@media (min-width: 560px) {
  .cards-list {
    display: grid;
    grid-template-columns: repeat(2, 300px);
    justify-content: center;
    align-items: start;
  }
}

/* ── Responsive: side nav (1024px+) ─────────────────────────────────────── */
@media (min-width: 1024px) {
  /* Sidebar occupies left 220px; body content is pushed right via padding */
  body {
    padding-left: 220px;
  }

  #main {
    flex: 1;
    overflow: hidden;
  }

  .bottom-nav {
    position: fixed;
    top: 0;
    left: 0;
    right: auto;
    bottom: 0;
    width: 220px;
    height: auto;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    border-top: none;
    border-right: 1px solid var(--border);
    padding-bottom: 0;
  }

  .nav-item {
    flex: 0;
    flex-direction: row;
    justify-content: flex-start;
    gap: 14px;
    padding: 16px 20px;
    height: auto;
  }

  .nav-label { font-size: 0.9375rem; }

  .nav-icon { font-size: 20px; }

  .settings-view { padding: calc(60px + 40px) 48px 40px; }

  .cards-list { padding: calc(60px + 24px) 0 40px; }

  .app-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 220px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px 20px;
    font-family: 'DM Sans', sans-serif;
    font-size: 12px;
    letter-spacing: 0.3px;
    color: var(--subtle-text);
    border-top: 1px solid var(--border);
    transition: border-color 0.4s ease, color 0.4s ease;
  }

  .app-footer a {
    color: inherit;
    text-decoration: none;
  }
}

/* ── Responsive: 3-column card grid (1120px+) ────────────────────────────── */
@media (min-width: 1120px) {
  .cards-list {
    grid-template-columns: repeat(3, 300px);
  }
}
