/* RacinedeXIII basic styles */
:root {
  --bg: #e3e8f0;
  --card: #f7f9fc;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --danger: #ef4444;
  --secondary: #94a3b8;
  --border: #cdd5e3;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.08), 0 2px 8px rgba(16,24,40,0.06);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; background: var(--bg); color: var(--text); font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, 'Helvetica Neue', Arial, 'Noto Sans', 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', sans-serif; }
/* Force hidden elements to be fully hidden even if classes set display */
[hidden] { display: none !important; }

.container { max-width: 100%; width: 100%; margin: 0 auto; padding: 16px; }
header.container { padding-top: 0; padding-bottom: 0; height: 250px; }
header h1 { margin: 0 0 8px 0; }
header p { margin: 0; color: var(--muted); }

.header-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; height: 100%; }

/* Header actions (icon buttons) */
.header-actions { display: inline-flex; align-items: center; gap: 8px; }
.header-actions a { display: inline-flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--border); background: var(--card); color: var(--text); border-radius: 999px; text-decoration: none; box-shadow: var(--shadow); font-weight: 600; }
.header-actions a:hover { filter: brightness(0.97); }
.header-actions svg { width: 16px; height: 16px; display: inline-block; }
.header-actions .danger-link { border-color: rgba(239,68,68,0.3); }
[data-theme="dark"] .header-actions a { background: #1b2036; border-color: #2b3050; color: #e6e9ef; }

/* Brand (logo + title) */
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { margin: 0; line-height: 1; }
.brand-logo { display: inline-flex; width: 40px; height: 40px; color: var(--primary); }
.brand-logo svg { width: 100%; height: 100%; display: block; }
.brand-logo-img { width: 250px; height: 250px; display: block; border-radius: 8px; object-fit: contain; background: transparent; }

/* Theme switch (modern left/right toggle) */
.theme-switch { display: inline-flex; align-items: center; }
.theme-switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.theme-switch label { position: relative; display: inline-flex; align-items: center; justify-content: center; width: 64px; height: 32px; background: #e6ebf3; border: 1px solid var(--border); border-radius: 999px; cursor: pointer; box-shadow: var(--shadow); transition: background 0.2s ease, border-color 0.2s ease; }
.theme-switch label::after { content: ""; position: absolute; width: 26px; height: 26px; left: 3px; top: 50%; transform: translateY(-50%); background: #fff; border: 1px solid var(--border); border-radius: 50%; box-shadow: 0 1px 2px rgba(16, 24, 40, 0.12); transition: transform 0.25s ease, background 0.2s ease, border-color 0.2s ease; }
.theme-switch .icon { position: absolute; font-size: 14px; opacity: 0.8; transition: opacity 0.2s ease; }
.theme-switch .icon.sun { left: 10px; }
.theme-switch .icon.moon { right: 10px; }
.theme-switch input:checked + label { background: #20253b; border-color: #2b3050; }
.theme-switch input:checked + label::after { transform: translate(32px, -50%); background: #111728; border-color: #2b3050; }
.theme-switch input:not(:checked) + label .moon { opacity: 0.35; }
.theme-switch input:checked + label .sun { opacity: 0.35; }

/* Dark theme overrides */
[data-theme="dark"] {
  --bg: #0f1221;
  --card: #161a2f;
  --text: #e6e9ef;
  --muted: #a9b1bd;
  --primary: #4dabf7;
  --danger: #fa5252;
  --secondary: #7b8794;
  --border: #2b3050;
}

.grid { display: grid; grid-template-columns: 0.73fr 2fr; gap: 16px; align-items: start; }
@media (max-width: 800px) { .grid { grid-template-columns: 1fr; } }

.card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 16px; box-shadow: var(--shadow); }
.row { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }

label { font-size: 0.9rem; color: var(--muted); }
input[type="text"], input[type="password"], select { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--card); color: var(--text); box-shadow: 0 1px 0 rgba(16,24,40,0.02) inset; }
input::placeholder, textarea::placeholder { color: var(--muted); }
input[type="text"]:focus, input[type="password"]:focus, select:focus { outline: none; border-color: #93c5fd; box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15); }
input[type="color"] { width: 100%; border: 1px solid var(--border); border-radius: 10px; background: var(--card); height: 36px; padding: 0; }
button { padding: 10px 14px; border: 0; background: var(--primary); color: #fff; border-radius: 10px; cursor: pointer; font-weight: 600; box-shadow: var(--shadow); }
button:hover { filter: brightness(0.95); }
button.secondary { background: var(--secondary); color: #0f172a; }
button.danger { background: var(--danger); color: #fff; }
button:disabled { opacity: 0.6; cursor: default; }

.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.scrollable { max-height: 70vh; overflow: auto; padding-right: 4px; }
.video-item, .annotation-item { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 10px; box-shadow: var(--shadow); }
.video-row, .annotation-row { display: flex; align-items: center; gap: 8px; }
.video-row .title { flex: 1 1 auto; min-width: 0; }
.annotation-row .name, .annotation-row .note { flex: 0 1 auto; }
.video-row .delete { margin-left: auto; }
.annotation-row .delete { margin-left: 0; }
.annotation-row .ann-actions { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; }
.video-row .title { font-weight: 600; }
.video-row .ytid { color: var(--muted); font-size: 0.85rem; }
.badge-src { display: inline-flex; align-items: center; gap: 4px; padding: 2px 6px; border: 1px solid var(--border); border-radius: 999px; background: var(--card); color: var(--muted); font-size: 12px; line-height: 1; }
.badge-src .ico { width: 12px; height: 12px; display: inline-block; }
[data-theme="dark"] .badge-src img { filter: brightness(1.1); }
.badge-src img { width: 36px; height: 24px; display: block; object-fit: contain; }
[data-theme="dark"] .badge-src { background: #1b2036; border-color: #2b3050; color: #a9b1bd; }
.annotation-row .dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; margin-right: 6px; }
.annotation-row .name { font-weight: 600; }
.annotation-row .note { color: var(--muted); margin-left: 4px; }

.controls { margin-top: 12px; margin-bottom: 12px; }
#player { width: 100%; max-width: 100%; aspect-ratio: 16/9; background: #e1e7f0; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }

/* Progress bar (used for local hash calculation) */
.progress { margin-top: 8px; }
.progress-track { width: 100%; height: 10px; background: #e6ebf3; border: 1px solid var(--border); border-radius: 999px; overflow: hidden; }
.progress-bar { height: 100%; background: linear-gradient(90deg, #60a5fa, #2563eb); transition: width 0.15s ease; }
.progress-label { font-size: 12px; color: var(--muted); margin-top: 6px; }
[data-theme="dark"] .progress-track { background: #1b2036; border-color: #2b3050; }

/* Fullscreen overlay (right) */
.player-container { position: relative; }
.fs-bottom-header { font-weight: 700; font-size: 14px; margin-bottom: 8px; opacity: 0.9; }
.fs-legend { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.fs-legend .legend-item { display: inline-flex; align-items: center; gap: 8px; background: rgba(255,255,255,0.12); padding: 6px 10px; border-radius: 999px; cursor: pointer; border: 1px solid rgba(255,255,255,0.25); }
.fs-legend .legend-item .color { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

/* Right-side tab button */
.fs-tab { position: absolute; top: 50%; right: 0; transform: translate(50%, -50%) rotate(-90deg); transform-origin: right center; z-index: 5; background: rgba(255,255,255,0.95); color: #0b1028; border: 1px solid var(--border); border-radius: 8px 8px 0 0; padding: 6px 10px; font-weight: 700; box-shadow: var(--shadow); }
.fs-tab:hover { background: #fff; }
.player-container:fullscreen .fs-tab { display: inline-block !important; }

.fs-toggle { position: absolute; bottom: 8px; right: 8px; z-index: 6; background: rgba(255,255,255,0.95); color: #0b1028; border-radius: 10px; padding: 12px 18px; font-weight: 800; border: 1px solid var(--border); box-shadow: var(--shadow); font-size: 22px; line-height: 1; }
.fs-toggle:hover { background: #fff; filter: brightness(1.02); }

.fs-edge { position: absolute; top: 0; right: 0; width: 60px; height: 100%; z-index: 3; background: transparent; }
.player-container:fullscreen .fs-edge { display: block !important; }

/* Fullscreen helper hint (centered) */
.fs-hint { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 7; background: rgba(15,23,42,0.92); color: #e6e9ef; border: 1px solid rgba(255,255,255,0.18); border-radius: 12px; padding: 16px 22px; font-size: 20px; font-weight: 800; letter-spacing: 0.2px; box-shadow: 0 10px 30px rgba(0,0,0,0.45); opacity: 0; pointer-events: none; transition: opacity .25s ease, transform .25s ease; max-width: 90vw; text-align: center; }
.fs-hint.show { opacity: 1; transform: translate(-50%, -50%); }

/* Fullscreen panel toggle button (always visible in FS, right middle) */
.fs-panel-btn { position: absolute; top: 50%; right: 12px; transform: translateY(-50%); z-index: 6; display: none; background: rgba(255,255,255,0.95); color: #0b1028; border-radius: 999px; padding: 10px 14px; font-weight: 800; border: 1px solid var(--border); box-shadow: var(--shadow); font-size: 16px; line-height: 1; cursor: pointer; }
.fs-panel-btn:hover { background: #fff; filter: brightness(1.02); }
.player-container:fullscreen .fs-panel-btn { display: inline-flex !important; align-items: center; justify-content: center; }

/* Fullscreen EXIT button (always visible in FS, top-center) */
.fs-exit { position: absolute; top: 8px; left: 50%; transform: translateX(-50%); z-index: 7; display: none; background: rgba(255,255,255,0.95); color: #0b1028; border-radius: 12px; padding: 12px 18px; font-weight: 900; border: 1px solid var(--border); box-shadow: var(--shadow); font-size: 22px; line-height: 1; cursor: pointer; }
.fs-exit:hover { background: #fff; filter: brightness(1.02); }
.player-container:fullscreen .fs-exit { display: inline-flex !important; align-items: center; justify-content: center; }

/* Fullscreen note modal */
.fs-modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.45); display: flex; align-items: center; justify-content: center; z-index: 6; }
.fs-modal { width: min(560px, 92%); background: rgba(17, 24, 39, 0.95); color: #fff; border: 1px solid rgba(255,255,255,0.2); border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,0.4); overflow: hidden; }
.fs-modal-header { padding: 12px 14px; border-bottom: 1px solid rgba(255,255,255,0.15); font-weight: 700; }
.fs-modal-title { font-size: 16px; }
.fs-modal-body { padding: 12px 14px; }
.fs-modal-label { display: block; font-size: 13px; margin-bottom: 6px; opacity: 0.9; }
.fs-modal-textarea { width: 100%; border-radius: 8px; border: 1px solid rgba(255,255,255,0.25); background: rgba(255,255,255,0.08); color: #fff; padding: 8px 10px; resize: vertical; min-height: 72px; }
.fs-modal-textarea::placeholder { color: rgba(255,255,255,0.6); }
.fs-modal-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 14px; border-top: 1px solid rgba(255,255,255,0.15); }
.fs-modal-actions .primary { background: #60a5fa; color: #0b1028; border: none; border-radius: 8px; padding: 8px 12px; font-weight: 700; }
.fs-modal-actions .secondary { background: rgba(255,255,255,0.9); color: #0b1028; border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; font-weight: 700; }

[data-theme="dark"] .fs-modal { background: rgba(8, 11, 20, 0.96); }

.fs-overlay { position: absolute; top: 0; right: 0; height: 100%; width: 28%; min-width: 260px; max-width: 520px; background: rgba(15, 23, 42, 0.55); backdrop-filter: blur(2px); border-left: 1px solid rgba(255,255,255,0.2); padding: 12px; box-sizing: border-box; overflow: auto; z-index: 4; color: #fff; transition: transform 0.25s ease, opacity 0.25s ease; }
.fs-overlay.auto-hide { transform: translateX(100%); opacity: 0; pointer-events: none; }
.fs-overlay.visible { transform: translateX(0); opacity: 1; pointer-events: auto; }
.fs-overlay-header { font-weight: 700; margin-bottom: 8px; }
.fs-annotations { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.fs-annotations li { background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.25); border-radius: 10px; padding: 10px; }
.fs-annotations .row { display: flex; align-items: center; gap: 8px; }
.fs-annotations .jump { margin-left: auto; }
.fs-annotations .dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

/* Only show overlay automatically while in fullscreen */
.player-container:fullscreen { background: #000; width: 100vw; height: 100vh; }
.player-container:fullscreen .fs-overlay { display: block !important; }
/* Let JS handle player sizing; just remove rounded corners and borders */
.player-container:fullscreen #player { border-radius: 0; border: 0; }
.player-container:fullscreen #player iframe { width: 100% !important; height: 100% !important; display: block; }

.timeline { margin-top: 12px; }
.timeline-track { position: relative; width: 100%; height: 24px; background: #e1e7f0; border: 1px solid var(--border); border-radius: 16px; }
.marker { position: absolute; top: 4px; width: 8px; height: 16px; border-radius: 4px; cursor: pointer; box-shadow: 0 0 0 2px rgba(17,24,39,0.06); }
.marker:hover { transform: scaleY(1.1); }

/* Timeline zoom controls */
.timeline { position: relative; }
.timeline-controls { position: static; display: flex; align-items: center; gap: 6px; background: rgba(15,23,42,0.9); border: 1px solid rgba(255,255,255,0.15); border-radius: 999px; padding: 2px 4px; box-shadow: 0 4px 14px rgba(0,0,0,0.25); margin-bottom: 24px; margin-top: 4px; margin-left: auto; width: fit-content; }
.timeline-controls .tl-btn { min-width: 24px; height: 24px; border-radius: 999px; border: 1px solid rgba(255,255,255,0.2); background: #1f2937; color: #e6e9ef; font-weight: 800; cursor: pointer; padding: 0 8px; font-size: 12px; line-height: 1; }
.timeline-controls .tl-btn:hover { filter: brightness(1.05); }
.timeline-controls .tl-zoom-label { font-weight: 800; font-size: 12px; color: #e6e9ef; padding: 0 6px; letter-spacing: 0.2px; }

/* When zoomed, make markers slightly thicker for readability */
.timeline-track .marker { transition: transform .06s ease; }

/* Timeline tooltip */
.timeline-tooltip { position: fixed; z-index: 2000; pointer-events: none; background: rgba(15,23,42,0.96); color: #e6e9ef; border: 1px solid rgba(255,255,255,0.15); border-radius: 8px; padding: 6px 8px; font-size: 12px; box-shadow: 0 6px 20px rgba(0,0,0,0.35); transform: translate(-50%, -120%); opacity: 0; transition: opacity .12s ease; }
.timeline-tooltip.show { opacity: 1; }
.timeline-tooltip .tt-name { font-weight: 700; font-size: 12px; }
.timeline-tooltip .tt-time { opacity: 0.8; font-size: 11px; }

.legend { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; background: var(--card); border: 1px solid var(--border); border-radius: 999px; padding: 6px 10px; box-shadow: var(--shadow); }
.legend-item .color { width: 12px; height: 12px; border-radius: 50%; display: inline-block; border: 1px solid rgba(0,0,0,0.12); }

/* Click-to-add behavior on legend */
.legend-clickable { cursor: pointer; user-select: none; transition: transform 0.05s ease, box-shadow 0.2s ease; }
.legend-clickable:hover { box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15); }
.legend-clickable:active { transform: scale(0.98); }

/* Right section two-column layout: player left, annotations list right */
.right-grid { 
  display: grid; 
  grid-template-columns: minmax(0, 1.4fr) minmax(300px, 0.8fr); 
  gap: 16px; 
  align-items: start; 
  width: 100%;
}
.player-col { min-width: 0; grid-column: 1; max-width: none; margin: 0 auto; }
.annotations-col { grid-column: 2; min-width: 280px; }
.annotations-col h3 { margin-top: 0; }
.annotations-col .list { max-height: 80vh; overflow: auto; }

/* Let player area, timeline and legend expand by default in normal mode */
.player-col .player-container { max-width: none; margin: 0 auto; }
#timeline, #legend { max-width: none; margin-left: auto; margin-right: auto; }

/* Compact icon button (e.g., share) */
.icon-btn { padding: 4px; border-radius: 8px; background: var(--secondary); color: #0f172a; display: inline-flex; align-items: center; justify-content: center; min-width: 28px; height: 28px; }
.icon-btn svg { width: 12px; height: 12px; }

@media (max-width: 900px) {
  .right-grid { grid-template-columns: 1fr; }
  .player-col { grid-column: 1; }
  .annotations-col { grid-column: 1; min-width: 0; }
}

/* Allow hiding annotations column when toggled */
.right-grid.no-annotations { grid-template-columns: 1fr !important; }
.right-grid.no-annotations .annotations-col { display: none !important; }

/* Make header more compact on small screens to give room to the player */
@media (max-width: 900px) {
  header.container { height: auto; padding-top: 8px; padding-bottom: 8px; }
  .brand-logo-img { width: 120px; height: 120px; }
}

/* Legacy: far-right annotations card (not used now) */
.annotations-card { position: sticky; top: 16px; height: fit-content; }
.annotations-card .list { max-height: 70vh; overflow: auto; }

/* Toast notifications */
.toast-container { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 2000; display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; }
.toast { background: var(--card); color: var(--text); border: 1px solid var(--border); border-radius: 12px; padding: 16px 24px; box-shadow: var(--shadow); opacity: 0; transition: opacity .2s ease, transform .2s ease; transform: translateY(6px); font-size: 1.1rem; }
.toast.show { opacity: 1; transform: translateY(0); }

/* Floating toast near cursor or element */
.toast-float { position: fixed; z-index: 2001; pointer-events: none; background: rgba(15,23,42,0.96); color: #e6e9ef; border: 1px solid rgba(255,255,255,0.15); border-radius: 10px; padding: 10px 14px; box-shadow: 0 8px 24px rgba(0,0,0,0.35); opacity: 0; transform: translate(-50%, -8px) scale(0.98); transition: opacity .18s ease, transform .18s ease; font-size: 14px; }
.toast-float.show { opacity: 1; transform: translate(-50%, -12px) scale(1); }
/* Arrow variants for anchored toast */
.toast-float.arrow { position: fixed; }
.toast-float.arrow::after { content: ""; position: absolute; left: 50%; transform: translateX(-50%); width: 0; height: 0; }
.toast-float.arrow.above::after { bottom: -8px; border-left: 8px solid transparent; border-right: 8px solid transparent; border-top: 8px solid rgba(15,23,42,0.96); }
.toast-float.arrow.below::after { top: -8px; border-left: 8px solid transparent; border-right: 8px solid transparent; border-bottom: 8px solid rgba(15,23,42,0.96); }

/* --- Folders tree & breadcrumb --- */
.folder-toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.folder-tree { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; max-height: 35vh; overflow: auto; }
.folder-tree > li { margin-left: 0; }
.folder-sub { list-style: none; margin: 4px 0 4px 14px; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.folder-node { padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--card); cursor: pointer; box-shadow: var(--shadow); user-select: none; }
.folder-node:hover { filter: brightness(0.98); }
.folder-node.selected { outline: 2px solid rgba(37,99,235,0.35); }
.folder-node.drop-target { box-shadow: 0 0 0 3px rgba(37,99,235,0.3) inset; }

/* Folder row: name left, small actions right */
.folder-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.folder-name-btn { background: transparent; border: 0; padding: 4px 2px; font-weight: 600; color: inherit; cursor: pointer; text-align: left; flex: 1; }
.folder-name-btn:hover { text-decoration: underline; }
.folder-actions { display: inline-flex; align-items: center; gap: 6px; margin-left: auto; }

/* Unified icon-only button style */
.icon-only { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; padding: 0; border-radius: 8px; border: 1px solid var(--border); background: var(--card); color: var(--text); cursor: pointer; }
.icon-only svg { width: 16px; height: 16px; display: block; }
.icon-only:hover { filter: brightness(0.98); }

/* Variants */
.folder-rename-btn { background: var(--primary); color: #fff; border-color: transparent; }
.folder-rename-btn:hover { filter: brightness(0.95); }
.folder-del-btn { background: var(--danger); color: #fff; border-color: transparent; }
.folder-del-btn:hover { filter: brightness(0.95); }

/* Breadcrumb home icon styled like icon-only */
.breadcrumb .crumb-root { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: 8px; border: 1px solid transparent; background: var(--primary); color: #fff; }
.breadcrumb .crumb-root svg { width: 16px; height: 16px; }
.breadcrumb .crumb-root:hover { filter: brightness(0.95); }

.breadcrumb { display: flex; align-items: center; gap: 6px; padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--card); box-shadow: var(--shadow); font-weight: 600; }
.breadcrumb .crumb { cursor: pointer; padding: 3px 6px; border-radius: 6px; }
.breadcrumb .crumb:hover { background: rgba(37,99,235,0.12); }
.breadcrumb .crumb.drop-target { outline: 2px dashed rgba(37,99,235,0.55); }

/* Draggable video feedback */
.video-item.dragging { opacity: 0.6; }
