:root {
  color-scheme: light dark;
  font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background-color: #f5f6f8;
  color: #1b1d21;
  line-height: 1.5;
  font-size: 16px;
  --accent: #2c7be5;
  --accent-contrast: #ffffff;
  --border: #d9dee7;
  --card-bg: #ffffff;
  --card-shadow: rgba(15, 23, 42, 0.08);
  --muted: #6b7280;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--background, #f5f6f8);
}

.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.toolbar {
  display: flex;
  flex-direction: column;
  padding: 1rem clamp(1rem, 4vw, 2rem);
  gap: 0.75rem;
  border-bottom: 1px solid var(--border);
  background-color: var(--card-bg);
  position: sticky;
  top: 0;
  z-index: 10;
}

.toolbar__row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.toolbar__row--primary {
  justify-content: flex-start;
}

.toolbar__row--secondary {
  justify-content: flex-start;
}

.toolbar__row--tertiary {
  justify-content: flex-start;
}

.toolbar__more {
  display: none;
}

.toolbar__status {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  white-space: nowrap;
}

.toolbar--pulsing {
  animation: toolbar-pulse 2s ease-in-out infinite;
}

@keyframes toolbar-pulse {
  0%, 100% {
    background-color: var(--card-bg);
  }
  50% {
    background-color: rgba(44, 123, 229, 0.05);
  }
}

.slideshow-controls {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.slideshow-interval {
  width: 50px;
  padding: 0.4rem 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  font-size: 0.9rem;
  text-align: center;
  background-color: var(--card-bg);
}

.slideshow-interval:focus {
  outline: none;
  border-color: var(--accent);
}

.slideshow-toggle {
  min-width: 42px;
  padding: 0.5rem 0.75rem;
}

.slideshow-countdown {
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 600;
  min-width: 24px;
  text-align: center;
}

.toolbar__status {
  font-weight: 600;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.toolbar__api-count {
  font-size: 0.85rem;
  color: var(--muted);
}

.toolbar__refresh-time {
  font-size: 0.85rem;
  color: var(--muted);
}

.toolbar__actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.btn {
  padding: 0.5rem 1rem;
  border-radius: 999px;
  background-color: var(--accent);
  color: var(--accent-contrast);
  border: none;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.14s ease, box-shadow 0.14s ease, background-color 0.2s ease;
  text-decoration: none;
  display: inline-block;
}

.btn:disabled {
  background-color: rgba(44, 123, 229, 0.3);
  color: rgba(255, 255, 255, 0.7);
  cursor: not-allowed;
  box-shadow: none;
}

.btn:not(:disabled):hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 16px rgba(44, 123, 229, 0.25);
}

.btn:not(:disabled):active {
  transform: translateY(0);
  box-shadow: 0 4px 10px rgba(44, 123, 229, 0.2);
}

.btn--secondary {
  background-color: rgba(44, 123, 229, 0.1);
  color: var(--accent);
}

.btn--secondary:not(:disabled):hover {
  background-color: rgba(44, 123, 229, 0.15);
}


.card-container {
  flex: 1;
  padding: clamp(1rem, 4vw, 3rem);
  max-width: min(1200px, 90vw);
  width: 100%;
  margin: 0 auto;
}

.card {
  width: 100%;
  background-color: var(--card-bg);
  border-radius: 16px;
  padding: clamp(1.5rem, 4vw, 2.5rem);
  box-shadow: 0 12px 32px var(--card-shadow);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-height: 240px;
}

.card__topic {
  margin: 0;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.card--placeholder {
  color: var(--muted);
  text-align: center;
  justify-content: center;
  min-height: 240px;
}

.loading-progress {
  margin-top: 0.5rem;
  font-size: 0.9rem;
  color: var(--muted);
  font-weight: 500;
}

.card--error {
  color: #b91c1c;
  border: 1px solid rgba(185, 28, 28, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
}

.card__title {
  margin: 0;
  font-size: clamp(1.5rem, 4vw, 2rem);
  line-height: 1.2;
}

.card__text {
  margin: 0;
  font-size: 1.05rem;
  color: var(--muted);
}

.card__text a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid rgba(44, 123, 229, 0.3);
  transition: border-color 0.2s ease;
}

.card__text a:hover {
  border-bottom-color: var(--accent);
}

.card__children {
  margin-top: 0.5rem;
}

.card-children__list,
.card-children__nested {
  margin: 0.5rem 0 0 0;
  padding-left: 1.5rem;
  list-style-type: disc;
}

.card-children__list {
  padding-left: 1.25rem;
}

.card-child-item {
  margin: 0.35rem 0;
  padding-left: 0.25rem;
}

.card-child-item::marker {
  color: var(--accent);
}

.card-child-content {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.card-child-title {
  font-weight: 500;
  font-size: 1rem;
  line-height: 1.4;
}

.card-child-text {
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.5;
}

.card-child-text a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid rgba(44, 123, 229, 0.3);
  transition: border-color 0.2s ease;
}

.card-child-text a:hover {
  border-bottom-color: var(--accent);
}

.modal {
  border: none;
  border-radius: 16px;
  padding: 0;
  max-width: min(480px, 90vw);
  width: 100%;
  box-shadow: 0 24px 56px rgba(15, 23, 42, 0.2);
}

.modal--small {
  max-width: min(400px, 90vw);
}

.modal::backdrop {
  background: rgba(15, 23, 42, 0.35);
}

.modal__content {
  display: flex;
  flex-direction: column;
  max-height: 80vh;
  min-height: 70vh;
}

.modal__header {
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal__header h2 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
}

.modal__footer {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
  border-bottom: none;
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.modal__body {
  padding: 0.75rem 1rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  flex: 1;
}

.modal__close {
  border: none;
  background: none;
  font-size: 1.3rem;
  cursor: pointer;
  color: var(--muted);
  padding: 0;
  margin: 0;
  line-height: 1;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal__close:hover {
  color: #1b1d21;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.field--inline {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
}

.field--inline .field__label {
  margin: 0;
}

.field__label {
  font-weight: 600;
  color: var(--muted);
  font-size: 0.8rem;
}

.field__input,
.field__select {
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background-color: rgba(255, 255, 255, 0.8);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  font-size: 0.9rem;
}

.field__select {
  cursor: pointer;
  min-width: 120px;
}

.field__input:focus,
.field__select:focus {
  outline: none;
  border-color: rgba(44, 123, 229, 0.6);
  box-shadow: 0 0 0 3px rgba(44, 123, 229, 0.15);
}

.playlist-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  background-color: rgba(44, 123, 229, 0.05);
  border-radius: 8px;
}

.playlist-actions {
  display: flex;
  gap: 0.35rem;
}

.btn-icon {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1rem;
  color: var(--accent);
  transition: all 0.15s ease;
}

.btn-icon:hover {
  background-color: rgba(44, 123, 229, 0.1);
  border-color: var(--accent);
}

.btn-icon:active {
  transform: scale(0.95);
}

.modal-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.topic-list {
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.topic-actions {
  display: flex;
  gap: 0.5rem;
}

.btn--tertiary {
  background-color: rgba(44, 123, 229, 0.08);
  color: var(--accent);
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  border: none;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.85rem;
}

.btn--tertiary:hover {
  background-color: rgba(44, 123, 229, 0.12);
}

.topic-group {
  margin-bottom: 0.5rem;
}

.topic-group__header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background-color: rgba(44, 123, 229, 0.12);
  cursor: pointer;
  font-weight: 600;
  border-bottom: 1px solid rgba(44, 123, 229, 0.15);
}

.topic-group__header:hover {
  background-color: rgba(44, 123, 229, 0.15);
}

.topic-group__checkbox {
  width: 1rem;
  height: 1rem;
  accent-color: var(--accent);
  margin: 0;
  flex-shrink: 0;
}

.topic-group__title {
  font-size: 0.95rem;
  color: #1b1d21;
  flex: 1;
}

.topic-group__meta {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 500;
}

.topic-group__children {
  background-color: rgba(44, 123, 229, 0.02);
}

.topic-group__children .topic-option {
  padding-left: 2rem;
}

.topic-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.75rem;
  border-bottom: 1px solid rgba(44, 123, 229, 0.08);
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.topic-option:hover {
  background-color: rgba(44, 123, 229, 0.05);
}

.topic-option input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  accent-color: var(--accent);
  margin: 0;
  flex-shrink: 0;
}

.topic-option__content {
  display: flex;
  align-items: baseline;
  flex: 1;
  gap: 0.35rem;
  font-size: 0.9rem;
  line-height: 1.3;
}

.topic-option__title {
  color: #1b1d21;
}

.topic-option__meta {
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 500;
}

.form-error {
  color: #b91c1c;
  margin: 0;
}

/* Desktop: Single row layout */
@media (min-width: 601px) {
  .toolbar {
    flex-direction: row;
    justify-content: flex-start;
    align-items: center;
    padding: 0.75rem clamp(1rem, 4vw, 2rem);
    gap: 0.5rem;
  }
  
  .toolbar__row {
    display: flex;
    flex-wrap: nowrap;
    gap: 0.5rem;
  }
  
  /* Left side: Primary + Secondary rows combined */
  .toolbar__row--primary {
    flex: 0 0 auto;
    align-items: center;
  }
  
  .toolbar__row--secondary {
    flex: 0 0 auto;
    align-items: center;
  }
  
  /* Right side: Tertiary row with status - push to right */
  .toolbar__row--tertiary {
    flex: 0 0 auto;
    align-items: center;
    margin-left: auto;
  }
  
  .toolbar__status {
    gap: 0.75rem;
  }
  
  .toolbar__status > * {
    white-space: nowrap;
  }
  
  /* Hide More button on desktop */
  .toolbar__more {
    display: none !important;
  }
}

/* Mobile: Three-row collapsible layout */
@media (max-width: 600px) {
  .toolbar {
    padding: 0.75rem 1rem;
    gap: 0.5rem;
  }
  
  .toolbar__row {
    width: 100%;
  }
  
  .toolbar__row--primary {
    justify-content: space-between;
  }
  
  /* Rows 2 and 3 hidden by default on mobile */
  .toolbar__row--secondary,
  .toolbar__row--tertiary {
    display: none;
  }
  
  /* Show when toolbar is expanded */
  .toolbar--expanded .toolbar__row--secondary,
  .toolbar--expanded .toolbar__row--tertiary {
    display: flex;
  }
  
  .toolbar__more {
    display: flex;
    font-size: 0.8rem;
    padding: 0.4rem 0.6rem;
    min-width: auto;
  }
  
  /* Compact buttons on mobile */
  .btn {
    padding: 0.4rem 0.75rem;
    font-size: 0.85rem;
  }
  
  .btn--secondary,
  .btn--tertiary {
    padding: 0.4rem 0.65rem;
    font-size: 0.85rem;
  }
  
  .slideshow-interval {
    width: 45px;
    padding: 0.35rem 0.4rem;
    font-size: 0.85rem;
  }
  
  .slideshow-toggle {
    padding: 0.4rem 0.6rem;
    min-width: 36px;
  }
  
  .slideshow-countdown {
    font-size: 0.8rem;
    min-width: 20px;
  }
  
  .toolbar__status {
    flex-wrap: wrap;
    font-size: 0.85rem;
  }
  
  /* Full-bleed card on mobile */
  .card-container {
    padding: 0;
  }
  
  .card {
    border-radius: 0;
    box-shadow: none;
    min-height: calc(100vh - 60px);
    padding: 1.5rem 1rem;
  }
  
  .card__title {
    font-size: 1.5rem;
  }
}

