:root {
  --primary: #1e3a5f;
  --primary-light: #2d5a8a;
  --primary-soft: #eef4fb;
  --accent: #f59e0b;
  --accent-hover: #d97706;
  --success: #10b981;
  --danger: #ef4444;
  --bg: #faf9f7;
  --card: #ffffff;
  --card-soft: #f8fafc;
  --text: #1a1f2e;
  --muted: #6b7280;
  --border: #e5e7eb;
  --border-strong: #d7dde7;
  --shadow: 0 2px 12px rgba(30, 58, 95, 0.08);
  --shadow-lg: 0 8px 32px rgba(30, 58, 95, 0.12);
  --radius: 12px;
}

[data-theme="dark"] {
  --primary: #9cc3ee;
  --primary-light: #bfdbfe;
  --primary-soft: #172235;
  --accent: #fbbf24;
  --accent-hover: #f59e0b;
  --success: #34d399;
  --danger: #f87171;
  --bg: #0f172a;
  --card: #1e293b;
  --card-soft: #172033;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --border: #334155;
  --border-strong: #475569;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.30);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.42);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Sans SC", "PingFang SC", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.6;
  transition: background 0.2s, color 0.2s;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.app-shell {
  width: min(1100px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0 48px;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  padding: 0 0 28px;
}

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

.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: #ffffff;
  background: var(--primary);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 24px;
  font-weight: 700;
  box-shadow: var(--shadow);
}

.brand-copy h1 {
  color: var(--primary);
  font-size: 28px;
  line-height: 1.1;
  letter-spacing: 0;
}

.brand-copy p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.control-pill,
.icon-btn {
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(30, 58, 95, 0.04);
}

.control-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  min-width: 116px;
  font-weight: 700;
}

select.control-pill {
  appearance: none;
  padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}

.auto-pill input {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
}

.icon-btn {
  width: 44px;
  padding: 0;
  display: grid;
  place-items: center;
  color: var(--accent);
  font-size: 18px;
}

.settings-panel {
  display: grid;
  grid-template-columns: minmax(160px, 220px) minmax(220px, 280px) auto 1fr;
  align-items: end;
  gap: 12px;
  margin: -6px 0 18px;
}

.settings-panel label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

select:not(.control-pill),
input[type="search"],
input[type="text"] {
  width: 100%;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0 12px;
  background: var(--card);
  color: var(--text);
  outline: none;
  box-shadow: 0 1px 3px rgba(30, 58, 95, 0.03);
}

select:focus,
input:focus {
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(45, 90, 138, 0.12);
}

.range-field {
  grid-template-columns: 1fr;
}

.range-field input {
  width: 100%;
  accent-color: var(--primary);
}

.range-field output {
  color: var(--primary);
  font-weight: 700;
}

.today-mini {
  min-width: 112px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  color: var(--muted);
  font-weight: 700;
}

.today-mini strong {
  color: var(--primary);
  font-size: 18px;
}

.sync-state {
  justify-self: end;
  color: var(--muted);
  font-size: 12px;
}

.sync-state.ok {
  color: var(--success);
}

.sync-state.error {
  color: var(--danger);
}

.tab-bar {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 6px;
  padding: 6px;
  margin-bottom: 22px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-x: auto;
}

.tab-btn {
  min-width: 116px;
  height: 48px;
  border: 0;
  border-radius: 9px;
  color: var(--muted);
  background: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 700;
  white-space: nowrap;
  transition: background 0.18s, color 0.18s, transform 0.18s;
}

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

.tab-btn.active {
  color: #ffffff;
  background: #1f416d;
}

.tab-content {
  display: none;
  animation: fade-in 0.22s ease;
}

.tab-content.active {
  display: block;
}

@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.course-card,
.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.course-card {
  display: flex;
  align-items: center;
  gap: 28px;
  min-height: 146px;
  padding: 22px 26px;
  margin-bottom: 16px;
}

.progress-ring {
  position: relative;
  width: 124px;
  height: 124px;
  flex: 0 0 124px;
}

.progress-ring svg {
  width: 124px;
  height: 124px;
}

.ring-bg,
.ring-fill {
  fill: none;
  stroke-width: 10;
}

.ring-bg {
  stroke: #e5e7eb;
}

[data-theme="dark"] .ring-bg {
  stroke: #334155;
}

.ring-fill {
  stroke: var(--accent);
  stroke-linecap: round;
  transform: rotate(-90deg);
  transform-origin: 50% 50%;
  stroke-dasharray: 301.59;
  stroke-dashoffset: 301.59;
  transition: stroke-dashoffset 0.4s ease;
}

.ring-text {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
}

.ring-text strong {
  color: var(--primary);
  font-size: 28px;
  line-height: 1;
}

.ring-text span {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.course-copy h2 {
  color: var(--primary);
  font-size: 27px;
  line-height: 1.25;
  letter-spacing: 0;
}

.course-copy p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.step-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.step-pill {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card-soft);
  color: var(--muted);
  font-weight: 700;
}

.video-hero {
  position: relative;
  min-height: 260px;
  margin-bottom: 16px;
  padding: 28px;
  overflow: hidden;
  border-radius: var(--radius);
  background: linear-gradient(135deg, #1e3a5f 0%, #2d5a8a 100%);
  color: #ffffff;
  box-shadow: var(--shadow-lg);
}

.video-hero::after {
  content: "";
  position: absolute;
  right: -68px;
  top: -76px;
  width: 230px;
  height: 230px;
  background: rgba(255, 255, 255, 0.08);
  transform: rotate(22deg);
}

.video-hero > div {
  position: relative;
  z-index: 1;
}

.video-hero h2 {
  font-size: 21px;
  margin-bottom: 10px;
}

.video-hero p {
  max-width: 620px;
  color: rgba(255, 255, 255, 0.88);
  font-weight: 700;
}

.video-hero ul {
  margin: 22px 0 0;
  padding-left: 22px;
  color: rgba(255, 255, 255, 0.88);
  font-size: 15px;
  font-weight: 650;
}

.accent-btn {
  min-height: 44px;
  margin-top: 18px;
  padding: 0 22px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #ffffff;
  font-size: 16px;
  font-weight: 800;
  box-shadow: 0 8px 18px rgba(245, 158, 11, 0.22);
}

.accent-btn:hover {
  background: var(--accent-hover);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.panel {
  padding: 20px;
  margin-bottom: 16px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
  margin-bottom: 16px;
}

.panel-head h2 {
  color: var(--primary);
  font-size: 18px;
}

.panel-head h3 {
  color: var(--primary);
}

.panel-head p {
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}

.stack {
  display: grid;
  gap: 10px;
}

.learn-card,
.sentence-card,
.quiz-card,
.review-placeholder {
  background: var(--card-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
}

.learn-card {
  display: grid;
  gap: 5px;
  width: 100%;
  color: inherit;
  text-align: left;
}

.learn-card:hover,
.sentence-card:hover,
.quiz-card:hover {
  border-color: var(--primary-light);
  box-shadow: 0 6px 18px rgba(30, 58, 95, 0.08);
}

.learn-card strong,
.sentence-card strong {
  color: var(--primary);
  font-size: 16px;
}

.learn-card span,
.sentence-card p {
  color: var(--text);
}

.learn-card small,
.sentence-card small {
  color: var(--muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.badge-green {
  color: #047857;
  background: #e9f8f2;
}

.badge-amber {
  color: #a16207;
  background: #fff7e6;
}

[data-theme="dark"] .badge-green {
  color: var(--success);
  background: rgba(16, 185, 129, 0.12);
}

[data-theme="dark"] .badge-amber {
  color: var(--accent);
  background: rgba(245, 158, 11, 0.14);
}

.primary-btn,
.ghost-btn,
.danger-btn,
.speak-btn,
.pager button,
.tag-wrap button,
.quiz-options button {
  min-height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  padding: 0 13px;
  color: var(--text);
  background: var(--card);
  font-weight: 700;
  transition: background 0.16s, border-color 0.16s, color 0.16s;
}

.primary-btn {
  color: #ffffff;
  border-color: var(--primary);
  background: #1f416d;
}

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

.ghost-btn:hover,
.speak-btn:hover,
.pager button:hover,
.tag-wrap button:hover,
.quiz-options button:hover {
  color: var(--primary);
  border-color: var(--primary-light);
  background: var(--primary-soft);
}

.danger-btn {
  color: #ffffff;
  border-color: var(--danger);
  background: var(--danger);
}

.segmented {
  display: inline-flex;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card-soft);
}

.segmented button {
  min-width: 64px;
  height: 32px;
  border: 0;
  border-radius: 7px;
  color: var(--muted);
  background: transparent;
  font-weight: 700;
}

.segmented button.active {
  color: #ffffff;
  background: #1f416d;
}

.phonetic-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 8px;
}

.phonetic-item {
  min-height: 78px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card-soft);
  padding: 10px 6px;
  text-align: center;
  color: var(--text);
  transition: border-color 0.16s, background 0.16s, transform 0.16s;
}

.phonetic-item:hover {
  border-color: var(--primary-light);
  background: var(--primary-soft);
  transform: translateY(-1px);
}

.phonetic-symbol {
  color: var(--primary);
  font-size: 23px;
  font-weight: 900;
}

.phonetic-desc,
.phonetic-word {
  color: var(--muted);
  font-size: 12px;
}

.quiz-block {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.quiz-card p {
  margin-bottom: 12px;
  color: var(--text);
  font-weight: 700;
}

.quiz-card small {
  display: block;
  margin: 6px 0 12px;
  color: var(--muted);
}

.quiz-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.filter-line {
  display: grid;
  gap: 12px;
  margin-bottom: 14px;
}

.tag-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag-wrap button.active {
  color: #ffffff;
  border-color: #1f416d;
  background: #1f416d;
}

.sentence-list {
  display: grid;
  gap: 10px;
  min-height: 260px;
}

.sentence-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
}

.sentence-card p {
  margin-top: 4px;
}

.sentence-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.sentence-meta span {
  color: var(--primary-light);
  font-size: 12px;
  font-weight: 700;
}

.speak-btn {
  width: 38px;
  padding: 0;
}

.pager {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  color: var(--muted);
}

.video-box {
  display: grid;
  place-items: center;
  min-height: 320px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--card-soft);
  color: var(--muted);
  text-align: center;
  padding: 28px;
}

.video-box h3 {
  color: var(--primary);
  font-size: 20px;
  margin-bottom: 8px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.stat-tile {
  min-height: 120px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card-soft);
}

.stat-tile span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.stat-tile strong {
  display: block;
  margin-top: 10px;
  color: var(--primary);
  font-size: 32px;
  line-height: 1;
}

.spell-form {
  display: flex;
  gap: 8px;
}

.spell-form input {
  flex: 1;
}

.empty {
  color: var(--muted);
  padding: 24px;
  text-align: center;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(16px);
  max-width: min(420px, calc(100% - 32px));
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--text);
  color: var(--card);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}

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

@media (max-width: 900px) {
  .settings-panel,
  .dashboard-grid,
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .sync-state {
    justify-self: start;
  }

  .tab-bar {
    display: flex;
  }

  .course-card {
    align-items: flex-start;
  }

  .phonetic-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .app-shell {
    width: min(100% - 24px, 1100px);
    padding-top: 20px;
  }

  .app-header,
  .panel-head,
  .sentence-card,
  .course-card {
    display: grid;
    grid-template-columns: 1fr;
  }

  .header-actions {
    justify-content: flex-start;
  }

  .course-card {
    justify-items: center;
    text-align: center;
  }

  .step-row {
    justify-content: center;
  }

  .phonetic-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .spell-form {
    flex-direction: column;
  }
}
