/* ===== テーマ変数（ライトが既定、ダークは data-theme か OS 設定で切替） ===== */
:root {
  color-scheme: light;
  --bg: #f4f5f9;
  --surface: #ffffff;
  --surface-2: #eceef5;
  --text: #1c1f26;
  --muted: #6b7180;
  --border: #dfe2ea;
  --accent: #5b5fe6;
  --accent-text: #ffffff;
  --star: #f5a524;
  --wip: #b45309;
  --wip-bg: #fff1dc;
  --error: #c62828;
  --shadow: 0 1px 2px rgba(20, 24, 40, .06), 0 4px 14px rgba(20, 24, 40, .06);
  --radius: 14px;
  --tap: 44px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #15171c;
    --surface: #1f2229;
    --surface-2: #2a2e37;
    --text: #eceef3;
    --muted: #9aa1b0;
    --border: #343946;
    --accent: #8b8ef5;
    --accent-text: #0f1020;
    --star: #ffc247;
    --wip: #fbbf24;
    --wip-bg: #3d2f12;
    --error: #ff7b7b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 14px rgba(0, 0, 0, .25);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #15171c;
  --surface: #1f2229;
  --surface-2: #2a2e37;
  --text: #eceef3;
  --muted: #9aa1b0;
  --border: #343946;
  --accent: #8b8ef5;
  --accent-text: #0f1020;
  --star: #ffc247;
  --wip: #fbbf24;
  --wip-bg: #3d2f12;
  --error: #ff7b7b;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 14px rgba(0, 0, 0, .25);
}

/* ===== ベース ===== */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Hiragino Sans", "Noto Sans JP", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
[hidden] { display: none !important; }

/* ===== ヘッダー ===== */
.app-header {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.app-title { margin: 0; font-size: 1.35rem; font-weight: 700; letter-spacing: .01em; }
.icon-btn, .btn {
  min-width: var(--tap); min-height: var(--tap);
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  padding: 0 12px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); cursor: pointer;
  font-size: 1rem; white-space: nowrap;
}
.icon-btn:active, .btn:active { transform: scale(.96); }

/* ===== メイン ===== */
.app-main { max-width: 1100px; margin: 0 auto; padding: 4px 16px 24px; }
.toolbar { display: flex; gap: 8px; }
.search { flex: 1; display: block; min-width: 0; }
.search input, .sort select {
  width: 100%; min-height: var(--tap);
  padding: 0 14px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface);
}
.search input::-webkit-search-cancel-button { -webkit-appearance: none; }
.sort { flex: 0 0 auto; }
.sort select {
  padding-right: 30px; -webkit-appearance: none; appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%;
  background-size: 5px 5px; background-repeat: no-repeat;
}

/* スマホは横スクロール。右端をぼかしてスクロールできることを示す
   （スクロールバーを隠しているので、これが無いと続きがあると気づけない） */
.tags-wrap {
  margin: 10px -16px 0;
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
          mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
}
.tags {
  display: flex; gap: 8px; padding: 2px 16px 6px;
  overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.tags::-webkit-scrollbar { display: none; }
/* 画面が広いときは折り返して全部見せる（横に溢れたままだと気づけないため） */
@media (min-width: 720px) {
  .tags-wrap { -webkit-mask-image: none; mask-image: none; }
  .tags { flex-wrap: wrap; overflow-x: visible; }
}
.chip {
  flex: 0 0 auto; min-height: var(--tap); padding: 0 16px;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); color: var(--text); cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
.chip[aria-pressed="true"]::before { content: "✓ "; }

.status { margin: 24px 16px; text-align: center; color: var(--muted); }
.status.error { color: var(--error); font-weight: 600; }

/* ===== セクションとカード ===== */
.section { margin-top: 18px; }
.section-title { margin: 0 0 10px; font-size: 1rem; font-weight: 700; color: var(--muted); }
.grid {
  list-style: none; margin: 0; padding: 0;
  display: grid; gap: 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
@media (min-width: 560px) { .grid { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); } }
.empty { color: var(--muted); font-size: .9rem; margin: 4px 0; }

.card {
  position: relative;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.card-link { display: block; height: 100%; }
.card-link:active { opacity: .8; }
.thumb {
  position: relative; aspect-ratio: 4 / 3;
  background: var(--ph, var(--surface-2));
  display: grid; place-items: center; overflow: hidden;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; grid-area: 1 / 1; }
.ph { grid-area: 1 / 1; font-size: 2.6rem; font-weight: 700; color: #fff; text-shadow: 0 2px 8px rgba(0,0,0,.25); }
.badge {
  position: absolute; left: 8px; bottom: 8px;
  padding: 2px 8px; border-radius: 6px; font-size: .72rem; font-weight: 700;
  background: var(--wip-bg); color: var(--wip); border: 1px solid currentColor;
}
.card-body { padding: 10px 12px 12px; }
.card-title { margin: 0; font-size: 1rem; line-height: 1.35; }
.card-desc {
  margin: 4px 0 0; font-size: .8rem; color: var(--muted); line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card-meta { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 4px 8px; font-size: .75rem; color: var(--muted); align-items: center; }
.card-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.tag { padding: 1px 7px; border-radius: 999px; background: var(--surface-2); }

.fav {
  position: absolute; top: 2px; right: 2px;
  width: var(--tap); height: var(--tap);
  border: 0; border-radius: 50%; background: transparent;
  color: rgba(255,255,255,.92); font-size: 1.5rem; line-height: 1; cursor: pointer;
  text-shadow: 0 1px 4px rgba(0,0,0,.55);
}
.fav[aria-pressed="true"] { color: var(--star); }
.fav:active { transform: scale(1.2); }

.app-footer { padding: 8px 16px calc(16px + env(safe-area-inset-bottom)); text-align: center; color: var(--muted); font-size: .8rem; }

/* ===== 起動画面（play.html） ===== */
.play-page { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
.play-bar {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 8px;
  padding: calc(6px + env(safe-area-inset-top)) 10px 6px;
  border-bottom: 1px solid var(--border); background: var(--bg);
}
.play-title { flex: 1; min-width: 0; margin: 0; font-size: 1rem; font-weight: 600; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.play-main { flex: 1; min-height: 0; position: relative; background: var(--surface); }
.play-main iframe { width: 100%; height: 100%; border: 0; display: block; }
.play-page.immersive .play-bar { display: none; }
.restore {
  position: fixed; top: calc(8px + env(safe-area-inset-top)); right: 8px; z-index: 20;
  width: var(--tap); height: var(--tap);
  border: 1px solid var(--border); border-radius: 50%;
  background: color-mix(in srgb, var(--bg) 75%, transparent);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  font-size: 1.1rem; cursor: pointer; opacity: .75;
}
