:root {
  --bg: #0a0a0c;
  --border: #333;
  --text: #f1f1f1;
  --muted: #aaa;
  --accent: #ff3b30;
  --accent-2: #3ea6ff;
  --glass: rgba(22, 22, 28, 0.55);
  --glass-brd: rgba(255, 255, 255, 0.12);
  --glass-hi: rgba(255, 255, 255, 0.08);
  --glow: rgba(62, 166, 255, 0.35);
  --gap: 8px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* Ambient brand glow behind the glass — without it the toolbar's blur has
   nothing to tint and "glass" collapses to a flat panel. */
html {
  background:
    radial-gradient(1200px 600px at 18% -10%, rgba(62, 166, 255, 0.10), transparent 60%),
    radial-gradient(1000px 520px at 100% 0%, rgba(255, 59, 48, 0.07), transparent 55%),
    var(--bg);
  background-attachment: fixed;
}

body {
  display: flex;
  flex-direction: column;
}

/* ---- Toolbar ---- */
#toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 10px;
  padding: 10px 14px;
  background: var(--glass);
  border: 1px solid var(--glass-brd);
  border-radius: 16px;
  backdrop-filter: blur(16px) saturate(140%);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.3px;
  white-space: nowrap;
}
.brand-yt { color: var(--accent); }
.brand-logo {
  width: 32px;
  height: 32px;
  flex: none;
  border-radius: 50%;
  overflow: hidden;
  background: #000;
  border: 1px solid rgba(255, 255, 255, 0.15);
}
.brand-logo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scale(1.12); /* zoom slightly to hide the sticker's light edges */
}

.add-form {
  display: flex;
  gap: 8px;
  flex: 1 1 320px;
  min-width: 240px;
}

#add-input {
  flex: 1;
  padding: 9px 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--glass-brd);
  border-radius: 10px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
#add-input::placeholder { color: var(--muted); }
#add-input:focus {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(62, 166, 255, 0.22);
}

.controls {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.btn {
  padding: 9px 12px;
  background: var(--glass-hi);
  color: var(--text);
  border: 1px solid var(--glass-brd);
  border-radius: 10px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.btn:hover {
  background: rgba(255, 255, 255, 0.14);
  border-color: var(--accent-2);
  box-shadow: 0 0 0 1px var(--accent-2), 0 6px 20px var(--glow);
}
/* Icon-only control buttons read as a deliberate row: square, equal padding. */
.controls .btn { padding: 9px 11px; font-size: 15px; line-height: 1; }
.btn.primary {
  background: var(--accent-2);
  border-color: var(--accent-2);
  color: #002b46;
  font-weight: 600;
  box-shadow: 0 4px 16px var(--glow);
}
.btn.primary:hover { filter: brightness(1.08); box-shadow: 0 6px 22px var(--glow); }
.btn.active {
  background: var(--accent-2);
  border-color: var(--accent-2);
  color: #002b46;
  box-shadow: 0 0 0 1px var(--accent-2), 0 6px 20px var(--glow);
}

/* ---- Grid ---- */
.grid {
  flex: 1;
  display: grid;
  gap: var(--gap);
  padding: var(--gap);
  /* columns/rows set dynamically in JS via inline style */
  min-height: 0;
}

.cell {
  position: relative;
  background: #000;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  min-height: 0;
}

/* Twitch nests its iframe inside the host div (YouTube replaces it), so the
   host must fill the cell for the iframe's height:100% to resolve. */
.player-host {
  position: absolute;
  inset: 0;
}

.cell iframe {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}

/* Per-cell overlay controls */
.cell-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background: linear-gradient(to bottom, rgba(0,0,0,0.75), rgba(0,0,0,0));
  opacity: 0;
  transition: opacity 0.15s;
  pointer-events: none;
}
.cell:hover .cell-bar { opacity: 1; }
.cell-bar .cell-title {
  flex: 1;
  font-size: 12px;
  color: #fff;
  text-shadow: 0 1px 2px #000;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cell-bar button {
  pointer-events: auto;
  background: rgba(0,0,0,0.55);
  border: 1px solid rgba(255,255,255,0.22);
  color: #fff;
  border-radius: 8px;
  font-size: 12px;
  padding: 4px 7px;
  cursor: pointer;
  line-height: 1;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: background 0.12s, border-color 0.12s;
}
.cell-bar button:hover { background: rgba(255,255,255,0.18); border-color: rgba(255,255,255,0.4); }

/* Error overlay inside a cell */
.cell-error {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 16px;
  text-align: center;
  background: #141416;
  color: var(--muted);
  font-size: 13px;
}
.cell-error p { margin: 0; max-width: 90%; }
.cell-error a {
  color: var(--accent-2);
  text-decoration: none;
  border: 1px solid var(--accent-2);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 13px;
}
.cell-error a:hover { background: var(--accent-2); color: #002b46; }
.cell-error-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
}
.err-remove {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
}
.err-remove:hover { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---- Empty state ---- */
.empty {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--muted);
  gap: 6px;
}
.empty .hint { font-size: 14px; max-width: 460px; }
.empty b { color: var(--text); }
.empty-art {
  width: 240px;
  max-width: 45vw;
  height: auto;
  margin-bottom: 4px;
  filter: drop-shadow(0 8px 30px rgba(0, 0, 0, 0.6));
}
