:root {
  --bg: #0b0f17;
  --bg-elevated: #121824;
  --surface: #171f2e;
  --surface-hover: #1e293d;
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(245, 185, 66, 0.45);
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #f5b942;
  --accent-dim: rgba(245, 185, 66, 0.16);
  --yt-red: #ef4444;
  --done-green: #22c55e;
  --radius-lg: 14px;
  --radius-md: 10px;
}

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

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

button, input {
  font: inherit;
  color: inherit;
}

/* トップバー（YouTube風） */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(11, 15, 23, 0.88);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1440px;
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.brand-icon {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, #f5b942, #d97706);
  color: #0b0f17;
  display: grid;
  place-items: center;
  box-shadow: 0 2px 10px rgba(245, 185, 66, 0.28);
}

.brand-title {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.search-wrap {
  flex: 1;
  max-width: 460px;
  margin: 0 auto;
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 12px;
  color: var(--muted);
  pointer-events: none;
}

.search-input {
  width: 100%;
  height: 36px;
  padding: 0 34px 0 36px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 13px;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.search-input::placeholder {
  color: var(--muted);
}

.search-input:focus {
  border-color: var(--accent);
  background: #161e2d;
}

.search-clear {
  position: absolute;
  right: 8px;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 12px;
}

.search-clear.hidden {
  display: none;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.progress-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}

.progress-pill-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}

.btn-random {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid rgba(245, 185, 66, 0.4);
  background: var(--accent-dim);
  color: #fde68a;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, transform 0.12s ease;
}

.btn-random:hover {
  background: rgba(245, 185, 66, 0.26);
  transform: translateY(-1px);
}

/* チップバー（カテゴリ切り替え） */
.chipbar-wrap {
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 20px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
}

.chipbar-wrap::-webkit-scrollbar {
  display: none;
}

.chip {
  flex-shrink: 0;
  height: 32px;
  padding: 0 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: #cbd5e1;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.chip:hover {
  background: var(--surface-hover);
  color: #ffffff;
}

.chip.active {
  background: #f8fafc;
  color: #0f172a;
  border-color: #f8fafc;
}

.chip-count {
  font-size: 11px;
  opacity: 0.72;
}

/* メインコンテナ */
.main-wrap {
  max-width: 1440px;
  margin: 0 auto;
  padding: 18px 20px 56px;
}

/* 続きから再生バナー */
.resume-banner {
  margin-bottom: 24px;
  padding: 14px 16px;
  border-radius: var(--radius-lg);
  background: linear-gradient(125deg, rgba(245, 185, 66, 0.14), rgba(30, 41, 59, 0.92) 55%);
  border: 1px solid var(--border-strong);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.resume-banner.hidden {
  display: none;
}

.resume-left {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.resume-thumb {
  width: 120px;
  aspect-ratio: 16 / 9;
  border-radius: 8px;
  overflow: hidden;
  flex-shrink: 0;
  position: relative;
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.resume-info {
  min-width: 0;
}

.resume-kicker {
  font-size: 11px;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: 0.04em;
  margin-bottom: 2px;
}

.resume-title {
  font-size: 16px;
  font-weight: 800;
  color: #ffffff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.resume-sub {
  font-size: 12px;
  color: #cbd5e1;
  margin-top: 2px;
}

.resume-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  padding: 0 16px;
  border-radius: 999px;
  background: var(--accent);
  color: #0b0f17;
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
  border: none;
  cursor: pointer;
  transition: filter 0.15s ease, transform 0.12s ease;
}

.btn-primary:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

.btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  padding: 0 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 700;
  text-decoration: none;
  border: 1px solid var(--border);
  cursor: pointer;
}

.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.14);
}

/* セクション */
.shelf-section {
  margin-bottom: 30px;
}

.shelf-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.shelf-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 800;
  color: #f8fafc;
}

.shelf-badge {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: 999px;
}

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

/* YouTube / ゲーム風カード */
.unit-card {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: transform 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

.unit-card:hover {
  transform: translateY(-3px);
  border-color: rgba(245, 185, 66, 0.55);
  background: var(--surface-hover);
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.42);
}

.thumb-link {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  background: #0f172a;
}

.thumb-bg {
  position: absolute;
  inset: 0;
  transition: transform 0.25s ease;
}

.unit-card:hover .thumb-bg {
  transform: scale(1.03);
}

.thumb-grid-overlay {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.06) 1px, transparent 1px);
  background-size: 24px 24px;
  mask-image: radial-gradient(circle at 65% 45%, rgba(0, 0, 0, 0.9), transparent 82%);
}

.thumb-art {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 54%;
  height: 82%;
  opacity: 0.92;
  pointer-events: none;
  filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.35));
}

.thumb-vignette {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(11, 15, 23, 0.12) 0%, rgba(11, 15, 23, 0.04) 45%, rgba(11, 15, 23, 0.72) 100%);
  pointer-events: none;
}

.thumb-code {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 2;
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.04em;
  padding: 2px 8px;
  border-radius: 6px;
  background: rgba(11, 15, 23, 0.76);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #f8fafc;
}

.thumb-status {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  font-size: 10.5px;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 6px;
  background: rgba(21, 128, 61, 0.9);
  color: #f0fdf4;
  border: 1px solid rgba(134, 239, 172, 0.4);
}

.thumb-status.in-progress {
  background: rgba(217, 119, 6, 0.92);
  color: #fffbeb;
  border-color: rgba(253, 224, 71, 0.45);
}

.thumb-duration {
  position: absolute;
  right: 8px;
  bottom: 9px;
  z-index: 2;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 5px;
  background: rgba(0, 0, 0, 0.82);
  color: #f8fafc;
}

/* サムネ左下のゆっくりミニアイコン */
.thumb-chars {
  position: absolute;
  left: 8px;
  bottom: 8px;
  z-index: 2;
  display: flex;
  align-items: flex-end;
  pointer-events: none;
}

.yukkuri-mini {
  position: relative;
  width: 38px;
  height: 34px;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.65));
}

.yukkuri-mini.marisa {
  margin-left: -10px;
}

.yukkuri-mini img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.thumb-play-hover {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-items: center;
  background: rgba(11, 15, 23, 0.25);
  opacity: 0;
  transition: opacity 0.16s ease;
}

.unit-card:hover .thumb-play-hover {
  opacity: 1;
}

.play-circle {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: rgba(245, 185, 66, 0.95);
  color: #0b0f17;
  display: grid;
  place-items: center;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
}

/* YouTube風 視聴進捗バー */
.thumb-progress-track {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 4px;
  background: rgba(255, 255, 255, 0.2);
  z-index: 4;
}

.thumb-progress-fill {
  height: 100%;
  background: var(--yt-red);
  transition: width 0.25s ease;
}

.thumb-progress-fill.completed {
  background: var(--done-green);
}

/* カード下部（メタエリア） */
.card-body {
  padding: 11px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

.card-main-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.card-title-link {
  text-decoration: none;
  color: inherit;
  flex: 1;
  min-width: 0;
}

.card-title {
  font-size: 14.5px;
  font-weight: 800;
  color: #f8fafc;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: auto;
}

.card-sub {
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-chapters {
  flex-shrink: 0;
  height: 26px;
  padding: 0 9px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.05);
  color: #cbd5e1;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: background 0.14s ease, border-color 0.14s ease;
}

.btn-chapters:hover {
  background: rgba(245, 185, 66, 0.18);
  border-color: var(--border-strong);
  color: #fde68a;
}

/* 空状態 */
.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
}

.empty-state.hidden {
  display: none;
}

/* チャプター選択モーダル */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(5, 8, 14, 0.76);
  backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  padding: 16px;
}

.modal-backdrop.hidden {
  display: none;
}

.modal-panel {
  width: min(640px, 100%);
  max-height: min(84vh, 680px);
  background: #131a27;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 16px;
  box-shadow: 0 24px 56px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-kicker {
  font-size: 11px;
  font-weight: 800;
  color: var(--accent);
}

.modal-title {
  font-size: 17px;
  font-weight: 800;
  color: #ffffff;
}

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.modal-close:hover {
  background: rgba(255, 255, 255, 0.14);
}

.modal-actions-bar {
  padding: 10px 18px;
  background: rgba(255, 255, 255, 0.02);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.modal-body {
  padding: 12px 18px 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chapter-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 13px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  text-decoration: none;
  color: inherit;
  transition: border-color 0.14s ease, background 0.14s ease, transform 0.12s ease;
}

.chapter-item:hover {
  border-color: var(--accent);
  background: var(--surface-hover);
  transform: translateX(2px);
}

.chapter-item.is-current {
  border-color: var(--accent);
  background: rgba(245, 185, 66, 0.11);
}

.chapter-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.chapter-num {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 800;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  color: #fde68a;
}

.chapter-title {
  font-size: 13.5px;
  font-weight: 700;
  color: #f8fafc;
}

.chapter-steps {
  flex-shrink: 0;
  font-size: 11.5px;
  color: var(--muted);
}

/* 横画面タブレット・スマホ（iPad mini / nubia S2R 等）向け最適化 */
@media (max-width: 960px) {
  .topbar-inner {
    padding: 8px 14px;
    gap: 10px;
  }
  .chipbar-wrap {
    padding: 0 14px 8px;
  }
  .main-wrap {
    padding: 14px 14px 40px;
  }
  .card-grid {
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 12px;
  }
}

@media (max-width: 680px) {
  .brand-title {
    font-size: 14px;
  }
  .progress-pill {
    display: none;
  }
  .resume-banner {
    flex-direction: column;
    align-items: stretch;
  }
  .resume-actions {
    justify-content: flex-end;
  }
}

@media (max-height: 520px) and (orientation: landscape) {
  .topbar-inner {
    padding: 6px 14px;
  }
  .chipbar-wrap {
    padding: 0 14px 6px;
  }
  .chip {
    height: 28px;
    padding: 0 11px;
    font-size: 12px;
  }
  .main-wrap {
    padding: 10px 14px 28px;
  }
  .resume-banner {
    padding: 10px 12px;
    margin-bottom: 16px;
  }
  .resume-thumb {
    width: 96px;
  }
  .card-grid {
    grid-template-columns: repeat(auto-fill, minmax(205px, 1fr));
    gap: 10px;
  }
}
