:root {
  --bg: #0b0b0c;
  --fg: #9b9b9f;
  --fg-dim: #55555a;
  --fg-bright: #d5d5d8;
  --line: #232326;
  --r: 4px;
  /* 映像以外が食う縦幅: ヘッダー + セル帯2段 + コントロールバー */
  --chrome: 149px;
}

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

html, body {
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Helvetica Neue", "Hiragino Sans", "Noto Sans JP", Meiryo, sans-serif;
  font-size: 12px;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

#site-head {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 34px;
  padding: 0 12px;
  border-bottom: 1px solid var(--line);
}

#site-head .logo {
  color: var(--fg);
  text-decoration: none;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.18em;
}

#site-head nav {
  display: flex;
  gap: 14px;
}

#site-head nav a {
  color: var(--fg-dim);
  text-decoration: none;
  font-size: 11px;
}

#site-head nav a:hover { color: var(--fg); }

/* 狭い画面ではロゴとナビを詰め、入り切らなければ2行に折り返す */
@media (max-width: 480px) {
  #site-head {
    padding: 4px 8px;
    height: auto;
    min-height: 34px;
    flex-wrap: wrap;
    row-gap: 2px;
  }
  #site-head .logo { font-size: 10px; letter-spacing: 0.1em; }
  #site-head nav { gap: 8px; flex-wrap: wrap; }
  #site-head nav a { font-size: 10px; }
}

/* グリッド+コントロール+下部広告を、ヘッダーを除いた残り空間の上下中央に置く */
#stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 0;
}

#grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
  width: 100%;
  /* 4面(映像2段 + セル帯2段 + コントロールバー)が1画面に収まる幅に制限する。
     映像の高さは幅の 9/16 × 2段 なので、余った縦から逆算 */
  max-width: calc((100vh - var(--chrome)) * 16 / 9);
  max-width: calc((100dvh - var(--chrome)) * 16 / 9);
  margin: 0 auto;
}

.cell {
  background: #000;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.frame {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #000;
  overflow: hidden;
}

.frame iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

.msg {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--fg-dim);
}

/* プレイヤーの外（下帯）に置く操作列。プレイヤー上には何も重ねない */
.cell-bar {
  display: flex;
  align-items: center;
  gap: 2px;
  height: 30px;
  padding: 0 4px;
  background: var(--bg);
}

.cell-bar button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 26px;
  background: none;
  border: 0;
  border-radius: var(--r);
  color: var(--fg-dim);
  cursor: pointer;
}

.cell-bar button svg { width: 14px; height: 14px; }
.cell-bar button.on { color: var(--fg-bright); }

.cell-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--fg-dim);
  text-align: right;
  padding-right: 2px;
}

#controls {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 6px;
  background: var(--bg);
  border-top: 1px solid var(--line);
  width: 100%;
  max-width: calc((100vh - var(--chrome)) * 16 / 9);
  max-width: calc((100dvh - var(--chrome)) * 16 / 9);
  margin: 0 auto;
}

#controls button {
  background: none;
  border: 1px solid var(--line);
  border-radius: var(--r);
  color: var(--fg);
  cursor: pointer;
  font-size: 12px;
}

#playpause {
  flex: none;
  width: 34px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#playpause svg { width: 14px; height: 14px; }

#rates {
  display: flex;
  border: 1px solid var(--line);
  border-radius: var(--r);
  overflow: hidden;
}

#rates { flex: none; }

#rates button {
  border: 0;
  border-radius: 0;
  border-right: 1px solid var(--line);
  padding: 7px 5px;
  color: var(--fg-dim);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

#rates button:last-child { border-right: 0; }

#rates button.on {
  background: var(--line);
  color: var(--fg-bright);
}

#nextset {
  flex: none;
  padding: 7px 8px;
  white-space: nowrap;
}

#timer {
  margin-left: auto;
  color: var(--fg-dim);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* 広告レール: 右サイドに常時スペースを確保して固定表示。
   プレイヤーと誤認されないよう、グリッドの外にのみ置く。
   表示可否はCSSのみで制御する(回転時のresizeイベント頼みにしない)。
   幅640px未満(縦持ちスマホ)ではレールごと消え、レイアウトは元のまま */
#ad-rail {
  display: none;
  position: fixed;
  top: 50%;
  right: 8px;
  transform: translateY(-50%);
  align-items: center;
  justify-content: center;
}

@media (min-width: 640px) {
  body { padding-right: 176px; }
  body.page { padding-right: 16px; }
  #ad-rail { display: flex; }
}

/* 縦持ちスマホ: コントロールバー下の空きに広告枠 */
#ad-bottom {
  display: none;
  margin: 16px auto 0;
  align-items: center;
  justify-content: center;
}

@media (max-width: 639px) {
  #ad-bottom { display: flex; }
}

/* 縦が低い画面(横持ちスマホ)ではUIを圧縮して映像を広げる */
@media (max-height: 500px) {
  :root { --chrome: 110px; }
  #site-head { height: 26px; padding: 0 8px; }
  .cell-bar { height: 22px; }
  .cell-bar button { height: 20px; width: 28px; }
  #controls { padding: 4px 6px; }
  #playpause { height: 26px; width: 30px; }
  #rates button { padding: 4px 5px; }
  #nextset { padding: 4px 8px; }
}

/* 記事ページ(about / notice) */
.page {
  display: block;
  padding: 0 16px 48px;
}

.page article {
  max-width: 640px;
  margin: 0 auto;
}

.page h1 {
  font-size: 18px;
  color: var(--fg-bright);
  margin: 36px 0 8px;
}

.page h2 {
  font-size: 14px;
  color: var(--fg-bright);
  margin: 28px 0 8px;
}

.page p, .page li {
  font-size: 13px;
  line-height: 1.9;
  color: var(--fg);
}

.page ul { padding-left: 1.4em; }

.page a { color: var(--fg-bright); }

.page .back {
  display: inline-block;
  margin-top: 32px;
  color: var(--fg-dim);
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 8px 14px;
}

.ad-placeholder {
  width: 100%;
  height: 100%;
  border: 1px dashed var(--line);
  border-radius: var(--r);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--fg-dim);
  font-size: 11px;
}
