:root {
  color-scheme: dark;
  --bg: #0f1115; --card: #181b22; --text: #f0f2f5; --muted: #9aa0a6; --accent: #e50914;
  --surface: #222630; --border: #323846; --line: #262a34; --header-bg: rgba(15,17,21,0.9);
  --menu-bg: #1c2029; --hover: #262b36; --soft-text: #d5d8de; --link: #c9ced8;
  --chip-bg: #232834; --chip-border: #343b4d; --chip-text: #e8eaed; --chip-hover: #2a3040;
  --secondary-bg: #2c313f; --toast-border: #3a4152; --skeleton-hi: #2b303d;
  --shadow: rgba(0,0,0,0.5); --shadow-strong: rgba(0,0,0,0.6); --rating-text: #ffd700;
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f5f7; --card: #ffffff; --text: #15181d; --muted: #5d636c; --accent: #e50914;
  --surface: #eceef2; --border: #d4d8df; --line: #e2e5ea; --header-bg: rgba(255,255,255,0.88);
  --menu-bg: #ffffff; --hover: #eef0f4; --soft-text: #2d323a; --link: #3b414b;
  --chip-bg: #f2f4f7; --chip-border: #d4d8df; --chip-text: #1d2127; --chip-hover: #e7eaef;
  --secondary-bg: #e6e9ee; --toast-border: #d4d8df; --skeleton-hi: #f7f8fa;
  --shadow: rgba(20,25,35,0.14); --shadow-strong: rgba(20,25,35,0.18); --rating-text: #9a7200;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
body { transition: background-color 0.2s, color 0.2s; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); padding-bottom: 50px; }

header { background: var(--header-bg); backdrop-filter: blur(10px); position: sticky; top: 0; z-index: 10; padding: 16px 24px; border-bottom: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: 16px; align-items: center; justify-content: space-between; }
.logo { font-size: 22px; font-weight: 800; letter-spacing: 0.5px; color: var(--accent); text-decoration: none; }
.tabs { display: flex; gap: 8px; flex-wrap: wrap; }
.tab { background: var(--surface); color: var(--text); border: none; padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 14px; transition: 0.2s; }
.tab.active, .tab:hover { background: var(--accent); color: #fff; }
.controls { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.search { background: var(--surface); border: 1px solid var(--border); color: var(--text); padding: 8px 14px; border-radius: 8px; width: 220px; outline: none; font-size: 14px; }
.search:focus { border-color: var(--accent); }
.lang-switch { display: flex; background: var(--surface); border-radius: 8px; padding: 3px; border: 1px solid var(--border); }
.lang-btn { background: transparent; color: var(--muted); border: none; padding: 5px 10px; border-radius: 6px; cursor: pointer; font-size: 12px; font-weight: 700; transition: 0.2s; }
.lang-btn.active { background: var(--accent); color: #fff; }
main { max-width: 1320px; margin: 24px auto; padding: 0 20px; }

.random-bar { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px 18px; margin-bottom: 24px; display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; }
.random-left { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.random-label { font-size: 14px; font-weight: 600; color: var(--muted); margin-right: 4px; }
.select { background: var(--surface); color: var(--text); border: 1px solid var(--border); padding: 8px 12px; border-radius: 8px; font-size: 14px; outline: none; cursor: pointer; max-width: 220px; }
.select:focus { border-color: var(--accent); }
.random-btn { background: linear-gradient(135deg, #e50914, #b20710); color: #fff; border: none; padding: 9px 18px; border-radius: 8px; font-size: 14px; font-weight: 600; cursor: pointer; transition: transform 0.15s, opacity 0.2s; }
.random-btn:hover { opacity: 0.9; transform: translateY(-1px); }
.random-btn:disabled { opacity: 0.5; cursor: wait; }

.year-range { display: inline-flex; align-items: center; gap: 6px; }
.year-select { width: auto; min-width: 96px; padding: 8px 10px; }
.year-sep { color: var(--muted); font-size: 13px; }

.sort-wrap { position: relative; display: inline-block; }
.sort-trigger { background: var(--surface); color: var(--text); border: 1px solid var(--border); width: 36px; height: 36px; border-radius: 8px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; font-size: 16px; transition: 0.2s; }
.sort-trigger:hover, .sort-trigger.active { border-color: var(--accent); color: var(--text); }
.sort-menu { display: none; position: absolute; top: calc(100% + 6px); left: 0; min-width: 195px; background: var(--menu-bg); border: 1px solid var(--border); border-radius: 10px; padding: 6px; box-shadow: 0 12px 28px var(--shadow-strong); z-index: 50; }
.sort-menu.open { display: block; }
.sort-opt { width: 100%; background: transparent; color: var(--text); border: none; padding: 8px 10px; border-radius: 6px; text-align: left; font-size: 13px; cursor: pointer; display: flex; align-items: center; justify-content: space-between; transition: 0.15s; }
.sort-opt:hover { background: var(--hover); }
.sort-opt.active { background: rgba(229, 9, 20, 0.18); color: var(--text); font-weight: 600; }
.sort-divider { height: 1px; background: var(--line); margin: 6px 0; }
.sort-dir-row { display: flex; gap: 6px; }
.sort-dir-btn { flex: 1; background: var(--surface); color: var(--muted); border: 1px solid var(--border); padding: 6px 8px; border-radius: 6px; font-size: 12px; cursor: pointer; transition: 0.15s; }
.sort-dir-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

.content-layout { display: flex; gap: 24px; align-items: flex-start; }
.music-sidebar { display: none; width: 260px; flex-shrink: 0; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px; position: sticky; top: 82px; max-height: calc(100vh - 100px); overflow-y: auto; }
.music-sidebar.visible { display: block; }
.sidebar-title { font-size: 13px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--muted); margin-bottom: 12px; padding: 0 6px; font-weight: 700; }
.playlist-item { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 8px; cursor: pointer; transition: 0.2s; margin-bottom: 4px; }
.playlist-item:hover { background: var(--surface); }
.playlist-item.active { background: rgba(229, 9, 20, 0.18); border: 1px solid rgba(229, 9, 20, 0.45); }
.playlist-item img { width: 42px; height: 42px; border-radius: 6px; object-fit: cover; flex-shrink: 0; background: var(--surface); }
.playlist-icon { width: 42px; height: 42px; border-radius: 6px; background: linear-gradient(135deg, #e50914, #8b0000); display: flex; align-items: center; justify-content: center; font-size: 18px; flex-shrink: 0; }
.playlist-info { min-width: 0; }
.playlist-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.playlist-sub { font-size: 11px; color: var(--muted); }

.content-main { flex: 1; min-width: 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 20px; transition: opacity 0.18s ease; }
.grid.is-loading { opacity: 0.35; }
.card { background: var(--card); border-radius: 12px; overflow: hidden; cursor: pointer; transition: transform 0.2s, box-shadow 0.2s; position: relative; }
.card:hover { transform: translateY(-5px); box-shadow: 0 10px 25px var(--shadow); }
.card img { width: 100%; aspect-ratio: 2/3; object-fit: cover; display: block; background: var(--surface); }
.card.music-card img { aspect-ratio: 1/1; }
.card.game-card img { aspect-ratio: 3/4; }
.badge { position: absolute; top: 10px; right: 10px; background: rgba(0,0,0,0.8); color: #ffd700; font-weight: 700; font-size: 12px; padding: 4px 8px; border-radius: 6px; }
.card-body { padding: 12px; }
.title { font-size: 14px; font-weight: 600; margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.date { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status { text-align: center; color: var(--muted); margin-top: 60px; font-size: 16px; }
.status:not(:empty) { animation: fadeIn 0.2s ease-out; }

.site-footer { max-width: 1400px; margin: 40px auto 0; padding: 18px 24px 0; border-top: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: 6px; align-items: center; justify-content: center; color: var(--muted); font-size: 12px; }
.site-footer a { color: var(--link); text-decoration: none; }
.site-footer a:hover { color: var(--accent); }
.footer-note { flex-basis: 100%; text-align: center; opacity: 0.7; }
.load-more-wrap { display: none; text-align: center; margin-top: 28px; }

.card:focus-visible, .playlist-item:focus-visible, .collection-item:focus-visible,
.tab:focus-visible, .lang-btn:focus-visible, .sort-trigger:focus-visible, .random-btn:focus-visible,
.trailer-btn:focus-visible, .store-btn:focus-visible, .modal-close:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.search::-webkit-search-cancel-button { filter: invert(0.7); cursor: pointer; }
:root[data-theme="light"] .search::-webkit-search-cancel-button { filter: none; }
body.modal-open { overflow: hidden; }

.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); transform: translate(-50%, 20px); background: var(--secondary-bg); color: var(--text); border: 1px solid var(--toast-border); padding: 10px 16px; border-radius: 10px; font-size: 14px; box-shadow: 0 10px 28px var(--shadow); opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; z-index: 200; max-width: calc(100% - 32px); text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.modal-bg { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.8); z-index: 100; align-items: center; justify-content: center; padding: 20px; }
.modal-bg.open { display: flex; animation: backdropIn 0.18s ease-out; }
.modal-bg.closing { display: flex; animation: fadeOut 0.18s ease-in forwards; pointer-events: none; }
.modal { background: var(--card); max-width: 680px; width: 100%; border-radius: 16px; overflow: hidden; position: relative; max-height: 90vh; overflow-y: auto; }
.modal-bg.open .modal { animation: modalIn 0.24s cubic-bezier(0.2, 0.8, 0.3, 1.04); }
.modal-bg.closing .modal { animation: modalOut 0.18s ease-in forwards; }
.modal-close { position: absolute; top: 12px; right: 12px; background: rgba(0,0,0,0.6); color: #fff; border: none; width: 32px; height: 32px; border-radius: 50%; cursor: pointer; font-size: 18px; }
.modal-banner { width: 100%; height: 240px; object-fit: cover; background: var(--surface); display: block; }
.modal-content { padding: 24px; }
.modal-title { font-size: 24px; margin-bottom: 8px; }
.modal-meta { color: var(--muted); font-size: 13px; margin-bottom: 16px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.meta-pill { display: inline-flex; align-items: center; gap: 4px; background: var(--surface); border: 1px solid var(--border); color: var(--soft-text); padding: 3px 9px; border-radius: 6px; font-size: 12px; font-weight: 500; line-height: 1.3; }
.meta-pill.rating { color: var(--rating-text); border-color: rgba(255, 215, 0, 0.25); background: rgba(255, 215, 0, 0.08); font-weight: 700; }
.modal-desc { line-height: 1.6; color: var(--soft-text); font-size: 15px; margin-bottom: 18px; }
.audio-player { width: 100%; margin-bottom: 18px; height: 40px; border-radius: 8px; }

.store-links { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 18px; }
.store-links:empty { display: none; }
.store-btn { display: inline-flex; align-items: center; gap: 6px; background: var(--chip-bg); border: 1px solid var(--chip-border); color: var(--chip-text); text-decoration: none; padding: 5px 10px; border-radius: 7px; font-size: 12px; font-weight: 600; line-height: 1; transition: 0.15s; }
.store-btn:hover { border-color: var(--accent); background: var(--chip-hover); }
.store-btn img { width: 16px; height: 16px; border-radius: 3px; object-fit: contain; flex-shrink: 0; display: block; }

.modal-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; min-height: 40px; }
.trailer-btn { display: inline-flex; align-items: center; gap: 8px; background: var(--accent); color: #fff; text-decoration: none; padding: 10px 18px; border-radius: 8px; font-weight: 600; font-size: 14px; border: none; cursor: pointer; transition: opacity 0.2s; }
.trailer-btn:hover { opacity: 0.85; }
.trailer-btn:disabled { opacity: 0.5; cursor: wait; }
.trailer-btn.secondary { background: var(--secondary-bg); color: var(--soft-text); }

.collection-wrap { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.collection-title { font-size: 13px; color: var(--muted); font-weight: 600; margin-bottom: 10px; }
.collection-list { display: flex; gap: 12px; overflow-x: auto; padding: 2px 2px 10px; scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
.collection-list::-webkit-scrollbar { height: 6px; }
.collection-list::-webkit-scrollbar-track { background: transparent; }
.collection-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.collection-item { flex: 0 0 104px; cursor: pointer; transition: transform 0.15s; }
.collection-item:hover { transform: translateY(-3px); }
.collection-item.current { opacity: 0.6; cursor: default; pointer-events: none; }
.collection-item img { width: 104px; height: 156px; object-fit: cover; border-radius: 8px; background: var(--surface); display: block; margin-bottom: 6px; }
.collection-item.current img { outline: 2px solid var(--accent); outline-offset: -2px; }
.collection-name { font-size: 11px; line-height: 1.3; color: var(--text); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin-bottom: 2px; }
.collection-year { font-size: 10px; color: var(--muted); }

.skeleton { display: inline-block; background: linear-gradient(90deg, var(--surface) 25%, var(--skeleton-hi) 50%, var(--surface) 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: 7px; }
.skeleton-pill { width: 92px; height: 28px; }
.skeleton-btn { width: 170px; height: 38px; border-radius: 8px; }
.fade-in { animation: fadeIn 0.22s ease-out; }

/* Cards enter with a short staggered rise; `backwards` fill keeps the final
   state out of the animation so the hover transform still works afterwards. */
.card-enter { animation: cardIn 0.32s ease-out backwards; animation-delay: var(--d, 0ms); }

@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: translateY(0); } }
@keyframes cardIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }
@keyframes backdropIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes modalIn { from { opacity: 0; transform: translateY(16px) scale(0.98); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes modalOut { from { opacity: 1; transform: translateY(0) scale(1); } to { opacity: 0; transform: translateY(10px) scale(0.98); } }

@media (prefers-reduced-motion: reduce) {
  .card-enter, .fade-in, .modal-bg.open, .modal-bg.closing,
  .modal-bg.open .modal, .modal-bg.closing .modal { animation: none; }
}

@media (max-width: 820px) {
  .content-layout { flex-direction: column; gap: 16px; }
  .music-sidebar { width: 100%; position: static; max-height: none; padding: 12px; }
  #playlistList { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  #playlistList::-webkit-scrollbar { display: none; }
  .playlist-item { flex: 0 0 auto; width: 185px; margin-bottom: 0; background: var(--surface); border: 1px solid var(--line); }
}

@media (max-width: 640px) {
  header { padding: 12px 14px; gap: 10px; }
  .logo { font-size: 20px; order: 1; }
  .controls { order: 2; width: 100%; gap: 8px; flex-wrap: nowrap; }
  .search { flex: 1; width: auto; font-size: 16px; padding: 9px 12px; }
  .lang-switch { flex-shrink: 0; }
  .tabs { order: 3; width: 100%; flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; padding-bottom: 2px; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { flex: 0 0 auto; padding: 8px 14px; }

  main { margin: 14px auto; padding: 0 12px; }
  .random-bar { padding: 12px; gap: 10px; margin-bottom: 16px; }
  .random-left { width: 100%; gap: 8px; }
  .random-label { width: 100%; font-size: 13px; margin-right: 0; }
  .select { flex: 1 1 calc(50% - 4px); max-width: none; font-size: 16px; padding: 9px 10px; }
  .sort-trigger { width: 40px; height: 40px; }
  .random-btn { width: 100%; padding: 11px 16px; font-size: 15px; }

  .grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .card-body { padding: 9px 10px; }
  .title { font-size: 13px; }
  .badge { top: 6px; right: 6px; font-size: 11px; padding: 3px 6px; }

  .modal-bg { padding: 10px; }
  .modal-banner { height: 180px; }
  .modal-content { padding: 16px; }
  .modal-title { font-size: 20px; }
  .modal-desc { font-size: 14px; }
  .modal-actions { flex-direction: column; align-items: stretch; }
  .modal-actions #mTrailer { display: flex; flex-direction: column; gap: 8px; }
  .trailer-btn { justify-content: center; width: 100%; padding: 11px 16px; }
}
/* ---------- Theme toggle ---------- */
.theme-btn { background: var(--surface); border: 1px solid var(--border); color: var(--text); width: 36px; height: 36px; border-radius: 8px; cursor: pointer; font-size: 16px; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; transition: border-color 0.2s; }
.theme-btn:hover { border-color: var(--accent); }
.theme-btn:focus-visible, .card-share:focus-visible, .share-opt:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Sharing ---------- */
.card-share { position: absolute; top: 10px; left: 10px; z-index: 2; width: 32px; height: 32px; border-radius: 50%; border: none; background: rgba(0,0,0,0.65); color: #fff; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; opacity: 0; transform: scale(0.9); transition: opacity 0.15s, transform 0.15s, background 0.15s; }
.card-share svg { width: 16px; height: 16px; }
.card:hover .card-share, .card:focus-within .card-share, .card-share:focus-visible { opacity: 1; transform: scale(1); }
.card-share:hover { background: var(--accent); }
@media (hover: none) { .card-share { opacity: 1; transform: none; width: 30px; height: 30px; top: 6px; left: 6px; } }

.share-btn svg { width: 16px; height: 16px; }

.share-menu { display: none; position: fixed; z-index: 300; min-width: 210px; background: var(--menu-bg); border: 1px solid var(--border); border-radius: 12px; padding: 6px; box-shadow: 0 14px 34px var(--shadow-strong); }
.share-menu.open { display: block; animation: fadeIn 0.14s ease-out; }
.share-title { font-size: 12px; color: var(--muted); padding: 6px 10px 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 240px; }
.share-opt { width: 100%; display: flex; align-items: center; gap: 10px; background: transparent; border: none; color: var(--text); padding: 8px 10px; border-radius: 8px; font-size: 14px; text-align: left; text-decoration: none; cursor: pointer; transition: background 0.15s; }
.share-opt:hover { background: var(--hover); }
.share-ico { width: 24px; height: 24px; border-radius: 6px; display: inline-flex; align-items: center; justify-content: center; color: #fff; flex-shrink: 0; font-size: 12px; font-weight: 800; }
.share-ico svg { width: 14px; height: 14px; }
.share-divider { height: 1px; background: var(--line); margin: 6px 0; }

@media (max-width: 640px) {
  .theme-btn { width: 40px; height: 40px; }
  .share-menu { left: 10px !important; right: 10px; bottom: calc(10px + env(safe-area-inset-bottom, 0px)); top: auto !important; min-width: 0; }
  .share-title { max-width: none; }
  .share-opt { padding: 11px 10px; font-size: 15px; }
}
