/* shadcn-inspired NCE UI — Minimal black & white design system */
:root {
  /* Core colors - Pure black and white */
  --white: #ffffff;
  --black: #000000;
  
  /* Gray scale for nuanced surfaces */
  --gray-50: #fafafa;
  --gray-100: #f4f4f5;
  --gray-200: #e4e4e7;
  --gray-300: #d4d4d8;
  --gray-400: #a1a1aa;
  --gray-500: #71717a;
  --gray-600: #52525b;
  --gray-700: #3f3f46;
  --gray-800: #27272a;
  --gray-900: #18181b;
  --gray-950: #09090b;
  
  /* Semantic tokens */
  --bg: var(--white);
  --surface: var(--white);
  --card: var(--white);
  --text: var(--gray-950);
  --text-secondary: var(--gray-600);
  --muted: var(--gray-500);
  --border: var(--gray-200);
  --border-light: var(--gray-100);
  --accent: var(--black);
  --accent-hover: var(--gray-900);
  
  /* Effects */
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
  
  /* Spacing & sizing */
  --radius-sm: 0.25rem;
  --radius: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
}

/* Dark mode - inverted palette */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--black);
    --surface: var(--gray-950);
    --card: var(--gray-900);
    --text: var(--gray-50);
    --text-secondary: var(--gray-400);
    --muted: var(--gray-500);
    --border: var(--gray-800);
    --border-light: var(--gray-900);
    --accent: var(--white);
    --accent-hover: var(--gray-100);
    
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.4), 0 1px 2px -1px rgb(0 0 0 / 0.4);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.4), 0 2px 4px -2px rgb(0 0 0 / 0.4);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.5), 0 4px 6px -4px rgb(0 0 0 / 0.5);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.6), 0 8px 10px -6px rgb(0 0 0 / 0.6);
  }
}

*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0;
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "SF Pro Text", "Helvetica Neue", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.container{
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

@media (max-width: 640px) {
  .container { padding: 0 16px; }
}

/* Header / Hero */
.hero {
  padding: 60px 0 32px;
  text-align: center;
}

.hero .brand {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: .1em;
  text-transform: uppercase;
  margin-bottom: 12px;
}

.hero h1 {
  font-size: 56px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -.03em;
  margin: 0 0 16px;
  color: var(--text);
}

.hero .subtitle {
  margin: 0 0 24px;
  font-size: 16px;
  color: var(--text-secondary);
  font-weight: 400;
}

/* Back button */
.back-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s ease;
}

.back-inline:hover {
  background: var(--gray-50);
  border-color: var(--gray-300);
}

.back-inline svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

@media (prefers-color-scheme: dark) {
  .back-inline:hover {
    background: var(--gray-800);
    border-color: var(--gray-700);
  }
}

/* Segmented control - shadcn style tabs */
.segmented {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 1px;
  background: var(--gray-100);
  border-radius: var(--radius-md);
  padding: 2px;
}

.segmented .seg {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  padding: 8px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s ease;
}

.segmented .seg:hover:not(.active) {
  color: var(--text);
}

.segmented .seg.active {
  background: var(--white);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* Tabs variant */
.segmented.tabs {
  background: transparent;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  padding: 0;
  gap: 0;
}

.segmented.tabs .seg {
  padding: 12px 24px;
  border-radius: 0;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.segmented.tabs .seg.active {
  background: transparent;
  border-bottom-color: var(--accent);
  box-shadow: none;
}

@media (prefers-color-scheme: dark) {
  .segmented {
    background: var(--gray-800);
  }
  .segmented .seg.active {
    background: var(--gray-900);
  }
}

@media (max-width: 768px){
  .hero { padding: 48px 0 24px; }
  .hero h1 { font-size: 40px; }
  .hero .subtitle { font-size: 14px; }
}

/* Statistics panel */
.stats-container {
  margin: 24px auto;
  max-width: 800px;
  padding: 20px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 24px;
  text-align: center;
}

.stat-item {
  padding: 12px;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}

.stat-label {
  font-size: 12px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

@media (prefers-color-scheme: dark) {
  .stats-container {
    background: var(--gray-900);
  }
}

/* Book cards grid */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
  padding: 40px 0 60px;
}

.card {
  position: relative;
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: all 0.2s ease;
}

.card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.card img {
  width: 100%;
  height: 180px;
  object-fit: cover;
  display: block;
}

.card .body {
  padding: 20px;
}

.card .title {
  font-weight: 600;
  font-size: 18px;
  margin: 0 0 8px;
  color: var(--text);
}

.card .sub {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.6;
}

/* Lessons grid */
.lessons {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 12px;
  padding: 32px 0 48px;
}

.lesson-item {
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  display: flex;
  gap: 12px;
  align-items: center;
  color: inherit;
  text-decoration: none;
  transition: all 0.15s ease;
  position: relative;
}

.lesson-item:hover {
  background: var(--gray-50);
  box-shadow: var(--shadow);
  transform: translateX(2px);
}

/* Progress indicators */
.lesson-item.completed {
  border-color: var(--gray-400);
  background: var(--gray-50);
}

.lesson-item.completed::after {
  content: '✓';
  position: absolute;
  right: 20px;
  color: var(--gray-600);
  font-weight: 600;
}

.lesson-item.in-progress {
  border-left: 3px solid var(--accent);
}

.lesson-num {
  font-weight: 600;
  color: var(--accent);
  font-size: 14px;
  min-width: 60px;
}

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

.lesson-title {
  flex: 1;
}

@media (prefers-color-scheme: dark) {
  .lesson-item:hover {
    background: var(--gray-800);
  }
  .lesson-item.completed {
    background: var(--gray-900);
  }
}

/* Dictation mode styles */
.sentence.hidden-text .sentence-content {
  filter: blur(8px);
  user-select: none;
  pointer-events: none;
  opacity: 0.3;
  transition: all 0.3s ease;
}

.sentence .reveal-hint {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: var(--gray-900);
  color: var(--white);
  padding: 6px 12px;
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 500;
  box-shadow: var(--shadow);
  pointer-events: none;
  z-index: 1;
}

@media (prefers-color-scheme: light) {
  .sentence .reveal-hint {
    background: var(--gray-700);
  }
}

.sentence.hidden-text {
  cursor: pointer;
  position: relative;
}

.sentence.hidden-text:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--accent);
}

/* Dictation mode indicator */
.dictation-mode .toolbar {
  border-bottom-color: var(--accent);
  border-bottom-width: 2px;
}

/* Lesson page */
.toolbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
}

.toolbar .row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
}

.toolbar .info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.toolbar .title {
  font-weight: 600;
  font-size: 16px;
}

.toolbar .sub {
  font-size: 14px;
  color: var(--text-secondary);
}

.controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Button styles */
.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: var(--radius);
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn:hover {
  background: var(--gray-50);
  box-shadow: var(--shadow-sm);
}

@media (prefers-color-scheme: dark) {
  .btn:hover {
    background: var(--gray-800);
  }
}

.sentences {
  padding: 24px 0 32px;
  max-width: 800px;
  margin: 0 auto;
}

.sentence {
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  margin: 0 0 12px;
  cursor: pointer;
  transition: all 0.15s ease;
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.sentence:hover {
  box-shadow: var(--shadow);
  border-color: var(--gray-300);
}

.sentence.active {
  border-color: var(--accent);
  background: var(--gray-50);
  box-shadow: var(--shadow-md);
}

/* Favorite button */
.favorite-btn {
  appearance: none;
  background: transparent;
  border: none;
  padding: 4px;
  cursor: pointer;
  opacity: 0.4;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.favorite-btn:hover {
  opacity: 0.8;
  transform: scale(1.1);
}

.favorite-btn.active {
  opacity: 1;
}

.favorite-btn svg {
  width: 18px;
  height: 18px;
  fill: var(--gray-400);
}

.favorite-btn.active svg {
  fill: var(--accent);
}

.sentence-content {
  flex: 1;
}

.en {
  font-weight: 500;
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
}

.cn {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 8px;
  line-height: 1.5;
}

.lang-en .cn { display: none; }
.lang-cn .en { display: none; }

@media (prefers-color-scheme: dark) {
  .sentence:hover {
    border-color: var(--gray-700);
  }
  .sentence.active {
    background: var(--gray-900);
  }
}

/* Audio Player */
.player {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0;
}

.player audio {
  display: block;
  flex: 1;
  width: 100%;
  max-width: 600px;
  height: 40px;
  border-radius: var(--radius);
}

/* Player controls */
.player-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
}

/* Timeline container */
.timeline-container {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  max-width: 500px;
}

.timeline {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  background: var(--gray-200);
  border-radius: 3px;
  outline: none;
  cursor: pointer;
}

.timeline::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.15s ease;
}

.timeline::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

.timeline::-moz-range-thumb {
  width: 14px;
  height: 14px;
  background: var(--accent);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.15s ease;
}

.timeline::-moz-range-thumb:hover {
  transform: scale(1.2);
}

.time-display {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.volume-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 80px;
  height: 6px;
  background: var(--gray-200);
  border-radius: 3px;
  outline: none;
  cursor: pointer;
}

.volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.15s ease;
}

.volume-slider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

.volume-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  background: var(--accent);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.15s ease;
}

.volume-slider::-moz-range-thumb:hover {
  transform: scale(1.2);
}

@media (prefers-color-scheme: dark) {
  .timeline,
  .volume-slider {
    background: var(--gray-700);
  }
}

.control-btn {
  appearance: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s ease;
}

.control-btn:hover {
  background: var(--gray-50);
  box-shadow: var(--shadow-sm);
}

.control-btn.active {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}

.control-btn svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.speed-select {
  appearance: none;
  padding: 6px 12px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.speed-select:hover {
  background: var(--gray-50);
  box-shadow: var(--shadow-sm);
}

@media (prefers-color-scheme: dark) {
  .control-btn:hover {
    background: var(--gray-800);
  }
  .speed-select:hover {
    background: var(--gray-800);
  }
}

/* Hide native audio controls */
audio {
  display: none;
}

/* Lesson bottom navigation */
.lesson-nav {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 24px 0 32px;
  max-width: 800px;
  margin: 0 auto;
}

.btn-nav {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 20px;
  min-width: 120px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  transition: all 0.15s ease;
}

.btn-nav:hover {
  background: var(--gray-50);
  box-shadow: var(--shadow);
  transform: translateX(3px);
}

.btn-nav.prev:hover {
  transform: translateX(-3px);
}

@media (prefers-color-scheme: dark) {
  .btn-nav:hover {
    background: var(--gray-800);
  }
}

/* Notification toast */
.notification {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(-100px);
  background: var(--gray-900);
  color: var(--white);
  padding: 12px 24px;
  border-radius: var(--radius-lg);
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  opacity: 0;
  transition: all 0.3s ease;
  pointer-events: none;
}

.notification.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

@media (prefers-color-scheme: light) {
  .notification {
    background: var(--gray-800);
  }
}

/* Keyboard help tooltip */
.help-tooltip {
  position: absolute;
  top: calc(100% + 12px);
  right: 0;
  z-index: 100;
  width: 280px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px) scale(0.95);
  transition: all 0.2s ease;
  pointer-events: none;
}

.help-tooltip.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.help-tooltip-arrow {
  position: absolute;
  top: -5px;
  right: 48px;
  width: 10px;
  height: 10px;
  background: var(--card);
  border-top: 1px solid var(--border);
  border-left: 1px solid var(--border);
  transform: rotate(45deg);
}

.help-tooltip-content {
  padding: 16px;
  position: relative;
  z-index: 1;
}

.help-tooltip-title {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 12px;
  color: var(--text);
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.help-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.help-item {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: var(--text-secondary);
}

.help-item kbd {
  min-width: 40px;
  text-align: center;
}

.help-item span {
  flex: 1;
}

kbd {
  display: inline-block;
  padding: 3px 8px;
  font-size: 11px;
  font-family: monospace;
  background: var(--gray-100);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: 0 1px 0 var(--gray-200);
  color: var(--text);
  font-weight: 600;
}

@media (prefers-color-scheme: dark) {
  .help-tooltip {
    background: var(--gray-900);
  }
  .help-tooltip-arrow {
    background: var(--gray-900);
  }
  kbd {
    background: var(--gray-800);
    box-shadow: 0 1px 0 var(--gray-700);
  }
}

/* Position adjustment for player controls */
.player {
  position: relative;
}

/* Mobile adjustments */
@media (max-width: 640px) {
  .help-tooltip {
    right: auto;
    left: 50%;
    transform: translateX(-50%) translateY(-8px) scale(0.95);
    width: 260px;
  }
  
  .help-tooltip.show {
    transform: translateX(-50%) translateY(0) scale(1);
  }
  
  .help-tooltip-arrow {
    right: 50%;
    transform: translateX(50%) rotate(45deg);
  }
}

/* Footer */
footer {
  padding: 48px 0 32px;
  color: var(--text-secondary);
  text-align: center;
  border-top: 1px solid var(--border);
  margin-top: 48px;
}

footer p {
  margin: 8px 0;
  font-size: 14px;
}

.repo {
  margin-bottom: 12px;
}

.byline,
.thanks {
  font-size: 13px;
  color: var(--muted);
}

/* Links */
a {
  color: inherit;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.back-inline:hover,
.btn:hover,
.btn-nav:hover,
.lesson-item:hover {
  text-decoration: none;
}

/* GitHub icon link */
.gh-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  transition: all 0.15s ease;
}

.gh-link:hover {
  background: var(--gray-50);
  box-shadow: var(--shadow-sm);
  text-decoration: none;
}

.gh-link svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

@media (prefers-color-scheme: dark) {
  .gh-link:hover {
    background: var(--gray-800);
  }
}

/* Smooth theme transitions */
* {
  transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

/* Focus states */
button:focus-visible,
a:focus-visible,
.seg:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Selection */
::selection {
  background: var(--accent);
  color: var(--bg);
}
