/* Netflix-style dark theme */
* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: #141414;
  color: #e5e5e5;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue",
               "Hiragino Sans", "Noto Sans JP", sans-serif;
  overflow: hidden;
  height: 100vh;
}

#app {
  display: flex;
  height: 100vh;
}

#sidebar {
  width: 240px;
  flex-shrink: 0;
  background: #0a0a0a;
  border-right: 1px solid #2a2a2a;
  padding: 20px 16px;
  overflow-y: auto;
}

#sidebar h1 {
  margin-bottom: 20px;
}
#sidebar h1.brand a {
  display: inline-block;
  text-decoration: none;
  cursor: pointer;
  line-height: 1.1;
  padding: 8px 12px;
  border-radius: 8px;
  background: linear-gradient(135deg, #00a8e1 0%, #0070b8 100%);
  box-shadow: 0 2px 8px rgba(0, 168, 225, 0.25);
  transition: transform 0.15s, box-shadow 0.15s;
}
#sidebar h1.brand a:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 168, 225, 0.4);
}
#sidebar h1.brand .brand-name {
  display: block;
  font-size: 22px;
  font-weight: 900;
  color: #fff;
  letter-spacing: -0.5px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
#sidebar h1.brand .brand-sub {
  display: block;
  font-size: 10px;
  color: rgba(255,255,255,0.85);
  font-weight: 500;
  letter-spacing: 0.5px;
  margin-top: 2px;
}

.search-box {
  position: relative;
}
.search-box input {
  width: 100%;
  padding: 8px 28px 8px 12px;
  background: #1a1a1a;
  border: 1px solid #333;
  color: #fff;
  border-radius: 4px;
  font-size: 13px;
}
.search-box input:focus {
  outline: none;
  border-color: #e50914;
}
#search-clear {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: #888;
  font-size: 18px;
  cursor: pointer;
  display: none;
  padding: 0 4px;
  line-height: 1;
}
#search-clear:hover { color: #fff; }
#search-clear.show { display: block; }

.filters {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.filters label {
  font-size: 11px;
  color: #888;
  margin-top: 8px;
}
.filters select {
  background: #1a1a1a;
  color: #fff;
  border: 1px solid #333;
  padding: 6px 8px;
  border-radius: 4px;
  font-size: 12px;
}

.genre-header {
  font-size: 11px;
  text-transform: uppercase;
  color: #888;
  margin: 20px 0 8px;
  letter-spacing: 1px;
}

.sidebar-links {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid #2a2a2a;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.sidebar-links a {
  color: #777;
  text-decoration: none;
  font-size: 12px;
  padding: 4px 6px;
  border-radius: 4px;
  transition: background 0.15s, color 0.15s;
}
.sidebar-links a:hover {
  color: #7dd3fc;
  background: #1a1a1a;
}

.featured-link {
  display: block;
  margin: 16px 0 8px;
  padding: 10px 14px;
  background: linear-gradient(135deg, #1a2535 0%, #0f1822 100%);
  border: 1px solid #00a8e1;
  border-radius: 6px;
  color: #7dd3fc;
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  transition: background 0.15s, transform 0.15s;
}
.featured-link:hover {
  background: linear-gradient(135deg, #1f2d40 0%, #122030 100%);
  transform: translateY(-1px);
}

#genres {
  list-style: none;
}
#genres li {
  padding: 7px 10px;
  cursor: pointer;
  border-radius: 4px;
  transition: background .15s;
  font-size: 13px;
  display: flex;
  justify-content: space-between;
}
#genres li:hover {
  background: #222;
}
#genres li.active {
  background: #e50914;
  color: #fff;
}
#genres li .count {
  color: #777;
  font-size: 11px;
}
#genres li.active .count { color: rgba(255,255,255,0.8); }

#main {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

header {
  margin-bottom: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
#status {
  color: #999;
  font-size: 13px;
}

#grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
}

.card {
  position: relative;
  background: #1a1a1a;
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  transition: transform .2s ease, box-shadow .2s ease;
  display: flex;
  flex-direction: column;
}
.card:hover {
  transform: scale(1.06);
  box-shadow: 0 12px 30px rgba(0,0,0,0.8);
  z-index: 10;
}
.card-poster {
  position: relative;
  aspect-ratio: 2/3;
  background: #333;
  overflow: hidden;
}
.card-title-text {
  padding: 6px 8px 8px;
  font-size: 12px;
  color: #ddd;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: break-word;
  min-height: 38px;
}

.card .badge {
  position: absolute;
  top: 8px;
  left: 8px;
  font-size: 10px;
  font-weight: 600;
  color: #fff;
  padding: 3px 7px;
  border-radius: 3px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.5);
  pointer-events: none;
  letter-spacing: 0.2px;
}

.card .badge-new {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 10px;
  background: #e50914;
  color: #fff;
  padding: 3px 6px;
  border-radius: 3px;
  font-weight: 700;
  animation: pulse 2s infinite;
}
.card .badge-leaving {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 10px;
  background: #ff8800;
  color: #fff;
  padding: 3px 6px;
  border-radius: 3px;
  font-weight: 700;
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
}
.card .badge-leaving.confidence-medium {
  background: #b88500;
  opacity: 0.85;
}

/* スケルトン (初回ロード) */
.skeleton {
  background: #1a1a1a;
  border-radius: 6px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.skeleton-poster {
  aspect-ratio: 2/3;
  background: linear-gradient(110deg, #1a1a1a 30%, #2a2a2a 50%, #1a1a1a 70%);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
}
.skeleton-title {
  height: 38px;
  margin: 6px 8px 8px;
  background: linear-gradient(110deg, #222 30%, #2c2c2c 50%, #222 70%);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
  border-radius: 3px;
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ===== タグ(chip)UI ===== */
#selected-tags {
  padding: 4px 10px 0;
}
#selected-tags:not(:empty) {
  padding-bottom: 6px;
  border-bottom: 1px solid #333;
  margin-bottom: 6px;
}
#keyword-chips {
  padding: 4px 10px 8px;
  max-height: 420px;
  overflow-y: auto;
}
#keyword-chips::-webkit-scrollbar { width: 6px; }
#keyword-chips::-webkit-scrollbar-thumb { background: #444; border-radius: 3px; }

.chip {
  display: inline-block;
  background: #262626;
  color: #ddd;
  padding: 3px 8px;
  margin: 2px 3px 2px 0;
  border-radius: 12px;
  font-size: 11px;
  cursor: pointer;
  border: 1px solid #333;
  transition: all 0.15s;
  user-select: none;
  white-space: nowrap;
}
.chip:hover {
  background: #333;
  border-color: #555;
}
.chip.active, .chip.selected {
  background: #0066cc;
  color: #fff;
  border-color: #0088ff;
  font-weight: 600;
}
.chip.selected:hover {
  background: #aa3333;
}
.chip.type-chip {
  background: #1f2a25;
  border-color: #2f4a3a;
}
.chip.type-chip:hover { background: #2a3a32; }
.chip.type-chip.active {
  background: #2c8a55;
  border-color: #44cc77;
  color: #fff;
}
.chip.origin-chip {
  background: #2a2520;
  border-color: #4a3520;
}
.chip.origin-chip:hover { background: #3a3530; }
.chip.origin-chip.active {
  background: #c87800;
  border-color: #ffaa33;
  color: #fff;
}
.chip-section-label {
  display: block;
  font-size: 10px;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 8px 0 4px;
}
.cat-sep {
  display: block;
  height: 0;
  border-top: 1px dashed #333;
  margin: 8px 0 4px;
}
.chip-count {
  margin-left: 4px;
  opacity: 0.6;
  font-size: 9px;
}
.chip-remove {
  margin-left: 5px;
  opacity: 0.8;
  font-weight: bold;
}
.chip-clear {
  display: inline-block;
  color: #ff8888;
  font-size: 10px;
  padding: 3px 8px;
  margin: 2px 0;
  cursor: pointer;
  text-decoration: underline;
}
.chip-clear:hover {
  color: #ff4444;
}
#selected-tags-count {
  color: #0088ff;
  font-size: 10px;
  font-weight: normal;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.card .fav-star {
  position: absolute;
  bottom: 8px;
  right: 8px;
  font-size: 20px;
  cursor: pointer;
  text-shadow: 0 0 6px rgba(0,0,0,0.8);
  transition: transform .15s;
  z-index: 2;
}
.card .fav-star:hover { transform: scale(1.3); }
.card .fav-star.active { color: #f59e0b; }

.card .search-btn {
  position: absolute;
  bottom: 8px;
  left: 8px;
  font-size: 16px;
  cursor: pointer;
  opacity: 0.6;
  text-shadow: 0 0 6px rgba(0,0,0,0.8);
  transition: opacity .15s, transform .15s;
  z-index: 2;
  background: rgba(0,0,0,0.5);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.card:hover .search-btn { opacity: 1; }
.card .search-btn:hover { transform: scale(1.2); opacity: 1; }

.card-poster img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: #333;
}
.card-poster .placeholder {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #3a3a3a, #1a1a1a);
  color: #aaa;
  font-size: 13px;
  padding: 10px;
  text-align: center;
}

.tooltip {
  position: fixed;
  background: rgba(20, 20, 20, 0.97);
  border: 1px solid #333;
  border-radius: 6px;
  padding: 12px;
  max-width: 340px;
  z-index: 100;
  font-size: 13px;
  line-height: 1.5;
  color: #e5e5e5;
  box-shadow: 0 8px 24px rgba(0,0,0,0.7);
  pointer-events: none;
}
.tooltip.hidden { display: none; }
.tooltip .t-title {
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 4px;
}
.tooltip .t-orig {
  font-size: 11px;
  color: #bbb;
  font-style: italic;
  margin-bottom: 4px;
}
.tooltip .t-country {
  font-size: 11px;
  color: #aaa;
  margin-bottom: 6px;
}
.tooltip .t-meta {
  font-size: 11px;
  color: #999;
  margin-bottom: 8px;
}
.tooltip .t-meta .rating {
  color: #f5c518;
  font-weight: 600;
  margin-right: 8px;
}
.tooltip .t-desc {
  font-size: 12px;
  color: #ccc;
  display: -webkit-box;
  -webkit-line-clamp: 6;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.tooltip .t-genres {
  margin-top: 8px;
  font-size: 11px;
}
.tooltip .t-genres span {
  display: inline-block;
  background: #333;
  padding: 2px 8px;
  border-radius: 10px;
  margin: 2px 4px 0 0;
}

#loader-sentinel { height: 40px; margin-top: 20px; text-align: center; color: #777; }

/* U-NEXT風 ジャンル内タグバー */
#genre-tags-bar {
  display: none;
  background: #14151a;
  border-bottom: 1px solid #2a2e3a;
  padding: 8px 0 12px;
  margin: -10px -20px 12px;
  padding-left: 20px;
  padding-right: 20px;
}
.genre-tags-label {
  font-size: 11px;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 6px;
}
.genre-tags-scroll {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  white-space: nowrap;
  padding-bottom: 4px;
  scrollbar-width: thin;
  scrollbar-color: #444 transparent;
}
.genre-tags-scroll::-webkit-scrollbar { height: 6px; }
.genre-tags-scroll::-webkit-scrollbar-thumb { background: #444; border-radius: 3px; }
.genre-tags-scroll .chip { flex-shrink: 0; }

/* トップに戻るボタン */
#toTop {
  position: fixed;
  right: 24px;
  bottom: 28px;
  z-index: 50;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #e50914;
  color: #fff;
  border: none;
  font-size: 20px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,.55);
  display: none;
  transition: background .15s, transform .1s;
}
#toTop:hover { background: #ff1c2c; }
#toTop:active { transform: translateY(1px); }
#toTop.show { display: block; }

/* ハンバーガーメニュー (モバイルのみ表示) */
#sidebar-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 60;
  width: 44px;
  height: 44px;
  border-radius: 6px;
  background: rgba(20,20,20,0.92);
  color: #fff;
  border: 1px solid #333;
  font-size: 20px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,.5);
}
#sidebar-toggle:active { background: rgba(40,40,40,0.95); }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 40;
}
.sidebar-overlay.show { display: block; }

/* ===== 詳細モーダル ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal.hidden { display: none; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.85);
}
.modal-content {
  position: relative;
  background: #1a1a1a;
  border-radius: 8px;
  width: min(720px, 92vw);
  max-height: 88vh;
  overflow-y: auto;
  padding: 0;
  box-shadow: 0 20px 60px rgba(0,0,0,0.8);
}
.modal-close {
  position: absolute;
  top: 8px;
  right: 12px;
  background: rgba(20,20,20,0.7);
  color: #fff;
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 22px;
  cursor: pointer;
  z-index: 5;
}
.modal-close:hover { background: rgba(40,40,40,0.95); }
.modal-body {
  padding: 24px;
}
.modal-body .m-hero {
  display: flex;
  gap: 18px;
  margin-bottom: 16px;
}
.modal-body .m-poster {
  flex-shrink: 0;
  width: 160px;
  aspect-ratio: 2/3;
  background: #333;
  border-radius: 4px;
  overflow: hidden;
}
.modal-body .m-poster img {
  width: 100%; height: 100%; object-fit: cover;
}
.modal-body .m-info { flex: 1; min-width: 0; }
.modal-body .m-title {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 4px;
  color: #fff;
}
.modal-body .m-orig {
  font-size: 12px;
  color: #aaa;
  font-style: italic;
  margin-bottom: 8px;
}
.modal-body .m-meta {
  font-size: 13px;
  color: #bbb;
  margin-bottom: 12px;
}
.modal-body .m-meta .rating {
  color: #f5c518;
  font-weight: 600;
  margin-right: 10px;
}
.modal-body .m-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}
.modal-body .m-badges .badge {
  display: inline-block;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 3px;
  color: #fff;
  font-weight: 600;
}
.modal-body .m-desc {
  font-size: 13px;
  line-height: 1.6;
  color: #ddd;
  margin-bottom: 18px;
}
.modal-body .m-genres span {
  display: inline-block;
  background: #2a2a2a;
  padding: 3px 9px;
  border-radius: 12px;
  font-size: 11px;
  margin: 2px 4px 2px 0;
  color: #ccc;
}
.modal-body .m-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid #2a2a2a;
}
.modal-body .m-actions a, .modal-body .m-actions button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 18px;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  border: none;
}
.modal-body .m-actions .btn-primary {
  background: #00a8e1;
  color: #fff;
}
.modal-body .m-actions .btn-primary:hover { background: #0095c8; }
.modal-body .m-actions .btn-secondary {
  background: #2a2a2a;
  color: #ddd;
  border: 1px solid #444;
}
.modal-body .m-actions .btn-secondary:hover { background: #3a3a3a; }
.modal-body .m-actions .btn-fav {
  background: #2a2a2a;
  color: #ddd;
  border: 1px solid #444;
}
.modal-body .m-actions .btn-fav.active {
  background: #f59e0b;
  color: #1a1a1a;
}

/* ===== モバイルレスポンシブ ===== */
@media (max-width: 900px) {
  #grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
  }
}

@media (max-width: 768px) {
  body { overflow: auto; }
  #app { display: block; height: auto; min-height: 100vh; }

  #sidebar-toggle { display: block; }

  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: 280px;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 2px 0 20px rgba(0,0,0,0.6);
  }
  #sidebar.open { transform: translateX(0); }

  #main {
    height: auto;
    overflow-y: visible;
    padding: 64px 12px 24px;  /* ハンバーガー分のtop padding */
  }

  header { margin-bottom: 12px; }
  #status { font-size: 12px; }

  #grid {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 10px;
  }
  .card-title-text { font-size: 11px; padding: 5px 6px 6px; min-height: 32px; }

  .tooltip { display: none !important; }  /* スマホはモーダルを使用 */

  #toTop { right: 14px; bottom: 14px; width: 42px; height: 42px; font-size: 16px; }
  #genre-tags-bar { margin: -10px -12px 8px; padding: 8px 12px 10px; }

  .modal-body { padding: 16px; }
  .modal-body .m-hero { flex-direction: column; gap: 12px; }
  .modal-body .m-poster { width: 120px; margin: 0 auto; }
  .modal-body .m-title { font-size: 18px; text-align: center; }
  .modal-body .m-orig, .modal-body .m-meta { text-align: center; }
}

@media (max-width: 420px) {
  #grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
  .card-title-text { font-size: 10.5px; min-height: 30px; }
  #sidebar { width: 86vw; }
}
