/**
 * Korean Numbers Drill - Clean Minimal Styles
 * Elegant, distraction-free interface for learning
 */

/* ============================================
   CSS Custom Properties (Design Tokens)
   ============================================ */
:root {
  /* Colors */
  --color-bg: #fafaf9;
  --color-surface: #ffffff;
  --color-text: #1a1a1a;
  --color-text-muted: #a8a29e;
  --color-text-subtle: #78716c;
  --color-primary: #6366f1;
  --color-primary-hover: #4f46e5;
  --color-primary-light: #e0e7ff;
  --color-success: #22c55e;
  --color-success-light: #dcfce7;
  --color-error: #ef4444;
  --color-error-light: #fee2e2;
  --color-border: #e7e5e4;
  --color-shadow: rgba(0, 0, 0, 0.04);
  --color-shadow-hover: rgba(0, 0, 0, 0.08);

  /* Typography */
  --font-korean-sans: 'Noto Sans KR', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-korean-handwritten: 'Gaegu', cursive;
  --font-korean: var(--font-korean-sans);
  --font-mono: 'DM Mono', 'JetBrains Mono', 'Fira Code', monospace;
  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;

  /* Spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;
  --space-3xl: 4rem;

  /* Sizing */
  --max-width: 480px;
  --card-radius: 12px;
  --btn-radius: 8px;
  --input-radius: 8px;

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
  --transition-slow: 400ms ease;

  /* Shadows */
  --shadow-sm: 0 1px 2px var(--color-shadow);
  --shadow-md: 0 4px 12px var(--color-shadow), 0 1px 3px var(--color-shadow);
  --shadow-lg: 0 8px 24px var(--color-shadow), 0 2px 8px var(--color-shadow);
  --shadow-xl: 0 16px 48px var(--color-shadow), 0 4px 12px var(--color-shadow);
}

/* ============================================
   Reset & Base
   ============================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-ui);
  background-color: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ============================================
   Typography
   ============================================ */
.korean-text {
  font-family: var(--font-korean);
}

.mono-text {
  font-family: var(--font-mono);
}

h1, h2, h3 {
  font-weight: 600;
  line-height: 1.3;
}

/* Font style classes */
.font-sans {
  font-family: var(--font-korean-sans);
}

.font-handwritten {
  font-family: var(--font-korean-handwritten);
}

/* When handwritten font is active */
body.font-handwritten .flashcard-number.korean,
body.font-handwritten .input-field,
body.font-handwritten .key.syllable {
  font-family: var(--font-korean-handwritten);
}

body.font-handwritten .flashcard-number.korean {
  font-weight: 700;
}

body.font-handwritten .key.syllable {
  font-weight: 400;
}

/* ============================================
   Layout
   ============================================ */
.app-layout {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
  width: 100%;
}

.app-container {
  flex: 1;
  max-width: 100%;
  padding: var(--space-xs) var(--space-sm);
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ============================================
   Sidebars (Desktop)
   ============================================ */
.sidebar {
  display: none;
  width: 200px;
  flex-shrink: 0;
  background: var(--color-surface);
  border-color: var(--color-border);
  padding: var(--space-md);
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
}

.sidebar-left {
  border-right: 1px solid var(--color-border);
}

.sidebar-right {
  border-left: 1px solid var(--color-border);
}

.sidebar-header {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  margin-bottom: var(--space-md);
  padding-bottom: var(--space-sm);
  border-bottom: 1px solid var(--color-border);
}

.sidebar-content {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.sidebar-mode {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  width: 100%;
  padding: var(--space-sm);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--btn-radius);
  cursor: pointer;
  transition: all var(--transition-fast);
  text-align: left;
}

.sidebar-mode:hover {
  background: var(--color-bg);
}

.sidebar-mode.active {
  background: var(--color-primary-light);
  border-color: var(--color-primary);
}

.sidebar-mode-icon {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
  color: var(--color-text-muted);
}

.sidebar-mode.active .sidebar-mode-icon {
  color: var(--color-primary);
}

.sidebar-mode-name {
  font-size: 0.8125rem;
  color: var(--color-text);
}

.sidebar-mode.active .sidebar-mode-name {
  color: var(--color-primary);
  font-weight: 500;
}

/* Right Sidebar Settings */
.sidebar-group {
  margin-bottom: var(--space-md);
  padding-bottom: var(--space-md);
  border-bottom: 1px solid var(--color-border);
}

.sidebar-group:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

.sidebar-label {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  margin-bottom: var(--space-sm);
}

.sidebar-duration,
.sidebar-levels {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-xs);
}

.sidebar-duration .duration-btn,
.sidebar-levels .level-btn {
  padding: var(--space-xs);
  font-size: 0.75rem;
}

.sidebar-fonts {
  display: flex;
  gap: var(--space-xs);
}

.sidebar-fonts .font-btn {
  flex: 1;
  padding: var(--space-sm);
}

.sidebar-fonts .font-preview {
  font-size: 1.25rem;
}

.sidebar-fonts .font-name {
  display: none;
}

.sidebar-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-xs) 0;
}

.sidebar-row-label {
  font-size: 0.8125rem;
  color: var(--color-text);
}

.sidebar-row .toggle {
  transform: scale(0.85);
}

/* Disabled state during active session */
.sidebar.disabled {
  opacity: 0.5;
  pointer-events: none;
}

.sidebar.disabled .sidebar-header::after {
  content: ' (in session)';
  font-weight: 400;
  font-size: 0.625rem;
}

/* ============================================
   Header
   ============================================ */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-xs) 0;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: var(--space-sm);
  flex-shrink: 0;
}

.site-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text);
  letter-spacing: -0.02em;
}

.header-actions {
  display: flex;
  gap: var(--space-sm);
}

.header-btn {
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: var(--btn-radius);
  padding: var(--space-sm) var(--space-md);
  font-size: 0.875rem;
  color: var(--color-text-subtle);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.header-btn:hover {
  background: var(--color-surface);
  border-color: var(--color-text-muted);
  color: var(--color-text);
}

.header-btn.active {
  background: var(--color-primary-light);
  border-color: var(--color-primary);
  color: var(--color-primary);
}

/* Mode selector button - more prominent */
.header-btn.mode-selector {
  background: var(--color-primary-light);
  border-color: var(--color-primary);
  color: var(--color-primary);
  font-weight: 500;
}

.header-btn.mode-selector::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  background: var(--color-primary);
  border-radius: 2px;
  margin-right: var(--space-sm);
}

.header-btn.mode-selector:hover {
  background: var(--color-primary);
  color: white;
}

.header-btn.mode-selector:hover::before {
  background: white;
}

/* ============================================
   Stats Bar
   ============================================ */
.stats-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-xs);
  padding: var(--space-xs);
  background: var(--color-surface);
  border-radius: var(--card-radius);
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}

.stat-item {
  text-align: center;
}

.stat-item.stop-btn {
  cursor: pointer;
  border-radius: var(--btn-radius);
  transition: all var(--transition-fast);
  background: var(--color-error-light);
  margin: calc(-1 * var(--space-xs));
  padding: var(--space-xs);
}

.stat-item.stop-btn .stat-label {
  color: var(--color-error);
  font-weight: 600;
}

.stat-item.stop-btn:hover {
  background: var(--color-error);
}

.stat-item.stop-btn:hover .stat-value,
.stat-item.stop-btn:hover .stat-label {
  color: white;
}

/* Flash animation for stop button */
.stat-item.stop-btn.flash {
  animation: flashStop 0.5s ease;
}

@keyframes flashStop {
  0%, 100% { background: var(--color-error-light); }
  25%, 75% { background: var(--color-error); }
  25%, 75% { color: white; }
}

.stat-item.stop-btn.flash .stat-value,
.stat-item.stop-btn.flash .stat-label {
  animation: flashStopText 0.5s ease;
}

@keyframes flashStopText {
  0%, 100% { color: var(--color-error); }
  25%, 75% { color: white; }
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--color-text);
  line-height: 1.2;
}

.stat-value.timer {
  color: var(--color-primary);
}

.stat-value.timer.warning {
  color: var(--color-error);
  animation: pulse 1s ease infinite;
}

.stat-label {
  font-size: 0.6875rem;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* ============================================
   Main Card Area
   ============================================ */
.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  min-height: 0;
  overflow: hidden;
}

/* Flashcard */
.flashcard {
  background: var(--color-surface);
  border-radius: var(--card-radius);
  box-shadow: var(--shadow-md);
  padding: var(--space-sm);
  text-align: center;
  flex: 1;
  min-height: 80px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  position: relative;
  transition: all var(--transition-normal);
  overflow: hidden;
}

.flashcard.correct {
  box-shadow: 0 0 0 3px var(--color-success-light), var(--shadow-md);
  animation: correctPop 0.3s ease;
}

.flashcard.incorrect {
  box-shadow: 0 0 0 3px var(--color-error-light), var(--shadow-md);
  animation: shake 0.4s ease;
}

@keyframes correctPop {
  0% { transform: scale(1); }
  50% { transform: scale(1.02); }
  100% { transform: scale(1); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-8px); }
  40%, 80% { transform: translateX(8px); }
}

.flashcard-context {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  margin-bottom: var(--space-sm);
}

.flashcard-number {
  font-family: var(--font-mono);
  font-size: clamp(1.5rem, 8vw, 3rem);
  font-weight: 700;
  color: var(--color-text);
  line-height: 1.1;
  max-width: 100%;
  padding: 0 var(--space-sm);
  overflow-wrap: break-word;
  word-break: keep-all;
}

.flashcard-number.korean {
  font-family: var(--font-korean);
  font-size: clamp(1.5rem, 7vw, 2.75rem);
}

/* Long content like dates - auto-scale font */
.flashcard-number.long-content {
  font-size: clamp(1rem, 4.5vw, 1.75rem);
  letter-spacing: -0.02em;
}

.flashcard-number.long-content.korean {
  font-size: clamp(1rem, 4vw, 1.5rem);
}

.flashcard-hint {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  margin-top: var(--space-sm);
}

.mode-indicator {
  position: absolute;
  top: var(--space-md);
  right: var(--space-md);
  font-size: 0.75rem;
  color: var(--color-text-muted);
  background: var(--color-bg);
  padding: var(--space-xs) var(--space-sm);
  border-radius: 999px;
}

/* ============================================
   Input Area
   ============================================ */
.input-area {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  flex-shrink: 1;
  min-height: 0;
  overflow: hidden;
}

.input-field-wrapper {
  position: relative;
}

.input-field {
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  font-family: var(--font-korean);
  font-size: 1.25rem;
  text-align: center;
  border: 2px solid var(--color-border);
  border-radius: var(--input-radius);
  background: var(--color-surface);
  color: var(--color-text);
  outline: none;
  transition: all var(--transition-fast);
}

.input-field:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 4px var(--color-primary-light);
}

.input-field.correct {
  border-color: var(--color-success);
  background: var(--color-success-light);
}

.input-field.incorrect {
  border-color: var(--color-error);
  background: var(--color-error-light);
}

.input-field::placeholder {
  color: var(--color-text-muted);
}

/* ============================================
   Keypad
   ============================================ */
.keypad-container {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.keypad {
  display: grid;
  gap: var(--space-xs);
  padding: var(--space-sm);
  background: var(--color-surface);
  border-radius: var(--card-radius);
  box-shadow: var(--shadow-sm);
}

/* Numeric keypad: standard 3-column phone layout */
.keypad.numeric {
  grid-template-columns: repeat(3, 1fr);
  width: 100%;
}

/* Syllable grid: flexible auto-fit columns for full words */
.keypad.syllable-grid {
  grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
  max-height: 180px;
  overflow-y: auto;
}

/* Action row: delete + enter side by side */
.keypad-action-row {
  display: flex;
  gap: var(--space-xs);
  padding: var(--space-sm);
  background: var(--color-surface);
  border-radius: var(--card-radius);
  box-shadow: var(--shadow-sm);
}

.keypad-action-row .key {
  flex: 1;
}

.key {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: var(--space-xs) var(--space-sm);
  font-size: 1rem;
  font-weight: 500;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--btn-radius);
  cursor: pointer;
  transition: all var(--transition-fast);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  min-height: 40px;
}

.key:hover {
  background: var(--color-surface);
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.key:active, .key.pressed {
  transform: scale(0.95);
  background: var(--color-primary-light);
  border-color: var(--color-primary);
}

.key.number {
  font-family: var(--font-mono);
}

.key.syllable {
  font-family: var(--font-korean);
}

.key.action {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: white;
}

.key.action:hover {
  background: var(--color-primary-hover);
}

.key.delete {
  background: var(--color-error-light);
  border-color: var(--color-error);
  color: var(--color-error);
}

.key.delete:hover {
  background: var(--color-error);
  color: white;
}

.key.wide {
  grid-column: span 2;
}

.key.full-width {
  grid-column: 1 / -1;
}

/* ============================================
   Structured Keyboard Layouts
   ============================================ */

/* Grouped layout: stacked groups */
.keypad-grouped {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  padding: var(--space-sm);
}

/* Dual layout: side-by-side panels for mixed systems (Time mode) */
.keypad-dual {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-sm);
  padding: var(--space-sm);
}

/* Panel container for dual layout */
.keypad-panel {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  padding: var(--space-xs);
  border-radius: var(--btn-radius);
  background: var(--color-bg);
}

.keypad-panel-native {
  background: #fef7ee;
  border: 1px solid #fed7aa;
}

.keypad-panel-sino {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
}

.keypad-panel-label {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: var(--space-xs) var(--space-xs);
  text-align: center;
  border-radius: 4px;
}

.keypad-panel-native .keypad-panel-label {
  color: #c2410c;
  background: #ffedd5;
}

.keypad-panel-sino .keypad-panel-label {
  color: #1d4ed8;
  background: #dbeafe;
}

/* Group container - flexbox for centered incomplete rows */
.keypad-group {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
}

.keypad-group .key {
  /* Calculate width based on column count, accounting for gaps */
  flex: 0 0 calc((100% - (var(--group-columns, 3) - 1) * 4px) / var(--group-columns, 3));
  max-width: calc((100% - (var(--group-columns, 3) - 1) * 4px) / var(--group-columns, 3));
}

/* System-based key coloring */
.key-sino {
  background: #eff6ff;
  border-color: #bfdbfe;
  color: #1e40af;
}

.key-sino:hover {
  background: #dbeafe;
  border-color: #93c5fd;
}

.key-native {
  background: #fef7ee;
  border-color: #fed7aa;
  color: #c2410c;
}

.key-native:hover {
  background: #ffedd5;
  border-color: #fdba74;
}

.key-particle {
  background: #f0fdf4;
  border-color: #bbf7d0;
  color: #166534;
  font-weight: 600;
}

.key-particle:hover {
  background: #dcfce7;
  border-color: #86efac;
}

/* Category-based styling */
.keypad-group-multiplier .key-sino {
  background: #e0e7ff;
  border-color: #a5b4fc;
}

.keypad-group-multiplier .key-sino:hover {
  background: #c7d2fe;
}

.keypad-group-tens .key-native {
  background: #fef3c7;
  border-color: #fcd34d;
  color: #92400e;
}

.keypad-group-tens .key-native:hover {
  background: #fde68a;
}

/* Learning mode: keys with hints */
.key-with-hint {
  flex-direction: column;
  padding: 2px var(--space-xs);
  gap: 0;
}

.key-char {
  font-family: var(--font-korean);
  line-height: 1.2;
}

.key-hint {
  font-family: var(--font-ui);
  font-size: 0.5625rem;
  font-weight: 400;
  color: var(--color-text-muted);
  line-height: 1;
  opacity: 0.8;
}

.key-sino .key-hint {
  color: #3b82f6;
}

.key-native .key-hint {
  color: #f97316;
}

.key-particle .key-hint {
  color: #22c55e;
}

/* Shuffled mode: all keys mixed together */
.keypad-system-mixed {
  /* Use a balanced column count for shuffled grids */
  grid-template-columns: repeat(var(--group-columns, 5), 1fr);
}

/* ============================================
   Mode Selector (Modal)
   ============================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: var(--space-md);
  z-index: 100;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-normal);
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--color-surface);
  border-radius: var(--card-radius);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 400px;
  max-height: 90vh;
  overflow-y: auto;
  transform: scale(0.95) translateY(10px);
  transition: all var(--transition-normal);
}

.modal.modal-sm {
  max-width: 320px;
}

.confirm-message {
  font-size: 0.9375rem;
  color: var(--color-text-subtle);
  margin-bottom: var(--space-lg);
  line-height: 1.5;
}

.confirm-actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.modal-overlay.active .modal {
  transform: scale(1) translateY(0);
}

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

.modal-title {
  font-size: 1.125rem;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--color-text-muted);
  cursor: pointer;
  padding: var(--space-xs);
  line-height: 1;
  transition: color var(--transition-fast);
}

.modal-close:hover {
  color: var(--color-text);
}

.modal-body {
  padding: var(--space-lg);
}

.mode-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.mode-option {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  background: var(--color-bg);
  border: 2px solid transparent;
  border-radius: var(--btn-radius);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.mode-option:hover {
  border-color: var(--color-primary-light);
}

.mode-option.active {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
}

.mode-icon {
  font-size: 1.5rem;
  width: 2.5rem;
  text-align: center;
}

.mode-info {
  flex: 1;
}

.mode-name {
  font-weight: 600;
  font-size: 0.9375rem;
}

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

/* ============================================
   About Content
   ============================================ */
.about-content {
  font-size: 0.875rem;
  line-height: 1.7;
  color: var(--color-text);
}

.about-content h4 {
  font-size: 0.9375rem;
  font-weight: 600;
  margin-top: var(--space-lg);
  margin-bottom: var(--space-sm);
  color: var(--color-text);
}

.about-content h4:first-child {
  margin-top: 0;
}

.about-content p {
  margin-bottom: var(--space-sm);
  color: var(--color-text-subtle);
}

.about-content ul {
  margin: var(--space-sm) 0;
  padding-left: var(--space-lg);
}

.about-content li {
  margin-bottom: var(--space-xs);
  color: var(--color-text-subtle);
}

.about-content strong {
  color: var(--color-text);
  font-weight: 500;
}

.about-content a {
  color: var(--color-primary);
  text-decoration: none;
}

.about-content a:hover {
  text-decoration: underline;
}

.about-footer {
  margin-top: var(--space-lg);
  padding-top: var(--space-md);
  border-top: 1px solid var(--color-border);
  font-size: 0.8125rem;
  color: var(--color-text-muted);
}

/* ============================================
   Settings Panel
   ============================================ */
.settings-group {
  margin-bottom: var(--space-xl);
}

.settings-group:last-child {
  margin-bottom: 0;
}

.settings-group + .settings-group {
  padding-top: var(--space-md);
  border-top: 1px solid var(--color-border);
}

.settings-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-sm);
}

.settings-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-sm) 0;
}

.settings-row-label {
  font-size: 0.9375rem;
}

/* Toggle Switch */
.toggle {
  position: relative;
  width: 48px;
  height: 28px;
  background: var(--color-border);
  border-radius: 999px;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.toggle.active {
  background: var(--color-primary);
}

.toggle::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 24px;
  height: 24px;
  background: white;
  border-radius: 50%;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition-fast);
}

.toggle.active::after {
  transform: translateX(20px);
}

/* Font Selector */
.font-options {
  display: flex;
  gap: var(--space-sm);
}

.font-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-sm);
  background: var(--color-bg);
  border: 2px solid var(--color-border);
  border-radius: var(--btn-radius);
  cursor: pointer;
  transition: all var(--transition-fast);
}

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

.font-btn.active {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
}

.font-preview {
  font-size: 1.5rem;
  line-height: 1;
}

.font-name {
  font-size: 0.75rem;
  color: var(--color-text-muted);
}

.font-btn.active .font-name {
  color: var(--color-primary);
}

/* Duration Selector */
.duration-options {
  display: flex;
  gap: var(--space-sm);
}

.duration-btn {
  flex: 1;
  padding: var(--space-sm);
  font-size: 0.875rem;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--btn-radius);
  cursor: pointer;
  transition: all var(--transition-fast);
}

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

.duration-btn.active {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: white;
}

/* Level Selector */
.level-options {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-sm);
}

.level-btn {
  padding: var(--space-sm);
  font-size: 0.875rem;
  text-align: center;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--btn-radius);
  cursor: pointer;
  transition: all var(--transition-fast);
}

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

.level-btn.active {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: white;
}

.level-range {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  margin-top: var(--space-xs);
}

.level-btn.active .level-range {
  color: rgba(255, 255, 255, 0.8);
}

/* ============================================
   Footer
   ============================================ */
.footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-xs) 0;
  border-top: 1px solid var(--color-border);
  margin-top: var(--space-sm);
  flex-shrink: 0;
}

.footer-info {
  display: flex;
  gap: var(--space-lg);
}

.footer-item {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
}

.footer-item strong {
  color: var(--color-text);
  font-weight: 600;
}

.footer-btn {
  font-size: 0.8125rem;
  color: var(--color-primary);
  background: none;
  border: none;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

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

/* Footer credit */
.footer-credit {
  display: flex;
  justify-content: center;
  padding: var(--space-xs) 0;
  flex-shrink: 0;
}

.footer-credit .footer-item {
  font-size: 0.75rem;
}

.footer-credit a {
  color: var(--color-primary);
  text-decoration: none;
  transition: color var(--transition-fast);
}

.footer-credit a:hover {
  color: var(--color-primary-hover);
}

/* ============================================
   Start Screen
   ============================================ */
.start-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  gap: var(--space-md);
  padding: var(--space-sm);
  min-height: 0;
}

.start-title {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.2;
}

.start-subtitle {
  font-size: 0.9375rem;
  color: var(--color-text-muted);
  max-width: 280px;
  line-height: 1.5;
}

.start-btn {
  padding: var(--space-sm) var(--space-xl);
  font-size: 1rem;
  font-weight: 600;
  background: var(--color-primary);
  color: white;
  border: none;
  border-radius: var(--btn-radius);
  cursor: pointer;
  transition: all var(--transition-fast);
  box-shadow: var(--shadow-md);
}

.start-btn:hover {
  background: var(--color-primary-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

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

/* ============================================
   Results Screen
   ============================================ */
.results-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: var(--space-md);
  padding: var(--space-sm);
  min-height: 0;
}

.results-header {
  text-align: center;
}

.results-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: var(--space-xs);
}

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

.results-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-sm);
}

.result-card {
  background: var(--color-surface);
  border-radius: var(--card-radius);
  padding: var(--space-sm) var(--space-md);
  text-align: center;
  box-shadow: var(--shadow-sm);
}

.result-value {
  font-family: var(--font-mono);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color-primary);
}

.result-label {
  font-size: 0.75rem;
  color: var(--color-text-muted);
}

.results-actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.result-btn {
  padding: var(--space-sm) var(--space-md);
  font-size: 0.9375rem;
  font-weight: 600;
  border-radius: var(--btn-radius);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.result-btn.primary {
  background: var(--color-primary);
  color: white;
  border: none;
}

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

.result-btn.secondary {
  background: transparent;
  color: var(--color-text-subtle);
  border: 1px solid var(--color-border);
}

.result-btn.secondary:hover {
  border-color: var(--color-text-muted);
  color: var(--color-text);
}

/* ============================================
   Utility Classes
   ============================================ */
.hidden {
  display: none !important;
}

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

/* ============================================
   Responsive Design (Mobile-first)
   ============================================ */

/* Tablet and up */
@media (min-width: 640px) {
  :root {
    --max-width: 540px;
    --card-radius: 16px;
    --btn-radius: 12px;
    --input-radius: 12px;
  }

  .app-container {
    padding: var(--space-md);
  }

  .header {
    padding: var(--space-sm) 0;
    margin-bottom: var(--space-md);
  }

  .stats-bar {
    padding: var(--space-md);
    gap: var(--space-sm);
  }

  .stat-value {
    font-size: 1.5rem;
  }

  .main-area {
    gap: var(--space-md);
  }

  .flashcard {
    padding: var(--space-lg);
  }

  .flashcard-number {
    font-size: clamp(2rem, 10vw, 4rem);
  }

  .flashcard-number.korean {
    font-size: clamp(1.75rem, 9vw, 3.5rem);
  }

  .input-area {
    gap: var(--space-sm);
  }

  .input-field {
    padding: var(--space-md);
    font-size: 1.5rem;
  }

  .keypad {
    padding: var(--space-sm);
    gap: var(--space-xs);
  }

  .key {
    padding: var(--space-xs) var(--space-sm);
    font-size: 1.125rem;
    min-height: 44px;
  }

  .start-title {
    font-size: 2rem;
  }

  .start-btn {
    padding: var(--space-md) var(--space-xl);
  }

  .result-value {
    font-size: 2rem;
  }
}

/* Desktop */
@media (min-width: 768px) {
  :root {
    --max-width: 600px;
  }

  .app-container {
    padding: var(--space-lg) var(--space-xl);
  }

  .header {
    padding: var(--space-md) 0;
    margin-bottom: var(--space-lg);
  }

  .site-title {
    font-size: 1.125rem;
  }

  .stats-bar {
    padding: var(--space-lg);
    gap: var(--space-md);
  }

  .stat-value {
    font-size: 1.75rem;
  }

  .main-area {
    gap: var(--space-lg);
  }

  .flashcard {
    padding: var(--space-xl);
  }

  .flashcard-number {
    font-size: clamp(2.5rem, 8vw, 5rem);
  }

  .flashcard-number.korean {
    font-size: clamp(2rem, 7vw, 4rem);
  }

  .input-field {
    padding: var(--space-md) var(--space-lg);
    font-size: 1.75rem;
  }

  .keypad {
    padding: var(--space-sm);
    gap: var(--space-xs);
  }

  .key {
    padding: var(--space-sm);
    font-size: 1.25rem;
    min-height: 48px;
  }

  .start-screen {
    gap: var(--space-xl);
  }

  .start-title {
    font-size: 2.5rem;
  }

  .start-subtitle {
    font-size: 1.125rem;
  }

  .start-btn {
    padding: var(--space-lg) var(--space-2xl);
    font-size: 1.125rem;
  }

  .results-screen {
    gap: var(--space-xl);
  }

  .result-card {
    padding: var(--space-lg);
  }

  .result-value {
    font-size: 2.5rem;
  }
}

/* Large desktop - show sidebars */
@media (min-width: 1024px) {
  .app-layout {
    background: var(--color-bg);
  }

  .app-container {
    flex: 1;
    max-width: none;
    padding: var(--space-md) var(--space-xl);
  }

  .sidebar {
    display: flex;
    flex-direction: column;
    width: 240px;
  }

  /* Hide mobile modal buttons on desktop */
  #mode-btn,
  #settings-btn {
    display: none;
  }

  .header-actions {
    gap: 0;
  }

  /* Larger flashcard on desktop */
  .flashcard {
    max-width: 600px;
    margin: 0 auto;
    width: 100%;
  }

  .flashcard-number {
    font-size: clamp(2.5rem, 6vw, 5rem);
  }

  .flashcard-number.korean {
    font-size: clamp(2.25rem, 5.5vw, 4.5rem);
  }

  /* Center the main area content */
  .main-area {
    max-width: 600px;
    margin: 0 auto;
    width: 100%;
  }

  .start-screen,
  .results-screen {
    max-width: 500px;
    margin: 0 auto;
  }

  .input-area {
    max-width: 600px;
    margin: 0 auto;
    width: 100%;
  }

  .stats-bar {
    max-width: 600px;
    margin: 0 auto var(--space-md);
    width: 100%;
  }
}

/* Extra large desktop */
@media (min-width: 1280px) {
  .sidebar {
    width: 280px;
    padding: var(--space-lg);
  }

  .app-container {
    padding: var(--space-lg) var(--space-2xl);
  }

  .sidebar-mode {
    padding: var(--space-sm) var(--space-md);
  }

  .sidebar-mode-name {
    font-size: 0.875rem;
  }

  .flashcard,
  .main-area,
  .input-area,
  .stats-bar {
    max-width: 640px;
  }

  .flashcard-number {
    font-size: clamp(3rem, 5vw, 6rem);
  }

  .flashcard-number.korean {
    font-size: clamp(2.5rem, 4.5vw, 5rem);
  }
}

/* Small mobile adjustments */
@media (max-width: 380px) {
  .header {
    flex-wrap: wrap;
    gap: var(--space-xs);
  }

  .header-actions {
    width: 100%;
    justify-content: flex-end;
  }

  .stats-bar {
    grid-template-columns: repeat(2, 1fr);
  }

  .flashcard-number {
    font-size: clamp(1.25rem, 12vw, 2.5rem);
  }

  .flashcard-number.korean {
    font-size: clamp(1.125rem, 11vw, 2.25rem);
  }

  .keypad {
    gap: 2px;
    padding: var(--space-xs);
  }

  .keypad.syllable-grid {
    max-height: 140px;
  }

  .key {
    font-size: 0.75rem;
    padding: 2px 4px;
    min-height: 28px;
  }

  .keypad-action-row {
    padding: var(--space-xs);
    gap: 2px;
  }

  .keypad-action-row .key {
    min-height: 32px;
  }

  .footer {
    flex-direction: column;
    gap: var(--space-xs);
    text-align: center;
  }

  .footer-info {
    flex-direction: column;
    gap: var(--space-xs);
  }

  /* Structured keyboard adjustments for small screens */
  .keypad-dual {
    grid-template-columns: 1fr;
    gap: var(--space-xs);
  }

  .keypad-panel-label {
    font-size: 0.5625rem;
    padding: 2px;
  }

  .keypad-group {
    gap: 2px;
  }

  .key-char {
    font-size: 0.8125rem;
  }

  .key-hint {
    font-size: 0.5rem;
  }

  .keypad-grouped {
    gap: var(--space-xs);
    padding: var(--space-xs);
  }
}

/* Medium mobile (380-640px) - dual layout works but compact */
@media (min-width: 380px) and (max-width: 640px) {
  .keypad-dual {
    gap: var(--space-xs);
  }

  .keypad-panel {
    padding: var(--space-xs);
  }

  .keypad-panel-label {
    font-size: 0.625rem;
  }

  .keypad-group {
    gap: 3px;
  }
}

/* ============================================
   Animations
   ============================================ */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.fade-in {
  animation: fadeIn 0.3s ease forwards;
}

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

.slide-up {
  animation: slideUp 0.4s ease forwards;
}

/* Staggered animations for lists */
.stagger > *:nth-child(1) { animation-delay: 0ms; }
.stagger > *:nth-child(2) { animation-delay: 50ms; }
.stagger > *:nth-child(3) { animation-delay: 100ms; }
.stagger > *:nth-child(4) { animation-delay: 150ms; }
.stagger > *:nth-child(5) { animation-delay: 200ms; }
.stagger > *:nth-child(6) { animation-delay: 250ms; }

/* ============================================
   Print Styles
   ============================================ */
@media print {
  .header-actions,
  .keypad,
  .footer-btn {
    display: none;
  }

  .flashcard {
    box-shadow: none;
    border: 1px solid var(--color-border);
  }
}
