/* ══════════════════════════════════════════════════════════════════
   TV Tamakun — shared styles
   Controller: dark UI with 3 cards.
   Display: black full-viewport stage that always fits the current media.
   ══════════════════════════════════════════════════════════════════ */

* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0b0b0f;
  --card: #14141a;
  --card-hover: #1a1a22;
  --border: #26262f;
  --text: #f0f0f5;
  --text-dim: #8a8a95;
  --accent: #6b7cff;
  --accent-hover: #8695ff;
  --danger: #ff3b30;
  --success: #30d158;
  --radius: 14px;
  --radius-sm: 8px;
}

html, body {
  height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Tajawal', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ── Controller ──────────────────────────────────────────────────── */

body.controller {
  padding-bottom: 40px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 24px;
  background: rgba(11, 11, 15, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }
.live-dot {
  color: var(--success);
  font-size: 10px;
  transition: color .2s;
}
.live-dot.stale { color: #f39c12; }
.live-dot.offline { color: var(--danger); }
.link-btn {
  margin-inline-start: auto;
  color: var(--accent);
  font-size: 14px;
  text-decoration: none;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  transition: background .15s;
}
.link-btn:hover { background: rgba(107, 124, 255, 0.1); }

.wrap {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
  display: grid;
  gap: 20px;
  grid-template-columns: 1fr;
}
@media (min-width: 900px) {
  .wrap { grid-template-columns: 1fr 1fr; grid-template-areas: 'up cur' 'gal gal'; }
  .upload-card { grid-area: up; }
  .current-card { grid-area: cur; }
  .gallery-card { grid-area: gal; }
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.card-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
.card-head h2 { font-size: 15px; font-weight: 600; color: var(--text); }
.count-chip {
  margin-inline-start: auto;
  background: var(--border);
  color: var(--text-dim);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.ghost-btn {
  margin-inline-start: auto;
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  transition: all .15s;
}
.ghost-btn:hover { color: var(--text); border-color: var(--text-dim); }

/* Upload drop zone */
.drop-zone {
  display: block;
  position: relative;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  transition: all .15s;
}
.drop-zone:hover, .drop-zone.dragover, .drop-zone:focus-visible {
  border-color: var(--accent);
  background: rgba(107, 124, 255, 0.04);
  outline: none;
}
.drop-icon { font-size: 40px; margin-bottom: 10px; }
.drop-title { font-size: 16px; font-weight: 600; }
.drop-hint { font-size: 13px; color: var(--text-dim); margin-top: 4px; }

.progress-wrap {
  padding: 14px 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-top: 12px;
}
.progress-name {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width .1s linear;
}
.progress-info {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
}

/* Current preview */
.current-preview {
  position: relative;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.current-preview img,
.current-preview video {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.current-preview .empty { color: var(--text-dim); font-size: 14px; }

/* Gallery */
.gallery-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
}
.gallery-grid .empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 40px 20px;
  color: var(--text-dim);
  font-size: 14px;
}
.tile {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #000;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform .1s;
}
.tile:hover { transform: translateY(-2px); }
.tile.active { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(107, 124, 255, 0.25); }
.tile img, .tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
}
.tile-badge {
  position: absolute;
  top: 6px;
  inset-inline-start: 6px;
  background: rgba(0,0,0,0.7);
  color: #fff;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
}
.tile-delete {
  position: absolute;
  top: 6px;
  inset-inline-end: 6px;
  background: rgba(0,0,0,0.7);
  color: #fff;
  border: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity .1s;
}
.tile:hover .tile-delete { opacity: 1; }
.tile-delete:hover { background: var(--danger); }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: all .2s;
  z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { border-color: var(--danger); background: rgba(255, 59, 48, 0.1); }
.toast.success { border-color: var(--success); background: rgba(48, 209, 88, 0.1); }

/* ── Display page (TV) ─────────────────────────────────────────── */

body.display {
  background: #000;
  overflow: hidden;
  height: 100vh;
  height: 100dvh;
  cursor: none;
}
.stage {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
}
.stage img, .stage video {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  animation: fade-in .3s ease-out;
}
@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.idle {
  text-align: center;
  color: var(--text-dim);
}
.idle-logo {
  font-size: 96px;
  font-weight: 800;
  letter-spacing: -0.05em;
  color: rgba(255,255,255,0.08);
  margin-bottom: 12px;
}
.idle-sub { font-size: 18px; opacity: 0.5; }

.offline {
  position: fixed;
  top: 16px;
  inset-inline-end: 16px;
  color: var(--danger);
  font-size: 20px;
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 0.4; }
  50%      { opacity: 1; }
}

/* Sound-unmute overlay — visible on the display only when the current
   media is a video and the browser is still blocking sound. One tap
   anywhere on the button unmutes and hides the overlay. */
.sound-cta {
  position: fixed;
  inset: auto 24px 24px auto;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 14px 22px;
  background: rgba(107, 124, 255, 0.95);
  color: #fff;
  border: none;
  border-radius: 999px;
  font-family: inherit;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 12px 40px rgba(107, 124, 255, 0.5);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  animation: nudge 1.6s ease-in-out infinite;
  z-index: 100;
}
.sound-cta:hover {
  background: rgba(107, 124, 255, 1);
}
.sound-cta-icon {
  font-size: 22px;
  line-height: 1;
}
@keyframes nudge {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-6px); }
}

/* Fullscreen toggle FAB. Bottom-left corner (opposite the sound CTA so
   the two never overlap). Half-faded until hover so it doesn't fight
   the media on screen, then pops out clearly when you approach it. */
.fs-fab {
  position: fixed;
  inset: auto auto 24px 24px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(20, 20, 26, 0.75);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.15);
  cursor: pointer;
  font-size: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  opacity: 0.3;
  transition: opacity .2s, background .2s, transform .1s;
  z-index: 99;
}
.fs-fab:hover, .fs-fab:focus-visible {
  opacity: 1;
  background: rgba(20, 20, 26, 0.95);
  outline: none;
}
.fs-fab:active { transform: scale(0.94); }
@media (pointer: coarse) { .fs-fab { opacity: 0.6; } }
/* Once we're in real browser fullscreen there's no browser chrome to
   avoid — hide the FAB completely so nothing sits on top of the TV
   image. Press F or Esc to toggle back. */
:fullscreen .fs-fab,
:-webkit-full-screen .fs-fab { display: none; }
