:root {
  --bg: #0b0d10;
  --panel: #15191f;
  --panel-2: #1d232b;
  --border: #2a313b;
  --text: #eef1f5;
  --dim: #98a2ae;
  --accent: #ff4d5e;
  --tabs: calc(58px + env(safe-area-inset-bottom));
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
body { overflow: hidden; overscroll-behavior: none; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- stream ---------- */
#player-wrap { position: fixed; inset: 0 0 var(--tabs) 0; z-index: 0; background: #000; pointer-events: none; opacity: 0; transition: opacity 0.15s; }
#player-wrap iframe, #player { width: 100%; height: 100%; border: 0; }
body[data-view="stream"].playing:not(.moving) #player-wrap { opacity: 1; }

.view { position: fixed; inset: 0 0 var(--tabs) 0; z-index: 1; }
#feed { height: 100%; overflow-y: auto; scroll-snap-type: y mandatory; scrollbar-width: none; overscroll-behavior: contain; }
#feed::-webkit-scrollbar { display: none; }

.card { position: relative; height: 100%; scroll-snap-align: start; scroll-snap-stop: always; overflow: hidden; background: transparent; }
.card .thumb { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; transition: opacity 0.15s; }
.card .thumb.wide { object-fit: contain; }
body.playing:not(.moving) .card.active .thumb { opacity: 0; }
.card .shade { position: absolute; left: 0; right: 0; bottom: 0; height: 45%; background: linear-gradient(transparent, rgba(0, 0, 0, 0.75)); pointer-events: none; }
.card .info { position: absolute; left: 14px; right: 76px; bottom: 16px; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8); pointer-events: none; }
.card .title { font-size: 15.5px; font-weight: 600; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.card .meta { margin-top: 5px; font-size: 13px; color: #d6dbe1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .tag { display: inline-block; font-size: 11.5px; padding: 2px 7px; border-radius: 99px; background: rgba(255, 255, 255, 0.16); margin-bottom: 6px; }
.card .actions { position: absolute; right: 10px; bottom: 18px; display: flex; flex-direction: column; gap: 14px; }
.card .actions button, .card .actions a {
  width: 50px; height: 50px; border-radius: 50%; border: 0; background: rgba(0, 0, 0, 0.45); color: #fff;
  font-size: 21px; display: flex; align-items: center; justify-content: center; text-decoration: none; cursor: pointer;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.card .actions button.on { background: var(--accent); }
.card .paused { position: absolute; left: 50%; top: 45%; transform: translate(-50%, -50%); font-size: 64px; opacity: 0; pointer-events: none; text-shadow: 0 2px 10px rgba(0, 0, 0, 0.6); transition: opacity 0.15s; }
body.paused .card.active .paused { opacity: 0.85; }

.sound, .refresh {
  position: absolute; z-index: 3; border: 0; color: #fff; background: rgba(0, 0, 0, 0.55); cursor: pointer;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.sound { top: calc(14px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); padding: 10px 16px; border-radius: 99px; font-size: 14.5px; }
.refresh { top: calc(12px + env(safe-area-inset-top)); right: 12px; width: 42px; height: 42px; border-radius: 50%; font-size: 21px; }
.refresh.spin { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

#feed-mode { position: absolute; z-index: 3; top: calc(12px + env(safe-area-inset-top)); left: 12px; display: flex; align-items: center; gap: 8px; }
#feed-mode-label { font-size: 13px; color: #fff; text-shadow: 0 1px 3px #000; }
.chip { border: 0; background: rgba(0, 0, 0, 0.55); color: #fff; padding: 9px 13px; border-radius: 99px; font-size: 13.5px; cursor: pointer; }

.empty { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 30px; text-align: center; color: var(--dim); line-height: 1.5; }
.empty b { color: var(--text); font-size: 18px; }

/* ---------- pagine ---------- */
.page { overflow-y: auto; padding: calc(14px + env(safe-area-inset-top)) 16px 24px; background: var(--bg); }
.page-head { display: flex; align-items: baseline; gap: 10px; }
.page-head h1 { font-size: 24px; margin: 4px 0 14px; }
.dim { color: var(--dim); font-size: 13.5px; }
.box { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 14px; margin-bottom: 14px; }
.box h2 { font-size: 16px; margin: 0 0 4px; }
.hint { color: var(--dim); font-size: 13px; margin: 0 0 10px; line-height: 1.45; }
.row { display: flex; gap: 8px; align-items: center; }
.row.gap { margin-top: 10px; flex-wrap: wrap; }
.row input { flex: 1; min-width: 0; }
input:not([type]) , input[type="text"] {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border); border-radius: 10px; padding: 11px 12px; font-size: 16px;
}
.btn { background: var(--accent); border: 0; color: #fff; font-weight: 600; padding: 11px 14px; border-radius: 10px; cursor: pointer; flex-shrink: 0; }
.btn:disabled { opacity: 0.5; }
.btn.ghost { background: var(--panel-2); border: 1px solid var(--border); font-weight: 500; }
.msg { font-size: 13px; color: var(--dim); min-height: 0; margin-top: 6px; }
.msg.err { color: #ff8a8a; }
.list { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.list li { display: flex; align-items: center; gap: 10px; }
.list img { width: 36px; height: 36px; border-radius: 50%; background: var(--panel-2); object-fit: cover; flex-shrink: 0; }
.list .name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.x { border: 0; background: var(--panel-2); width: 32px; height: 32px; border-radius: 50%; cursor: pointer; flex-shrink: 0; color: var(--dim); }
.chips { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px; }
.chips:empty { margin-top: 0; }
.chips span { display: inline-flex; align-items: center; gap: 6px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 99px; padding: 6px 6px 6px 12px; font-size: 14px; }
.chips span button { border: 0; background: transparent; color: var(--dim); font-size: 15px; cursor: pointer; padding: 0 4px; }
.toggle { display: flex; align-items: center; gap: 10px; padding: 7px 0; font-size: 15px; }
.toggle input { width: 20px; height: 20px; accent-color: var(--accent); }

.box h3 { font-size: 13.5px; color: var(--dim); font-weight: 600; margin: 16px 0 0; text-transform: uppercase; letter-spacing: 0.04em; }
.learn:empty::after, #learn-kw-like:empty::after, #learn-kw-dislike:empty::after { content: "Ancora niente: guarda qualche video."; color: var(--dim); font-size: 13px; }
#learn-kw-like:empty, #learn-kw-dislike:empty { margin-top: 8px; }
.learn .score { font-size: 12.5px; font-variant-numeric: tabular-nums; color: var(--dim); }
.learn .score.pos { color: #6fe39a; }
.learn .score.neg { color: #ff8a8a; }
.chips span.pos { border-color: #2f6b47; }
.chips span.neg { border-color: #7a3238; }
.slider { margin: 10px 0 4px; }
.slider-labels { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--dim); margin-bottom: 4px; }
.slider-labels b { color: var(--text); font-weight: 600; }
.slider input { width: 100%; accent-color: var(--accent); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.grid .tile { position: relative; aspect-ratio: 9 / 14; border-radius: 10px; overflow: hidden; background: var(--panel); cursor: pointer; }
.grid .tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.grid .tile .t { position: absolute; left: 0; right: 0; bottom: 0; padding: 18px 8px 7px; font-size: 12.5px; line-height: 1.3; background: linear-gradient(transparent, rgba(0, 0, 0, 0.85)); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.grid .tile .x { position: absolute; top: 6px; right: 6px; background: rgba(0, 0, 0, 0.6); color: #fff; }
.empty-text { color: var(--dim); text-align: center; margin-top: 40px; line-height: 1.5; }

/* ---------- barra in basso ---------- */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; height: var(--tabs); padding-bottom: env(safe-area-inset-bottom); z-index: 5; display: flex; background: #0b0d10; border-top: 1px solid var(--border); }
.tabs button { flex: 1; border: 0; background: transparent; color: var(--dim); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11.5px; cursor: pointer; }
.tabs button span { font-size: 18px; }
.tabs button.active { color: var(--text); }

.toast { position: fixed; left: 50%; bottom: calc(var(--tabs) + 16px); transform: translateX(-50%); z-index: 9; background: #232a33; border: 1px solid var(--border); color: #fff; padding: 10px 14px; border-radius: 12px; font-size: 14px; display: flex; gap: 12px; align-items: center; opacity: 0; pointer-events: none; transition: opacity 0.2s; max-width: calc(100% - 32px); }
.toast.show { opacity: 1; pointer-events: auto; }
.toast button { border: 0; background: transparent; color: var(--accent); font-weight: 600; cursor: pointer; padding: 0; }
