:root {
  --bg:        #f8e2f8;
  --bg-2:      #f8e2f8;
  --text:      #7f4719;
  --text-dim:  #a99fc4;
  --accent:    #fa7aa9;
  --accent-2:  #fa7aa9;
  --radius:    16px;
  --chrome:    300px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(120% 80% at 50% 0%, var(--bg-2) 0%, var(--bg) 60%) fixed;
  color: var(--text);
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Noto Sans JP",
               system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  overflow: hidden;
}

/* ---------- 上部ロゴ ---------- */
.header {
  flex: none;
  display: grid;
  place-items: center;
  padding: max(12px, env(safe-area-inset-top)) 16px 8px;
}
.logo {
  height: clamp(48px, 9vh, 110px);
  width: auto;
  max-width: min(90vw, 680px);
  object-fit: contain;
}
.logo-text {
  margin: 0;
  font-size: clamp(22px, 4.5vw, 38px);
  font-weight: 800;
  letter-spacing: .06em;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.stage {
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 8px 16px;
}
.frame {
  position: relative;
  width: min(100%, (100dvh - var(--chrome)) * 16 / 9);
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
}
.frame video {
  display: block;
  width: 100%;
  height: 100%;
  background: #000;
}
.notice {
  position: absolute;
  inset: 0;
  margin: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  line-height: 1.8;
  white-space: pre-line;
  color: var(--text-dim);
  background: #000;
}

/* ---------- タイトル表示 ---------- */
.controls {
  flex: none;
  padding: 4px 16px max(16px, env(safe-area-inset-bottom));
}
.now {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 12px;
  margin-bottom: 12px;
  min-height: 1.6em;
}
.now-count {
  flex: none;
  font-variant-numeric: tabular-nums;
  font-size: 14px;
  color: var(--text-dim);
}
.now-title {
  font-size: clamp(16px, 2.6vw, 22px);
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.buttons {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  max-width: 960px;
  margin: 0 auto;
}
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 64px;
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, .06);
  color: var(--text);
  font: inherit;
  font-size: clamp(14px, 1.8vw, 17px);
  font-weight: 700;
  cursor: pointer;
  transition: background .15s, transform .08s, border-color .15s;
}
.btn svg { width: 24px; height: 24px; fill: currentColor; flex: none; }
.btn:active { transform: scale(.97); background: rgba(255, 255, 255, .12); }
.btn:focus-visible { outline: 3px solid var(--accent-2); outline-offset: 2px; }
.btn:disabled { opacity: .35; pointer-events: none; }

/* ループ ON のとき */
.btn[aria-pressed="true"] {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent;
  color: #fff;
}

@media (hover: hover) {
  .btn:hover { background: rgba(255, 255, 255, .14); }
  .btn[aria-pressed="true"]:hover { filter: brightness(1.08); }
}

/* ---------- 動画選択 ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(6, 4, 12, .78);
  backdrop-filter: blur(6px);
}
.modal-panel {
  width: min(100%, 1100px);
  max-height: min(88dvh, 900px);
  display: flex;
  flex-direction: column;
  background: var(--bg-2);
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 20px;
  overflow: hidden;
}

.modal-head {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, .1);
}
.modal-head h2 { margin: 0; font-size: 19px; }
.close {
  width: 48px; height: 48px;
  border: 0;
  border-radius: 12px;
  background: rgba(255, 255, 255, .08);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
}
.close:active { background: rgba(255, 255, 255, .18); }

.grid {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0;
  padding: 16px;
  list-style: none;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
}
.card {
  display: block;
  width: 100%;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 14px;
  background: rgba(255, 255, 255, .06);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  transition: border-color .15s, transform .08s;
}
.card:active { transform: scale(.98); }
.card[aria-current="true"] {
  border-color: var(--accent-2);
  background: rgba(236, 72, 153, .14);
}
.card-thumb {
  aspect-ratio: 16 / 9;
  width: 100%;
  object-fit: cover;
  display: block;
  background: #000;
}
.card-thumb.is-blank {
  display: grid;
  place-items: center;
  color: var(--text-dim);
  font-size: 13px;
  background: linear-gradient(135deg, #241a3d, #14101f);
}
.card-title {
  display: block;
  padding: 10px 12px 12px;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.4;
}
.card-badge {
  display: inline-block;
  margin-right: 6px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--accent-2);
  color: #fff;
  font-size: 11px;
  vertical-align: 1px;
}

@media (max-width: 600px) {
  .buttons { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .btn { min-height: 58px; }
  .stage { padding: 6px 10px; }
  .controls { padding-inline: 10px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
}

@media (max-height: 520px) {
  .header { padding-top: 6px; padding-bottom: 2px; }
  .logo { height: 40px; }
  .now { margin-bottom: 8px; }
  .btn { min-height: 48px; font-size: 14px; }
  .btn svg { width: 20px; height: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
