:root {
  --background: #121212;
  --surface: #1e1e1e;
  --surface-elevated: #2a2a2a;
  --text-primary: #e4e4e4;
  --text-secondary: #a0a0a0;
  --accent: #c00b95;
  --success: #4caf50;
  --error: #ef5350;
  --warning: #ffb74d;
  --border: #333333;
}

[data-theme="light"] {
  --background: #eceff1;
  --surface: #e3e6e9;
  --surface-elevated: #ffffff;
  --text-primary: #222831;
  --text-secondary: #5c6773;
  --accent: #c00b95;
  --success: #2e7d32;
  --error: #c62828;
  --warning: #ef6c00;
  --border: #d6dde3;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background-color: var(--background);
  color: var(--text-primary);
  line-height: 1.6;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.emphasis {
  color: var(--accent);
  font-weight: 700;
}

.container {
  max-width: 1000px;
  margin: 0 auto;
  padding: 2rem;
}

.site-footer {
  max-width: 1000px;
  margin: 0 auto;
  padding: 1rem 2rem 2rem;
  color: var(--text-secondary);
  border-top: 1px solid var(--border);
  font-size: 0.9rem;
}

.home-repository-link {
  margin-top: 2rem;
}

.home-book-section {
  margin-top: 2rem;
  padding: 1rem 1.2rem;
  border-left: 4px solid var(--accent);
  background-color: var(--surface-elevated);
  border-radius: 6px;
}

.home-book-section p {
  margin: 0;
  font-weight: 600;
  color: var(--text-primary);
}

.home-book-section a {
  font-weight: 700;
}

.offline-actions {
  display: flex;
  gap: 0.8rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.offline-guide pre {
  display: inline-block;
  width: auto;
  max-width: 100%;
  background-color: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.7rem 0.8rem;
  overflow-x: auto;
}

.card {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

button {
  background-color: var(--accent);
  color: white;
  border: none;
  padding: 0.6rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 500;
}

button:hover {
  opacity: 0.9;
}

header {
  background-color: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 1rem 2rem;
}

.header-content {
  max-width: 1000px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

.header-title {
  display: flex;
  flex-direction: column;
}

.header-title strong {
  font-size: 1rem;
}

.header-title span {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.header-actions {
  display: flex;
  align-items: center;
}

.mobile-menu-toggle {
  display: none;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 0.55rem 0.9rem;
  cursor: pointer;
}

.mobile-menu-icon {
  display: inline-flex;
  flex-direction: column;
  gap: 4px;
}

.mobile-menu-icon span {
  display: block;
  width: 18px;
  height: 2px;
  background-color: currentColor;
  border-radius: 999px;
}

.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 0.4rem 0.8rem;
}

.problem-description {
  background-color: var(--surface-elevated);
  border: 1px solid var(--border);
  padding: 1rem;
  border-radius: 6px;
  color: var(--text-primary);
  white-space: normal;
  line-height: 1.5;
}

.problem-description p {
  margin: 0;
}

.problem-description code {
  white-space: normal;
}

.problem-block + .problem-block {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.problem-block h4 {
  margin: 0 0 0.6rem;
}

.problem-suggestion-line {
  margin: 0;
}

.problem-examples,
.problem-params {
  display: grid;
  gap: 0.6rem;
}

.problem-example-item,
.problem-param-item,
.problem-return-item {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.7rem 0.8rem;
}

.problem-param-item header {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.problem-param-item p,
.problem-return-item p {
  margin-top: 0.45rem;
}

.problem-param-item header {
  padding: 0.2rem 0;
}

.type-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.type-tag {
  background-color: rgba(100, 181, 246, 0.15);
  border: 1px solid rgba(100, 181, 246, 0.45);
  color: var(--text-primary);
  border-radius: 999px;
  padding: 0.1rem 0.55rem;
  font-size: 0.8rem;
  line-height: 1.5;
}

.brand-link {
  display: flex;
  align-items: center;
  text-decoration: none;
  color: inherit;
  border-radius: 8px;
  padding: 0.4rem 0.6rem;
  transition: background-color 0.2s ease, transform 0.15s ease;
}

.brand-link:hover {
  background-color: var(--surface-elevated);
  transform: translateY(-1px);
  text-decoration: none;
}

.brand-link:active {
  transform: translateY(0);
}

.brand-link:hover .header-title strong {
  color: var(--accent);
}

.header-navigation {
  display: flex;
  align-items: center;
  gap: 1.2rem;
}

.nav-link {
  text-decoration: none;
  color: var(--text-primary);
  font-weight: 500;
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  transition: background-color 0.2s ease;
}

.nav-link:hover {
  background-color: var(--surface-elevated);
  text-decoration: none;
}

.dropdown {
  position: relative;
}

.dropdown-toggle {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  cursor: pointer;
}

.dropdown-menu {
  position: absolute;
  top: 110%;
  right: 0;
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  min-width: 160px;
  display: none;
  flex-direction: column;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  z-index: 100;
}

.dropdown-menu a {
  padding: 0.6rem 0.8rem;
  color: var(--text-primary);
  text-decoration: none;
  transition: background-color 0.2s ease;
}

.dropdown-menu a:hover {
  background-color: var(--surface-elevated);
}

.dropdown.open .dropdown-menu {
  display: flex;
}

.hero {
  margin-bottom: 3rem;
}

.hero h1 {
  margin-top: 0;
  margin-bottom: 0.5rem;
}

.hero-subtitle {
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

.hero-actions {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.hero-quote {
  margin-top: 1rem;
  color: var(--text-secondary);
}

.button-secondary {
  background-color: transparent;
  border: 1px solid var(--border);
  padding: 0.6rem 1rem;
  border-radius: 6px;
  color: var(--text-primary);
  text-decoration: none;
}

.button-secondary:hover {
  background-color: var(--surface-elevated);
}

.exercise-actions {
  display: flex;
  gap: 0.8rem;
  flex-wrap: wrap;
  align-items: center;
}

.exercise-navigation {
  margin-top: 1rem;
  display: flex;
  gap: 0.8rem;
  flex-wrap: wrap;
}

.exercise-next-link {
  margin-left: auto;
}

.categories-section {
  margin-top: 3rem;
}

.categories-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.5rem;
}

.category-card {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
  text-decoration: none;
  color: var(--text-primary);
  transition: transform 0.2s ease, background-color 0.2s ease;
}

.category-card:hover {
  transform: translateY(-3px);
  background-color: var(--surface-elevated);
}

.category-card h3 {
  margin-top: 0;
}

.category-progress {
  width: 100%;
  height: 6px;
  background-color: var(--border);
  border-radius: 4px;
  overflow: hidden;
  margin-top: 0.8rem;
}

.category-progress-bar {
  height: 100%;
  width: 0%;
  background-color: var(--border);
  transition: width 0.4s ease;
}

.category-progress-text {
  margin-top: 0.4rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.progress-placeholder {
  margin-top: 1rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.exercise-list-section {
  margin-top: 2.5rem;
}

.exercise-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.exercise-card {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.2rem;
  color: var(--text-primary);
  text-decoration: none;
  transition: transform 0.2s ease, background-color 0.2s ease;
}

.exercise-card:hover {
  transform: translateY(-2px);
  background-color: var(--surface-elevated);
  text-decoration: none;
}

.exercise-card h3 {
  margin: 0 0 0.3rem;
}

.exercise-card p {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.92rem;
}

.other-categories-section {
  margin-top: 2.5rem;
}

.section-divider {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 0 0 1.5rem;
}

.other-categories-section h3 {
  margin-top: 0;
  margin-bottom: 1rem;
}

@media (max-width: 720px) {
  body {
    overflow-x: hidden;
  }

  .container {
    padding: 1.25rem;
  }

  .site-footer {
    padding: 1rem 1.25rem 1.5rem;
  }

  header {
    padding: 0.8rem 1rem;
  }

  .header-content {
    display: flex;
    align-items: center;
    gap: 0.75rem;
  }

  .brand-link {
    flex: 1 1 auto;
    min-width: 0;
    padding: 0.35rem 0;
  }

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

  .header-title {
    min-width: 0;
  }

  .header-title strong,
  .header-title span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .header-actions {
    position: relative;
    flex: 0 0 auto;
  }

  .mobile-menu-toggle {
    display: inline-flex;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    width: 44px;
    padding: 0;
    flex-shrink: 0;
  }

  .header-navigation {
    display: none !important;
    position: absolute;
    top: calc(100% + 0.55rem);
    right: 0;
    z-index: 120;
    width: min(320px, calc(100vw - 2rem));
    flex-direction: column;
    align-items: stretch;
    gap: 0.6rem;
    padding: 0.8rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    background-color: var(--surface);
    box-shadow: 0 14px 32px rgba(0, 0, 0, 0.28);
  }

  .header-actions.open .header-navigation {
    display: flex !important;
  }

  .header-navigation > * {
    width: 100%;
  }

  .dropdown {
    width: 100%;
  }

  .nav-link,
  .mobile-menu-toggle,
  .dropdown-toggle,
  #progress-button,
  .theme-toggle {
    min-height: 44px;
    width: 100%;
    display: inline-flex;
    align-items: center;
    justify-content: flex-start;
    padding: 0.7rem 0.85rem;
    text-align: left;
    font-size: 0.95rem;
  }

  .mobile-menu-toggle {
    justify-content: center;
  }

  .dropdown-toggle,
  #progress-button {
    justify-content: space-between;
  }

  .dropdown-menu {
    position: static;
    left: auto;
    right: auto;
    min-width: 0;
    margin-top: 0.45rem;
    box-shadow: none;
  }

  .hero {
    margin-bottom: 2.25rem;
  }

  .hero-actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }

  .button-secondary {
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.8rem 1rem;
    text-align: center;
  }

  .exercise-navigation {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
  }

  .exercise-navigation .button-secondary {
    width: 100%;
  }

  .exercise-next-link {
    margin-left: 0;
  }

  .categories-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .category-card {
    padding: 1.2rem;
  }

  .exercise-grid {
    grid-template-columns: 1fr;
  }

  .exercise-card {
    padding: 1rem;
  }
}

.exercise-status {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 8px;
}

.exercise-status.not-attempted {
  background-color: var(--text-secondary);
}

.exercise-status.attempted {
  background-color: var(--warning);
}

.exercise-status.completed {
  background-color: var(--success);
}

#progress-button {
  border-radius: 6px;
  padding: 0.4rem 0.8rem;
  cursor: pointer;
}

#progress-button:hover {
  opacity: 0.9;
}

.import-label {
  display: block;
  margin: 0.8rem 0;
  cursor: pointer;
}

.import-label input {
  display: none;
}

.dropdown-item {
  width: 100%;
  background: none;
  border: none;
  padding: 0.6rem 0.8rem;
  text-align: left;
  color: var(--text-primary);
  cursor: pointer;
  font-size: 0.95rem;
}

.dropdown-item:hover {
  background-color: var(--surface-elevated);
}

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

.import-label input {
  display: none;
}

.exercise-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 2rem;
  align-items: start;
}

.exercise-sidebar {
  position: static;
}

.exercise-main {
  min-width: 0;
}

.sidebar-category {
  margin-bottom: 1rem;
}

.sidebar-category-toggle {
  width: 100%;
  background: none;
  border: none;
  text-align: left;
  font-weight: 600;
  padding: 0.6rem 0.4rem;
  cursor: pointer;
  color: var(--text-primary);
}

.sidebar-category-toggle:hover {
  color: var(--primary);
}

.sidebar-category.open .sidebar-exercises {
  display: block;
}

.sidebar-category-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
}

.sidebar-category-text {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.sidebar-category-progress {
  width: 100%;
  height: 4px;
  background-color: var(--border);
  border-radius: 4px;
  overflow: hidden;
  margin-top: 0.4rem;
}

.sidebar-category-progress-bar {
  height: 100%;
  width: 0%;
  background-color: var(--border);
  transition: width 0.4s ease;
}

.category-progress-bar.progress-zero,
.sidebar-category-progress-bar.progress-zero {
  background-color: var(--border);
}

.category-progress-bar.progress-partial,
.sidebar-category-progress-bar.progress-partial {
  background-color: var(--accent);
}

.category-progress-bar.progress-complete,
.sidebar-category-progress-bar.progress-complete {
  background-color: var(--success);
}

.sidebar-exercises {
  display: none;
  padding-left: 0.8rem;
}

.sidebar-exercise-link {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.4rem 0.4rem;
  font-size: 0.9rem;
  text-decoration: none;
  color: var(--text-secondary);
  border-radius: 6px;
}

.sidebar-exercise-link:hover {
  background-color: var(--surface-elevated);
  color: var(--text-primary);
}

.sidebar-exercise-link.active {
  background-color: var(--primary);
  color: var(--text-primary);
}

.sidebar-status {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  transition: background-color 0.3s ease;
}

.sidebar-status.not-attempted {
  background-color: var(--border);
}

.sidebar-status.attempted {
  background-color: var(--warning);
}

.sidebar-status.completed {
  background-color: var(--success);
}

@media (max-width: 900px) {
  .exercise-layout {
    grid-template-columns: 1fr;
  }

  .exercise-sidebar {
    order: 2;
    position: static;
  }

  .exercise-main {
    order: 1;
  }
}
