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

:root {
  --bg:       #0f0f0f;
  --surface:  #1a1a1a;
  --surface2: #222;
  --border:   #2a2a2a;
  --accent:   #f0a500;
  --green:    #27ae60;
  --red:      #c0392b;
  --text:     #eeeeee;
  --muted:    #777;
}

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

/* ── HEADER ── */
header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .85rem 2rem;
  background: rgba(15,15,15,.95); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.header-left  { display: flex; align-items: center; gap: 1rem; flex: 1; min-width: 0; }
.header-right { display: flex; align-items: center; gap: .5rem; flex-shrink: 0; }

h1 { font-size: 1.5rem; font-weight: 900; color: var(--accent);
     letter-spacing: .12em; white-space: nowrap; cursor: pointer; }

.breadcrumb { display: flex; align-items: center; gap: .5rem; font-size: .85rem;
              color: var(--muted); min-width: 0; }
.breadcrumb span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.breadcrumb .sep { flex-shrink: 0; }
.breadcrumb .crumb-link { cursor: pointer; color: var(--muted); }
.breadcrumb .crumb-link:hover { color: var(--text); }
.breadcrumb .crumb-current { color: var(--text); font-weight: 600; }

.stats-text { font-size: .78rem; color: var(--muted); white-space: nowrap; }

/* ── BUTTONS ── */
.btn {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .5rem 1rem; border: none; border-radius: 6px;
  cursor: pointer; font-size: .88rem; font-weight: 600;
  transition: opacity .15s, transform .1s; white-space: nowrap;
}
.btn:hover  { opacity: .85; }
.btn:active { transform: scale(.97); }
.btn.small  { padding: .35rem .75rem; font-size: .8rem; }

.btn-primary { background: var(--accent); color: #000; }
.btn-danger  { background: var(--red);    color: #fff; }
.btn-ghost   { background: transparent; color: var(--muted);
               border: 1px solid var(--border); }
.btn-ghost:hover { color: var(--text); border-color: #555; }

/* ── TABS ── */
.tab-row { display: flex; gap: .5rem; }
.tab-row.inner { margin-top: .25rem; }
.tab {
  padding: .35rem .85rem; border: 1px solid var(--border); border-radius: 20px;
  background: transparent; color: var(--muted); cursor: pointer;
  font-size: .82rem; font-weight: 600; transition: all .15s;
}
.tab.active { background: var(--accent); color: #000; border-color: var(--accent); }

/* ── MODAL ── */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.82);
         display: flex; align-items: center; justify-content: center;
         z-index: 100; padding: 1rem; }
.modal.hidden { display: none !important; }

.modal-box {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 1.5rem; width: 100%; max-width: 420px;
  display: flex; flex-direction: column; gap: 1rem;
  max-height: 85dvh; overflow-y: auto;
}
.modal-box h2 { font-size: 1.1rem; }

.field-label { font-size: .82rem; color: var(--muted); font-weight: 600; }
.modal-box input[type="text"],
.modal-box input[type="number"] {
  width: 100%; background: var(--surface2); border: 1px solid var(--border);
  border-radius: 6px; padding: .6rem .8rem; color: var(--text); font-size: .95rem;
}
.modal-box input:focus { outline: none; border-color: var(--accent); }
.input-row  { display: flex; gap: .5rem; }
.input-row input { flex: 1; }
.range-row  { display: flex; align-items: center; gap: .5rem; }
.range-row span { color: var(--muted); }
.range-row input { flex: 1; }
.hint { font-size: .78rem; color: var(--muted); line-height: 1.4; }
.hint code { background: #2a2a2a; padding: .1rem .3rem; border-radius: 3px; }
.modal-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: .25rem; }

/* ── FILE CHECKLIST ── */
.file-checklist {
  display: flex; flex-direction: column; gap: .35rem;
  max-height: 280px; overflow-y: auto;
  border: 1px solid var(--border); border-radius: 8px; padding: .5rem;
}
.file-item {
  display: flex; align-items: center; gap: .6rem;
  padding: .4rem .6rem; border-radius: 6px;
  font-size: .82rem; cursor: pointer; transition: background .1s;
}
.file-item:hover { background: var(--surface2); }
.file-item input[type="checkbox"] { accent-color: var(--accent); width: 15px; height: 15px; flex-shrink: 0; }
.file-name { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-sub  { color: var(--muted); font-size: .73rem; }

/* ── PLAYER MODAL ── */
.player-box {
  background: #000; border: 1px solid var(--border); border-radius: 12px;
  width: 100%; max-width: 920px; max-height: 95dvh;
  display: flex; flex-direction: column; overflow: hidden;
}
.player-header {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .75rem 1.25rem; background: #111; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
#player-title { font-size: .95rem; font-weight: 600; }
.player-header-actions { display: flex; align-items: center; gap: .5rem; }
.close-btn { background: none; border: none; color: var(--muted);
             font-size: 1.4rem; line-height: 1; cursor: pointer; padding: .1rem .3rem; }
.close-btn:hover { color: var(--text); }
#file-area {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1.25rem; padding: 2.5rem 1rem; flex: 1;
}
#resume-hint { font-size: .9rem; color: var(--accent); font-weight: 600; }
#file-input  { display: none; }
.file-btn {
  display: inline-flex; align-items: center; gap: .5rem;
  padding: .75rem 2rem; background: var(--accent); color: #000;
  border-radius: 8px; cursor: pointer; font-weight: 700; font-size: 1rem;
  transition: opacity .15s;
}
.file-btn:hover { opacity: .85; }
#video-player { width: 100%; background: #000; display: none; max-height: 65dvh; flex-shrink: 0; }
.player-footer {
  display: flex; align-items: center; gap: .75rem;
  padding: .75rem 1.25rem; background: #111; border-top: 1px solid var(--border);
  flex-shrink: 0; flex-wrap: wrap;
}
.sync-status { font-size: .75rem; color: var(--muted); }
.sync-status.ok { color: var(--green); }

/* ── TOAST ── */
.toast {
  position: fixed; bottom: 2rem; left: 50%; transform: translateX(-50%);
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text); padding: .6rem 1.2rem; border-radius: 20px;
  font-size: .85rem; font-weight: 500; z-index: 200;
  pointer-events: none; white-space: nowrap;
}
.toast.hidden { display: none; }
.toast.err    { border-color: var(--red); color: #ff7675; }

/* ── VIEWS ── */
main { padding: 0 0 4rem; }
main.hidden { display: none !important; }
section { padding: 1.5rem 2rem; }
section h2 {
  font-size: .85rem; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .08em; margin-bottom: 1.25rem;
}

/* ── CATALOG (home — series cards) ── */
.catalog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
}

.series-card {
  position: relative; border-radius: 10px; overflow: hidden;
  cursor: pointer; aspect-ratio: 16/9;
  transition: transform .2s, box-shadow .2s;
}
.series-card:hover { transform: scale(1.03); box-shadow: 0 8px 32px rgba(0,0,0,.6); }
.series-card-bg {
  position: absolute; inset: 0;
  background: linear-gradient(135deg, #c07800 0%, #7a4a00 60%, #2a1800 100%);
}
.series-card-overlay {
  position: absolute; inset: 0;
  background: linear-gradient(to top, rgba(0,0,0,.8) 0%, transparent 60%);
}
.series-card-body {
  position: absolute; bottom: 0; left: 0; right: 0;
  padding: 1rem 1.1rem;
}
.series-card-type { font-size: .7rem; font-weight: 700; color: var(--accent);
                    text-transform: uppercase; letter-spacing: .1em; }
.series-card-name { font-size: 1.2rem; font-weight: 900; color: #fff;
                    letter-spacing: .05em; text-transform: uppercase; margin-top: .15rem; }
.series-card-meta { font-size: .75rem; color: rgba(255,255,255,.6); margin-top: .3rem; }
.series-card-progress {
  position: absolute; bottom: 0; left: 0; right: 0;
  height: 3px; background: rgba(255,255,255,.15);
}
.series-card-progress-fill { height: 100%; background: var(--accent); transition: width .4s; }

/* ── CONTINUE WATCHING row ── */
.cards-row {
  display: flex; gap: 1rem; overflow-x: auto; padding-bottom: .5rem;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}

/* ── ARC GRID ── */
.arc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}

.arc-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 1.25rem 1.1rem;
  cursor: pointer; transition: transform .15s, background .15s, border-color .15s;
  position: relative; overflow: hidden;
}
.arc-card:hover { transform: translateY(-3px); background: var(--surface2); }
.arc-card.in_progress { border-color: var(--accent); }
.arc-card.completed   { border-color: var(--green); }

.arc-card-name { font-size: 1rem; font-weight: 700; color: var(--text); }
.arc-card-meta { font-size: .78rem; color: var(--muted); margin-top: .3rem; }
.arc-card-bar  { height: 3px; background: var(--border); border-radius: 2px; margin-top: .85rem; }
.arc-card-fill {
  height: 100%; border-radius: 2px;
  background: var(--green); transition: width .3s;
}
.arc-card.in_progress .arc-card-fill { background: var(--accent); }
.arc-card-badge {
  position: absolute; top: .8rem; right: .8rem;
  font-size: .7rem; font-weight: 700; padding: .15rem .45rem;
  border-radius: 10px;
}
.badge-done    { background: rgba(39,174,96,.2);  color: var(--green); }
.badge-ongoing { background: rgba(240,165,0,.2);  color: var(--accent); }
.badge-new     { background: rgba(255,255,255,.08); color: var(--muted); }

/* ── EPISODE CARDS grid ── */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
  gap: .85rem;
}

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: .85rem; cursor: pointer;
  transition: transform .15s, background .15s, border-color .15s;
  position: relative; overflow: hidden; min-width: 140px;
}
.card:hover            { transform: translateY(-3px); background: var(--surface2); }
.card.in_progress      { border-color: var(--accent); }
.card.watched          { opacity: .55; }
.card.watched:hover    { opacity: 1; }

.card-num   { font-size: .7rem; font-weight: 800; color: var(--accent);
              text-transform: uppercase; letter-spacing: .06em; }
.card-title { font-size: .88rem; font-weight: 500; color: var(--text);
              margin-top: .3rem; white-space: nowrap; overflow: hidden;
              text-overflow: ellipsis; }
.card-pos   { font-size: .72rem; color: var(--muted); margin-top: .2rem; }
.card-check { position: absolute; top: .5rem; right: 2rem;
              background: var(--green); color: #fff;
              width: 18px; height: 18px; border-radius: 50%;
              display: flex; align-items: center; justify-content: center;
              font-size: .65rem; font-weight: 700; }
.card-bar   { height: 3px; background: var(--border); border-radius: 2px; margin-top: .75rem; }
.card-bar-fill { height: 100%; background: var(--accent); border-radius: 2px;
                 transition: width .3s; }

/* Reset button on episode card */
.card-reset {
  position: absolute; top: .45rem; right: .45rem;
  background: none; border: none; color: #444; cursor: pointer;
  font-size: .85rem; line-height: 1; padding: .15rem;
  border-radius: 4px; transition: color .15s;
}
.card-reset:hover { color: var(--muted); }

/* Continue watching card (slightly wider) */
.card.continue { min-width: 170px; }

/* ── EMPTY ── */
.empty {
  grid-column: 1 / -1; padding: 3rem; text-align: center;
  color: var(--muted); font-size: .95rem;
}

/* ── RESPONSIVE ── */
@media (max-width: 600px) {
  header { padding: .75rem 1rem; }
  h1 { font-size: 1.2rem; }
  section { padding: 1rem; }
  .cards-grid { grid-template-columns: repeat(auto-fill, minmax(135px, 1fr)); gap: .6rem; }
  .catalog-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
  .arc-grid  { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .header-right { gap: .3rem; }
  .stats-text { display: none; }
}
