/* --- Luika Design Language & Token Architecture --- */
:root {
  /* Luika Typography */
  --font-display: "Cormorant Garamond", Georgia, "Times New Roman", serif;
  --font-body: "DM Sans", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;

  /* Luika Color Tokens */
  --color-bone: #f8f5f0;
  --color-bone-deep: #efe9df;
  --color-sand: #e7e2da;
  --color-paper: #ffffff;
  --color-ink: #2c3e50;
  --color-ink-soft: #34495e;
  --color-umber: #3e5468;
  --color-mute: #5d6d7e;
  --color-terra: #3caea3;
  --color-terra-deep: #2e8c82;
  --color-terra-soft: #6fc5bc;
  --color-amber: #3caea3;
  --color-terracotta: #c14c30;
  --color-terracotta-deep: #a33d24;

  /* Semantic Theme Mappings: Light Mode (Organic Bone & Slate) */
  --bg-app: var(--color-bone);
  --bg-surface: var(--color-paper);
  --bg-surface-elevated: var(--color-paper);
  --bg-sidebar: #fbf9f6;
  --bg-card: var(--color-paper);
  --bg-hover: var(--color-bone-deep);
  --bg-active: var(--color-sand);
  
  --border-subtle: var(--color-sand);
  --border-medium: #d8d1c5;
  --border-focus: var(--color-terra);
  
  --text-main: var(--color-ink);
  --text-muted: var(--color-mute);
  --text-subtle: #7f8c8d;
  --text-inverse: var(--color-paper);
  
  --primary: var(--color-ink);
  --primary-hover: var(--color-ink-soft);
  --primary-light: rgba(44, 62, 80, 0.08);
  
  --accent-terra: var(--color-terra);
  --accent-terra-light: rgba(60, 174, 163, 0.15);
  --accent-terracotta: var(--color-terracotta);
  --accent-terracotta-light: rgba(193, 76, 48, 0.12);

  --shadow-sm: 0 1px 3px 0 rgba(44, 62, 80, 0.04), 0 1px 2px -1px rgba(44, 62, 80, 0.03);
  --shadow-md: 0 4px 6px -1px rgba(44, 62, 80, 0.06), 0 2px 4px -2px rgba(44, 62, 80, 0.04);
  --shadow-lg: 0 10px 15px -3px rgba(44, 62, 80, 0.08), 0 4px 6px -4px rgba(44, 62, 80, 0.04);
  --shadow-xl: 0 20px 25px -5px rgba(44, 62, 80, 0.1), 0 8px 10px -6px rgba(44, 62, 80, 0.05);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-2xl: 24px;
  --radius-full: 9999px;

  --header-height: 72px;
  --app-footer-height: 2.25rem;
  --sidebar-width: 320px;
  --transition-fast: 0.15s cubic-bezier(0.16, 1, 0.3, 1);
  --transition-normal: 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

[data-theme="dark"] {
  /* Luika Dark Mode */
  --bg-app: #151d27;
  --bg-surface: #1d2734;
  --bg-surface-elevated: #243142;
  --bg-sidebar: #18212d;
  --bg-card: #1d2734;
  --bg-hover: #263445;
  --bg-active: #314257;
  
  --border-subtle: #2a3b4e;
  --border-medium: #384d66;
  --border-focus: var(--color-terra);
  
  --text-main: #f8f5f0;
  --text-muted: #a3b1c2;
  --text-subtle: #6c7d93;
  --text-inverse: #151d27;
  
  --primary: #f8f5f0;
  --primary-hover: #efe9df;
  --primary-light: rgba(248, 245, 240, 0.08);
  
  --color-terra: #4ecdc4;
  --color-terra-deep: #3caea3;
  --color-terra-soft: #7ee0d8;
  
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.6);
}

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

html {
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
  color: var(--text-main);
  background-color: var(--bg-app);
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  background-color: var(--bg-app);
  padding-bottom: calc(var(--app-footer-height) + env(safe-area-inset-bottom, 0px));
}

h1, h2, h3, .font-display {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: -0.015em;
  color: var(--text-main);
}

::selection {
  background: var(--color-terra);
  color: #FFFFFF;
}

/* Custom Luika Scrollbars */
::-webkit-scrollbar {
  width: 9px;
  height: 9px;
}
::-webkit-scrollbar-track {
  background: var(--bg-app);
}
::-webkit-scrollbar-thumb {
  background: var(--border-medium);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--color-mute);
}

/* App Header */
#app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: calc(var(--header-height) + env(safe-area-inset-top, 0px));
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: env(safe-area-inset-top, 0px) max(2rem, env(safe-area-inset-right, 0px)) 0 max(2rem, env(safe-area-inset-left, 0px));
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(16px);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.brand-badge {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  min-width: 0;
}

.brand-logo-icon {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-md);
  background: var(--color-ink);
  color: var(--color-terra);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.4rem;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-medium);
  transition: transform var(--transition-fast);
}

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

.brand-text h1 {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.15;
  color: var(--text-main);
  letter-spacing: -0.01em;
}

.brand-text p {
  font-family: var(--font-body);
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: 0.02em;
}

.header-center {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex: 1;
  max-width: 500px;
  margin: 0 2.5rem;
}

.course-progress-container {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.progress-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
}

.progress-bar-track {
  width: 100%;
  height: 6px;
  background-color: var(--bg-hover);
  border-radius: var(--radius-full);
  overflow: hidden;
  position: relative;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--color-terra) 0%, var(--color-terra-deep) 100%);
  width: 0%;
  transition: width 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  border-radius: var(--radius-full);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  flex-shrink: 0;
}

.lang-switch {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  background: var(--bg-hover);
  overflow: hidden;
  flex-shrink: 0;
}

.lang-btn {
  min-width: 36px;
  height: 32px;
  padding: 0 0.65rem;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  cursor: pointer;
}

.lang-btn.is-on {
  background: var(--color-ink);
  color: var(--color-bone);
}

.lms-pack .lang-switch {
  margin: 0 0 1.25rem;
}

.nav-toggle {
  display: none;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  background: var(--bg-surface);
  color: var(--text-main);
  cursor: pointer;
}

.nav-toggle:hover,
.nav-toggle:focus-visible {
  background: var(--bg-hover);
  border-color: var(--border-medium);
  outline: none;
}

.nav-toggle-bars,
.nav-toggle-bars::before,
.nav-toggle-bars::after {
  display: block;
  width: 16px;
  height: 2px;
  background: currentColor;
  border-radius: 1px;
  position: relative;
}

.nav-toggle-bars::before,
.nav-toggle-bars::after {
  content: "";
  position: absolute;
  left: 0;
}

.nav-toggle-bars::before {
  top: -5px;
}

.nav-toggle-bars::after {
  top: 5px;
}

body.nav-open .nav-toggle-bars {
  background: transparent;
}

body.nav-open .nav-toggle-bars::before {
  top: 0;
  transform: rotate(45deg);
}

body.nav-open .nav-toggle-bars::after {
  top: 0;
  transform: rotate(-45deg);
}

.nav-backdrop {
  display: none;
}

.sidebar-mobile-head {
  display: none;
}

/* Quick Search Button */
.search-trigger-btn {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 1rem;
  background: var(--bg-hover);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  color: var(--text-muted);
  font-size: 0.84rem;
  cursor: pointer;
  transition: var(--transition-fast);
}

.search-trigger-icon {
  line-height: 1;
}

.search-trigger-btn:hover {
  background: var(--bg-active);
  color: var(--text-main);
  border-color: var(--border-medium);
}

.search-kbd {
  font-size: 0.68rem;
  padding: 2px 6px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  font-family: var(--font-mono);
  font-weight: 600;
}

/* Luika Buttons */
.btn-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition-fast);
}

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

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.65rem 1.35rem;
  background: var(--color-ink);
  color: var(--color-bone);
  border: 1px solid var(--color-ink);
  border-radius: var(--radius-full);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  transition: var(--transition-fast);
  box-shadow: var(--shadow-sm);
  text-decoration: none;
}

[data-theme="dark"] .btn-primary {
  background: var(--color-terra);
  color: var(--color-ink);
  border-color: var(--color-terra);
}

.btn-primary:hover {
  background: var(--color-terra-deep);
  color: #FFFFFF;
  border-color: var(--color-terra-deep);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.65rem 1.35rem;
  background: var(--bg-hover);
  color: var(--text-main);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  transition: var(--transition-fast);
  text-decoration: none;
}

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

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

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-full);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.badge-purple {
  background: rgba(44, 62, 80, 0.08);
  color: var(--color-ink);
  border: 1px solid var(--border-subtle);
}

[data-theme="dark"] .badge-purple {
  background: rgba(248, 245, 240, 0.1);
  color: var(--color-bone);
}

.badge-blue {
  background: rgba(60, 174, 163, 0.15);
  color: var(--color-terra-deep);
}

[data-theme="dark"] .badge-blue {
  background: rgba(78, 205, 196, 0.2);
  color: var(--color-terra);
}

.badge-emerald {
  background: rgba(60, 174, 163, 0.15);
  color: var(--color-terra-deep);
}

.badge-amber {
  background: rgba(193, 76, 48, 0.12);
  color: var(--color-terracotta);
}

.badge-rose {
  background: rgba(193, 76, 48, 0.15);
  color: var(--color-terracotta-deep);
}

/* App Main Container */
#app-container {
  display: flex;
  flex: 1;
  min-height: calc(100vh - var(--header-height) - var(--app-footer-height));
  position: relative;
}

.app-footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 90;
  height: calc(var(--app-footer-height) + env(safe-area-inset-bottom, 0px));
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 1rem env(safe-area-inset-bottom, 0px);
  background: var(--bg-sidebar);
  border-top: 1px solid var(--border-subtle);
}

.app-footer p,
.app-footer .app-version-link {
  margin: 0;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-subtle);
  text-decoration: none;
  pointer-events: auto;
}

.app-footer .app-version-link:hover,
.app-footer .app-version-link:focus-visible {
  color: var(--text-main);
  text-decoration: underline;
}

.app-footer .app-version-link {
  cursor: pointer;
}

body.forum-drawer-open .app-footer {
  display: none;
}

/* Sidebar Navigation */
#sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-subtle);
  overflow-y: auto;
  max-height: calc(100dvh - var(--header-height) - env(safe-area-inset-top, 0px));
  position: sticky;
  top: calc(var(--header-height) + env(safe-area-inset-top, 0px));
  display: flex;
  flex-direction: column;
}

.sidebar-section {
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--border-subtle);
}

.sidebar-title {
  padding: 0.25rem 1.5rem 0.5rem;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-subtle);
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 1.5rem;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.86rem;
  font-weight: 500;
  transition: var(--transition-fast);
  cursor: pointer;
  border-left: 3px solid transparent;
}

.nav-link:hover {
  background: var(--bg-hover);
  color: var(--text-main);
}

.nav-link.active {
  background: var(--bg-hover);
  color: var(--text-main);
  font-weight: 600;
  border-left-color: var(--color-terra);
}

/* Module Accordions */
.module-accordion {
  margin-bottom: 0.2rem;
}

.module-header-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.55rem 1.5rem;
  background: none;
  border: none;
  color: var(--text-main);
  font-size: 0.84rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: var(--transition-fast);
}

.module-header-btn:hover {
  background: var(--bg-hover);
}

.module-meta-left {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex: 1;
  overflow: hidden;
}

.module-num-badge {
  width: 22px;
  height: 22px;
  min-width: 22px;
  border-radius: var(--radius-sm);
  background: var(--bg-hover);
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.module-accordion.completed .module-num-badge {
  background: var(--accent-terra-light);
  color: var(--color-terra-deep);
}

.module-title-truncate {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

.module-chevron {
  font-size: 0.75rem;
  color: var(--text-subtle);
  transition: transform var(--transition-fast);
}

.module-accordion.open .module-chevron {
  transform: rotate(90deg);
}

.module-subnav {
  display: none;
  background: var(--bg-app);
  padding: 0.25rem 0;
  border-left: 2px solid var(--border-subtle);
  margin-left: 1.75rem;
}

.module-accordion.open .module-subnav {
  display: block;
}

.lesson-sublink {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.4rem 1.25rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-decoration: none;
  transition: var(--transition-fast);
}

.lesson-sublink:hover {
  color: var(--text-main);
  background: var(--bg-hover);
}

.lesson-sublink.active {
  color: var(--text-main);
  font-weight: 700;
  border-left: 2px solid var(--color-terra);
  background: var(--bg-hover);
}

.lesson-status-icon {
  font-size: 0.75rem;
  color: var(--text-subtle);
}

.lesson-sublink.completed .lesson-status-icon {
  color: var(--color-terra);
}

/* Main Viewport Content */
#main-content {
  flex: 1;
  min-width: 0;
  padding: 3rem 3.5rem;
  max-width: 1260px;
  margin: 0 auto;
  width: 100%;
}

button,
a,
.nav-link,
.lesson-sublink,
.tab-btn {
  touch-action: manipulation;
}

/* Compact / phone chrome */
@media (max-width: 1024px) {
  :root {
    --header-height: 60px;
  }

  .nav-toggle {
    display: inline-flex;
  }

  #app-header {
    padding-left: max(0.85rem, env(safe-area-inset-left, 0px));
    padding-right: max(0.85rem, env(safe-area-inset-right, 0px));
    gap: 0.6rem;
  }

  .header-left {
    gap: 0.6rem;
    min-width: 0;
  }

  .brand-text h1 {
    font-size: 0.98rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 11.5rem;
  }

  .brand-text p {
    display: none;
  }

  .header-center {
    display: none;
  }

  .header-right {
    gap: 0.4rem;
  }

  .search-trigger-label,
  .search-kbd,
  .header-cert-label {
    display: none;
  }

  .search-trigger-btn {
    width: 40px;
    height: 40px;
    padding: 0;
    justify-content: center;
    border-radius: var(--radius-full);
  }

  .header-cert-btn {
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: var(--radius-full);
  }

  .nav-backdrop:not([hidden]) {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 98;
    background: rgba(21, 29, 39, 0.45);
  }

  #sidebar {
    display: flex;
    position: fixed;
    left: 0;
    top: calc(var(--header-height) + env(safe-area-inset-top, 0px));
    bottom: calc(var(--app-footer-height) + env(safe-area-inset-bottom, 0px));
    z-index: 99;
    width: min(var(--sidebar-width), 88vw);
    min-width: 0;
    max-height: none;
    height: auto;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    transform: translateX(-105%);
    transition: transform var(--transition-normal);
    box-shadow: none;
    overscroll-behavior: contain;
  }

  #sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: var(--shadow-xl);
  }

  .sidebar-mobile-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.85rem 1rem 0.85rem 1.25rem;
    border-bottom: 1px solid var(--border-subtle);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-subtle);
  }

  .nav-link,
  .module-header-btn,
  .lesson-sublink {
    min-height: 44px;
  }

  .module-title-truncate {
    max-width: 16rem;
  }

  body.nav-open {
    overflow: hidden;
  }

  #main-content {
    padding: 1.5rem 1.25rem 2.5rem;
  }
}

@media (max-width: 768px) {
  .brand-logo-icon {
    width: 36px;
    height: 36px;
    font-size: 1.2rem;
  }

  .brand-text {
    display: none;
  }

  .header-cert-btn {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  #sidebar {
    transition: none;
  }

  body.nav-open .nav-toggle-bars::before,
  body.nav-open .nav-toggle-bars::after {
    transition: none;
  }
}

@media print {
  .lang-switch,
  .nav-toggle,
  .nav-backdrop,
  .sidebar-mobile-head {
    display: none !important;
  }

  #sidebar {
    display: none !important;
  }
}
