/* ---------------------------------------------------------------------------
   Base
   --------------------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0e0e10;
  --surface: #18181b;
  --surface-hover: #1f1f23;
  --border: #2f2f35;
  --text: #efeff1;
  --text-dim: #adadb8;
  --accent: #9147ff;
  --accent-dim: #772ce8;
  --live: #eb0400;
  --scheduled: #9147ff;
  --inferred: #3a3a4a;
  --green: #00e676;
}

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

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

a:hover {
  text-decoration: underline;
}

/* ---------------------------------------------------------------------------
   Header
   --------------------------------------------------------------------------- */
header {
  text-align: center;
  padding: 2rem 1rem 1rem;
  border-bottom: 1px solid var(--border);
}

header h1 {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text);
}

.header-link {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-top: 0.3rem;
  display: inline-block;
}

.subtitle {
  color: var(--text-dim);
  font-size: 0.9rem;
  margin-top: 0.25rem;
}

.header-actions {
  margin-top: 0.75rem;
}

.auth-link {
  font-size: 0.85rem;
  color: var(--text-dim);
  padding: 0.4rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  display: inline-block;
  transition: background 0.15s;
}

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

.twitch-login {
  color: var(--accent);
  border-color: var(--accent-dim);
}

.user-name {
  color: var(--text);
  font-weight: 600;
  font-size: 0.85rem;
  margin-right: 0.5rem;
}

/* ---------------------------------------------------------------------------
   Layout
   --------------------------------------------------------------------------- */
main {
  max-width: 1000px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
}

.section {
  margin-bottom: 2.5rem;
}

.section-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 1rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.8rem;
}

.hidden {
  display: none !important;
}

/* ---------------------------------------------------------------------------
   Live Now
   --------------------------------------------------------------------------- */
.live-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

.live-card {
  background: var(--surface);
  border-radius: 8px;
  overflow: hidden;
  position: relative;
  display: block;
  color: var(--text);
  transition: transform 0.15s, box-shadow 0.15s;
}

.live-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  text-decoration: none;
}

.live-thumb {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  display: block;
}

.live-info {
  padding: 0.6rem 0.8rem;
}

.live-name {
  font-weight: 700;
  font-size: 0.95rem;
}

.live-game {
  color: var(--text-dim);
  font-size: 0.8rem;
  margin-top: 0.15rem;
}

.live-viewers {
  color: var(--live);
  font-size: 0.8rem;
  font-weight: 600;
  margin-top: 0.15rem;
}

.live-badge {
  position: absolute;
  top: 0.5rem;
  left: 0.5rem;
  background: var(--live);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 800;
  padding: 0.15rem 0.4rem;
  border-radius: 3px;
  letter-spacing: 0.05em;
}

/* ---------------------------------------------------------------------------
   Calendar (gcal-style)
   --------------------------------------------------------------------------- */
/* Calendar toolbar */
.cal-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.cal-nav {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.cal-nav-btn {
  padding: 0.3rem 0.6rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-dim);
  font-size: 0.78rem;
  cursor: pointer;
  transition: all 0.15s;
}

.cal-nav-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.cal-range {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  margin-left: 0.5rem;
}

.cal-views {
  display: flex;
  gap: 2px;
  background: var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.cal-view-btn {
  padding: 0.3rem 0.7rem;
  background: var(--surface);
  border: none;
  color: var(--text-dim);
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.15s;
}

.cal-view-btn.active {
  background: var(--accent);
  color: #fff;
}

.cal-view-btn:hover:not(.active) {
  background: var(--surface-hover);
}

.cal-options {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.cal-checkbox {
  font-size: 0.78rem;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
  user-select: none;
}

.cal-checkbox input {
  accent-color: var(--accent);
  cursor: pointer;
}

.calendar {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.calendar-legend {
  display: flex;
  gap: 1.5rem;
  margin-bottom: 0.75rem;
  font-size: 0.75rem;
  color: var(--text-dim);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.legend-swatch {
  display: inline-block;
  width: 14px;
  height: 10px;
  border-radius: 2px;
}

.legend-swatch.vod { background: #9147ff88; border-left: 3px solid #9147ff; }
.legend-swatch.live { background: #9147ff; border-left: 3px solid var(--live); }
.legend-swatch.scheduled { background: #9147ff44; border-left: 3px solid #9147ff; border-style: dashed; }
.legend-swatch.inferred { background: transparent; border: 2px dashed #9147ff66; }

.cal-grid {
  display: flex;
  min-width: 500px;
}

.cal-times {
  width: 50px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
}

.cal-times-header {
  padding: 0.5rem 0.25rem;
  border-bottom: 1px solid var(--border);
  visibility: hidden;
}

.cal-times-body {
  position: relative;
}

.cal-hour-label {
  position: absolute;
  left: 0;
  width: 100%;
  text-align: right;
  padding-right: 8px;
  font-size: 0.65rem;
  color: var(--text-dim);
  transform: translateY(-0.5em);
  pointer-events: none;
}

.cal-days {
  display: grid;
  flex: 1;
}

.cal-day-col {
  border-right: 1px solid var(--border);
}

.cal-day-col:last-child {
  border-right: none;
}

.cal-day-header {
  text-align: center;
  padding: 0.5rem 0.25rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 2;
}

.cal-day-header.today {
  background: #1a1a2e;
}

.cal-day-name {
  display: block;
  font-size: 0.7rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.cal-day-header.today .cal-day-name {
  color: var(--accent);
}

.cal-day-date {
  display: block;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text);
  margin-top: 0.1rem;
}

.cal-day-header.today .cal-day-date {
  color: var(--accent);
}

.cal-day-body {
  position: relative;
}

.cal-grid-line {
  position: absolute;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--border);
  pointer-events: none;
}

.cal-now-line {
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--live);
  z-index: 3;
}

.cal-now-line::before {
  content: '';
  position: absolute;
  left: -4px;
  top: -3px;
  width: 8px;
  height: 8px;
  background: var(--live);
  border-radius: 50%;
}

/* Events */
.cal-event {
  position: absolute;
  border-radius: 4px;
  padding: 2px 4px;
  overflow: hidden;
  font-size: 0.68rem;
  line-height: 1.3;
  z-index: 1;
  display: block;
  color: var(--text);
  cursor: pointer;
  transition: opacity 0.15s;
}

.cal-event:hover {
  opacity: 0.85;
  text-decoration: none;
}

.cal-event.inferred {
  background: transparent;
}

.cal-event.inferred .cal-event-name,
.cal-event.inferred .cal-event-detail {
  white-space: normal;
  word-break: break-word;
}

.cal-event-name {
  display: block;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cal-event-detail {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0.8;
  font-size: 0.62rem;
}

/* View-specific sizing */
.view-compact .cal-event-name { font-size: 0.8rem; }
.view-compact .cal-event-detail { font-size: 0.72rem; }
.view-compact .cal-event { padding: 4px 6px; }
.view-compact .cal-day-header,
.view-compact .cal-times-header { padding: 0.6rem 0.5rem; }
.view-compact .cal-day-name { font-size: 0.8rem; }
.view-compact .cal-day-date { font-size: 0.85rem; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.calendar-actions {
  margin-top: 0.75rem;
  display: flex;
  gap: 0.5rem;
}

.export-btn {
  padding: 0.35rem 0.8rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-dim);
  font-size: 0.78rem;
  cursor: pointer;
  transition: all 0.15s;
}

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

.subscribe-url-box {
  margin-top: 0.75rem;
  padding: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.subscribe-url-box p {
  width: 100%;
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-bottom: 0.25rem;
}

.subscribe-url-box input {
  flex: 1;
  min-width: 200px;
  padding: 0.4rem 0.6rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 0.75rem;
  font-family: monospace;
}

.subscribe-url-box button {
  padding: 0.4rem 0.8rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
}

.subscribe-url-box button:hover {
  background: var(--accent-dim);
}

.empty-state {
  color: var(--text-dim);
  font-size: 0.85rem;
  text-align: center;
  padding: 2rem 0;
}

/* ---------------------------------------------------------------------------
   Streamer Toggles
   --------------------------------------------------------------------------- */
.streamer-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.streamer-toggle {
  padding: 0.3rem 0.7rem;
  border-radius: 20px;
  border: 2px solid;
  background: transparent;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  opacity: 0.6;
}

.streamer-toggle.active {
  color: #fff;
  opacity: 1;
}

.streamer-toggle:hover {
  opacity: 0.9;
}

.toggle-remove {
  margin-left: 0.25rem;
  font-size: 0.85rem;
  line-height: 1;
  opacity: 0.6;
  cursor: pointer;
}

.toggle-remove:hover {
  opacity: 1;
}

/* ---------------------------------------------------------------------------
   Clips
   --------------------------------------------------------------------------- */
.clips-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}

.clip-card {
  background: var(--surface);
  border-radius: 8px;
  overflow: hidden;
  display: block;
  color: var(--text);
  transition: transform 0.15s, box-shadow 0.15s;
}

.clip-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  text-decoration: none;
}

.clip-thumb-wrap {
  position: relative;
}

.clip-thumb {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  display: block;
  background: var(--surface-hover);
}

.clip-duration {
  position: absolute;
  bottom: 0.4rem;
  right: 0.4rem;
  background: rgba(0, 0, 0, 0.8);
  color: var(--text);
  font-size: 0.65rem;
  font-weight: 600;
  padding: 0.1rem 0.35rem;
  border-radius: 3px;
}

.clip-info {
  padding: 0.5rem 0.7rem;
}

.clip-title {
  font-weight: 600;
  font-size: 0.82rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.clip-meta {
  color: var(--text-dim);
  font-size: 0.72rem;
  margin-top: 0.2rem;
}

/* ---------------------------------------------------------------------------
   Add Streamer (inline with toggles)
   --------------------------------------------------------------------------- */
.streamer-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
}

.add-form-inline {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.add-form-inline input {
  width: 130px;
  padding: 0.3rem 0.6rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text);
  font-size: 0.78rem;
  outline: none;
  transition: width 0.2s, border-color 0.15s;
}

.add-form-inline input:focus {
  border-color: var(--accent);
  width: 170px;
}

.add-form-inline button {
  padding: 0.3rem 0.6rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.add-form-inline button:hover {
  background: var(--accent-dim);
}

.add-error {
  color: var(--live);
  font-size: 0.75rem;
  margin-top: 0.3rem;
}


/* ---------------------------------------------------------------------------
   Responsive
   --------------------------------------------------------------------------- */
@media (max-width: 600px) {
  header h1 {
    font-size: 1.5rem;
  }

  .live-grid,
  .clips-grid {
    grid-template-columns: 1fr;
  }
}
