/* ==========================================================================
   VOCAB LAB — DESIGN SYSTEM & STYLESHEET
   Aesthetic Dark-Theme, Academic & Productivity Focus
   ========================================================================== */

:root {
  /* Color Palette - Deep Slate Dark Theme */
  --bg-base: #08090d;
  --bg-surface: #0f1219;
  --bg-surface-raised: #151923;
  --bg-surface-elevated: #1c2230;
  --bg-input: #121620;
  --bg-hover: #1f2536;

  /* Accent Colors */
  --accent-primary: #6366f1; /* Indigo */
  --accent-primary-hover: #4f46e5;
  --accent-primary-glow: rgba(99, 102, 241, 0.25);
  --accent-secondary: #06b6d4; /* Cyan */
  --accent-secondary-glow: rgba(6, 182, 212, 0.2);

  /* Category Badges & Tints */
  --cat-synonym: #10b981;
  --cat-synonym-bg: rgba(16, 185, 129, 0.12);
  --cat-synonym-border: rgba(16, 185, 129, 0.28);

  --cat-antonym: #f59e0b;
  --cat-antonym-bg: rgba(245, 158, 11, 0.12);
  --cat-antonym-border: rgba(245, 158, 11, 0.28);

  --cat-ows: #a855f7;
  --cat-ows-bg: rgba(168, 85, 247, 0.12);
  --cat-ows-border: rgba(168, 85, 247, 0.28);

  --cat-syno-anto: #0ea5e9;
  --cat-syno-anto-bg: rgba(14, 165, 233, 0.12);
  --cat-syno-anto-border: rgba(14, 165, 233, 0.28);

  --cat-idiom: #f43f5e;
  --cat-idiom-bg: rgba(244, 63, 94, 0.12);
  --cat-idiom-border: rgba(244, 63, 94, 0.28);

  /* Text & Border Tokens */
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --text-highlight: #ffffff;
  
  --border-subtle: rgba(255, 255, 255, 0.07);
  --border-medium: rgba(255, 255, 255, 0.12);
  --border-active: rgba(99, 102, 241, 0.5);

  --danger-bg: rgba(239, 68, 68, 0.12);
  --danger-border: rgba(239, 68, 68, 0.3);
  --danger-text: #f87171;

  --success-bg: rgba(16, 185, 129, 0.12);
  --success-border: rgba(16, 185, 129, 0.3);
  --success-text: #34d399;

  /* Typography */
  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', Menlo, monospace;

  /* Spacing & Radii */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.6);
  --shadow-glow: 0 0 24px var(--accent-primary-glow);

  /* Transitions */
  --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-smooth: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ==========================================================================
   RESET & BASE STYLES
   ========================================================================== */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  color-scheme: dark;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-base);
  color: var(--text-main);
  line-height: 1.6;
  min-height: 100vh;
  min-height: 100dvh;
  position: relative;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
}

button, input, textarea, select {
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: var(--bg-base);
}
::-webkit-scrollbar-thumb {
  background: var(--bg-surface-elevated);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-dim);
}

/* Ambient Background Lights */
.bg-glow {
  position: fixed;
  border-radius: 50%;
  pointer-events: none;
  filter: blur(140px);
  z-index: 0;
  opacity: 0.35;
}

.bg-glow-1 {
  width: min(500px, 80vw);
  height: min(500px, 80vw);
  background: radial-gradient(circle, #4338ca 0%, transparent 70%);
  top: -100px;
  left: 5%;
}

.bg-glow-2 {
  width: min(450px, 80vw);
  height: min(450px, 80vw);
  background: radial-gradient(circle, #0e7490 0%, transparent 70%);
  top: 400px;
  right: 5%;
}

.app-container {
  position: relative;
  z-index: 1;
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1.25rem calc(3.5rem + env(safe-area-inset-bottom, 0px));
}

/* ==========================================================================
   HEADER
   ========================================================================== */

.app-header {
  margin-bottom: 2.5rem;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 1.5rem;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 2rem;
}

.brand-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.brand-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  padding: 0.25rem 0.75rem;
  border-radius: var(--radius-full);
  width: fit-content;
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--accent-secondary);
  box-shadow: 0 0 8px var(--accent-secondary);
  animation: pulse 2s infinite ease-in-out;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 0.8; }
  50% { transform: scale(1.3); opacity: 1; }
}

.brand-title {
  font-size: 2.25rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text-highlight);
  background: linear-gradient(135deg, #ffffff 40%, #a5b4fc 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-subtitle {
  font-size: 1rem;
  color: var(--text-muted);
  font-weight: 400;
}

.header-stats {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
}

.stat-pill {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--text-muted);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  padding: 0.5rem 1rem;
  border-radius: var(--radius-md);
}

.stat-pill strong {
  color: var(--text-main);
  font-weight: 600;
}

.stat-pill.highlight {
  border-color: rgba(99, 102, 241, 0.35);
  background: rgba(99, 102, 241, 0.08);
}

.stat-pill.highlight strong {
  color: #a5b4fc;
}

/* ==========================================================================
   MAIN CONTROL CARD
   ========================================================================== */

.control-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  padding: 2rem;
  box-shadow: var(--shadow-md);
  backdrop-filter: blur(16px);
  margin-bottom: 2.5rem;
  transition: border-color var(--transition-smooth);
}

.control-card:hover {
  border-color: var(--border-medium);
}

.control-section {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

.section-title-group {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
}

.step-num {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--accent-primary);
  background: rgba(99, 102, 241, 0.12);
  border: 1px solid rgba(99, 102, 241, 0.3);
  padding: 0.25rem 0.55rem;
  border-radius: var(--radius-sm);
  margin-top: 0.15rem;
}

.section-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-highlight);
  letter-spacing: -0.01em;
}

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

.quick-selection-actions {
  display: flex;
  gap: 0.5rem;
}

.btn-ghost-sm, .btn-ghost-xs {
  font-family: var(--font-sans);
  background: transparent;
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-ghost-sm {
  font-size: 0.8rem;
  padding: 0.4rem 0.8rem;
}

.btn-ghost-xs {
  font-size: 0.75rem;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-sm);
}

.btn-ghost-sm:hover, .btn-ghost-xs:hover {
  color: var(--text-main);
  background: var(--bg-hover);
  border-color: var(--border-medium);
}

/* Categories Grid */
.categories-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 0.75rem;
}

.category-card {
  position: relative;
  cursor: pointer;
  user-select: none;
}

.category-card input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.card-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-surface-raised);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
  min-height: 54px;
  position: relative;
  transition: all var(--transition-smooth);
}

.category-card:hover .card-inner {
  background: var(--bg-hover);
  border-color: var(--border-medium);
  transform: translateY(-2px);
}

.card-info {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
  padding-right: 0.5rem;
}

.cat-tag {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius-sm);
  text-transform: uppercase;
}

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

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

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

.tag-syno-anto {
  color: var(--cat-syno-anto);
  background: var(--cat-syno-anto-bg);
  border: 1px solid var(--cat-syno-anto-border);
}

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

.cat-count {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: var(--text-dim);
}

.checkbox-indicator {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border-medium);
  background: var(--bg-surface);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.checkbox-indicator svg {
  width: 14px;
  height: 14px;
  stroke: #ffffff;
  stroke-width: 3;
  opacity: 0;
  transform: scale(0.6);
  transition: all var(--transition-fast);
}

/* Checked State */
.category-card input[type="checkbox"]:checked + .card-inner {
  border-color: var(--accent-primary);
  background: rgba(99, 102, 241, 0.07);
  box-shadow: inset 0 0 0 1px rgba(99, 102, 241, 0.4);
}

.category-card input[type="checkbox"]:checked + .card-inner .checkbox-indicator {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
}

.category-card input[type="checkbox"]:checked + .card-inner .checkbox-indicator svg {
  opacity: 1;
  transform: scale(1);
}

.category-card input[type="checkbox"]:focus-visible + .card-inner {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

.divider {
  border: none;
  border-top: 1px solid var(--border-subtle);
  margin: 2rem 0;
}

/* Distribution Grid */
.distribution-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
}

@media (max-width: 860px) {
  .distribution-grid {
    grid-template-columns: 1fr;
  }
}

.qty-control-box, .mode-control-box {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.qty-pill-group, .mode-switch-group {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.qty-pill, .mode-pill {
  font-family: var(--font-sans);
  font-size: 0.88rem;
  font-weight: 600;
  padding: 0.65rem 1.15rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface-raised);
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  transition: all var(--transition-fast);
}

.qty-pill svg, .mode-pill svg {
  width: 16px;
  height: 16px;
}

.qty-pill:hover, .mode-pill:hover {
  background: var(--bg-hover);
  color: var(--text-main);
  border-color: var(--border-medium);
}

.qty-pill.active, .mode-pill.active {
  background: var(--accent-primary);
  color: #ffffff;
  border-color: var(--accent-primary);
  box-shadow: 0 0 14px var(--accent-primary-glow);
}

.custom-qty-wrapper {
  background: var(--bg-surface-raised);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.9rem 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.25rem;
  animation: fadeIn 0.2s ease-out;
}

.input-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.input-with-stepper {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.stepper-btn {
  width: 38px;
  height: 38px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.stepper-btn:hover {
  background: var(--bg-hover);
  border-color: var(--border-medium);
}

.input-with-stepper input[type="number"] {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-highlight);
  font-family: var(--font-mono);
  font-size: 1.1rem;
  font-weight: 600;
  padding: 0.45rem 0.8rem;
  text-align: center;
  outline: none;
  transition: border-color var(--transition-fast);
}

.input-with-stepper input[type="number"]:focus {
  border-color: var(--accent-primary);
}

.helper-text {
  font-size: 0.78rem;
  color: var(--text-dim);
  font-family: var(--font-mono);
}

/* Custom Distribution Panel */
.custom-dist-container {
  background: var(--bg-surface-raised);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1rem 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  animation: fadeIn 0.2s ease-out;
}

.dist-header-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-size: 0.82rem;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 0.5rem;
}

.dist-sum-status {
  font-family: var(--font-mono);
  font-weight: 600;
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
}

.dist-sum-status.valid {
  color: var(--success-text);
  border-color: var(--success-border);
  background: var(--success-bg);
}

.dist-sum-status.invalid {
  color: var(--danger-text);
  border-color: var(--danger-border);
  background: var(--danger-bg);
}

.custom-dist-inputs {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  max-height: 220px;
  overflow-y: auto;
  padding-right: 0.25rem;
}

.dist-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.8rem;
}

.dist-row-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  font-weight: 500;
}

.dist-row-input {
  width: 70px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-highlight);
  font-family: var(--font-mono);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.25rem 0.5rem;
  text-align: right;
  outline: none;
}

.dist-row-input:focus {
  border-color: var(--accent-primary);
}

.dist-warning-msg {
  font-size: 0.8rem;
  color: var(--danger-text);
  background: var(--danger-bg);
  border: 1px solid var(--danger-border);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
}

/* Alert Notification */
.validation-alert {
  margin-top: 1.5rem;
  padding: 0.85rem 1.2rem;
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  animation: shake 0.3s ease-in-out;
}

.validation-alert.error {
  background: var(--danger-bg);
  border: 1px solid var(--danger-border);
  color: var(--danger-text);
}

.validation-alert.warning {
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.3);
  color: #fbbf24;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

/* Action Footer & Big Button */
.action-footer {
  margin-top: 2rem;
  display: flex;
  justify-content: center;
}

.primary-btn-wrapper {
  width: 100%;
  max-width: 500px;
}

.btn-primary-glow {
  width: 100%;
  font-family: var(--font-sans);
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: #ffffff;
  background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-lg);
  padding: 1.1rem 1.75rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  box-shadow: 0 4px 20px var(--accent-primary-glow), 0 2px 6px rgba(0, 0, 0, 0.4);
  transition: all var(--transition-smooth);
  position: relative;
  overflow: hidden;
}

.btn-primary-glow:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 28px rgba(99, 102, 241, 0.4), 0 2px 8px rgba(0, 0, 0, 0.5);
  background: linear-gradient(135deg, #6d70f7 0%, #5850ec 100%);
}

.btn-primary-glow:active {
  transform: translateY(0);
}

.btn-icon {
  font-size: 1.2rem;
}

.kbd-shortcut {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 500;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.2);
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-sm);
  color: rgba(255, 255, 255, 0.85);
  margin-left: auto;
}

/* ==========================================================================
   RESULTS SECTION
   ========================================================================== */

.results-container {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.results-header-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  padding: 1.5rem 1.75rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1.25rem;
  box-shadow: var(--shadow-sm);
}

.results-title {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text-highlight);
}

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

.results-actions-group {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  align-items: center;
}

.btn-action {
  font-family: var(--font-sans);
  font-size: 0.84rem;
  font-weight: 600;
  padding: 0.55rem 1rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface-raised);
  color: var(--text-main);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  transition: all var(--transition-fast);
}

.btn-action svg {
  width: 15px;
  height: 15px;
}

.btn-action:hover {
  background: var(--bg-hover);
  border-color: var(--border-medium);
  transform: translateY(-1px);
}

.btn-copy-all {
  background: rgba(99, 102, 241, 0.15);
  border-color: rgba(99, 102, 241, 0.4);
  color: #c7d2fe;
}

.btn-copy-all:hover {
  background: var(--accent-primary);
  color: #ffffff;
  border-color: var(--accent-primary);
}

.btn-copy-selected {
  background: rgba(6, 182, 212, 0.15);
  border-color: rgba(6, 182, 212, 0.4);
  color: #a5f3fc;
}

.btn-copy-selected:hover {
  background: var(--accent-secondary);
  color: #08090d;
  border-color: var(--accent-secondary);
}

.btn-regenerate:hover .spin-icon {
  animation: rotateIcon 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes rotateIcon {
  100% { transform: rotate(360deg); }
}

.btn-clear:hover {
  background: var(--danger-bg);
  border-color: var(--danger-border);
  color: var(--danger-text);
}

/* Statistics Summary Bar */
.stats-summary-bar {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 0.85rem 1.25rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.82rem;
}

.stats-breakdown {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.stat-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-sm);
  background: var(--bg-surface-raised);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
}

.stat-badge strong {
  color: var(--text-highlight);
  font-weight: 600;
}

.stat-badge.stat-total {
  background: rgba(99, 102, 241, 0.12);
  border-color: rgba(99, 102, 241, 0.35);
  color: #a5b4fc;
}

.stats-filter-status {
  color: var(--text-dim);
}

/* Filter & Search Toolbar */
.filter-toolbar {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 0.9rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.search-input-wrapper {
  position: relative;
  width: 100%;
}

.search-icon {
  position: absolute;
  left: 0.9rem;
  top: 50%;
  transform: translateY(-50%);
  width: 17px;
  height: 17px;
  stroke: var(--text-dim);
  pointer-events: none;
}

.search-input-wrapper input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-highlight);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  padding: 0.65rem 2.4rem 0.65rem 2.5rem;
  outline: none;
  transition: all var(--transition-fast);
}

.search-input-wrapper input:focus {
  border-color: var(--accent-primary);
  background: var(--bg-surface-raised);
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.search-clear-btn {
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 0.9rem;
  cursor: pointer;
  padding: 0.25rem;
  border-radius: var(--radius-sm);
}

.search-clear-btn:hover {
  color: var(--text-main);
}

.filter-tools {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.category-filter-pills {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.filter-pill {
  font-family: var(--font-sans);
  font-size: 0.78rem;
  font-weight: 500;
  padding: 0.3rem 0.75rem;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface-raised);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.filter-pill:hover {
  background: var(--bg-hover);
  color: var(--text-main);
}

.filter-pill.active {
  background: var(--accent-primary);
  color: #ffffff;
  border-color: var(--accent-primary);
}

.selection-helpers {
  display: flex;
  gap: 0.4rem;
}

/* ==========================================================================
   VOCABULARY ITEMS OUTPUT LIST
   ========================================================================== */

.output-wrapper {
  min-height: 350px;
}

.items-list-view {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

/* Single Vocab Item Card */
.vocab-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  display: flex;
  gap: 1.25rem;
  position: relative;
  transition: all var(--transition-smooth);
}

.vocab-card:hover {
  border-color: var(--border-medium);
  background: var(--bg-surface-raised);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

.vocab-card.selected {
  border-color: var(--accent-secondary);
  background: rgba(6, 182, 212, 0.04);
}

.vocab-card-select-wrap {
  display: flex;
  align-items: flex-start;
  padding-top: 0.2rem;
}

.vocab-item-checkbox {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: var(--accent-primary);
  border-radius: var(--radius-sm);
}

.vocab-card-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.vocab-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.vocab-heading-group {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.vocab-index {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-dim);
}

.vocab-term {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-highlight);
  letter-spacing: -0.01em;
}

.vocab-card-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.btn-card-copy, .btn-card-speak {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  padding: 0.25rem 0.6rem;
  font-size: 0.75rem;
  font-family: var(--font-sans);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  transition: all var(--transition-fast);
}

.btn-card-copy svg, .btn-card-speak svg {
  width: 13px;
  height: 13px;
}

.btn-card-copy:hover, .btn-card-speak:hover {
  color: var(--text-main);
  background: var(--bg-hover);
  border-color: var(--border-medium);
}

.vocab-meaning-row {
  font-size: 0.94rem;
  color: #cbd5e1;
  line-height: 1.5;
}

.vocab-meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1.5rem;
  margin-top: 0.2rem;
  padding-top: 0.5rem;
  border-top: 1px dashed rgba(255, 255, 255, 0.06);
  font-size: 0.86rem;
}

.vocab-meta-group {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.meta-label {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.1rem 0.35rem;
  border-radius: var(--radius-sm);
}

.meta-label.syn {
  color: #34d399;
  background: rgba(52, 211, 153, 0.12);
}

.meta-label.anto {
  color: #fbbf24;
  background: rgba(251, 191, 36, 0.12);
}

.meta-values {
  color: var(--text-muted);
}

/* Empty State */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: var(--bg-surface);
  border: 1px dashed var(--border-medium);
  border-radius: var(--radius-xl);
  padding: 4rem 2rem;
  gap: 1rem;
}

.empty-icon {
  font-size: 3rem;
  opacity: 0.7;
}

.empty-title {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text-highlight);
}

.empty-desc {
  max-width: 480px;
  font-size: 0.92rem;
  color: var(--text-muted);
}

.btn-secondary-glow {
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 700;
  padding: 0.8rem 1.5rem;
  border-radius: var(--radius-md);
  background: var(--bg-surface-elevated);
  border: 1px solid var(--accent-primary);
  color: #ffffff;
  cursor: pointer;
  margin-top: 0.5rem;
  transition: all var(--transition-fast);
}

.btn-secondary-glow:hover {
  background: var(--accent-primary);
  box-shadow: 0 0 16px var(--accent-primary-glow);
}

/* Raw Plain Text View */
.raw-text-view {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  animation: fadeIn 0.2s ease-out;
}

.raw-text-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.raw-text-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
}

#raw-text-output {
  width: 100%;
  height: 420px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: #e2e8f0;
  font-family: var(--font-mono);
  font-size: 0.86rem;
  line-height: 1.7;
  padding: 1rem 1.2rem;
  resize: vertical;
  outline: none;
}

#raw-text-output:focus {
  border-color: var(--accent-primary);
}

/* ==========================================================================
   FOOTER
   ========================================================================== */

.app-footer {
  margin-top: 4rem;
  border-top: 1px solid var(--border-subtle);
  padding-top: 2rem;
  text-align: center;
}

.footer-brand {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 0.35rem;
}

.footer-meta {
  font-size: 0.82rem;
  color: var(--text-dim);
}

/* ==========================================================================
   TOAST NOTIFICATIONS
   ========================================================================== */

.toast-container {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  pointer-events: none;
}

.toast {
  background: #181c28;
  border: 1px solid rgba(99, 102, 241, 0.4);
  color: #ffffff;
  padding: 0.85rem 1.25rem;
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6), 0 0 16px rgba(99, 102, 241, 0.25);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  pointer-events: auto;
  animation: slideToast 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.toast.toast-success {
  border-color: rgba(16, 185, 129, 0.4);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6), 0 0 16px rgba(16, 185, 129, 0.25);
}

.toast.toast-error {
  border-color: rgba(239, 68, 68, 0.4);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6), 0 0 16px rgba(239, 68, 68, 0.25);
}

@keyframes slideToast {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.toast-exit {
  opacity: 0;
  transform: translateY(10px) scale(0.95);
  transition: all 0.25s ease-in;
}

/* Floating Back to Top Button */
.btn-fab-top {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  width: 46px;
  height: 46px;
  border-radius: var(--radius-full);
  background: var(--accent-primary);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.25);
  box-shadow: 0 4px 18px rgba(99, 102, 241, 0.45), 0 2px 8px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 990;
  transition: all var(--transition-smooth);
}

.btn-fab-top svg {
  width: 20px;
  height: 20px;
  stroke-width: 3;
}

.btn-fab-top:hover {
  background: var(--accent-primary-hover);
  transform: translateY(-3px) scale(1.05);
}

.btn-fab-top:active {
  transform: translateY(0) scale(0.95);
}

/* ==========================================================================
   TOUCH INTERACTION POLISH
   ========================================================================== */

.category-card:active .card-inner,
.qty-pill:active,
.mode-pill:active,
.filter-pill:active,
.btn-action:active,
.btn-card-copy:active,
.btn-card-speak:active {
  transform: scale(0.97);
}

/* ==========================================================================
   RESPONSIVE DESIGN — SMARTPHONES & TABLETS
   ========================================================================== */

/* Medium Devices (Tablets, Large Phones <= 860px) */
@media (max-width: 860px) {
  .app-container {
    padding: 1.5rem 1rem calc(3rem + env(safe-area-inset-bottom, 0px));
  }

  .control-card {
    padding: 1.5rem 1.25rem;
    border-radius: var(--radius-lg);
    margin-bottom: 1.75rem;
  }

  .distribution-grid {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }

  .results-header-card {
    padding: 1.25rem 1.25rem;
    border-radius: var(--radius-lg);
  }
}

/* Small Devices (Smartphones <= 640px) */
@media (max-width: 640px) {
  .app-container {
    padding: 1.25rem 0.85rem calc(3rem + env(safe-area-inset-bottom, 0px));
  }

  /* Header */
  .app-header {
    margin-bottom: 1.5rem;
  }

  .header-content {
    flex-direction: column;
    align-items: stretch;
    gap: 1.25rem;
    padding-bottom: 1.5rem;
  }

  .brand-title {
    font-size: 1.75rem;
  }

  .brand-subtitle {
    font-size: 0.88rem;
    line-height: 1.45;
  }

  .header-stats {
    display: flex;
    width: 100%;
    gap: 0.5rem;
  }

  .stat-pill {
    flex: 1;
    text-align: center;
    padding: 0.45rem 0.6rem;
    font-size: 0.75rem;
  }

  /* Control Card */
  .control-card {
    padding: 1.25rem 1rem;
    border-radius: var(--radius-lg);
    gap: 1rem;
  }

  .section-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }

  .section-title-group {
    gap: 0.65rem;
  }

  .step-num {
    font-size: 0.75rem;
    padding: 0.2rem 0.45rem;
  }

  .section-title {
    font-size: 1.05rem;
  }

  .section-desc {
    font-size: 0.8rem;
    line-height: 1.35;
  }

  .quick-selection-actions {
    width: 100%;
    display: flex;
    gap: 0.5rem;
  }

  .quick-selection-actions .btn-ghost-sm {
    flex: 1;
    text-align: center;
    padding: 0.45rem 0.5rem;
  }

  /* Category Tiles Grid */
  .categories-grid {
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }

  .card-inner {
    padding: 0.65rem 0.85rem;
    min-height: 48px;
    border-radius: var(--radius-md);
  }

  .card-info {
    gap: 0.5rem;
  }

  .cat-tag {
    font-size: 0.72rem;
    padding: 0.2rem 0.5rem;
  }

  .cat-count {
    font-size: 0.72rem;
  }

  .checkbox-indicator {
    width: 20px;
    height: 20px;
  }

  /* Quantity & Distribution Controls */
  .divider {
    margin: 1.25rem 0;
  }

  .qty-pill-group {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.4rem;
  }

  .qty-pill-group .qty-pill:nth-child(4),
  .qty-pill-group .qty-pill:nth-child(5) {
    grid-column: span 1;
  }
  
  .qty-pill-group .qty-pill:nth-child(4) {
    grid-column: 1 / span 2;
  }

  .qty-pill {
    padding: 0.6rem 0.5rem;
    font-size: 0.84rem;
    justify-content: center;
  }

  .mode-switch-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
  }

  .mode-pill {
    padding: 0.6rem 0.5rem;
    font-size: 0.8rem;
    justify-content: center;
    text-align: center;
    gap: 0.35rem;
  }

  .mode-pill svg {
    width: 14px;
    height: 14px;
  }

  .custom-qty-wrapper {
    padding: 0.75rem 0.9rem;
  }

  .stepper-btn {
    width: 44px;
    height: 44px;
    font-size: 1.25rem;
  }

  .input-with-stepper input[type="number"] {
    font-size: 1.1rem;
    padding: 0.5rem 0.5rem;
  }

  /* Primary Button */
  .action-footer {
    margin-top: 1.25rem;
  }

  .btn-primary-glow {
    padding: 0.95rem 1.25rem;
    font-size: 0.96rem;
    border-radius: var(--radius-md);
  }

  .kbd-shortcut {
    display: none;
  }

  /* Results Section */
  .results-header-card {
    padding: 1.15rem 1rem;
    gap: 1rem;
  }

  .results-title {
    font-size: 1.2rem;
  }

  .results-subtitle {
    font-size: 0.8rem;
  }

  /* Action Buttons Grid on Mobile */
  .results-actions-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    width: 100%;
  }

  .btn-action {
    padding: 0.6rem 0.6rem;
    font-size: 0.8rem;
    justify-content: center;
    min-height: 40px;
  }

  .btn-copy-all {
    grid-column: 1 / -1;
    font-weight: 700;
  }

  .btn-copy-selected {
    grid-column: 1 / -1;
  }

  /* Dynamic Statistics Summary Bar */
  .stats-summary-bar {
    padding: 0.75rem 0.9rem;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  .stats-breakdown {
    gap: 0.4rem;
    width: 100%;
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 2px;
    scrollbar-width: none;
  }

  .stats-breakdown::-webkit-scrollbar {
    display: none;
  }

  .stat-badge {
    white-space: nowrap;
    font-size: 0.75rem;
    padding: 0.2rem 0.5rem;
    flex-shrink: 0;
  }

  .stats-filter-status {
    font-size: 0.76rem;
  }

  /* Filter & Search Toolbar */
  .filter-toolbar {
    padding: 0.85rem 0.9rem;
    gap: 0.75rem;
  }

  .search-input-wrapper input {
    font-size: 16px; /* Crucial to prevent mobile iOS zoom-in */
    padding: 0.65rem 2.2rem 0.65rem 2.2rem;
  }

  .search-icon {
    left: 0.75rem;
    width: 15px;
    height: 15px;
  }

  .filter-tools {
    gap: 0.6rem;
  }

  /* Smooth swipeable chip carousel on smartphone */
  .category-filter-pills {
    display: flex;
    gap: 0.4rem;
    overflow-x: auto;
    flex-wrap: nowrap;
    width: 100%;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .category-filter-pills::-webkit-scrollbar {
    display: none;
  }

  .filter-pill {
    flex-shrink: 0;
    white-space: nowrap;
    padding: 0.35rem 0.75rem;
    font-size: 0.76rem;
    min-height: 32px;
  }

  .selection-helpers {
    width: 100%;
    display: flex;
    gap: 0.5rem;
  }

  .selection-helpers .btn-ghost-xs {
    flex: 1;
    text-align: center;
    padding: 0.35rem 0.5rem;
  }

  /* Vocabulary Item Cards on Mobile */
  .vocab-card {
    padding: 1rem 0.9rem;
    gap: 0.75rem;
    border-radius: var(--radius-md);
  }

  .vocab-card-select-wrap {
    padding-top: 0.15rem;
  }

  .vocab-item-checkbox {
    width: 20px;
    height: 20px;
  }

  .vocab-card-top {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  .vocab-heading-group {
    gap: 0.4rem 0.6rem;
    align-items: center;
    width: 100%;
  }

  .vocab-term {
    font-size: 1.1rem;
    width: 100%;
    word-break: break-word;
  }

  .vocab-card-actions {
    width: 100%;
    display: flex;
    gap: 0.4rem;
  }

  .btn-card-copy, .btn-card-speak {
    flex: 1;
    justify-content: center;
    padding: 0.4rem 0.6rem;
    font-size: 0.76rem;
    min-height: 34px;
    border-radius: var(--radius-sm);
  }

  .vocab-meaning-row {
    font-size: 0.88rem;
    line-height: 1.45;
  }

  .vocab-meta-row {
    flex-direction: column;
    gap: 0.5rem;
    font-size: 0.82rem;
  }

  .vocab-meta-group {
    gap: 0.35rem;
  }

  .meta-values {
    word-break: break-word;
    font-size: 0.82rem;
  }

  /* Raw Plain Text View */
  .raw-text-view {
    padding: 1rem;
  }

  .raw-text-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  #raw-text-output {
    height: 280px;
    font-size: 0.8rem;
    padding: 0.75rem;
  }

  /* FAB & Toast */
  .btn-fab-top {
    bottom: 1.25rem;
    right: 1.25rem;
    width: 44px;
    height: 44px;
  }

  .toast-container {
    left: 0.75rem;
    right: 0.75rem;
    bottom: 1rem;
  }

  .toast {
    font-size: 0.82rem;
    padding: 0.75rem 1rem;
  }

  /* Empty State */
  .empty-state {
    padding: 2.5rem 1rem;
  }

  .empty-icon {
    font-size: 2.25rem;
  }

  .empty-title {
    font-size: 1.15rem;
  }

  .empty-desc {
    font-size: 0.84rem;
  }
}

/* Extra Small Devices (Phones <= 380px) */
@media (max-width: 380px) {
  .app-container {
    padding: 1rem 0.6rem calc(3rem + env(safe-area-inset-bottom, 0px));
  }

  .brand-title {
    font-size: 1.55rem;
  }

  .qty-pill-group {
    grid-template-columns: repeat(2, 1fr);
  }

  .qty-pill-group .qty-pill:nth-child(4) {
    grid-column: auto;
  }

  .results-actions-group {
    grid-template-columns: 1fr;
  }

  .btn-copy-all, .btn-copy-selected {
    grid-column: 1;
  }
}

