/* ==========================================================================
   CRAM STUDIO - MODERN NEO-MINIMALIST DESIGN SYSTEM
   PURE MONOCHROME & TECHNICAL SLATE | ZERO AI-SLOP PURPLE | HARMONIZED MOBILE ERGONOMICS
   ========================================================================== */

/* ==========================================================================
   THEME TOKENS: PURE BLACK (DARK) & PURE WHITE (LIGHT)
   ========================================================================== */

:root, html.theme-dark, body.theme-dark {
  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Pure Black Dark Theme (#000000) */
  --bg-page: #000000;
  --bg-surface: #000000;
  --bg-surface-elevated: #0F1218;
  --bg-subtle: #171C26;
  
  --border-subtle: #1A202C;
  --border: #283042;
  --border-strong: #3E495F;

  --text-main: #FFFFFF;
  --text-muted: #94A3B8;
  --text-dim: #64748B;
  --text-ipa: #38BDF8;
  --text-meaning: #38BDF8;

  /* Functional Accents */
  --accent-cyan: #38BDF8;
  --accent-amber: #F59E0B;
  --accent-green: #10B981;
  --accent-red: #F43F5E;

  /* Button Functional Tints */
  --btn-again-bg: #1A1215;
  --btn-again-border: #4C1D24;
  --btn-again-text: #F87171;

  --btn-reveal-bg: #11141C;
  --btn-reveal-border: #2E3648;
  --btn-reveal-text: #FFFFFF;

  --btn-good-bg: #0E1A16;
  --btn-good-border: #064E3B;
  --btn-good-text: #34D399;

  /* Tag Tokens */
  --tag-domain-bg: #131720;
  --tag-domain-border: #283042;
  --tag-domain-text: #38BDF8;

  --tag-topic-bg: #131720;
  --tag-topic-border: #1F2430;
  --tag-topic-text: #94A3B8;

  --tag-awl-bg: #1C2B36;
  --tag-awl-border: #2E4B60;
  --tag-awl-text: #7DD3FC;

  --tag-box-bg: #1F1A12;
  --tag-box-border: #453316;
  --tag-box-text: #F59E0B;

  /* Modal Overlay */
  --modal-overlay-bg: rgba(0, 0, 0, 0.75);

  /* Radius System */
  --radius-xs: 6px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-pill: 9999px;

  /* Animations */
  --speed-fast: 120ms;
  --speed-normal: 200ms;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

html.theme-light, body.theme-light {
  /* Pure White Light Theme (#FFFFFF) */
  --bg-page: #FFFFFF;
  --bg-surface: #FFFFFF;
  --bg-surface-elevated: #F8FAFC;
  --bg-subtle: #F1F5F9;
  
  --border-subtle: #E2E8F0;
  --border: #CBD5E1;
  --border-strong: #94A3B8;

  --text-main: #0F172A;
  --text-muted: #334155;
  --text-dim: #64748B;
  --text-ipa: #475569;
  --text-meaning: #0F172A;

  --accent-cyan: #0284C7;
  --accent-amber: #D97706;
  --accent-green: #059669;
  --accent-red: #DC2626;

  --btn-again-bg: #FEF2F2;
  --btn-again-border: #FECACA;
  --btn-again-text: #DC2626;

  --btn-reveal-bg: #F1F5F9;
  --btn-reveal-border: #CBD5E1;
  --btn-reveal-text: #0F172A;

  --btn-good-bg: #ECFDF5;
  --btn-good-border: #A7F3D0;
  --btn-good-text: #059669;

  /* Tag Tokens */
  --tag-domain-bg: #F1F5F9;
  --tag-domain-border: #CBD5E1;
  --tag-domain-text: #0F172A;

  --tag-topic-bg: #F8FAFC;
  --tag-topic-border: #E2E8F0;
  --tag-topic-text: #475569;

  --tag-awl-bg: #ECFDF5;
  --tag-awl-border: #A7F3D0;
  --tag-awl-text: #047857;

  --tag-box-bg: #FEF3C7;
  --tag-box-border: #FDE68A;
  --tag-box-text: #B45309;

  /* Modal Overlay */
  --modal-overlay-bg: rgba(15, 23, 42, 0.45);
}

/* ==========================================================================
   RESET & BASE & SLEEK SCROLLBAR
   ========================================================================== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  scrollbar-width: thin;
  scrollbar-color: rgba(148, 163, 184, 0.3) transparent;
}

/* Custom Sleek Ultra-Thin Minimalist Scrollbar */
::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.25);
  border-radius: var(--radius-pill);
  transition: background-color var(--speed-fast) var(--ease);
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(148, 163, 184, 0.5);
}

body.theme-dark ::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
}

body.theme-dark ::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.4);
}

body.theme-light ::-webkit-scrollbar-thumb {
  background: rgba(15, 23, 42, 0.18);
}

body.theme-light ::-webkit-scrollbar-thumb:hover {
  background: rgba(15, 23, 42, 0.35);
}

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  background-color: var(--bg-page);
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ==========================================================================
   ICON SYSTEM
   ========================================================================== */
.ui-icon {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  flex-shrink: 0;
  display: inline-block;
  vertical-align: middle;
}

.ui-icon.sm {
  width: 14px;
  height: 14px;
}

.flame-icon {
  color: #F97316;
  width: 14px;
  height: 14px;
}

.star-svg-icon {
  width: 20px;
  height: 20px;
  stroke: #64748B !important;
  fill: transparent !important;
  stroke-width: 2px !important;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: all var(--speed-fast) var(--ease);
}

.star-btn:hover .star-svg-icon {
  stroke: #94A3B8 !important;
}

.star-btn.starred .star-svg-icon {
  stroke: #F59E0B !important;
  fill: #FBBF24 !important;
}

/* ==========================================================================
   APP CONTAINER (MOBILE-FIRST FLEX LAYOUT)
   ========================================================================== */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: max(env(safe-area-inset-top, 0px), 12px) 16px max(env(safe-area-inset-bottom, 0px), 14px) 16px;
  position: relative;
  gap: 10px;
}

/* ==========================================================================
   APP HEADER (CLEAN 2-ROW HARMONIZED LAYOUT)
   ========================================================================== */
.app-header {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 2px;
  flex-shrink: 0;
  position: relative;
  z-index: 2;
}

/* Row 1: Brand & Deck Selection + Top Actions */
.header-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.brand-container {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.brand-logo {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--speed-fast) var(--ease);
}

.brand-logo:hover {
  transform: scale(1.05);
}

.brand-icon-svg {
  width: 32px;
  height: 32px;
  display: block;
}

.brand-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  min-width: 0;
}

.brand-title {
  font-family: var(--font-sans);
  font-size: 1.08rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text-main);
  line-height: 1.15;
}

.deck-selector-pill {
  background: transparent;
  border: none;
  padding: 0;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.72rem;
  font-weight: 600;
  max-width: 170px;
  transition: color var(--speed-fast) var(--ease);
}

.deck-selector-pill:hover,
.deck-selector-pill:active {
  color: var(--accent-cyan);
}

.deck-name-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chevron-icon {
  font-size: 0.65rem;
  color: var(--text-dim);
  transition: transform var(--speed-fast) var(--ease);
}

.deck-selector-pill:hover .chevron-icon {
  color: var(--accent-cyan);
  transform: translateY(1px);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.action-icon-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-pill);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--speed-fast) var(--ease);
}

.action-icon-btn:active {
  color: var(--text-main);
  background: var(--bg-surface-elevated);
  transform: scale(0.92);
}

/* Row 2: Mode Switcher + Daily Counter */
.header-sub-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.mode-segmented {
  display: flex;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 2px;
  gap: 2px;
}

.mode-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 0.78rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: all var(--speed-fast) var(--ease);
}

.mode-btn.active {
  background: var(--text-main);
  color: var(--bg-page);
}

.badge {
  background: var(--accent-amber);
  color: #000000;
  font-size: 0.65rem;
  font-weight: 800;
  padding: 1px 5px;
  border-radius: var(--radius-pill);
}

.daily-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
}

.streak-pill {
  display: flex;
  align-items: center;
  gap: 3px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  padding: 2px 7px;
  border-radius: var(--radius-pill);
}

.counter-text b {
  color: var(--text-main);
}

/* Hairline Progress */
.progress-track {
  height: 3px;
  background: var(--bg-surface);
  border-radius: var(--radius-pill);
  overflow: hidden;
  margin-top: 2px;
}

.progress-fill {
  height: 100%;
  background: var(--text-main);
  border-radius: var(--radius-pill);
  transition: width 220ms var(--ease);
}

/* ==========================================================================
   FLASHCARD STAGE & CARD (BUTTERY SMOOTH 120HZ PHYSICS)
   ========================================================================== */
.card-stage {
  flex: 1;
  display: flex;
  align-items: stretch;
  justify-content: center;
  position: relative;
  overflow: visible;
  perspective: 1200px;
  min-height: 0; /* Crucial for internal scroll */
  z-index: 10;
}

.flashcard-container {
  width: 100%;
  height: 100%;
  position: relative;
  display: flex;
  transform-style: preserve-3d;
  z-index: 10;
}

.flashcard {
  width: 100%;
  height: 100%;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden; /* Clips all children and scrollbar within rounded border */
  cursor: grab;
  position: relative;
  z-index: 10;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
  will-change: transform, opacity;
  transform-origin: 50% 100%;
}

.flashcard-scroll {
  width: 100%;
  height: 100%;
  padding: 16px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  -ms-overflow-style: none; /* IE and Edge */
  scrollbar-width: none; /* Firefox */
}

/* Hide scrollbar completely across Chrome, Safari, and WebKit */
.flashcard-scroll::-webkit-scrollbar,
.flashcard::-webkit-scrollbar {
  display: none !important;
  width: 0 !important;
  height: 0 !important;
  background: transparent !important;
}

.flashcard.dragging {
  cursor: grabbing;
  user-select: none;
  z-index: 25;
}

/* Card Header Meta Tags */
.card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  flex-shrink: 0;
}

.meta-tags {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}

.tag {
  font-size: 0.68rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: var(--radius-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Clean protection for empty badges & unrendered card elements */
.tag:empty,
.pos-badge:empty,
.word-ipa:empty,
.forms-text:empty {
  display: none !important;
}

/* ==========================================================================
   CARD SKELETON LOADING
   ========================================================================== */
.card-skeleton {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-surface) !important;
  border-radius: var(--radius-lg);
  padding: 18px;
  display: flex;
  flex-direction: column;
  z-index: 50;
  opacity: 1;
  transition: opacity 0.22s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.22s ease;
  pointer-events: none;
}

.card-skeleton.hidden {
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

@keyframes skeleton-pulse {
  0% {
    background-position: -200% 0;
  }
  100% {
    background-position: 200% 0;
  }
}

.skel-item {
  background: linear-gradient(90deg, var(--bg-subtle) 20%, var(--border) 50%, var(--bg-subtle) 80%);
  background-size: 200% 100%;
  animation: skeleton-pulse 1.4s infinite ease-in-out;
  border-radius: var(--radius-xs);
}

body.theme-light .skel-item {
  background: linear-gradient(90deg, #E2E8F0 20%, #F8FAFC 50%, #E2E8F0 80%);
  background-size: 200% 100%;
}

.skel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
}

.skel-tags {
  display: flex;
  gap: 8px;
}

.skel-tag-1 {
  width: 76px;
  height: 22px;
  border-radius: var(--radius-xs);
}

.skel-tag-2 {
  width: 96px;
  height: 22px;
  border-radius: var(--radius-xs);
}

.skel-box {
  width: 50px;
  height: 22px;
  border-radius: var(--radius-xs);
}

.skel-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.skel-word {
  width: 65%;
  height: 40px;
  border-radius: 8px;
  margin-bottom: 4px;
}

.skel-ipa-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.skel-ipa {
  width: 120px;
  height: 22px;
  border-radius: 6px;
}

.skel-speak {
  width: 28px;
  height: 28px;
  border-radius: 50%;
}

.skel-pos {
  width: 44px;
  height: 22px;
  border-radius: 6px;
}

.skel-hint {
  width: 100%;
  height: 48px;
  border-radius: var(--radius-md);
  margin-top: 18px;
}

.skel-content-box {
  margin-top: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.skel-label {
  width: 65px;
  height: 14px;
  border-radius: 4px;
}

.skel-line-full {
  width: 92%;
  height: 16px;
  border-radius: 6px;
}

.skel-line-half {
  width: 65%;
  height: 16px;
  border-radius: 6px;
}

.domain-tag {
  background: var(--tag-domain-bg);
  border: 1px solid var(--tag-domain-border);
  color: var(--tag-domain-text);
}

.topic-tag {
  background: var(--tag-topic-bg);
  border: 1px solid var(--tag-topic-border);
  color: var(--tag-topic-text);
}

.awl-tag {
  background: var(--tag-awl-bg);
  border: 1px solid var(--tag-awl-border);
  color: var(--tag-awl-text);
}

.meta-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.box-tag {
  background: var(--tag-box-bg);
  border: 1px solid var(--tag-box-border);
  color: var(--tag-box-text);
  font-family: var(--font-mono);
}

.star-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Front Recognition Content */
.card-front {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  padding: 4px 0;
}

.word-header {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.word-title {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text-main);
  line-height: 1.15;
}

.pronunciation-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.word-ipa {
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 500;
  letter-spacing: -0.01em;
  color: var(--text-ipa);
}

.speak-btn {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border);
  color: var(--text-main);
  width: 28px;
  height: 28px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  display: inline-flex !important;
  visibility: visible !important;
  opacity: 1 !important;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  transition: all var(--speed-fast) var(--ease);
}

.speak-btn:active {
  transform: scale(0.92);
}

.speak-btn.playing {
  border-color: var(--accent-cyan);
  background: var(--bg-subtle);
  color: var(--accent-cyan);
  animation: pulseAudio 0.8s ease-in-out infinite;
}

@keyframes pulseAudio {
  0% { transform: scale(1); }
  50% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

.pos-badge {
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: var(--radius-xs);
  font-family: var(--font-mono);
}

.forms-text {
  font-size: 0.8rem;
  color: var(--text-dim);
  font-style: italic;
}

.flip-hint {
  margin-top: 20px;
  padding: 10px;
  background: var(--bg-surface-elevated);
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.hint-icon {
  display: inline-flex;
  opacity: 0.7;
}

/* Device-Aware Contextual Hints (Mobile / Touch vs Desktop / Keyboard) */
.hint-touch {
  display: none;
}

.hint-desktop {
  display: inline-block;
}

@media (hover: none) and (pointer: coarse) {
  .hint-touch {
    display: inline-block;
  }
  .hint-desktop {
    display: none;
  }
}

body.touch-device .hint-touch {
  display: inline-block;
}

body.touch-device .hint-desktop {
  display: none;
}

/* Back Revealed Content */
.card-back {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border-subtle);
  animation: fadeIn 140ms var(--ease);
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.section-label {
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin-bottom: 3px;
}

.meaning-box {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
}

.vn-meaning {
  font-size: 1.22rem;
  font-weight: 800;
  color: var(--text-meaning);
  line-height: 1.35;
}

.definition-box {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
}

.en-definition {
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.examples-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.example-item {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ex-en {
  font-size: 0.85rem;
  color: var(--text-main);
  line-height: 1.4;
}

.ex-en b {
  color: var(--accent-amber);
  font-weight: 700;
}

.ex-vn {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.35;
}

.ex-vn b {
  color: var(--text-main);
  font-weight: 700;
}

.chips-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 2px;
}

.chip-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chip-label {
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--text-dim);
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.chip {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  padding: 3px 8px;
  border-radius: var(--radius-xs);
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* ==========================================================================
   BOTTOM ACTION BAR (HARMONIOUS ERGONOMIC THUMB ZONE)
   ========================================================================== */
.bottom-controls {
  display: grid;
  grid-template-columns: 1fr 1.15fr 1fr;
  gap: 8px;
  padding: 2px 0;
  flex-shrink: 0;
  position: relative;
  z-index: 2;
}

.action-btn {
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  padding: 9px 6px;
  min-height: 52px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  transition: transform var(--speed-fast) var(--ease), opacity var(--speed-fast) var(--ease);
}

.btn-title-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

.btn-title {
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 800;
}

.btn-sub {
  font-size: 0.62rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  opacity: 0.7;
}

.btn-interval {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 700;
  margin-top: 1px;
}

.btn-again {
  background: var(--btn-again-bg);
  border-color: var(--btn-again-border);
  color: var(--btn-again-text);
}

.btn-reveal {
  background: var(--btn-reveal-bg);
  border-color: var(--btn-reveal-border);
  color: var(--btn-reveal-text);
}

.btn-good {
  background: var(--btn-good-bg);
  border-color: var(--btn-good-border);
  color: var(--btn-good-text);
}

.action-btn:active {
  transform: scale(0.95);
}

/* ==========================================================================
   MODALS & BOTTOM SHEETS
   ========================================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--modal-overlay-bg);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  transition: opacity var(--speed-normal) var(--ease);
}

.modal-sheet {
  width: 100%;
  max-width: 480px;
  max-height: 80vh;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 16px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slideUp 200ms var(--ease);
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  flex-shrink: 0;
}

.modal-title-row {
  display: flex;
  align-items: center;
  gap: 7px;
}

.modal-header h2 {
  font-size: 1.1rem;
  font-weight: 800;
}

.close-btn {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border);
  color: var(--text-main);
  width: 28px;
  height: 28px;
  border-radius: var(--radius-pill);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.close-btn:active {
  transform: scale(0.92);
}

.modal-body {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-bottom: 20px;
}

/* Deck Cards */
.deck-select-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-main);
  cursor: pointer;
  text-align: left;
  transition: all var(--speed-fast) var(--ease);
}

.deck-select-card.active {
  border-color: var(--text-main);
  background: var(--bg-subtle);
}

.deck-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 6px;
}

.deck-card-title-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.deck-title {
  font-size: 0.92rem;
  font-weight: 800;
  color: var(--text-main);
}

.deck-subtitle {
  font-size: 0.74rem;
  color: var(--text-muted);
}

.deck-card-footer {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.72rem;
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-weight: 600;
}

.modal-section-title {
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin-top: 10px;
  margin-bottom: 2px;
}

.topic-select-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-main);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
}

.topic-item-left {
  display: flex;
  align-items: center;
  gap: 7px;
}

.sub-arrow {
  color: var(--text-dim);
  font-family: var(--font-mono);
}

.topic-select-item.active {
  border-color: var(--text-main);
  background: var(--bg-subtle);
}

.topic-select-item .count {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.stat-card {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px;
  text-align: center;
}

.stat-num {
  font-family: var(--font-mono);
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--accent-cyan);
}

.stat-lbl {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 600;
}

/* Box Bars */
.box-progress-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.box-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
}

.box-name {
  width: 120px;
  color: var(--text-muted);
}

.box-bar-bg {
  flex: 1;
  height: 6px;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  overflow: hidden;
}

.box-bar-fill {
  height: 100%;
  border-radius: var(--radius-pill);
}

.box-bar-fill.box-1 { background: var(--accent-red); }
.box-bar-fill.box-2 { background: var(--accent-amber); }
.box-bar-fill.box-3 { background: var(--accent-cyan); }
.box-bar-fill.box-4 { background: #60A5FA; }
.box-bar-fill.box-5 { background: var(--accent-green); }

.box-count {
  width: 30px;
  text-align: right;
  font-family: var(--font-mono);
  font-weight: 700;
}

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

.backup-btn {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-main);
  padding: 8px;
  font-size: 0.8rem;
  font-weight: 700;
  text-align: center;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

/* Settings Items */
.setting-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.setting-title {
  font-size: 0.85rem;
  font-weight: 700;
}

.setting-desc {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.setting-select {
  -webkit-appearance: none;
  appearance: none;
  background-color: var(--bg-surface-elevated);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2394A3B8' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 6px 32px 6px 12px;
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  outline: none;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  transition: border-color var(--speed-fast) var(--ease), box-shadow var(--speed-fast) var(--ease);
}

.setting-select:focus {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.15);
}

.setting-select option {
  background-color: var(--bg-surface-elevated);
  color: var(--text-main);
}

/* Modern iOS-Style Toggle Switch */
.setting-toggle {
  -webkit-appearance: none;
  appearance: none;
  width: 44px;
  height: 24px;
  background: var(--border-strong);
  border-radius: var(--radius-pill);
  position: relative;
  cursor: pointer;
  outline: none;
  transition: background-color 200ms cubic-bezier(0.4, 0, 0.2, 1), border-color 200ms ease;
  flex-shrink: 0;
  border: 1px solid var(--border);
  display: inline-block;
  vertical-align: middle;
}

.setting-toggle::before {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #FFFFFF;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: transform 200ms cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.setting-toggle:checked {
  background: var(--accent-cyan);
  border-color: var(--accent-cyan);
}

.setting-toggle:checked::before {
  transform: translateX(20px);
}

.hidden {
  display: none !important;
}

/* ==========================================================================
   CLOUD SYNC UI
   ========================================================================== */
.sync-status-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.sync-status-indicator {
  width: 12px;
  height: 12px;
  border-radius: var(--radius-pill);
  background: #64748B;
  flex-shrink: 0;
  transition: all var(--speed-normal) var(--ease);
}

.sync-status-indicator.connected {
  background: #10B981;
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.5);
}

.sync-status-indicator.waiting {
  background: #F59E0B;
  box-shadow: 0 0 8px rgba(245, 158, 11, 0.5);
}

.sync-status-indicator.syncing {
  background: #38BDF8;
  animation: pulseAudio 0.8s ease-in-out infinite;
}

.sync-status-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sync-status-title {
  font-size: 0.9rem;
  font-weight: 800;
  color: var(--text-main);
}

.sync-status-sub {
  font-size: 0.74rem;
  color: var(--text-muted);
}

.sync-form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 4px;
}

.sync-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

.sync-label-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sync-text-btn {
  background: none;
  border: none;
  color: var(--accent-cyan);
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  padding: 0;
  transition: opacity var(--speed-fast) var(--ease);
}

.sync-text-btn:hover {
  text-decoration: underline;
}

.sync-text-btn.copied {
  color: var(--status-good);
}

.sync-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.sync-text-input {
  width: 100%;
  padding: 10px 42px 10px 12px;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 600;
  outline: none;
  transition: border-color var(--speed-fast) var(--ease);
}

.sync-text-input:focus {
  border-color: var(--text-main);
}

.sync-copy-icon-btn {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 32px;
  height: 32px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--speed-fast) var(--ease);
}

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

.sync-copy-icon-btn.copied {
  color: var(--status-good);
}

.sync-btn-group {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.sync-action-btn {
  flex: 1;
  padding: 10px;
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 800;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--speed-fast) var(--ease);
}

.sync-action-btn:active {
  transform: scale(0.96);
}

.sync-action-btn.primary {
  background: var(--text-main);
  color: var(--bg-page);
  border-color: var(--text-main);
}

.sync-action-btn.secondary {
  background: var(--bg-surface-elevated);
  color: var(--text-main);
  border-color: var(--border);
}

.sync-action-btn.danger {
  background: var(--btn-again-bg);
  color: var(--btn-again-text);
  border-color: var(--btn-again-border);
}

.sync-devices-container {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px 12px;
}

.sync-devices-header {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.sync-device-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--text-main);
  padding: 3px 0;
}

.sync-device-name {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
}

.sync-device-tag {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: var(--radius-pill);
  background: var(--border);
  color: var(--text-muted);
}

.sync-device-tag.this-device {
  background: rgba(56, 189, 248, 0.15);
  color: var(--accent-cyan);
}

.sync-help-box {
  background: var(--bg-surface-elevated);
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  font-size: 0.75rem;
  line-height: 1.45;
  color: var(--text-muted);
}

.sync-help-box code {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--text-main);
  background: var(--bg-surface);
  padding: 1px 4px;
  border-radius: 4px;
}

/* ==========================================================================
   DEDICATED COMPLETION CARD (INBOX ZERO & GOAL REACHED)
   ========================================================================== */
.completion-card {
  width: 100%;
  height: 100%;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  position: relative;
  z-index: 10;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
  animation: fadeIn 200ms var(--ease);
  overflow-y: auto;
}

.completion-badge-wrap {
  margin-bottom: 14px;
}

.completion-icon-badge {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border);
  color: var(--accent-cyan);
  display: flex;
  align-items: center;
  justify-content: center;
}

.completion-icon-badge svg {
  width: 26px;
  height: 26px;
}

.completion-title {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--text-main);
  letter-spacing: -0.02em;
  margin-bottom: 6px;
}

.completion-subtitle {
  font-size: 0.84rem;
  color: var(--text-muted);
  line-height: 1.45;
  max-width: 320px;
  margin-bottom: 18px;
}

.completion-stats-box {
  display: flex;
  align-items: center;
  justify-content: space-around;
  width: 100%;
  max-width: 340px;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 8px;
  margin-bottom: 20px;
}

.comp-stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  flex: 1;
}

.comp-stat-val {
  font-family: var(--font-sans);
  font-size: 1.12rem;
  font-weight: 800;
  color: var(--text-main);
}

.comp-stat-lbl {
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.comp-stat-divider {
  width: 1px;
  height: 24px;
  background: var(--border-subtle);
}

.completion-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 320px;
}

.comp-action-btn {
  width: 100%;
  padding: 11px 16px;
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: 0.88rem;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all var(--speed-fast) var(--ease);
  border: 1px solid transparent;
}

.comp-action-btn.primary {
  background: var(--text-main);
  color: var(--bg-page);
}

.comp-action-btn.primary:active {
  transform: scale(0.97);
  opacity: 0.9;
}

.comp-action-btn.secondary {
  background: var(--bg-surface-elevated);
  border-color: var(--border);
  color: var(--text-main);
}

.comp-action-btn.secondary:active {
  transform: scale(0.97);
  background: var(--bg-subtle);
}

/* ==========================================================================
   CUSTOM SLEEK DROPDOWN (ZERO NATIVE OS SELECT)
   ========================================================================== */
.custom-select {
  position: relative;
  display: inline-block;
  width: 100%;
  max-width: 200px;
}

.custom-select-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background-color: var(--bg-surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  outline: none;
  transition: border-color var(--speed-fast) var(--ease), box-shadow var(--speed-fast) var(--ease);
}

.custom-select-trigger:focus,
.custom-select.open .custom-select-trigger {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.15);
}

.custom-select-arrow {
  font-size: 0.65rem;
  color: var(--text-dim);
  transition: transform var(--speed-fast) var(--ease);
}

.custom-select.open .custom-select-arrow {
  transform: rotate(180deg);
  color: var(--accent-cyan);
}

.custom-select-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  left: 0;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 4px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  z-index: 150;
  display: none;
  flex-direction: column;
  gap: 2px;
  animation: fadeIn 120ms var(--ease);
}

.custom-select.open .custom-select-dropdown {
  display: flex;
}

.custom-select-option {
  padding: 7px 10px;
  border-radius: var(--radius-xs);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: all var(--speed-fast) var(--ease);
}

.custom-select-option:hover {
  background: var(--bg-subtle);
  color: var(--text-main);
}

.custom-select-option.selected {
  background: rgba(56, 189, 248, 0.12);
  color: var(--accent-cyan);
  font-weight: 700;
}

.custom-select-option.selected::after {
  content: '✓';
  font-size: 0.8rem;
  font-weight: 900;
}
