:root {
  /* Core Colors - Refined Palette */
  --bg-color: #f1f5f9;
  --surface-color: #ffffff;
  --primary-color: #4f46e5;
  --primary-hover: #4338ca;
  --primary-surface: #f5f3ff;
  --text-main: #0f172a;
  --text-muted: #475569;
  --text-on-primary: #ffffff;
  --border-color: #e2e8f0;
  
  /* Accent Colors */
  --accent-thai: #ef4444;
  --success: #10b981;
  --warning: #f59e0b;
  
  /* Class Colors - Softened for modern look */
  --class-mid: #0ea5e9;
  --class-high: #10b981;
  --class-low: #f59e0b;
  --class-vowel: #8b5cf6;
  --class-number: #f43f5e;
  --class-day: #06b6d4;
  
  /* Depth & Radii */
  --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  --shadow-xl: 0 25px 50px -12px rgba(0, 0, 0, 0.15);
  
  --radius-sm: 0.5rem;
  --radius-md: 0.75rem;
  --radius-lg: 1rem;
  --radius-xl: 1.5rem;
  --radius-2xl: 2rem;
  --radius-full: 9999px;

  --sidebar-width: 320px;
  --header-height: 72px;
  --max-width: 1280px;
}

[data-theme="dark"] {
  --bg-color: #0b0f1a;
  --surface-color: #161b26;
  --primary-color: #6366f1;
  --primary-hover: #818cf8;
  --primary-surface: rgba(99, 102, 241, 0.1);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-on-primary: #ffffff;
  --border-color: #2d3748;
  
  --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.6);
  --shadow-xl: 0 25px 50px -12px rgba(0, 0, 0, 0.7);

  /* Adjusted class colors for dark mode contrast */
  --class-mid: #38bdf8;
  --class-high: #34d399;
  --class-low: #fbbf24;
  --class-vowel: #a78bfa;
  --class-number: #fb7185;
  --class-day: #22d3ee;
}

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

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background-color: var(--bg-color);
  background-image: 
    radial-gradient(at 0% 0%, rgba(79, 70, 229, 0.05) 0px, transparent 50%),
    radial-gradient(at 100% 100%, rgba(139, 92, 246, 0.05) 0px, transparent 50%);
  color: var(--text-main);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  transition: background-color 0.3s ease, color 0.3s ease;
}

[data-theme="dark"] body {
  background-image: 
    radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.1) 0px, transparent 50%),
    radial-gradient(at 100% 100%, rgba(167, 139, 250, 0.1) 0px, transparent 50%);
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  border: none;
  background: none;
  transition: all 0.2s ease;
}

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

/* Layout */
.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.app-header {
  height: var(--header-height);
  background: var(--surface-color);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 40;
  transition: all 0.3s ease;
}

[data-theme="dark"] .app-header {
  background: rgba(22, 27, 38, 0.8);
  backdrop-filter: blur(12px);
}

.header-content {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 2rem;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.logo-link {
  color: inherit;
  text-decoration: none;
}

.logo-icon {
  font-size: 1.75rem;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
}

.logo h1 {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  background: linear-gradient(135deg, var(--primary-color), #8b5cf6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.main-layout {
  display: flex;
  flex: 1;
  position: relative;
  max-width: var(--max-width);
  margin: 0 auto;
  width: 100%;
}

/* Sidebar Updates */
.settings-sidebar {
  width: 100%;
  background: var(--surface-color);
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  transform: translateX(-100%);
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1), background-color 0.3s ease;
  z-index: 100;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-xl);
}

.settings-sidebar.is-open {
  transform: translateX(0);
}

@media (min-width: 1024px) {
  .settings-sidebar {
    width: var(--sidebar-width);
    position: sticky;
    top: var(--header-height);
    height: calc(100vh - var(--header-height));
    border-right: 1px solid var(--border-color);
    transform: translateX(0);
    z-index: 10;
    box-shadow: none;
    background: transparent;
  }

  #settingsToggle {
    display: none;
  }

  .sidebar-overlay {
    display: none;
  }
}

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

.sidebar-header h2 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.settings-content {
  padding: 1.5rem;
  overflow-y: auto;
  flex: 1;
}

.settings-section {
  margin-bottom: 1.75rem;
}

.settings-section .label {
  font-size: 0.8125rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 1rem;
  display: block;
}

/* Study Area */
.study-area {
  flex: 1;
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  max-width: 100%;
  animation: fadeIn 0.5s ease-out;
}

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

.study-header {
  width: 100%;
  max-width: 600px;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.status-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.meta-group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.meta-tag, .progress-tag {
  font-size: 0.875rem;
  font-weight: 700;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-full);
  background: var(--surface-color);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
}

.progress-tag {
  color: var(--primary-color);
  background: var(--primary-surface);
  border-color: transparent;
}

/* Flashcard */
.card-container {
  width: 100%;
  max-width: 550px;
  perspective: 2000px;
  padding: 1rem 0;
  display: flex;
  justify-content: center;
}

.card-trigger {
  width: 100%;
  padding: 0;
  background: none;
  border: none;
  text-align: inherit;
  outline: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.flashcard {
  --flip-rotate: 0deg;
  --lift-y: 0px;
  --card-scale: 1;
  position: relative;
  width: 100%;
  height: 420px;
  transform-style: preserve-3d;
  transform: rotateY(var(--flip-rotate)) translateY(var(--lift-y)) scale(var(--card-scale));
  transition: transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.flashcard.is-flipped {
  --flip-rotate: 180deg;
}

.card-trigger:hover .flashcard {
  --lift-y: -8px;
}

.card-trigger:active .flashcard {
  --lift-y: -2px;
  --card-scale: 0.98;
}

.card-face {
  position: absolute;
  inset: 0;
  background: var(--surface-color);
  border-radius: var(--radius-2xl);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-xl);
  backface-visibility: hidden;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: all 0.3s ease;
}

[data-theme="dark"] .card-face {
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.card-face:hover {
  box-shadow: var(--shadow-2xl);
}

.card-back {
  transform: rotateY(180deg);
}

.card-header, .card-footer {
  padding: 1.5rem;
  display: flex;
  justify-content: center;
  align-items: center;
}

.face-label {
  font-size: 0.8125rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}

.glyph-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 7.5rem;
  font-weight: 800;
  filter: drop-shadow(0 4px 12px rgba(0,0,0,0.08));
}

.glyph-wrap.is-word {
  font-size: 4.5rem;
  padding: 0 2rem;
}

.hint-text {
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--text-muted);
}

.back-content {
  flex: 1;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  text-align: center;
}

.card-title {
  font-size: 2.5rem;
  font-weight: 800;
  color: var(--text-main);
  letter-spacing: -0.02em;
}

.details-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.25rem;
  width: 100%;
}

.detail-item {
  background: var(--bg-color);
  padding: 1rem;
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  transition: transform 0.2s ease;
  border: 1px solid var(--border-color);
}

.detail-item:hover {
  transform: scale(1.02);
}

.detail-item:last-child {
  grid-column: span 2;
}

.detail-label {
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.detail-value {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text-main);
}

/* Filter Pills */
.filter-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.625rem;
}

.pill {
  padding: 0.5rem 1rem;
  border-radius: var(--radius-full);
  font-size: 0.8125rem;
  font-weight: 600;
  background: var(--bg-color);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.pill:hover {
  background: var(--border-color);
  color: var(--text-main);
  transform: translateY(-1px);
}

.pill.active {
  background: var(--primary-color);
  border-color: var(--primary-color);
  color: var(--text-on-primary);
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

.study-controls {
  width: 100%;
  max-width: 550px;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.secondary-actions {
  display: flex;
  gap: 0.75rem;
  width: 100%;
}

.secondary-actions .action-button {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  height: 3.75rem;
  border-radius: var(--radius-full);
  font-weight: 600;
  font-size: 0.9375rem;
  color: var(--text-muted);
  box-shadow: var(--shadow-sm);
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.secondary-actions .action-button:hover {
  background: var(--primary-surface);
  border-color: var(--primary-color);
  color: var(--primary-color);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.secondary-actions .action-button svg {
  transition: transform 0.4s ease;
}

.secondary-actions .action-button:hover svg {
  transform: scale(1.1) rotate(15deg);
}

/* Ads */
.ad-panel {
  width: min(100%, 728px);
  min-height: 120px;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.5rem;
  padding: 0.75rem;
  background: color-mix(in srgb, var(--surface-color) 72%, transparent);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
}

.ad-panel-compact {
  width: min(100%, 560px);
  margin-top: 1.5rem;
}

.ad-label {
  color: var(--text-muted);
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  line-height: 1;
  text-transform: uppercase;
}

.adsbygoogle {
  width: 100%;
  min-height: 90px;
}

/* 404 */
.not-found {
  flex: 1;
  min-height: calc(100vh - var(--header-height));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: clamp(2rem, 6vw, 5rem) 1rem;
  animation: fadeIn 0.5s ease-out;
}

.not-found-card {
  width: min(100%, 560px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: clamp(2rem, 6vw, 4rem);
  text-align: center;
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-2xl);
  box-shadow: var(--shadow-xl);
}

[data-theme="dark"] .not-found-card {
  background: rgba(22, 27, 38, 0.82);
  backdrop-filter: blur(12px);
}

.not-found-glyph {
  width: clamp(7rem, 34vw, 11rem);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  margin: 0.5rem 0;
  color: var(--primary-color);
  font-size: clamp(4rem, 18vw, 7rem);
  font-weight: 800;
  line-height: 1;
  background: var(--primary-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-2xl);
  box-shadow: var(--shadow-lg);
}

.not-found-card h2 {
  font-size: clamp(1.75rem, 5vw, 2.5rem);
  line-height: 1.1;
}

.not-found-card p {
  max-width: 34rem;
  color: var(--text-muted);
}

.not-found-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 3.25rem;
  margin-top: 0.5rem;
  padding: 0.75rem 1.35rem;
  color: var(--text-on-primary);
  font-weight: 700;
  text-decoration: none;
  background: var(--primary-color);
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-md);
  transition: transform 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease;
}

.not-found-action:hover {
  background: var(--primary-hover);
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

/* Study Actions (Bottom Nav) */
.study-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
}

.nav-button {
  width: 3.75rem;
  height: 3.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-md);
  color: var(--text-main);
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.nav-button:hover {
  background: var(--bg-color);
  transform: scale(1.1) translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.nav-button:active {
  transform: scale(0.95);
}

.audio-button {
  flex: 1;
  height: 3.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  border-radius: var(--radius-full);
  background: var(--primary-color);
  color: var(--text-on-primary);
  font-weight: 800;
  font-size: 1rem;
  box-shadow: 0 10px 20px -5px rgba(79, 70, 229, 0.4);
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.audio-button:hover {
  background: var(--primary-hover);
  transform: scale(1.02) translateY(-2px);
  box-shadow: 0 15px 25px -5px rgba(79, 70, 229, 0.5);
}

.audio-button:active {
  transform: scale(0.98);
}

.audio-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* Progress Bar */
.progress-container {
  width: 100%;
  height: 6px;
  background: var(--border-color);
  border-radius: var(--radius-full);
  overflow: hidden;
  margin-top: 0.5rem;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary-color), #818cf8);
  border-radius: var(--radius-full);
  transition: width 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 0 10px rgba(79, 70, 229, 0.3);
}

/* Icons */
.icon-button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 3rem;
  height: 3rem;
  border-radius: var(--radius-lg);
  color: var(--text-main);
  transition: all 0.2s ease;
}

.icon-button:hover {
  background: var(--primary-surface);
  color: var(--primary-color);
  transform: translateY(-1px);
}

/* View Sections */
.view-section {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.view-section.hidden {
  display: none;
}

/* Grid View */
.grid-content {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 1rem;
  width: 100%;
  max-width: 900px;
}

.grid-item {
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  text-align: center;
  transition: all 0.2s ease;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
}

.grid-item:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-md);
  border-color: var(--primary-color);
}

.grid-glyph {
  font-size: 2.25rem;
  font-weight: 700;
  line-height: 1.1;
  word-break: break-word;
  overflow-wrap: break-word;
  width: 100%;
}

.grid-glyph.is-word {
  font-size: 1.5rem;
}

.grid-name {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-main);
}

.grid-sound {
  font-size: 0.75rem;
  color: var(--text-muted);
}
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

.sidebar-overlay.is-visible {
  opacity: 1;
  pointer-events: auto;
}

/* Class-specific Colors */
.class-mid { color: var(--class-mid); }
.class-high { color: var(--class-high); }
.class-low { color: var(--class-low); }
.class-vowel { color: var(--class-vowel); }
.class-number { color: var(--class-number); }
.class-day { color: var(--class-day); }

/* Responsive adjustments */
@media (max-width: 640px) {
  .study-area {
    padding: 1.25rem 0.75rem;
    gap: 1.25rem;
  }
  
  .flashcard {
    height: 380px;
  }
  
  .glyph-wrap {
    font-size: 6rem;
  }
  
  .card-title {
    font-size: 2rem;
  }

  .nav-button {
    width: 3.25rem;
    height: 3.25rem;
  }

  .audio-button {
    height: 3.25rem;
  }

  .secondary-actions .action-button {
    height: 3.25rem;
    font-size: 0.875rem;
  }

  .grid-content {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.75rem;
  }

  .grid-item {
    padding: 1rem;
  }

  .grid-glyph {
    font-size: 1.75rem;
  }

  .grid-glyph.is-word {
    font-size: 1.25rem;
  }
}

.mobile-only {
  display: none;
}

@media (max-width: 1023px) {
  .mobile-only {
    display: flex;
  }
}
