:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --border: #2d3a4d;
  --text: #e6edf3;
  --muted: #8b9eb0;
  --accent: #58a6ff;
  --accent-hover: #79b8ff;
  --success: #3fb950;
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

.app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem 1.5rem 2rem;
}

.header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem 1.5rem;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.header h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 600;
}

.tabs {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 1rem;
}

.tab {
  padding: 0.5rem 1rem;
  background: transparent;
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  cursor: pointer;
}

.tab:hover {
  color: var(--text);
  background: var(--surface);
}

.tab.active {
  background: var(--surface);
  color: var(--accent);
  font-weight: 500;
  margin-bottom: -1px;
  padding-bottom: calc(0.5rem + 1px);
}

.view-panel.hidden {
  display: none !important;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
  margin-left: auto;
}

.view-range,
.tag-filter {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.view-range label,
.tag-filter label {
  color: var(--muted);
  font-size: 0.875rem;
}

select {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.4rem 0.75rem;
  font-size: 0.9rem;
  cursor: pointer;
  min-width: 9ch; /* enough for 8-char tag labels in dropdown */
}

#tag {
  min-width: 14ch; /* wide enough that native dropdown shows 8-char options */
}

select:hover,
select:focus {
  border-color: var(--accent);
  outline: none;
}

.btn {
  display: inline-flex;
  align-items: center;
  padding: 0.5rem 1rem;
  background: var(--accent);
  color: var(--bg);
  text-decoration: none;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 500;
}

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

.btn-outline {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}

.btn-outline:hover {
  background: rgba(88, 166, 255, 0.15);
}

.subscribe-panel {
  padding: 1.5rem 0;
  max-width: 560px;
}

.subscribe-label {
  display: block;
  color: var(--muted);
  font-size: 0.875rem;
  margin-bottom: 0.35rem;
}

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

.subscribe-url {
  flex: 1;
  min-width: 200px;
  padding: 0.4rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.85rem;
  font-family: inherit;
}

.subscribe-hint {
  margin: 0.5rem 0 0;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.4;
}

.error {
  background: rgba(248, 81, 73, 0.15);
  border: 1px solid #f85149;
  color: #ff7b72;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
}

.loading {
  color: var(--muted);
  padding: 1rem 0;
}

.calendar {
  display: grid;
  gap: 0.75rem;
}

.calendar-day {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.calendar-day-header {
  padding: 0.6rem 1rem;
  background: rgba(0, 0, 0, 0.2);
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--muted);
}

.calendar-day-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.calendar-episode {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
  display: grid;
  gap: 0.25rem;
}

.calendar-episode:first-of-type {
  border-top: none;
}

.calendar-episode .series {
  font-weight: 600;
  color: var(--text);
}

.calendar-episode .episode-title {
  color: var(--muted);
  font-size: 0.9rem;
}

.calendar-episode .meta {
  font-size: 0.8rem;
  color: var(--muted);
}

.calendar-episode .meta time {
  color: var(--accent);
}

.empty-day .calendar-day-list {
  padding: 1rem;
  color: var(--muted);
  font-size: 0.9rem;
}

/* Calendar grid view */
.cal-grid {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.cal-grid-head {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  background: rgba(0, 0, 0, 0.2);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
}

.cal-grid-head span {
  padding: 0.5rem;
  text-align: center;
  border-right: 1px solid var(--border);
}

.cal-grid-head span:last-child {
  border-right: none;
}

.cal-grid-body {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-auto-rows: minmax(100px, auto);
}

.cal-grid-cell {
  min-height: 100px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 0.35rem;
  overflow: auto;
}

.cal-grid-cell:nth-child(7n) {
  border-right: none;
}

.cal-grid-cell.other-month {
  background: rgba(0, 0, 0, 0.15);
  color: var(--muted);
}

.cal-grid-cell .day-num {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.cal-grid-cell .day-events {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 0.75rem;
}

.cal-grid-cell .day-events li {
  padding: 0.2rem 0.3rem;
  margin-bottom: 0.2rem;
  background: rgba(88, 166, 255, 0.15);
  border-radius: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cal-grid-cell .day-events li .time {
  color: var(--accent);
  margin-right: 0.25rem;
}

.cal-grid-cell .day-events li .ep-count {
  color: var(--muted);
  font-size: 0.9em;
}

@media (max-width: 640px) {
  .header {
    flex-direction: column;
    align-items: stretch;
  }
  .controls {
    margin-left: 0;
  }
  .cal-grid-cell {
    min-height: 80px;
    font-size: 0.7rem;
  }
}
