:root {
  --bg: #121212;
  --card: #1d1d1f;
  --text: #f5f5f7;
  --muted: #b3b3b3;
  --accent: #ff3b30;
  --accent-hover: #d62e25;
  --border: #2a2a2a;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
}

body {
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  margin: 0;
  padding: 24px;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden; /* prevent horizontal scroll on mobile */
}

/* -------- Page container (centers everything) -------- */
.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px; /* desktop gutters */
}

/* Media should never overflow container */
img,
video,
canvas {
  max-width: 100%;
  height: auto;
  display: block;
}

/* -------- Header -------- */
h1 {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto 24px;
  text-align: center;
  font-weight: 700;
}

/* -------- Input row -------- */
.input-section {
  display: flex;
  gap: 12px;
  max-width: 720px;
  width: 100%;
  margin: 0 auto 24px;
}

input[type="text"] {
  flex: 1;
  padding: 12px 14px;
  font-size: 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  outline: none;
}

button {
  padding: 12px 16px;
  font-size: 16px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.15s ease;
}

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

.error {
  color: #ffb3ae;
  text-align: center;
  margin: 10px 0 0;
}

/* -------- Sections -------- */
.section {
  width: 100%;
  max-width: 1200px;
  margin: 36px auto;         /* consistent spacing between sections */
}

.section:first-of-type {
  margin-top: 28px;          /* slightly tighter to header */
}

.section h2 {
  margin: 0 0 14px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--border);
  text-align: left;          /* desktop default */
  font-weight: 700;
}

.section:first-of-type h2 {
  border-color: #ffcfcc;
}

/* -------- Grids -------- */
.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 18px;
  justify-items: stretch;
  width: 100%;
}

/* -------- Cards -------- */
.video-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  /* JS adds colorful glow on top of this base shadow */
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.12s ease;
}

.video-item:hover {
  transform: translateY(-2px);
}

.video-item a img {
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  object-fit: cover;
}

/* Card content */
.content {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.video-title {
  font-size: 16px;
  line-height: 1.3;
  margin: 0;
}

/* Meta: channel (left) + duration/notes (right) */
.video-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.channel {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.channel img {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: block;
}

.channel-name {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.right-meta {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.duration {
  font-variant-numeric: tabular-nums;
}

/* Notes */
.notes-btn {
  background: transparent;
  border: none;
  padding: 4px;
  cursor: pointer;
  border-radius: 8px;
  color: var(--muted);
}

.notes-btn:hover {
  background: rgba(255, 255, 255, 0.06);
}

/* KEY FIX: the notes wrapper must be visible */
.notes {
  display: block;            /* was: none; this prevents the editor from ever showing */
  padding-top: 8px;
}

.notes textarea {
  width: 100%;
  min-height: 72px;
  resize: vertical;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #0f0f10;
  color: var(--text);
  padding: 10px 12px;
  font-size: 13px;
  font-style: italic;
}

/* editor area stays hidden until 📝 toggles it */
.notes-controls {
  display: none;             /* JS switches this to grid */
  grid-template-columns: 1fr;
  gap: 8px;
}

.notes-actions {
  display: flex;
  justify-content: flex-end; /* right align the save button */
}

.notes-controls textarea,
.notes-controls input[type="text"] {
  width: 100%;
  box-sizing: border-box;
}

.notes .notes-preview {
  margin-top: 6px;
  display: grid;
  gap: 6px;
  word-break: break-word;
}

.notes .notes-preview a {
  color: #9bd;               /* subtle link color on dark bg */
  text-decoration: none;
}
.notes .notes-preview a:hover {
  text-decoration: underline;
}

/* Save emoji under notes */
.notes-save {
  margin-top: 6px;
  align-self: flex-start;
  background: transparent;
  border: none;
  font-size: 20px;      /* bigger emoji */
  line-height: 1;
  cursor: pointer;
  justify-self: end;
  filter: drop-shadow(0 0 6px rgba(16, 185, 129, .45)); /* soft green glow */
}

.notes-save:hover {
  transform: translateY(-1px);
}

.watched-btn {
  align-self: flex-start;
  margin-top: 6px;
  background: var(--accent);
  color: #fff;
  padding: 10px 14px;
  border-radius: 25%;
  transition: background 0.15s ease;
}

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

#addBtn, #searchBtn {
  /* offset-x | offset-y | blur | color */
  text-shadow:
  3px 1px 2px rgba(119, 37, 37, 0.95),
  6px 2px 6px rgba(119, 37, 37, 0.95),
  10px 3px 10px rgba(119, 37, 37, 0.95);
}

/* -------- Mobile rules -------- */

/* --- MOBILE SINGLE COLUMN + CENTER --- */
@media (max-width: 668px) {
  html, body {
    width: 100% !important;
    overflow-x: hidden !important;
  }

  /* Hard clamp the whole page */
  .page {
    max-width: 420px !important;
    margin: 0 auto !important;
    padding: 0 16px !important;
  }

  /* Titles centered */
  .section h2 {
    text-align: center !important;
  }

  /* Make sure grids are actually grids, and only one column */
  .video-grid {
    display: grid !important;
    grid-template-columns: 1fr !important;
    justify-items: center !important;
    width: 100% !important;
    gap: 16px !important;
  }

  /* Cards fill the column */
  .video-item {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 auto !important;
  }

  /* Input row stacked and centered */
  .input-section {
    display: flex !important;
    flex-direction: column !important;
    gap: 12px !important;
    max-width: 420px !important;
    width: 100% !important;
    margin: 0 auto 24px !important;
  }

  .input-section input[type="text"],
  .input-section button {
    width: 100% !important;
  }
}
