/* ============================================================
   Bendoflix - TV and desktop
   ============================================================ */

:root {
    --bg:        #101314;
    --bg-soft:   #171a1b;
    --surface:   #1b2020;
    --surface-2: #252b2b;
    --surface-3: #303838;
    --text:      #f4f6f2;
    --text-dim:  #b1bdb9;
    --accent:    #91edc1;
    --danger:    #9c3b39;
    --focus:     #ffffff;
    --radius:    8px;
    --row-gap:   50px;
    --sidebar-collapsed: 110px;
    --sidebar-expanded: 320px;
    --shadow:    0 18px 46px rgba(0,0,0,0.72);
    --glow:      0 0 24px rgba(67,239,164,0.42);
}

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

html, body {
    width: 100%;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    -webkit-font-smoothing: antialiased;
}
html.avplay-mode,
body.avplay-mode {
    background: transparent !important;
    cursor: none !important;
}
body.avplay-mode * {
    cursor: none !important;
    caret-color: transparent !important;
}
body.avplay-mode #sidebar,
body.avplay-mode #content,
body.avplay-mode #toast,
body.avplay-mode #loader,
body.avplay-mode #text-editor,
body.avplay-mode #player-debug {
    visibility: hidden !important;
}
body.avplay-mode .focused {
    box-shadow: none !important;
    transform: none !important;
}

img { -webkit-user-drag: none; }

/* ---- Scrollbar nascosta -------------------------------------- */
::-webkit-scrollbar { width: 0; height: 0; background: transparent; }

/* ============================================================
   SIDEBAR
   ============================================================ */
#sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--sidebar-collapsed);
    background: rgba(14,14,18,0.95);
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 60px 0 36px;
    border-right: 1px solid rgba(255,255,255,0.05);
    transition: width 0.18s ease, background 0.16s ease, padding 0.18s ease;
}
#sidebar.expanded {
    width: var(--sidebar-expanded);
    background: rgba(14,14,18,0.98);
    align-items: flex-start;
    padding-left: 30px;
}
#sidebar .logo {
    font-size: 32px;
    font-weight: 800;
    letter-spacing: 0;
    color: var(--accent);
    margin-bottom: 80px;
    white-space: nowrap;
    overflow: hidden;
    text-shadow: 0 0 18px rgba(67,239,164,0.2);
}
#sidebar .logo .full { display: none; }
#sidebar.expanded .logo .short { display: none; }
#sidebar.expanded .logo .full  { display: inline; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 0;
    width: 100%;
    height: 80px;
    margin-bottom: 12px;
    padding: 0;
    color: var(--text-dim);
    font-size: 24px;
    border-radius: 12px 0 0 12px;
    cursor: pointer;
    white-space: nowrap;
    position: relative;
    transition: background 0.18s ease, color 0.18s ease, transform 0.18s ease;
}
#sidebar:not(.expanded) .nav-item { justify-content: center; }
.nav-item .icon {
    font-size: 34px;
    width: var(--sidebar-collapsed);
    text-align: center;
    flex-shrink: 0;
    transition: transform 0.18s ease, text-shadow 0.18s ease;
}
#sidebar.expanded .nav-item .icon {
    width: 50px;
    margin-right: 20px;
    text-align: left;
}
.nav-item .label {
    display: inline;
    opacity: 0;
    transform: translateX(-10px);
    font-weight: 650;
    transition: opacity 0.25s ease, transform 0.25s ease;
}
#sidebar.expanded .nav-item .label { opacity: 1; transform: translateX(0); }
.nav-item.focused {
    background: rgba(67,239,164,0.1);
    color: #fff;
    box-shadow: inset 4px 0 0 var(--accent);
}
.nav-item.active { color: var(--accent); }
.nav-item.focused .icon {
    transform: scale(1.06);
    text-shadow: 0 0 16px rgba(67,239,164,0.65);
}

/* ============================================================
   AREA CONTENUTO
   ============================================================ */
#content {
    position: absolute;
    top: 0; left: var(--sidebar-collapsed); right: 0; bottom: 0;
    overflow-y: auto;
    overflow-x: hidden;
    transition: left 0.18s ease;
}
#sidebar.expanded + #content { left: var(--sidebar-expanded); }

/* ---- HERO ---------------------------------------------------- */
#hero {
    position: relative;
    width: 100%;
    height: 700px;
    background-size: cover;
    background-position: center 20%;
    background-color: var(--surface);
    display: flex;
    align-items: flex-start;
}
#hero::after {
    content: '';
    position: absolute; inset: 0;
    background:
      linear-gradient(90deg, rgba(19,19,23,1) 6%, rgba(19,19,23,0.8) 38%, rgba(19,19,23,0) 100%),
      linear-gradient(0deg, var(--bg) 0%, rgba(19,19,23,0) 52%);
}
.hero-inner {
    position: relative;
    z-index: 2;
    padding: 120px 80px 0;
    max-width: 900px;
}
.hero-title {
    font-size: 84px;
    font-weight: 800;
    line-height: 1;
    margin-bottom: 24px;
    text-shadow: 0 4px 18px rgba(0,0,0,0.62);
}
.hero-meta {
    display: flex;
    gap: 20px;
    align-items: center;
    color: var(--accent);
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 20px;
}
.hero-meta .score { color: var(--accent); font-weight: 700; }
.hero-plot {
    font-size: 24px;
    line-height: 1.6;
    color: #d6d6dd;
    margin-bottom: 40px;
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-shadow: 0 2px 5px rgba(0,0,0,0.35);
}
.hero-actions { display: flex; gap: 20px; }

.btn {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    padding: 18px 40px;
    border-radius: var(--radius);
    font-size: 24px;
    font-weight: 700;
    cursor: pointer;
    border: 2px solid transparent;
    background: rgba(255,255,255,0.1);
    color: var(--text);
    white-space: nowrap;
    transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}
.btn.primary { background: var(--accent); color: #003822; }
.btn.focused {
    border-color: var(--focus);
    box-shadow: var(--glow);
    transform: scale(1.04);
}

/* ============================================================
   CAROSELLI (rows)
   ============================================================ */
#rows { padding: 0 80px 80px; margin-top: -80px; position: relative; z-index: 3; }
.row { margin-bottom: var(--row-gap); }
.row-title {
    font-size: 32px;
    font-weight: 700;
    margin-bottom: 24px;
    color: var(--text);
}
.row-track {
    display: flex;
    gap: 24px;
    overflow-x: auto;
    scroll-behavior: auto;
    padding: 10px 60px 14px 0;
}

.card {
    position: relative;
    flex: 0 0 auto;
    width: 240px;
    height: 360px;
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--surface);
    cursor: pointer;
    border: 2px solid transparent;
    transition: transform 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
}
.card img {
    width: 100%; height: 100%;
    object-fit: cover;
    display: block;
}
.card .card-fallback {
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    padding: 14px; text-align: center;
    font-size: 18px; color: var(--text-dim);
}
.card.focused {
    transform: scale(1.06);
    border-color: var(--accent);
    box-shadow: var(--shadow), 0 0 16px rgba(67,239,164,0.5);
    z-index: 50;
}
.card .card-badge {
    position: absolute; top: 10px; left: 10px;
    background: rgba(0,0,0,0.72);
    color: var(--accent);
    font-size: 14px; font-weight: 700;
    padding: 4px 10px; border-radius: 6px;
}
.card .card-title {
    position: absolute; left: 0; right: 0; bottom: 0;
    padding: 30px 12px 12px;
    font-size: 17px; font-weight: 600;
    background: linear-gradient(0deg, rgba(0,0,0,0.92), transparent);
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
    overflow: hidden;
}
.card-progress {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 8px;
    border-radius: 0;
    overflow: hidden;
    background: rgba(255,255,255,0.28);
    z-index: 2;
}
.card-progress div {
    height: 100%;
    background: var(--accent);
    box-shadow: 0 0 10px rgba(67,239,164,0.85);
}

/* ============================================================
   GRID (ricerca / archivio)
   ============================================================ */
#view-grid { padding: 80px 80px 80px; }
.grid-head { font-size: 48px; font-weight: 800; margin-bottom: 40px; }
.grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 30px;
}
.grid .card { width: 100%; height: 330px; }
.grid-more-wrap {
    margin-top: 42px;
    display: flex;
    justify-content: center;
}

/* ============================================================
   RICERCA — tastiera a schermo
   ============================================================ */
#view-search { padding: 100px 80px 80px; }
.search-box {
    display: flex; align-items: center; gap: 18px;
    width: 1000px;
    height: 90px;
    background: var(--surface);
    border-radius: 45px;
    padding: 0 40px;
    font-size: 36px;
    margin: 0 auto 40px;
    border: 3px solid transparent;
}
.search-box .q,
.search-input {
    flex: 1;
    min-width: 0;
    background: transparent;
    border: 0;
    outline: none;
    color: var(--text);
    font: inherit;
}
.search-input::placeholder { color: rgba(244,244,246,0.45); }
.search-input.focused,
.search-input:focus { color: var(--text); }
.search-box .caret {
    width: 3px; height: 40px; background: var(--accent);
    animation: blink 1s step-end infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.keyboard { display: flex; flex-direction: column; gap: 14px; max-width: 1120px; margin: 0 auto; }
.kb-row { display: flex; gap: 14px; }
.key {
    flex: 1;
    min-width: 70px;
    height: 70px;
    background: var(--surface-2);
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 26px; font-weight: 600; cursor: pointer;
    border: 2px solid transparent;
    transition: transform 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}
.key.wide { flex: 2; }
.key.focused {
    background: var(--accent); color: #003822;
    box-shadow: var(--glow);
    transform: scale(1.06);
    z-index: 10;
}

/* ============================================================
   DETTAGLIO TITOLO
   ============================================================ */
#view-detail { position: relative; min-height: 1080px; }
#detail-hero {
    position: relative;
    height: 640px;
    background-size: cover; background-position: center 20%;
}
#detail-hero::after {
    content: ''; position: absolute; inset: 0;
    background:
      linear-gradient(90deg, rgba(19,19,23,0.98) 6%, rgba(19,19,23,0.72) 46%, rgba(19,19,23,0.08) 100%),
      linear-gradient(0deg, var(--bg) 0%, rgba(19,19,23,0) 62%);
}
.detail-body { position: relative; z-index: 2; padding: 0 80px 90px; margin-top: -380px; }
.detail-title { font-size: 72px; line-height: 1; font-weight: 800; margin-bottom: 20px; max-width: 1000px; text-shadow: 0 4px 18px rgba(0,0,0,0.6); }
.detail-meta { display: flex; gap: 20px; color: var(--accent); font-size: 22px; font-weight: 650; margin-bottom: 30px; flex-wrap: wrap; }
.detail-meta .tag {
    background: rgba(67,239,164,0.12);
    color: var(--accent);
    padding: 6px 16px;
    border-radius: 999px;
    font-size: 18px;
}
.detail-plot { font-size: 24px; line-height: 1.6; color: #d6d6dd; max-width: 1000px; margin-bottom: 40px; }
.detail-actions { display: flex; gap: 20px; margin-bottom: 60px; }

/* Selettore stagioni */
.season-bar {
    display: flex;
    gap: 20px;
    margin-bottom: 30px;
    flex-wrap: wrap;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    padding-bottom: 16px;
}
.season-chip {
    padding: 14px 26px; border-radius: 999px; background: var(--surface-2);
    font-size: 20px; cursor: pointer;
    border: 2px solid transparent;
    transition: transform 0.16s ease, border-color 0.16s ease, background 0.16s ease;
}
.season-chip.focused { border-color: var(--focus); box-shadow: var(--glow); transform: scale(1.06); }
.season-chip.active { background: var(--accent); color: #003822; font-weight: 700; }

/* Lista episodi */
.episodes { display: flex; flex-direction: column; gap: 20px; padding-bottom: 80px; max-width: 1220px; }
.episode {
    display: flex; gap: 22px; align-items: center;
    background: rgba(31,31,35,0.92); border-radius: 16px;
    padding: 16px; cursor: pointer;
    border: 2px solid transparent;
    transition: transform 0.16s ease, border-color 0.16s ease, background 0.16s ease;
}
.episode.focused { border-color: var(--accent); box-shadow: var(--glow); background: var(--surface-2); transform: translateY(-2px); }
.episode .ep-thumb {
    width: 220px; height: 124px; border-radius: 10px; object-fit: cover; flex-shrink: 0;
    background: var(--surface-2);
}
.episode .ep-info { flex: 1; }
.episode .ep-num { color: var(--accent); font-size: 16px; font-weight: 700; margin-bottom: 4px; }
.episode .ep-name { font-size: 23px; font-weight: 650; margin-bottom: 8px; }
.anime-episode { width: 100%; justify-content: space-between; color: var(--text); text-align: left; }
.anime-episode .ep-name, .anime-episode .ep-num { margin: 0; }
.anime-episode .ep-num { flex-shrink: 0; }
.episode .ep-plot {
    font-size: 17px; color: var(--text-dim); line-height: 1.4;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

/* ============================================================
   PLAYER
   ============================================================ */
#player {
    position: fixed; inset: 0; width: 100%; height: 100%;
    background: #000; z-index: 200;
    display: none;
}
#player.active { display: block; }
#player.native { background: transparent; }
#player-mount {
    position: absolute; inset: 0;
    width: 100%; height: 100%;
    z-index: 2;
}
#player.native #player-mount { background: transparent; }
#player video, #player iframe {
    position: absolute; inset: 0;
    width: 100%; height: 100%; border: none; background: #000;
}
#player video {
    object-fit: contain;
}
#player-subtitles {
    position: absolute;
    left: 9%;
    right: 9%;
    bottom: 92px;
    z-index: 8;
    display: none;
    color: #fff;
    font-family: Arial, sans-serif;
    font-size: 42px;
    font-weight: 650;
    line-height: 1.28;
    letter-spacing: 0;
    text-align: center;
    white-space: pre-line;
    text-shadow:
        -2px -2px 2px #000,
         2px -2px 2px #000,
        -2px  2px 2px #000,
         2px  2px 2px #000,
         0 4px 8px #000;
    pointer-events: none;
}
#player-subtitles.show { display: block; }
.native-surface {
    position: fixed;
    left: -16px; top: -16px;
    width: 1px; height: 1px;
    background: transparent;
    z-index: 1;
    opacity: 0 !important;
    pointer-events: none !important;
    border: 0 !important;
    outline: 0 !important;
    box-shadow: none !important;
    color: transparent !important;
}
.player-error {
    position: absolute; inset: 0;
    display: flex; flex-direction: column; justify-content: center;
    max-width: 1180px;
    padding: 80px;
    color: #fff;
}
.player-error-title {
    font-size: 42px;
    font-weight: 800;
    margin-bottom: 18px;
}
.player-error-detail {
    font-size: 22px;
    line-height: 1.5;
    color: var(--text-dim);
    white-space: pre-wrap;
}
.player-error-hint {
    margin-top: 28px;
    font-size: 20px;
    color: var(--accent);
}
#player-overlay {
    position: absolute; inset: 0; z-index: 5;
    display: flex; flex-direction: column; justify-content: flex-end;
    padding: 80px;
    background: linear-gradient(0deg, rgba(0,0,0,0.9) 0%, transparent 32%);
    opacity: 0; transition: opacity 0.3s; pointer-events: none;
}
#player-overlay.show { opacity: 1; }
#player-title { font-size: 36px; font-weight: 800; margin-bottom: 12px; text-shadow: 0 2px 10px #000; }
.player-bottom { display: flex; flex-direction: column; gap: 16px; }
.progress-wrap { height: 10px; background: rgba(255,255,255,0.2); border-radius: 999px; overflow: hidden; cursor: pointer; pointer-events: auto; }
.progress-bar { height: 100%; width: 0; background: var(--accent); border-radius: 999px; box-shadow: 0 0 12px rgba(67,239,164,0.8); pointer-events: none; }
.player-time { font-size: 22px; font-weight: 650; color: var(--accent); }
.player-meta-row {
    min-height: 42px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    font-size: 19px;
    color: rgba(255,255,255,0.76);
}
.player-badges {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}
#player-quality-badge,
#player-server-badge {
    padding: 7px 12px;
    border: 1px solid rgba(255,255,255,0.48);
    border-radius: 6px;
    color: #fff;
    font-weight: 750;
}
#player-server-badge {
    border-color: rgba(145,237,193,0.55);
    color: var(--accent);
}
#player-server-badge[hidden] { display: none; }
.player-settings-label { font-weight: 700; }

#player-settings {
    position: absolute;
    top: 90px;
    right: 90px;
    width: 610px;
    max-height: 900px;
    z-index: 12;
    display: none;
    overflow: hidden;
    background: rgba(20,20,24,0.98);
    border: 1px solid rgba(255,255,255,0.16);
    border-radius: 8px;
    color: #fff;
    box-shadow: 0 22px 70px rgba(0,0,0,0.72);
}
#player-settings.open { display: block; }
.player-settings-head {
    height: 92px;
    padding: 0 34px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}
.player-settings-title { font-size: 30px; font-weight: 800; }
.player-settings-close { font-size: 17px; font-weight: 750; color: var(--text-dim); }
.player-settings-tabs {
    height: 78px;
    padding: 0 18px;
    display: flex;
    align-items: stretch;
    gap: 4px;
    background: rgba(255,255,255,0.025);
}
.player-settings-tab {
    flex: 1 1 0;
    min-width: 0;
    padding: 0 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-bottom: 4px solid transparent;
    color: var(--text-dim);
    font-size: 20px;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
}
.player-settings-tab.active {
    color: #fff;
    border-bottom-color: var(--accent);
}
#player-settings-list {
    max-height: 690px;
    overflow-y: auto;
    padding: 18px 20px 24px;
}
.player-setting-option {
    position: relative;
    min-height: 68px;
    padding: 14px 24px 14px 62px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border: 3px solid transparent;
    border-radius: 6px;
    color: #e8e8eb;
    font-size: 23px;
    font-weight: 600;
}
.player-setting-option::before {
    content: '';
    position: absolute;
    left: 25px;
    width: 13px;
    height: 13px;
    border-radius: 50%;
    background: transparent;
}
.player-setting-option.selected::before { background: var(--accent); }
.player-setting-option.focused {
    border-color: #fff;
    background: rgba(255,255,255,0.11);
}
.player-setting-option .option-note {
    margin-left: 20px;
    color: var(--text-dim);
    font-size: 17px;
    font-weight: 550;
}
.player-setting-empty {
    padding: 36px 28px;
    color: var(--text-dim);
    font-size: 21px;
    line-height: 1.45;
}

/* I vecchi WebKit Tizen lasciano talvolta residui durante scale e scroll. */
body.tizen-ui .card,
body.tizen-ui .btn,
body.tizen-ui .nav-item,
body.tizen-ui .nav-item .icon,
body.tizen-ui .nav-item .label,
body.tizen-ui .season-chip,
body.tizen-ui .episode,
body.tizen-ui .setting-field {
    transition: none !important;
}
body.tizen-ui .card.focused,
body.tizen-ui .btn.focused,
body.tizen-ui .nav-item.focused .icon,
body.tizen-ui .season-chip.focused,
body.tizen-ui .episode.focused,
body.tizen-ui .setting-field.focused {
    transform: none !important;
}

/* ============================================================
   IMPOSTAZIONI
   ============================================================ */
#view-settings { padding: 80px; max-width: none; }
.settings-head { font-size: 48px; font-weight: 800; margin-bottom: 40px; }
.setting-field {
    max-width: 1220px;
    margin-bottom: 20px;
    padding: 30px 40px;
    border-radius: 16px;
    background: var(--surface);
    border: 2px solid transparent;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 36px;
}
.setting-field label {
    display: block;
    font-size: 24px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 0;
}
.setting-field .value {
    min-width: 520px;
    max-width: 650px;
    background: rgba(255,255,255,0.04);
    border-radius: 12px;
    padding: 16px 22px;
    font-size: 22px;
    cursor: pointer;
    color: var(--accent);
    font-family: Consolas, 'Courier New', monospace;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    border: 2px solid transparent;
}
.setting-field .value.focused {
    border-color: var(--accent);
    background: var(--surface-2);
    box-shadow: var(--glow);
}
.settings-hint { max-width: 1040px; font-size: 20px; color: var(--text-dim); line-height: 1.6; margin-top: 32px; }

.text-editor {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 350;
    background: rgba(0,0,0,0.9);
    padding: 0;
    align-items: center;
    justify-content: center;
}
.te-panel {
    width: 1200px;
    max-width: 1200px;
    background: var(--bg);
    border-radius: 32px;
    padding: 60px;
    border: 2px solid rgba(255,255,255,0.1);
    box-shadow: var(--shadow);
}
.te-label {
    font-size: 32px;
    font-weight: 800;
    margin-bottom: 40px;
    text-align: center;
}
.te-input {
    width: 100%;
    height: 86px;
    border: 3px solid var(--accent);
    border-radius: 16px;
    background: var(--surface);
    color: var(--text);
    font-size: 32px;
    padding: 0 40px;
    outline: none;
}
.te-input:focus,
.te-input.focused {
    border-color: var(--accent);
    box-shadow: var(--glow);
}
.te-actions {
    display: flex;
    gap: 20px;
    justify-content: center;
    margin-top: 34px;
}
.te-action.focused {
    border-color: var(--focus);
    box-shadow: var(--glow);
    transform: scale(1.04);
}
.te-hint {
    margin-top: 28px;
    color: var(--text-dim);
    font-size: 20px;
    text-align: center;
}

/* ============================================================
   STATI: loading / errore / toast
   ============================================================ */
#loader {
    position: fixed; inset: 0; z-index: 300;
    background: rgba(19,19,23,0.92);
    display: none; align-items: center; justify-content: center;
    flex-direction: column; gap: 24px;
}
#loader.active { display: flex; }
.spinner {
    width: 80px; height: 80px;
    border: 6px solid rgba(67,239,164,0.1);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loader .msg { font-size: 24px; font-weight: 650; color: var(--text-dim); }

#toast {
    position: fixed; bottom: 60px; left: 50%; transform: translateX(-50%);
    background: rgba(244,244,246,0.94); color: #111;
    padding: 16px 40px; border-radius: 999px;
    font-size: 22px; font-weight: 700; z-index: 400;
    box-shadow: var(--shadow);
    opacity: 0; transition: opacity 0.3s; pointer-events: none;
}
#toast.show { opacity: 1; }
#toast.error { background: var(--danger); color: #fff; }

#diag-output {
    max-width: 1220px;
    margin-top: 34px !important;
    padding: 24px 28px;
    border-radius: 16px;
    background: rgba(0,0,0,0.32);
    color: #00ff88 !important;
    border: 1px solid rgba(67,239,164,0.18);
}

#search-results {
    margin-top: 60px !important;
}

/* ---- Views: una sola visibile alla volta -------------------- */
.view { display: none; }
.view.active { display: block; }

.empty {
    padding: 90px 70px; text-align: center;
    color: var(--text-dim); font-size: 24px;
    background: rgba(31,31,35,0.72);
    border-radius: 18px;
}
.grid .empty { grid-column: 1 / -1; }
#hero[hidden] { display: none; }
.home-actions { padding: 0 32px 32px; }
.tizen-ui .home-actions { display: none; }
#profiles-screen {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 140;
    overflow: auto;
    background: var(--bg);
    padding: 8% 32px 36px;
    text-align: center;
}
body.profiles-open #profiles-screen { display: block; }
body.profiles-open #sidebar, body.profiles-open #content { visibility: hidden; }
#profiles-title { font-size: 58px; margin-bottom: 48px; }
#profiles-list { display: flex; flex-wrap: wrap; justify-content: center; gap: 20px; margin: 0 auto 34px; max-width: 1240px; }
.profile-button {
    width: 170px;
    min-height: 146px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 12px;
    background: var(--surface);
    color: var(--text);
    border: 3px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    font: inherit;
    font-size: 21px;
    gap: 12px;
    overflow-wrap: anywhere;
}
.profile-button span { max-width: 100%; }
.profile-avatar {
    display: grid;
    place-items: center;
    width: 58px;
    height: 58px;
    border-radius: 50%;
    background: #255645;
    color: #e9fff7;
    font-size: 28px;
    font-weight: 700;
}
.profile-button.focused, .profile-button:focus-visible { border-color: var(--focus); background: var(--surface-3); }
.profile-button:hover { border-color: var(--accent); }
#profiles-settings.focused { border-color: var(--focus); }
html:not(.tizen) #profiles-title { font-size: 42px; margin-bottom: 30px; }
html:not(.tizen) .profile-button { width: 132px; min-height: 118px; font-size: 16px; }

.cloud-head { margin: 48px 0 24px; font-size: 32px; }
#diag-output:empty { display: none; }
.search-box { max-width: 100%; }
.search-box:focus-within { border-color: var(--accent); }
.search-box.focused { border-color: var(--focus); }
#player-exit, #player-menu-button {
    font: inherit;
    color: #fff;
    background: #232329;
    border: 1px solid #67676d;
    border-radius: 6px;
}
#player-exit {
    position: absolute;
    top: 24px;
    right: 24px;
    z-index: 20;
    height: 46px;
    width: 46px;
    font-size: 28px;
    cursor: pointer;
}
.tizen-ui #player-exit { display: none; }
#player-menu-button { padding: 8px 14px; cursor: pointer; }
.tizen-ui #player-menu-button { pointer-events: none; }
#player-overlay.show #player-menu-button { pointer-events: auto; }
#player.embedded #player-overlay { display: none; }
.embed-status {
    position: absolute;
    top: 30px;
    left: 30px;
    right: 88px;
    color: #fff;
    background: rgba(15,15,20,0.88);
    padding: 14px 20px;
    border-radius: 6px;
    pointer-events: none;
}
.tizen-ui #sidebar, .tizen-ui #content, .tizen-ui #player-overlay { transition: none; }
.tizen-ui .te-panel { align-self: flex-start; margin-top: 40px; }
.tizen-ui .card.focused,
.tizen-ui .episode.focused { box-shadow: none; border-color: var(--focus); }

html:not(.tizen) #sidebar {
    width: 172px;
    align-items: flex-start;
    padding: 32px 12px;
    transition: none;
}
html:not(.tizen) #sidebar .logo { font-size: 23px; margin: 0 0 48px 8px; }
html:not(.tizen) #sidebar .logo .full { display: inline; }
html:not(.tizen) #sidebar .logo .short { display: none; }
html:not(.tizen) #sidebar .nav-item { height: 48px; font-size: 15px; justify-content: flex-start; margin-bottom: 4px; }
html:not(.tizen) #sidebar .nav-item .icon { width: 40px; font-size: 21px; margin: 0; text-align: center; }
html:not(.tizen) #sidebar .nav-item .label { opacity: 1; transform: none; }
html:not(.tizen) #content { left: 172px; transition: none; }
html:not(.tizen) #hero { height: 520px; align-items: flex-end; }
html:not(.tizen) .hero-inner { padding: 40px 32px 80px; max-width: 780px; }
html:not(.tizen) .hero-title, html:not(.tizen) .detail-title { font-size: 46px; overflow-wrap: anywhere; }
html:not(.tizen) .hero-plot, html:not(.tizen) .detail-plot { font-size: 17px; margin-bottom: 20px; }
html:not(.tizen) .hero-meta, html:not(.tizen) .detail-meta { font-size: 16px; }
html:not(.tizen) .hero-actions, html:not(.tizen) .detail-actions { flex-wrap: wrap; }
html:not(.tizen) .btn { font-size: 16px; padding: 11px 20px; }
html:not(.tizen) #rows { padding: 0 32px 48px; margin-top: -35px; }
html:not(.tizen) .row { margin-bottom: 28px; }
html:not(.tizen) .row-title { font-size: 23px; margin-bottom: 12px; }
html:not(.tizen) .row-track { gap: 16px; }
html:not(.tizen) .card { width: 148px; height: 222px; border-radius: 8px; }
html:not(.tizen) .card:hover { border-color: var(--accent); }
html:not(.tizen) #view-grid, html:not(.tizen) #view-search, html:not(.tizen) #view-settings { padding: 36px 32px; }
html:not(.tizen) .grid { grid-template-columns: repeat(auto-fill, minmax(138px, 1fr)); gap: 18px; }
html:not(.tizen) .grid .card { width: 100%; height: auto; aspect-ratio: 2 / 3; }
html:not(.tizen) .search-box { height: 54px; font-size: 20px; margin: 0; padding: 0 18px; border-radius: 8px; }
html:not(.tizen) #detail-hero { height: 500px; }
html:not(.tizen) .detail-body { padding: 0 32px 50px; margin-top: -280px; }
html:not(.tizen) .episode .ep-thumb { width: 135px; height: 76px; }
html:not(.tizen) .settings-head { font-size: 28px; }
html:not(.tizen) .setting-field { padding: 14px 18px; gap: 16px; flex-wrap: wrap; border-radius: 8px; }
html:not(.tizen) .setting-field label, html:not(.tizen) .setting-field .value { font-size: 16px; }
html:not(.tizen) .setting-field .value { min-width: 0; width: min(100%, 450px); overflow-wrap: anywhere; }
html:not(.tizen) .te-panel { width: min(90%, 640px); padding: 24px; border-radius: 8px; }
html:not(.tizen) .te-input { font-size: 20px; height: 52px; padding: 0 12px; }
html:not(.tizen) .te-hint { display: none; }
html:not(.tizen) #player-settings { top: 80px; right: 24px; max-width: calc(100% - 48px); }
html:not(.tizen) #player-settings-list { max-height: calc(100vh - 260px); }
html:not(.tizen) .empty { padding: 32px 16px; font-size: 18px; }

@media (max-width: 680px) {
    html:not(.tizen) #sidebar { width: 58px; padding: 22px 4px; align-items: center; }
    html:not(.tizen) #sidebar .logo { margin-left: 0; }
    html:not(.tizen) #sidebar .logo .full, html:not(.tizen) #sidebar .nav-item .label { display: none; }
    html:not(.tizen) #sidebar .logo .short { display: inline; }
    html:not(.tizen) #content { left: 58px; }
    html:not(.tizen) .hero-inner, html:not(.tizen) .detail-body { padding-left: 16px; padding-right: 16px; }
    html:not(.tizen) .hero-title, html:not(.tizen) .detail-title { font-size: 34px; }
    html:not(.tizen) #view-grid, html:not(.tizen) #view-search, html:not(.tizen) #view-settings, html:not(.tizen) #rows { padding-left: 16px; padding-right: 16px; }
    html:not(.tizen) .episode .ep-thumb { width: 88px; height: 50px; }
    html:not(.tizen) .episode .ep-info { min-width: 0; overflow-wrap: anywhere; }
    html:not(.tizen) .player-settings-tab { min-width: 0; padding: 0 8px; font-size: 16px; }
}

/* Brand, content imagery and shared focus treatment. */
button { font-family: inherit; }
button[hidden] { display: none; }
.catalog-fallback + #rows:empty + .home-actions { display: none; }
.brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    flex: 0 0 auto;
    border-radius: 8px;
    border: 1px solid #527d6d;
    background: #233f35;
    color: var(--accent);
    font-size: 30px;
    font-weight: 800;
}
#sidebar {
    background: #101515;
    border-right-color: #29312f;
    padding-top: 40px;
}
#sidebar.expanded { background: #101515; padding-left: 18px; padding-right: 18px; }
#sidebar .logo {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text);
    text-shadow: none;
    font-size: 30px;
    margin-bottom: 48px;
}
#sidebar .nav-item {
    gap: 14px;
    width: calc(100% - 24px);
    min-width: 0;
    height: 64px;
    padding: 0 12px;
    background: transparent;
    border: 2px solid transparent;
    border-radius: 8px;
    font-weight: 650;
    box-shadow: none;
}
#sidebar:not(.expanded) .nav-item { width: 64px; padding: 0; gap: 0; }
#sidebar:not(.expanded) .label { display: none; }
#sidebar .nav-item.active { background: #20302b; color: var(--accent); }
#sidebar .nav-item.focused,
#sidebar .nav-item:focus-visible { color: #fff; background: #2d3634; border-color: var(--focus); }
#sidebar .nav-item .icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    margin: 0;
    flex: 0 0 26px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linejoin: round;
    stroke-linecap: round;
    transform: none;
}
#sidebar .nav-item .label { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
#sidebar .nav-item[data-nav="settings"] { margin-top: auto; }
#sidebar .nav-item .profile-letter {
    color: #e5fff2;
    background: #305144;
    border-radius: 6px;
    font-size: 17px;
}
.tizen-ui #sidebar.expanded + #content { left: var(--sidebar-collapsed); }
#hero {
    height: 730px;
    align-items: flex-end;
    background-position: center center;
    background-color: var(--bg);
}
#hero.catalog-fallback { background-image: url("cinema-room.png"); }
#hero::after {
    background: linear-gradient(90deg, #101314 0%, rgba(16,19,20,.89) 25%, rgba(16,19,20,.12) 76%),
        linear-gradient(0deg, #101314 0%, rgba(16,19,20,0) 37%);
}
.hero-inner { padding: 48px 68px 120px; max-width: 920px; }
.hero-title { font-size: 76px; line-height: 1.05; max-height: 2.1em; overflow: hidden; overflow-wrap: break-word; }
.hero-meta { color: var(--text-dim); flex-wrap: wrap; }
.hero-plot { line-height: 1.48; margin-bottom: 28px; -webkit-line-clamp: 3; }
.btn { border-radius: 8px; background: #2a3332; color: var(--text); box-shadow: none; }
.btn.primary { color: #0c2118; }
.btn.focused, .btn:focus-visible { border-color: #fff; box-shadow: none; transform: none; }
.btn:hover { border-color: var(--accent); }
#rows { padding-left: 68px; padding-right: 54px; margin-top: -50px; }
.row-title { font-size: 30px; margin-bottom: 12px; }
.row-track { padding-top: 4px; padding-bottom: 8px; }
.card { border: 3px solid transparent; background: var(--surface-2); }
.card.focused { border-color: #fff; box-shadow: none; transform: none; }
.card .card-badge { background: #111817; color: var(--text); }
.card .card-title { font-size: 20px; font-weight: 700; line-height: 1.25; padding: 24px 12px 12px; }
.resume-row .card { width: 324px; height: 186px; }
.resume-row .card .card-title { padding-bottom: 17px; }
.card-remaining { font-size: 15px; color: #d7dfdb; margin-top: 5px; font-weight: 500; }
.card-progress { height: 5px; }
.card-progress div { box-shadow: none; }
#detail-hero::after {
    background: linear-gradient(90deg,#101314 0%,rgba(16,19,20,.7) 52%,rgba(16,19,20,.1) 100%),
        linear-gradient(0deg,#101314 0%,rgba(16,19,20,0) 58%);
}
.detail-title { overflow-wrap: break-word; line-height: 1.08; }
.detail-actions { flex-wrap: wrap; }
.season-chip { border-radius: 8px; }
.episode { border-radius: 8px; background: #1b2020; }
.episode .ep-thumb { border-radius: 6px; }
.settings-section, .cloud-head { font-size: 26px; font-weight: 700; margin-bottom: 20px; }
.setting-field {
    padding: 17px 0;
    margin-bottom: 0;
    border-radius: 0;
    border: 0;
    border-bottom: 1px solid #29312f;
    background: transparent;
}
.setting-field .value { border-radius: 8px; color: var(--text); background: #202827; border: 2px solid transparent; }
.setting-field .value.focused { border-color: #fff; box-shadow: none; }
.te-panel { border-radius: 8px; background: #1b2221; }
#player-settings { background: #1b2221; }
.player-settings-close { height: 42px; width: 42px; border: 1px solid #56605e; border-radius: 6px; background: #242d2b; color: #fff; font-size: 27px; cursor: pointer; }
.player-setting-option { overflow-wrap: break-word; }
.player-setting-option .option-note { flex: 0 0 auto; }
#player-subtitles { bottom: 116px; }
#player.controls-visible #player-subtitles { bottom: 270px; }

#profiles-screen {
    padding: 0;
    text-align: left;
    background: linear-gradient(90deg, rgba(16,19,20,.98) 0%, rgba(16,19,20,.83) 45%, rgba(16,19,20,.36)),
        url("cinema-room.png") center / cover no-repeat fixed;
}
.profile-layout { max-width: 1440px; margin: auto; padding: 96px 70px 64px; }
.profile-brand { display: flex; align-items: center; gap: 12px; color: var(--text); font-size: 30px; font-weight: 750; margin-bottom: 64px; }
#profiles-title { font-size: 64px; margin-bottom: 36px; }
#profiles-list { margin: 0 0 34px; justify-content: flex-start; }
.profile-button { width: 184px; height: 156px; background: #202a28; }
.profile-avatar { border-radius: 8px; color: #eafff3; }
.profile-button:nth-child(4n+2) .profile-avatar { background: #6a493c; color: #fff2df; }
.profile-button:nth-child(4n+3) .profile-avatar { background: #354c5a; color: #e9f8ff; }
.profile-button:nth-child(4n+4) .profile-avatar { background: #5c5550; color: #fff1de; }
.profile-button:not([data-profile]) .profile-avatar { background: #32423b; color: var(--accent); }
#profiles-settings { background: #222b29; }
#profiles-avatars { margin: 0 12px 12px 0; }
.profile-button[aria-pressed="true"] { border-color: var(--accent); }
.profile-button[aria-pressed="true"].focused { border-color: var(--focus); }
.profile-avatar, #profile-letter { position: relative; overflow: hidden; }
.profile-avatar img, #profile-letter img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    background: var(--surface-2);
}

html:not(.tizen) #sidebar:not(.expanded) .nav-item,
html:not(.tizen) #sidebar.expanded .nav-item { width: 100%; padding: 0 10px; gap: 10px; }
html:not(.tizen) #sidebar:not(.expanded) .label { display: inline; }
html:not(.tizen) #sidebar .nav-item .icon { width: 21px; height: 21px; flex-basis: 21px; }
html:not(.tizen) #sidebar .logo { font-size: 18px; margin-left: 0; gap: 7px; }
html:not(.tizen) #sidebar .brand-mark { width: 30px; height: 30px; font-size: 19px; }
html:not(.tizen) #sidebar .nav-item[data-nav="settings"] { margin-top: auto; }
html:not(.tizen) .hero-title { font-size: 50px; }
html:not(.tizen) .resume-row .card { width: 230px; height: 134px; }
html:not(.tizen) .card .card-title { font-size: 16px; }
html:not(.tizen) .card-remaining { font-size: 12px; }
html:not(.tizen) #player-subtitles { font-size: 26px; }
html:not(.tizen) .profile-layout { padding: 62px 52px 44px; }
html:not(.tizen) .profile-brand { font-size: 24px; margin-bottom: 40px; }
html:not(.tizen) .profile-brand .brand-mark { width: 38px; height: 38px; font-size: 23px; }
html:not(.tizen) .profile-button { height: 118px; }
html:not(.tizen) #toast { width: max-content; max-width: calc(100vw - 28px); padding: 10px 18px; border-radius: 8px; font-size: 16px; }
html:not(.tizen) #profile-nav { max-width: 95px; }

@media (max-width: 680px) {
    html:not(.tizen) #sidebar .logo .full,
    html:not(.tizen) #sidebar:not(.expanded) .label,
    html:not(.tizen) #sidebar.expanded .label { display: none; }
    html:not(.tizen) #sidebar:not(.expanded) .nav-item,
    html:not(.tizen) #sidebar.expanded .nav-item { padding: 0; justify-content: center; }
    html:not(.tizen) .hero-title { font-size: 34px; }
    html:not(.tizen) #hero { height: 410px; }
    html:not(.tizen) .hero-actions .btn { padding-left: 12px; padding-right: 12px; }
    html:not(.tizen) .profile-layout { padding: 34px 22px; }
    html:not(.tizen) #profiles-title { font-size: 36px; }
    html:not(.tizen) #profiles-list { gap: 10px; }
    html:not(.tizen) .profile-button { width: 110px; height: 110px; font-size: 14px; }
}


/* ============================================================
   ANILIST VIEW, BADGES & MODAL
   ============================================================ */
#sidebar .logo { margin-bottom: 30px; }
#sidebar .nav-item { height: 58px; margin-bottom: 8px; }
html:not(.tizen) #sidebar .logo { margin-bottom: 28px; }
html:not(.tizen) #sidebar .nav-item { height: 42px; margin-bottom: 3px; }

#view-anilist { padding: 80px; }
html:not(.tizen) #view-anilist { padding: 36px 32px; }
@media (max-width: 680px) {
    html:not(.tizen) #view-anilist { padding: 28px 16px; }
}

.anilist-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 24px;
    flex-wrap: wrap;
    margin-bottom: 32px;
}
.anilist-sub {
    font-size: 21px;
    color: var(--text-dim);
}
html:not(.tizen) .anilist-sub { font-size: 15px; }
.anilist-header-actions {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
}

.card .card-badge-right {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(16, 25, 23, 0.9);
    color: #91edc1;
    border: 1px solid rgba(145, 237, 193, 0.45);
    font-size: 13px;
    font-weight: 750;
    padding: 4px 8px;
    border-radius: 6px;
}

.episode.watched {
    border-color: rgba(145, 237, 193, 0.28);
    background: rgba(28, 42, 38, 0.72);
}
.ep-watched-tag {
    display: inline-block;
    margin-left: 12px;
    padding: 3px 10px;
    border-radius: 999px;
    background: rgba(145, 237, 193, 0.18);
    color: var(--accent);
    font-size: 14px;
    font-weight: 750;
    vertical-align: middle;
}

.btn.anilist-btn {
    border-color: rgba(61, 180, 242, 0.5);
    background: rgba(24, 44, 58, 0.85);
    color: #bfe8ff;
}
.btn.anilist-btn.focused,
.btn.anilist-btn:focus-visible {
    border-color: #fff;
}

.anilist-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 340;
    background: rgba(0, 0, 0, 0.82);
    align-items: center;
    justify-content: center;
    padding: 24px;
}
.anilist-modal.open {
    display: flex;
}
.anilist-modal-panel {
    width: 680px;
    max-width: 100%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    background: #1b2221;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 10px;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.8);
    overflow: hidden;
}
.anilist-modal-list {
    overflow-y: auto;
    padding: 18px 20px 24px;
}
