:root {
  --bg: #0b0c0f;
  --surface: #16181d;
  --surface-2: #1f2229;
  --line: #2a2e37;
  --text: #f2f3f5;
  --muted: #9aa1ad;
  --accent: #e82127;
  --twitch: #9146ff;
  --cyan: #00d4ff;
  --success: #4ade80;
  --nav: 96px;
  --radius: 16px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

h1 { margin: 0 0 4px; font-size: 30px; letter-spacing: -0.02em; }
h2 { margin: 28px 0 14px; font-size: 20px; }
.sub { margin: 0 0 22px; color: var(--muted); }

/* Menü */
.nav {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--nav);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 18px 8px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  z-index: 5;
}
.brand { margin-bottom: 14px; font-weight: 700; font-size: 15px; }
.brand span { color: var(--accent); }
.nav a {
  width: 80px;
  min-height: 76px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 13px;
  text-decoration: none;
}
.nav a.active { background: var(--surface-2); color: var(--text); }
.nav a.active svg { stroke: var(--accent); }
svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

main { margin-left: var(--nav); padding: 28px 32px 48px; }

.bar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 18px; align-items: center; }
.bar-form { display: flex; gap: 10px; flex: 1 1 320px; }
.bar input[type="search"], .bar input[type="url"], .bar-form input { flex: 1 1 240px; }

input, select, button, .btn {
  min-height: 56px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible, .tile:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}
button.ghost, .btn.ghost { background: var(--surface); border-color: var(--line); color: var(--text); font-weight: 500; }

.status {
  margin: 0 0 18px;
  padding: 14px 16px;
  border-radius: 14px;
  background: var(--surface);
  color: var(--muted);
}
.status.error { color: #ff8b8f; }

.grid { display: grid; gap: 14px; }
.grid.tiles { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.grid.videos { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 20px 16px; }

.tile {
  position: relative;
  min-height: 132px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-weight: 500;
  text-align: center;
  overflow-wrap: anywhere;
}
.tile:active, .video:active { transform: scale(0.98); }
.tile .badge {
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  color: #fff;
  font-weight: 700;
  font-size: 18px;
}
.tile img { width: 56px; height: 56px; object-fit: contain; }
.tile small { color: var(--muted); font-weight: 400; font-size: 13px; }

.tile .del-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  min-height: 28px;
  width: 28px;
  padding: 0;
  border-radius: 50%;
  background: rgba(255,255,255,0.08);
  border: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1;
  display: grid;
  place-items: center;
}
.tile .del-btn:hover { background: rgba(232,33,39,0.3); color: #fff; }

.tile-live-indicator {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
}
.tile-live-indicator .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #666;
}
.tile-live-indicator.online { color: var(--success); }
.tile-live-indicator.online .dot {
  background: #ff3b30;
  box-shadow: 0 0 8px #ff3b30;
}

.video {
  display: block;
  min-height: 0;
  padding: 0;
  border: 0;
  background: none;
  text-align: left;
  font-weight: 400;
}
.video img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: var(--radius);
  background: var(--surface);
  display: block;
}
.video strong {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-top: 10px;
  font-weight: 600;
}
.video small { color: var(--muted); }

/* ================== PLAYER ================== */
.player {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  background: #000;
}
.player[hidden] { display: none !important; }

.player header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.player header button#player-close, .player header button#player-full {
  min-height: 44px;
  width: 44px;
  padding: 0;
  background: var(--surface);
  border-color: var(--line);
  border-radius: 12px;
}
.player-title {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  font-size: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Pill buttons for player */
.btn-pill {
  min-height: 42px;
  padding: 0 14px;
  border-radius: 21px;
  font-size: 13px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}
.btn-pill:hover { color: var(--text); border-color: #555; }
.btn-pill.active {
  background: rgba(0, 212, 255, 0.15);
  border-color: var(--cyan);
  color: var(--cyan);
  box-shadow: 0 0 14px rgba(0, 212, 255, 0.25);
}
.btn-pill .pill-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #666;
  transition: all 0.2s;
}
.btn-pill.active .pill-dot {
  background: var(--cyan);
  box-shadow: 0 0 8px var(--cyan);
}
.select-pill {
  min-height: 42px;
  padding: 0 12px;
  background: var(--surface-2);
  color: var(--text);
  border-radius: 21px;
}
.fps-badge {
  font-family: monospace;
  font-size: 12px;
  font-weight: bold;
  color: #00ff66;
  background: rgba(0,0,0,0.6);
  border: 1px solid #222;
  padding: 4px 8px;
  border-radius: 8px;
}

.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.stage video, .stage iframe, .stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: #000;
  object-fit: contain;
}

.player-overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  background: rgba(0,0,0,0.75);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}
.spinner {
  width: 44px;
  height: 44px;
  border: 3px solid rgba(255,255,255,0.15);
  border-top-color: var(--cyan);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.player-error {
  position: absolute;
  inset: 0;
  margin: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  color: #ff8b8f;
  background: rgba(11,12,15,0.9);
  text-align: center;
  z-index: 15;
}

/* Canvas bar */
.canvas-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 16px;
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.btn-sm {
  min-height: 40px;
  padding: 0 16px;
  border-radius: 12px;
  font-size: 13px;
}
.vol-control {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
  flex: 1;
  max-width: 240px;
}
.vol-control input[type="range"] {
  flex: 1;
  min-height: 24px;
  accent-color: var(--cyan);
}
.canvas-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}
.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ff3b30;
  box-shadow: 0 0 8px #ff3b30;
}

/* Probe view */
.probe-results-box {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin-top: 16px;
  font-family: monospace;
  font-size: 14px;
}
.probe-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--surface-2);
}
.probe-row:last-child { border-bottom: 0; }
.probe-label { color: var(--muted); }
.probe-val.ok { color: var(--success); font-weight: bold; }
.probe-val.fail { color: #f87171; font-weight: bold; }

@media (max-width: 720px) {
  .nav {
    inset: auto 0 0 0;
    width: auto;
    height: calc(76px + env(safe-area-inset-bottom));
    flex-direction: row;
    justify-content: space-around;
    padding: 6px 8px env(safe-area-inset-bottom);
    border-right: 0;
    border-top: 1px solid var(--line);
  }
  .brand { display: none; }
  .nav a { min-height: 62px; width: 64px; }
  main { margin-left: 0; padding: 20px 16px calc(100px + env(safe-area-inset-bottom)); }
  h1 { font-size: 26px; }
  .grid.tiles { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .player header { flex-wrap: wrap; }
  .player-controls { margin-left: auto; }
}

@media (prefers-reduced-motion: no-preference) {
  .tile, .video, .btn-pill { transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease; }
}
