:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-strong: #eef2f6;
  --text: #19202a;
  --muted: #667085;
  --line: #d8dee8;
  --accent: #c92828;
  --accent-dark: #9e1f1f;
  --warning-bg: #fff6e5;
  --warning-line: #f1c56d;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px clamp(16px, 4vw, 44px);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(12px);
}

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

h1 {
  font-size: 28px;
  line-height: 1;
  letter-spacing: 0;
}

#statusText {
  margin-top: 7px;
  color: var(--muted);
  font-size: 14px;
}

button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0 16px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  font: inherit;
  font-weight: 650;
}

button:hover:not(:disabled) {
  background: var(--accent-dark);
}

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

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

.video-search-input {
  width: min(260px, 24vw);
  min-width: 180px;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.filter-control {
  display: inline-flex;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.filter-button {
  min-height: 38px;
  border: 0;
  border-radius: 0;
  padding: 0 12px;
  background: transparent;
  color: var(--muted);
}

.filter-button:hover:not(:disabled),
.filter-button.is-active {
  background: var(--surface-strong);
  color: var(--text);
}

main {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 24px clamp(14px, 3vw, 32px) 44px;
}

.error-panel {
  margin-bottom: 18px;
  border: 1px solid var(--warning-line);
  border-radius: 8px;
  padding: 14px 16px;
  background: var(--warning-bg);
  color: #59410d;
  font-size: 14px;
}

.feed {
  display: grid;
  gap: 28px;
}

.day-group {
  display: grid;
  gap: 12px;
}

.day-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

.day-heading h2 {
  font-size: 19px;
  letter-spacing: 0;
}

.day-heading span {
  color: var(--muted);
  font-size: 13px;
}

.video-card {
  scroll-margin-top: 96px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
}

.video-summary {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  min-height: 54px;
  padding: 13px 16px;
  cursor: pointer;
  list-style: none;
}

.video-summary:focus-visible {
  outline: 3px solid rgb(201 40 40 / 28%);
  outline-offset: -3px;
}

.video-summary::-webkit-details-marker {
  display: none;
}

.video-summary::before {
  content: "›";
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  margin-right: 8px;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  transform: rotate(0deg);
  transition: transform 140ms ease;
}

.read-toggle {
  display: inline-grid;
  place-items: center;
  width: 34px;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0;
  background: var(--surface);
  color: var(--accent);
}

.read-toggle:hover:not(:disabled) {
  background: var(--surface-strong);
  color: var(--accent);
}

.read-toggle svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.read-toggle.is-read {
  color: var(--muted);
}

.video-card[open] .video-summary {
  border-bottom: 1px solid var(--line);
  background: #fbfcfe;
}

.video-card[open] .video-summary::before {
  transform: rotate(90deg);
}

.summary-title {
  min-width: 0;
  color: var(--text);
  font-size: 16px;
  line-height: 1.3;
  font-weight: 750;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.summary-date {
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
  white-space: nowrap;
}

.video-expanded {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(0, 1fr);
  gap: 16px;
  padding: 12px;
}

.thumb-link {
  display: block;
  overflow: hidden;
  align-self: start;
  border-radius: 6px;
  background: var(--surface-strong);
  aspect-ratio: 16 / 9;
}

.thumb-link img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.video-content {
  min-width: 0;
  display: grid;
  gap: 9px;
}

.video-title {
  color: var(--text);
  font-size: 18px;
  line-height: 1.25;
  font-weight: 750;
  text-decoration: none;
  overflow-wrap: anywhere;
}

.video-title:hover {
  color: var(--accent);
}

.download-button {
  justify-self: start;
  min-height: 36px;
  border-color: var(--line);
  padding: 0 12px;
  background: var(--surface);
  color: var(--text);
}

.download-button:hover:not(:disabled) {
  background: var(--surface-strong);
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  color: var(--muted);
  font-size: 13px;
}

.description {
  max-height: 120px;
  overflow: auto;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfe;
  color: #333b47;
  font-size: 14px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.empty {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 32px;
  background: var(--surface);
  color: var(--muted);
  text-align: center;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-top: 28px;
}

.pager button {
  background: var(--surface);
  color: var(--text);
  border-color: var(--line);
}

.pager button:hover:not(:disabled) {
  background: var(--surface-strong);
}

#pageInfo {
  min-width: 130px;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}

.download-dialog {
  width: min(460px, calc(100% - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 24px 80px rgb(25 32 42 / 24%);
}

.download-dialog::backdrop {
  background: rgb(25 32 42 / 45%);
}

.download-dialog form {
  display: grid;
  gap: 16px;
  padding: 18px;
}

.dialog-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.dialog-heading h2 {
  font-size: 20px;
  letter-spacing: 0;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 36px;
  min-height: 36px;
  border-color: var(--line);
  padding: 0;
  background: var(--surface);
  color: var(--text);
  font-size: 24px;
  line-height: 1;
}

.icon-button:hover:not(:disabled) {
  background: var(--surface-strong);
}

.download-title {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.open-video-url-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.open-video-url {
  min-width: 0;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  background: var(--surface-strong);
  color: var(--text);
  font: inherit;
  font-size: 13px;
}

.open-video-url-row .icon-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.download-dialog fieldset {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.download-dialog legend {
  padding: 0 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.download-dialog label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 10px;
  border-radius: 6px;
  background: var(--surface-strong);
  cursor: pointer;
  font-weight: 650;
}

.download-dialog input {
  accent-color: var(--accent);
}

.download-message {
  min-height: 20px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.4;
}

.download-message.is-success {
  color: #126a3a;
}

.download-message.is-error {
  color: var(--accent-dark);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.dialog-actions button[type="button"] {
  border-color: var(--line);
  background: var(--surface);
  color: var(--text);
}

.dialog-actions button[type="button"]:hover:not(:disabled) {
  background: var(--surface-strong);
}

.video-link-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.video-link-actions #openYoutubeVideo,
.video-link-actions #openAlternateVideo {
  border-color: transparent;
  background: var(--accent);
  color: white;
}

.video-link-actions #openYoutubeVideo:hover:not(:disabled),
.video-link-actions #openAlternateVideo:hover:not(:disabled) {
  background: var(--accent-dark);
}

.video-link-actions #cancelOpenVideo {
  grid-column: 1 / -1;
}

.subscriptions-dialog {
  width: min(680px, calc(100% - 28px));
}

.subscription-add-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.subscription-add-row input {
  min-width: 0;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.subscription-tools {
  display: grid;
  grid-template-columns: minmax(170px, 1fr) minmax(150px, auto) minmax(170px, auto);
  gap: 8px;
}

.subscription-search-input,
.subscription-tools select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.subscription-tools select {
  min-width: 0;
}

.subscriptions-list {
  display: grid;
  max-height: min(460px, 58vh);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.subscription-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.subscription-item:last-child {
  border-bottom: 0;
}

.subscription-avatar {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--accent);
  font-weight: 800;
}

.subscription-body {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.subscription-body strong,
.subscription-body span,
.subscription-latest,
.subscription-url {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.subscription-body span {
  color: var(--muted);
  font-size: 13px;
}

.subscription-latest {
  color: var(--muted);
  font-size: 13px;
}

.subscription-url {
  color: var(--accent);
  font-size: 13px;
  text-decoration: none;
}

.subscription-url:hover {
  text-decoration: underline;
}

.subscription-url.is-missing {
  color: var(--muted);
}

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

.subscription-actions button {
  min-height: 34px;
  border-color: var(--line);
  background: var(--surface);
  color: var(--text);
}

.subscription-copy-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.subscription-actions button:hover:not(:disabled) {
  background: var(--surface-strong);
}

.subscriptions-empty {
  margin: 10px;
}

@media (max-width: 720px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .filter-control {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .video-search-input {
    width: 100%;
    min-width: 0;
  }

  .video-card {
    display: block;
  }

  .video-summary {
    grid-template-columns: auto auto minmax(0, 1fr);
    gap: 8px;
  }

  .summary-date {
    grid-column: 3;
  }

  .video-expanded {
    grid-template-columns: 1fr;
  }

  .thumb-link {
    width: 100%;
  }

  .download-button {
    justify-self: stretch;
  }

  .download-dialog fieldset {
    grid-template-columns: 1fr;
  }

  .subscription-add-row,
  .subscription-tools,
  .subscription-item {
    grid-template-columns: 1fr;
  }

  .subscription-tools select {
    min-width: 0;
  }

  .subscription-actions {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
  }

  .subscription-avatar {
    display: none;
  }

  .dialog-actions {
    flex-direction: column-reverse;
  }
}
