/* ===== DESIGN TOKENS ===== */
:root {
  --bg: #0A0F0E;
  --bg-rgb: 10, 15, 14;
  --surface: #131A18;
  --surface-raised: #1A2421;
  --surface-hover: #22302C;
  --border: #243430;
  --border-subtle: #18211F;
  --text: #ECF3F1;
  --text-secondary: #9DB0AC;
  --text-muted: #6B807B;
  --accent: #2FD3B0;
  --accent-on: #04221C;
  --accent-on-soft: rgba(4,34,28,0.62);
  --accent-on-faint: rgba(4,34,28,0.12);
  --accent-dim: rgba(47, 211, 176, 0.10);
  --success: #5DBF3A;
  --warning: #D9A94E;
  --danger: #F0714C;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --radius-xl: 24px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.25);
  --shadow-md: 0 4px 20px rgba(0,0,0,0.35);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.45);
  --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-base: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="light"] {
  --bg: #EEF4F2;
  --bg-rgb: 238, 244, 242;
  --surface: #FFFFFF;
  --surface-raised: #FFFFFF;
  --surface-hover: #E3EFEB;
  --border: #D5E2DE;
  --border-subtle: #E6EEEB;
  --text: #0C1F1B;
  --text-secondary: #5A6E69;
  --text-muted: #8A9C97;
  --accent: #0C6E5C;
  --accent-on: #FFFFFF;
  --accent-on-soft: rgba(255,255,255,0.68);
  --accent-on-faint: rgba(255,255,255,0.14);
  --accent-dim: rgba(12, 110, 92, 0.08);
  --success: #1E8A3B;
  --warning: #C9943A;
  --danger: #D23B2A;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 20px rgba(0,0,0,0.08);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.1);
}

/* ===== RESET ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body, #root { height: 100%; width: 100%; overflow: hidden; }
.screen-enter { height: 100%; width: 100%; animation: fadeIn 0.25s ease; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
::-webkit-scrollbar { display: none; }

/* ===== APP SHELL ===== */
.app-shell {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  background: var(--bg);
}

/* ===== LOADING ===== */
.loading-shell {
  height: 100vh;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 18px;
  background: var(--bg);
  animation: fadeIn 0.4s ease;
}
.spinner {
  width: 48px;
  height: 48px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
.loading-text {
  color: var(--text-muted);
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0.3px;
}

/* ===== HOME ===== */
.home-wrap {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}
.home-header {
  flex-shrink: 0;
  background: rgba(var(--bg-rgb), 0.82);
  backdrop-filter: blur(20px) saturate(1.8);
  -webkit-backdrop-filter: blur(20px) saturate(1.8);
  border-bottom: 1px solid var(--border);
  z-index: 10;
  position: relative;
}
.home-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--text) 22%, transparent) transparent;
}
.home-scroll::-webkit-scrollbar { display: block; width: 8px; }
.home-scroll::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--text) 20%, transparent);
  border-radius: 99px;
  border: 2px solid transparent;
  background-clip: content-box;
}
.home-scroll::-webkit-scrollbar-track { background: transparent; }
.home-content {
  padding: 16px;
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
}
.home-spacer { height: calc(96px + env(safe-area-inset-bottom)); }

.hero-title {
  font-weight: 900;
  font-size: 26px;
  letter-spacing: -0.8px;
  color: var(--text);
  line-height: 1.1;
}
.hero-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
  font-weight: 600;
}

/* Overflow menu (Backup / Restore moved here to declutter header) */
.home-menu-wrap { position: relative; }
.home-menu {
  position: absolute;
  top: 44px;
  right: 0;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  min-width: 210px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 2px;
  animation: menu-pop 0.16s cubic-bezier(0.34,1.56,0.64,1);
  transform-origin: top right;
}
@keyframes menu-pop { from { opacity: 0; transform: scale(0.92) translateY(-4px); } to { opacity: 1; transform: scale(1) translateY(0); } }
.home-menu button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: none;
  border: none;
  cursor: pointer;
  padding: 10px 12px;
  border-radius: 9px;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  text-align: left;
  transition: background var(--transition-fast);
}
.home-menu button:hover { background: var(--surface-hover); }
.home-menu-note {
  padding: 8px 12px 4px;
  font-size: 11px;
  line-height: 1.4;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  margin-top: 4px;
}
.menu-backdrop { position: fixed; inset: 0; z-index: 40; }

/* Search */
.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.search-input {
  width: 100%;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 40px 12px 16px;
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  font-family: inherit;
}
.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(242, 242, 242, 0.10);
}
[data-theme="light"] .search-input:focus {
  box-shadow: 0 0 0 3px rgba(242, 242, 242, 0.16);
}
.search-clear {
  position: absolute;
  right: 6px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 20px;
  color: var(--text-muted);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background var(--transition-fast), color var(--transition-fast);
}
.search-clear:hover { background: var(--surface-hover); color: var(--text-secondary); }

/* ===== Deck Grid (redesigned: warmer, softer, cleaner) ===== */
.deck-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 32px;
}
.deck-card {
  --c: var(--deck-color, var(--accent));
  border-radius: var(--radius-lg);
  padding: 16px;
  cursor: pointer;
  min-height: 132px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: relative;
  overflow: hidden;
  /* soft tint wash derived from the deck colour, layered over surface */
  background:
    linear-gradient(150deg, color-mix(in srgb, var(--c) 14%, transparent), color-mix(in srgb, var(--c) 3%, transparent)),
    var(--surface);
  border: 1px solid color-mix(in srgb, var(--c) 22%, var(--border));
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition-base), box-shadow var(--transition-base), border-color var(--transition-base);
  user-select: none;
}
.deck-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 30px color-mix(in srgb, var(--c) 22%, transparent);
  border-color: color-mix(in srgb, var(--c) 55%, var(--border));
}
.deck-card:active { transform: translateY(-1px) scale(0.99); }

/* rounded glyph badge with the deck initial */
.deck-card-glyph {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(140deg, var(--c), color-mix(in srgb, var(--c) 70%, #000));
  box-shadow: 0 3px 10px color-mix(in srgb, var(--c) 35%, transparent);
  flex-shrink: 0;
  letter-spacing: -0.5px;
}
.deck-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}
.deck-card-title {
  font-size: 14px;
  font-weight: 750;
  color: var(--text);
  line-height: 1.3;
  letter-spacing: -0.2px;
}
.deck-card-count {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
  margin-top: 2px;
}
.deck-card-body { display: flex; flex-direction: column; gap: 4px; }
.deck-card-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; }
.deck-card-stats {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}
.deck-stat {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 20px;
  background: color-mix(in srgb, var(--text) 8%, transparent);
  color: var(--text-secondary);
}
.deck-pct {
  font-size: 11px;
  font-weight: 800;
  margin-left: auto;
  color: var(--c);
}
.deck-progress-track {
  height: 5px;
  background: color-mix(in srgb, var(--text) 9%, transparent);
  border-radius: 99px;
  overflow: hidden;
}
.deck-progress-fill {
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--c), color-mix(in srgb, var(--c) 65%, #fff));
  transition: width 0.7s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ===== Minimalist deck list (home screen) ===== */
.deck-list {
  display: flex;
  flex-direction: column;
  margin-bottom: 28px;
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface);
}
.deck-row {
  --c: var(--deck-color, var(--accent));
  position: relative;
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 13px 14px 14px 16px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: pan-y;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition-base), transform 0.18s ease, box-shadow 0.18s ease;
  background: var(--surface);
}
.deck-list.is-reordering .deck-row { touch-action: none; }
.deck-row.reordering { touch-action: none; }
.deck-row:last-child { border-bottom: none; }
.deck-row:hover { background: color-mix(in srgb, var(--c) 7%, transparent); }
.deck-row:active { background: color-mix(in srgb, var(--c) 12%, transparent); }
/* thin colour accent on the left edge keeps each deck's identity now the chip is gone */
.deck-row::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--c);
  opacity: 0.85;
}

/* drag handle (visible, becomes prominent in reorder mode) */
.deck-row-grip {
  flex-shrink: 0;
  width: 18px;
  height: 26px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
  opacity: 0.28;
  transition: opacity var(--transition-base);
}
.deck-row-grip span {
  display: block;
  height: 2px;
  width: 14px;
  border-radius: 2px;
  background: var(--text-muted);
}
.deck-row:hover .deck-row-grip { opacity: 0.5; }

/* reorder mode: every row lifts slightly so it reads as "rearrangeable" */
.deck-list .deck-row.reordering { cursor: grab; }
.deck-list .deck-row.reordering .deck-row-grip { opacity: 0.7; }
.deck-list .deck-row.reordering .deck-row-arrow { opacity: 0; }
.deck-row.dragging {
  cursor: grabbing;
  background: color-mix(in srgb, var(--c) 16%, var(--surface));
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
  transform: scale(1.02);
  z-index: 5;
  border-radius: var(--radius-md);
}
.deck-row.dragging .deck-row-grip { opacity: 1; }
.deck-row.dragging .deck-row-grip span { background: var(--c); }

.deck-row-main { flex: 1; min-width: 0; }
.deck-row-title {
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.2px;
  color: var(--text);
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.deck-row-meta {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 2px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}
.deck-row-dot { color: var(--text-muted); opacity: 0.5; }
.deck-row-pct {
  font-size: 12px;
  font-weight: 800;
  color: var(--c);
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}
.deck-row-arrow {
  font-size: 19px;
  font-weight: 400;
  color: var(--text-muted);
  opacity: 0.4;
  flex-shrink: 0;
  line-height: 1;
}
/* hairline progress sitting on the row's bottom edge */
.deck-row-progress {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 2px;
  background: var(--c);
  border-radius: 0 2px 2px 0;
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}


.group-block { margin-bottom: 4px; }
.group-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 2px 2px 10px;
}
.group-label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--text-muted);
}
.group-count {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  opacity: 0.7;
  padding: 1px 7px;
  border-radius: 99px;
  background: color-mix(in srgb, var(--text) 7%, transparent);
}

/* Search results */
.results-header {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 12px;
}
.result-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-left: 4px solid var(--result-color, var(--accent));
  border-radius: var(--radius-md);
  padding: 14px 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  transition: all var(--transition-fast);
  margin-bottom: 8px;
}
.result-card:hover {
  transform: translateX(3px);
  box-shadow: var(--shadow-sm);
  border-color: var(--result-color, var(--accent));
}
.result-card-text {
  flex: 1;
  min-width: 0;
}
.result-card-title {
  font-weight: 800;
  font-size: 15px;
  color: var(--result-color, var(--accent));
  letter-spacing: -0.2px;
}
.result-card-sub {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 2px;
}
.result-card-hindi {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 3px;
}
.result-card-badge {
  font-size: 10px;
  color: var(--result-color, var(--accent));
  background: var(--result-color, var(--accent));
  opacity: 0.85;
  padding: 3px 10px;
  border-radius: 20px;
  font-weight: 700;
  margin-top: 6px;
  display: inline-block;
  color: var(--accent-on);
}
.result-arrow {
  font-size: 18px;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* ===== DECK SCREEN ===== */
.deck-shell {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  background: var(--bg);
}
.deck-header {
  flex-shrink: 0;
  background: rgba(var(--bg-rgb), 0.82);
  backdrop-filter: blur(20px) saturate(1.8);
  -webkit-backdrop-filter: blur(20px) saturate(1.8);
  border-bottom: 1px solid var(--border);
  z-index: 10;
  position: relative;
}
.deck-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 16px calc(16px + env(safe-area-inset-bottom));
  gap: 10px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Pills */
.pill-row {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}
.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 12px;
  border-radius: 20px;
  border: 1.5px solid var(--border);
  background: transparent;
  color: var(--text);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  min-height: 28px;
  transition: all var(--transition-fast);
  user-select: none;
  font-family: inherit;
}
.pill.active {
  background: var(--pill-color, var(--accent));
  border-color: var(--pill-color, var(--accent));
  color: var(--accent-on);
}
.pill:hover:not(.active) {
  background: var(--surface-hover);
  border-color: var(--text-muted);
}
.pill-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  display: inline-block;
  margin-right: 4px;
}

/* Buttons */
.btn-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
}
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 16px;
  transition: all var(--transition-fast);
  font-family: inherit;
}
.btn-icon:hover {
  background: var(--surface-hover);
  color: var(--text);
  transform: translateY(-1px);
}
.btn-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: var(--radius-lg);
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  min-height: 44px;
  transition: all var(--transition-fast);
  user-select: none;
  font-family: inherit;
  flex: 1;
}
.btn-action:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
  border-color: var(--text-muted);
}
.btn-action.active {
  background: var(--btn-color, var(--accent));
  border-color: var(--btn-color, var(--accent));
  color: var(--accent-on);
}
.btn-action.active:hover {
  filter: brightness(1.1);
}
.btn-nav {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 20px;
  font-weight: 700;
  transition: all var(--transition-fast);
  font-family: inherit;
}
.btn-nav:hover:not(:disabled) {
  background: var(--surface-hover);
  color: var(--text);
  transform: scale(1.05);
}
.btn-nav:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.btn-counter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 20px;
  border-radius: var(--radius-lg);
  border: 1.5px solid var(--border);
  background: var(--surface-raised);
  color: var(--text);
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  min-height: 48px;
  transition: all var(--transition-fast);
  font-family: inherit;
}
.btn-counter:hover {
  border-color: var(--text-muted);
}
/* first / last (« ») buttons: slightly smaller and quieter than prev/next */
.btn-nav.edge {
  width: 42px;
  height: 42px;
  font-size: 17px;
  color: var(--text-muted);
}

/* Progress */
.progress-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 0;
}
.progress-track {
  flex: 1;
  height: 4px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: 4px;
  background: var(--progress-color, var(--accent));
  transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}
.progress-text {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  font-weight: 600;
}
.progress-known {
  font-size: 11px;
  color: #10b981;
  font-weight: 800;
  white-space: nowrap;
}

/* Meta bar */
.meta-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  width: 100%;
  max-width: 480px;
}
.meta-tag {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 6px;
  background: rgba(0,0,0,0.15);
}
.meta-count {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.3px;
}
[data-theme="light"] .meta-tag {
  background: rgba(0,0,0,0.04);
}

/* ===== FLIP CARDS ===== */
.flip-wrap {
  width: 100%;
  max-width: 480px;
  --card-h: 254px;
  perspective: 1200px;
  cursor: pointer;
  user-select: none;
  touch-action: pan-y;
  position: relative;
}
@media (max-height: 720px) {
  .flip-wrap { --card-h: 224px; }
}
@media (max-height: 620px) {
  .flip-wrap { --card-h: 198px; }
}
.flip-inner {
  position: relative;
  width: 100%;
  display: grid;
  transform-style: preserve-3d;
  transition: transform 0.55s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: var(--radius-lg);
}
.flip-inner > .flip-front,
.flip-inner > .flip-back {
  grid-area: 1 / 1;
}
.flip-inner.flipped {
  transform: rotateY(180deg);
}
.flip-front, .flip-back {
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: var(--radius-lg);
  height: var(--card-h, 239px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px 18px;
  box-sizing: border-box;
  gap: 4px;
  box-shadow: var(--shadow-md);
  position: relative;
  overflow: hidden;
}
.flip-front {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-top: 4px solid var(--card-color, var(--accent));
}
.flip-front::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(180deg, rgba(255,255,255,0.03) 0%, transparent 40%);
  pointer-events: none;
}
.flip-back {
  transform: rotateY(180deg);
  background: var(--card-color, var(--accent));
  color: var(--accent-on);
  border: 1.5px solid transparent;
}
.flip-back::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.12) 0%, transparent 60%);
  pointer-events: none;
}
.card-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--card-color, var(--accent));
  z-index: 1;
}
.card-main {
  font-size: 32px;
  font-weight: 800;
  color: var(--text);
  text-align: center;
  line-height: 1.2;
  word-break: break-word;
  z-index: 1;
  letter-spacing: -0.5px;
}
.card-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
  z-index: 1;
}
.back-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--accent-on-soft);
  z-index: 1;
}
.back-main {
  font-size: 28px;
  font-weight: 800;
  color: var(--accent-on);
  text-align: center;
  line-height: 1.25;
  word-break: break-word;
  z-index: 1;
  letter-spacing: -0.3px;
}
.back-hindi {
  font-size: 18px;
  color: var(--accent-on-soft);
  font-weight: 500;
  z-index: 1;
}
.back-ordinal {
  margin-top: 10px;
  background: var(--accent-on-faint);
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  text-align: center;
  z-index: 1;
}
.back-ordinal-label {
  font-size: 10px;
  color: var(--accent-on-soft);
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  margin-bottom: 3px;
}
.back-ordinal-value {
  font-size: 17px;
  font-weight: 800;
  color: var(--accent-on);
}
.back-example {
  margin-top: 10px;
  padding: 8px 14px;
  background: var(--accent-on-faint);
  border-left: 3px solid var(--accent-on-soft);
  border-radius: var(--radius-sm);
  text-align: center;
  max-width: 94%;
  z-index: 1;
}
.back-example-fr {
  font-size: 15px;
  font-weight: 600;
  color: var(--accent-on);
  font-style: italic;
  line-height: 1.4;
}
.back-example-en {
  font-size: 12px;
  font-weight: 500;
  color: var(--accent-on-soft);
  margin-top: 4px;
  line-height: 1.35;
}

/* Conjugation card */
.conj-wrap {
  width: 100%;
  max-width: 480px;
  perspective: 1200px;
  cursor: pointer;
  user-select: none;
}
.conj-inner {
  position: relative;
  width: 100%;
  transform-style: preserve-3d;
  transition: transform 0.55s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: var(--radius-lg);
}
.conj-inner.flipped {
  transform: rotateY(180deg);
}
.conj-front, .conj-back {
  backface-visibility: hidden;
  border-radius: var(--radius-lg);
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
  box-sizing: border-box;
  gap: 6px;
  box-shadow: var(--shadow-md);
  overflow: hidden;
}
.conj-front {
  position: absolute;
  inset: 0;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-top: 4px solid var(--card-color, var(--accent));
}
.conj-back {
  position: relative;
  transform: rotateY(180deg);
  background: var(--card-color, var(--accent));
  color: var(--accent-on);
  padding: 16px;
  justify-content: flex-start;
  overflow-y: visible;
}
.conj-verb {
  font-size: 36px;
  font-weight: 900;
  color: var(--text);
  letter-spacing: -0.5px;
}
.conj-meaning {
  font-size: 14px;
  color: var(--text-muted);
  font-weight: 600;
}
.conj-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
}
.conj-table-title {
  font-size: 10px;
  color: var(--accent-on-soft);
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  text-align: center;
  margin: 8px 0 6px;
}
.conj-table {
  width: 100%;
  border-collapse: collapse;
}
.conj-table td {
  padding: 5px 8px;
  font-size: 13px;
}
.conj-table td:first-child {
  color: var(--accent-on-soft);
  font-weight: 600;
  font-size: 11px;
  width: 70px;
}
.conj-table td:nth-child(2) {
  font-weight: 800;
  color: var(--accent-on);
}
.conj-table td:nth-child(3) {
  color: var(--accent-on-soft);
  font-size: 12px;
}
.conj-table tr:nth-child(odd) {
  background: var(--accent-on-faint);
}

/* Quiz card */
.quiz-wrap {
  width: 100%;
  max-width: 480px;
  perspective: 1200px;
  cursor: pointer;
  user-select: none;
}
.quiz-inner {
  position: relative;
  width: 100%;
  transform-style: preserve-3d;
  transition: transform 0.55s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: var(--radius-lg);
}
.quiz-inner.flipped {
  transform: rotateY(180deg);
}
.quiz-front, .quiz-back {
  backface-visibility: hidden;
  border-radius: var(--radius-lg);
  min-height: 220px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  box-sizing: border-box;
  gap: 10px;
  box-shadow: var(--shadow-md);
  position: relative;
  overflow: hidden;
}
.quiz-front {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-top: 4px solid var(--card-color, var(--accent));
}
.quiz-back {
  position: absolute;
  inset: 0;
  transform: rotateY(180deg);
  background: var(--card-color, var(--accent));
  color: var(--accent-on);
}
.quiz-subject {
  padding: 8px 24px;
  border-radius: 24px;
  background: var(--card-color, var(--accent));
  opacity: 0.15;
  border: 2px solid var(--card-color, var(--accent));
}
.quiz-subject-text {
  font-size: 18px;
  font-weight: 800;
  color: var(--card-color, var(--accent));
}
.quiz-verb {
  font-size: 30px;
  font-weight: 900;
  color: var(--text);
  letter-spacing: -0.5px;
}

/* Drag */
.drag-hint {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  font-size: 28px;
  opacity: 0;
  pointer-events: none;
  color: var(--card-color, var(--accent));
  transition: opacity 0.15s ease;
  z-index: 10;
  font-weight: 300;
}
.drag-hint.left { left: 12px; }
.drag-hint.right { right: 12px; }
.drag-hint.visible { opacity: 0.7; }

/* ===== MODALS ===== */
.modal-backdrop {
  position: absolute;
  inset: 0;
  z-index: 200;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: flex-end;
  animation: fadeIn 0.2s ease;
}
.modal-backdrop.centered {
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-sheet {
  width: 100%;
  background: var(--surface);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  border: 1px solid var(--border);
  border-bottom: none;
  padding: 24px 20px calc(20px + env(safe-area-inset-bottom, 0px));
  box-sizing: border-box;
  animation: slideUp 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  max-height: 90vh;
  max-height: 90dvh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}
.modal-centered {
  width: 100%;
  max-width: 560px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  padding: 22px 20px 24px;
  box-sizing: border-box;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  animation: scaleIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: var(--shadow-lg);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-shrink: 0;
}
.modal-title {
  font-size: 17px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.3px;
}
.modal-title-accent {
  color: var(--title-color, var(--accent));
  font-size: 15px;
  font-weight: 700;
}
.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 24px;
  color: var(--text-muted);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all var(--transition-fast);
  font-family: inherit;
}
.modal-close:hover {
  background: var(--surface-hover);
  color: var(--text-secondary);
}
.modal-body {
  overflow-y: auto;
  flex: 1;
  scrollbar-width: none;
}

/* Add-card modal: scrollable fields with pinned action bar */
.addcard-fields {
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 4px;
}
.addcard-fields::-webkit-scrollbar { display: none; }
.addcard-actions {
  position: sticky;
  bottom: 0;
  flex-shrink: 0;
  background: var(--surface);
  padding-top: 12px;
  margin-top: 8px !important;
  border-top: 1px solid var(--border);
  /* keep clear of the iOS home indicator / nav bar */
  padding-bottom: calc(env(safe-area-inset-bottom, 0px));
}

/* ===== SUMMARY ===== */
.summary-table-wrap {
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border);
  margin-bottom: 14px;
}
.summary-header {
  padding: 10px 12px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-muted);
  background: var(--surface-raised);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 6px;
}
.summary-row {
  display: grid;
  align-items: center;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  transition: background var(--transition-fast);
}
.summary-row:last-child { border-bottom: none; }
.summary-row:nth-child(even) { background: var(--surface-hover); }
.summary-cell {
  padding: 10px 12px;
  font-size: 13px;
  color: var(--text-secondary);
}
.summary-cell strong {
  color: var(--text);
  font-weight: 700;
}
.summary-cell-muted {
  color: var(--text-muted);
  font-size: 12px;
}

/* Article table */
.article-table {
  width: 100%;
  border-collapse: collapse;
}
.article-table th {
  padding: 10px;
  font-size: 11px;
  font-weight: 700;
  text-align: center;
  background: #1e3a6e;
  color: #fff;
  border-right: 1px solid #2a4a8a;
}
.article-table th:first-child {
  text-align: left;
  width: 32%;
}
.article-table td {
  padding: 8px 10px;
  text-align: center;
  border-right: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-secondary);
  vertical-align: top;
}
.article-table td:first-child {
  text-align: left;
  font-weight: 700;
  color: var(--text);
}
.article-table tr {
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.article-table tr:nth-child(even) { background: var(--surface-hover); }

/* ===== NETWORK MAP ===== */
.net-shell {
  position: absolute;
  inset: 0;
  z-index: 200;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  animation: fadeIn 0.25s ease;
}
.net-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.net-title {
  font-size: 16px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.2px;
}
.net-subtitle {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
  font-weight: 500;
}
.net-canvas-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
}
.net-canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: default;
}
.net-canvas.pointer { cursor: pointer; }
.net-hint {
  position: absolute;
  bottom: 14px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  pointer-events: none;
  font-weight: 500;
}
.net-panel {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 16px;
  flex-shrink: 0;
  max-height: 46vh;
  overflow-y: auto;
}
.net-panel-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: #f97316;
  margin-bottom: 8px;
}
.net-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 20px;
  border: 1.5px solid #f97316;
  background: rgba(249, 115, 22, 0.08);
  font-size: 12px;
  font-weight: 700;
  color: #f97316;
}
.net-chip button {
  background: none;
  border: none;
  cursor: pointer;
  color: #ef4444;
  font-size: 15px;
  line-height: 1;
  padding: 0 0 0 2px;
  font-family: inherit;
}

/* ===== LINKS ===== */
.link-list {
  overflow-y: auto;
  flex: 1;
  scrollbar-width: none;
}
.link-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  margin-bottom: 6px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  transition: all var(--transition-fast);
}
.link-row:hover {
  background: var(--surface-hover);
  transform: translateX(2px);
}
.link-row.linked {
  background: rgba(249, 115, 22, 0.06);
  border-color: #f97316;
}
.link-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.link-title {
  font-weight: 700;
  font-size: 14px;
  color: var(--text);
  min-width: 70px;
  flex-shrink: 0;
}
.link-sub {
  font-size: 12px;
  color: var(--text-muted);
  flex: 1;
}
.link-toggle {
  font-size: 18px;
  color: var(--text-muted);
  flex-shrink: 0;
}
.link-toggle.linked { color: #f97316; }

/* Linked chips in deck */
.linked-chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  width: 100%;
  max-width: 480px;
}
.linked-chip {
  padding: 6px 12px 6px 14px;
  border-radius: 20px;
  border: 1.5px solid var(--border);
  background: var(--surface-hover);
  display: flex;
  gap: 6px;
  align-items: center;
  min-height: 36px;
  cursor: pointer;
  transition: all var(--transition-fast);
}
.linked-chip:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
  border-color: var(--accent);
}
.linked-chip-text {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}
.linked-chip-sub {
  font-size: 11px;
  color: var(--text-secondary);
}
.linked-chip-remove {
  background: none;
  border: none;
  cursor: pointer;
  color: #ef4444;
  font-size: 16px;
  line-height: 1;
  padding: 0 0 0 3px;
  font-family: inherit;
}

/* ===== NOTES ===== */
.note-preview {
  width: 100%;
  max-width: 480px;
  background: rgba(242, 242, 242, 0.05);
  border: 1.5px solid rgba(242, 242, 242, 0.16);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  cursor: pointer;
  transition: all var(--transition-fast);
  box-sizing: border-box;
}
.note-preview:hover {
  background: rgba(242, 242, 242, 0.09);
  border-color: rgba(242, 242, 242, 0.28);
}
.note-preview-label {
  font-size: 10px;
  color: var(--accent);
  font-weight: 700;
  margin-bottom: 5px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
}
.note-preview-text {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.note-textarea {
  width: 100%;
  min-height: 120px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  color: var(--text);
  font-size: 15px;
  outline: none;
  resize: vertical;
  box-sizing: border-box;
  font-family: inherit;
  line-height: 1.6;
  transition: border-color var(--transition-fast);
}
.note-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(242, 242, 242, 0.08);
}
.note-read {
  width: 100%;
  min-height: 120px;
  max-height: 50vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px;
  font-size: 17px;
  line-height: 1.6;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}
.note-read-empty {
  color: var(--text-muted);
  font-style: italic;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.note-btn {
  padding: 10px 18px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  min-height: 44px;
  font-family: inherit;
  border: 1.5px solid transparent;
}
.note-btn-primary {
  background: var(--accent);
  color: var(--accent-on);
  border-color: var(--accent);
}
.note-btn-cancel {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border);
}
.note-btn-danger {
  background: transparent;
  color: var(--danger, #F0714C);
  border-color: var(--danger, #F0714C);
}

/* ===== EMPTY / ERROR ===== */
.empty-state {
  color: var(--text-muted);
  font-size: 15px;
  text-align: center;
  padding: 48px 0;
  font-weight: 500;
}

/* ===== ANIMATIONS ===== */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(40px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes scaleIn { from { transform: scale(0.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ===== RESPONSIVE ===== */
@media (min-width: 640px) {
  .deck-grid { grid-template-columns: repeat(3, 1fr); gap: 14px; }
  .home-content { padding: 24px; }
  .deck-body { padding: 16px 24px 24px; }
}

@media (min-width: 768px) {
  .deck-grid { grid-template-columns: repeat(4, 1fr); }
}

/* ===== LINKED WORDS (grouped list) ===== */
.link-sheet { max-height: 85vh; display: flex; flex-direction: column; }
.link-groups {
  margin-top: 8px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-right: 2px;
}
.link-empty {
  color: var(--text-muted);
  font-size: 14px;
  text-align: center;
  padding: 32px 16px;
  line-height: 1.5;
}
.link-group {
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  overflow: hidden;
}
.link-group-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  background: var(--surface-hover);
  border-bottom: 1px solid var(--border);
}
.link-group-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.link-group-word {
  font-size: 15px;
  font-weight: 800;
  color: var(--text);
  cursor: pointer;
}
.link-group-word:hover { color: var(--accent); }
.link-group-en {
  font-size: 12px;
  color: var(--text-secondary);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.link-add-btn {
  flex-shrink: 0;
  padding: 5px 12px;
  border-radius: 16px;
  border: 1.5px solid var(--accent);
  background: transparent;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  min-height: 32px;
}
.link-children {
  display: flex;
  flex-direction: column;
}
.link-child {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-subtle);
}
.link-child:last-child { border-bottom: none; }
.link-child-word {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
  flex: 1;
  min-width: 0;
}
.link-child-word:hover { color: var(--accent); }
.link-child-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}
.link-child-en {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.link-unlink {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
}
.link-unlink:hover { color: var(--danger, #F0714C); background: var(--surface-hover); }
.link-add-box { padding: 12px 14px; background: var(--surface-hover); }
.link-add-input {
  width: 100%;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 13px;
  outline: none;
  box-sizing: border-box;
  font-family: inherit;
}
.link-add-input:focus { border-color: var(--accent); }
.link-add-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-top: 8px;
}
.link-add-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  background: var(--surface);
  border: 1.5px solid var(--border);
}
.link-add-item:hover { border-color: var(--accent); }
.link-add-word {
  font-weight: 700;
  font-size: 13px;
  color: var(--text);
  flex-shrink: 0;
}
.link-add-en {
  font-size: 11px;
  color: var(--text-muted);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.link-add-plus {
  font-size: 18px;
  color: var(--accent);
  flex-shrink: 0;
}
