/* ══════════════════════════════════════════════════════════════
   同時視聴 — ふたりの部屋
   やわらかい・まるい・あたたかい。暗いところでも目が疲れない。
   ══════════════════════════════════════════════════════════════ */

:root {
  color-scheme: light;
  --bg: #fff6f8;
  --bg2: #fdeef4;
  --panel: #ffffff;
  --field: #fff2f6;
  --text: #3d2b35;
  --muted: #8b7280;
  --border: #f3dbe4;
  --accent: #e05b8c;          /* 桜 */
  --accent2: #6f8fe0;         /* 空 */
  --on-accent: #ffffff;
  --soft: #ffe7ef;
  --own: #ffd7e5;
  --other: #f1edf6;
  --error: #c8264c;
  --warning: #fff3d6;
  --warning-text: #6b4a00;
  --success: #12805a;
  --shadow: 0 10px 30px rgba(200, 120, 150, .13);
  --shadow-sm: 0 3px 12px rgba(200, 120, 150, .10);
  --r: 22px;
  --dockH: 132px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --bg: #191220; --bg2: #221728; --panel: #241a2d; --field: #1e1526;
    --text: #f8eef6; --muted: #bda9bd; --border: #3d2e46;
    --accent: #ff9dc2; --accent2: #a6bcff; --on-accent: #34101f;
    --soft: #38263f; --own: #4d2c42; --other: #2c2336;
    --error: #ff9bb0; --warning: #4a3a1c; --warning-text: #ffe3a6; --success: #7fe3b6;
    --shadow: 0 10px 34px rgba(0, 0, 0, .45);
    --shadow-sm: 0 3px 12px rgba(0, 0, 0, .35);
  }
}
:root[data-theme='dark'] {
  color-scheme: dark;
  --bg: #191220; --bg2: #221728; --panel: #241a2d; --field: #1e1526;
  --text: #f8eef6; --muted: #bda9bd; --border: #3d2e46;
  --accent: #ff9dc2; --accent2: #a6bcff; --on-accent: #34101f;
  --soft: #38263f; --own: #4d2c42; --other: #2c2336;
  --error: #ff9bb0; --warning: #4a3a1c; --warning-text: #ffe3a6; --success: #7fe3b6;
  --shadow: 0 10px 34px rgba(0, 0, 0, .45);
  --shadow-sm: 0 3px 12px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-padding-top: 90px; }
body {
  margin: 0; color: var(--text); font-size: 16px; line-height: 1.6;
  background: var(--bg);
  background-image: radial-gradient(120% 60% at 50% 0%, var(--bg2) 0%, var(--bg) 62%);
  background-attachment: fixed;
  font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'Segoe UI', sans-serif;
  -webkit-text-size-adjust: 100%;
}

/* ── 見出し・文字 ───────────────────────────────────────── */
h1 { margin: 0; font-size: 20px; line-height: 1.3; letter-spacing: .01em; }
h1 .mark { color: var(--accent); margin-right: 6px; }
h1 span:not(.mark) { display: block; color: var(--muted); font-size: 13px; font-weight: 400; letter-spacing: .02em; }
h2 { font-size: 19px; line-height: 1.4; margin: 0 0 12px; letter-spacing: .01em; }
p { margin: 9px 0; overflow-wrap: anywhere; }
a { color: var(--accent); text-underline-offset: 3px; overflow-wrap: anywhere; }
.small, .muted, footer { color: var(--muted); font-size: 13.5px; line-height: 1.55; }
.tiny { font-size: 12.5px; margin: 4px 0 0; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ── 骨組み ─────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 30;
  background: linear-gradient(180deg, var(--soft) 0%, var(--panel) 100%);
  border-bottom: 1px solid var(--border); padding-top: env(safe-area-inset-top);
}
.topbar-inner { width: min(100%, 720px); margin: auto; padding: 10px 16px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
main { width: min(100%, 720px); margin: auto; padding: 14px max(12px, env(safe-area-inset-right)) calc(170px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); }

.card {
  padding: 17px; margin-bottom: 13px; background: var(--panel);
  border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--shadow-sm);
  min-width: 0; scroll-margin-top: 12px;
}
.journey { background: linear-gradient(160deg, var(--soft), var(--panel)); border-color: var(--accent); }
.eyebrow { margin: 0 0 4px; font-size: 13px; font-weight: 700; color: var(--accent); letter-spacing: .06em; }
.journey h2 { font-size: 21px; }
.steps { list-style: none; margin: 13px 0 0; padding: 10px 0 0; border-top: 1px dashed var(--border); }
.steps li { display: flex; justify-content: space-between; gap: 6px; color: var(--muted); padding: 3px 0; font-size: 14.5px; }
.steps li span { flex-shrink: 0; }
.steps li.current { color: var(--text); font-weight: 700; }
.steps li.done, .steps li.done span { color: var(--success); }
.steps li.current span { color: var(--accent); }
.partner { font-size: 24px; overflow-wrap: anywhere; margin-bottom: 4px; }

.badge {
  display: inline-flex; align-items: center; gap: 6px; flex-shrink: 0;
  padding: 5px 11px; border-radius: 99px; background: var(--field);
  border: 1px solid var(--border); color: var(--muted); font-weight: 700; font-size: 13px; white-space: nowrap;
}
.badge::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.badge[data-state='ok'] { color: var(--success); }
.badge[data-state='busy'] { color: var(--accent); }
.badge[data-state='bad'] { color: var(--error); }

.hint, .warning { border-radius: 16px; padding: 12px 14px; background: var(--soft); }
.warning { color: var(--warning-text); background: var(--warning); border-left: 4px solid currentColor; }
.error { color: var(--error); font-weight: 650; font-size: 14px; margin: 6px 0 9px; }
.error:empty { display: none; }

/* ── 入力・釦 ───────────────────────────────────────────── */
label { display: block; margin: 13px 0 5px; font-weight: 600; font-size: 14.5px; }
input, textarea, select, button { font: inherit; font-size: 16px; }
input, textarea, select {
  display: block; width: 100%; min-width: 0; min-height: 50px; padding: 11px 15px;
  color: var(--text); background: var(--field); border: 1px solid var(--border); border-radius: 18px;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
input[aria-invalid='true'] { border: 2px solid var(--error); }
input[readonly] { color: var(--muted); }
textarea { resize: vertical; }
input[type='range'] { accent-color: var(--accent); min-height: 44px; padding: 4px 0; border: 0; background: transparent; touch-action: pan-y; }
input[type='number'] { max-width: 140px; }

button, .btnlink {
  display: inline-flex; align-items: center; justify-content: center; text-decoration: none;
  min-height: 48px; border: 1px solid transparent; border-radius: 999px;
  background: linear-gradient(180deg, var(--accent), color-mix(in srgb, var(--accent) 84%, #000 16%));
  color: var(--on-accent); padding: 10px 18px; font-weight: 700; cursor: pointer;
  touch-action: manipulation; box-shadow: var(--shadow-sm);
}
button.secondary, .btnlink.secondary { color: var(--text); background: var(--soft); border-color: var(--border); box-shadow: none; font-weight: 650; }
button.danger { color: var(--error); background: var(--panel); border-color: var(--error); box-shadow: none; }
button.attention { color: var(--warning-text); background: var(--warning); border-color: currentColor; margin: 10px 0; }
button:disabled, input:disabled, select:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }
button:active:not(:disabled) { transform: translateY(1px); }
button.primary, form > button, .btnlink.block { display: flex; width: 100%; }
form > button { margin-top: 12px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; margin: 11px 0; }
.row > button, .row > .btnlink { flex: 1 1 130px; }
.check { display: flex; align-items: center; gap: 11px; min-height: 48px; cursor: pointer; font-weight: 600; font-size: 14.5px; }
.check input { width: 24px; height: 24px; min-height: 24px; flex: 0 0 24px; accent-color: var(--accent); }
summary { cursor: pointer; min-height: 48px; padding: 11px 0; font-weight: 700; color: var(--accent); font-size: 15px; }
details > summary { list-style-position: outside; margin-left: 18px; }
details[open] > summary { margin-bottom: 8px; }
.card > details { margin-top: 10px; border-top: 1px dashed var(--border); }

audio { display: block; width: 100%; height: 46px; margin: 11px 0; }
.meters { padding: 8px 13px 12px; background: var(--field); border: 1px solid var(--border); border-radius: 16px; }
.meters label { margin: 5px 0; display: flex; align-items: center; gap: 12px; }
meter { flex: 1; width: 100%; height: 20px; accent-color: var(--success); }
meter::-webkit-meter-optimum-value { background: var(--success); }
output { float: right; font-variant-numeric: tabular-nums; color: var(--muted); font-weight: 600; }

/* ── 動画 ───────────────────────────────────────────────── */
.playerbox { width: 100%; aspect-ratio: 16 / 9; background: #000; border-radius: 16px; overflow: hidden; }
.playerbox > div, .playerbox iframe { display: block; width: 100%; height: 100%; border: 0; }
.empty-player {
  display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 2px;
  min-height: 150px; text-align: center; color: var(--muted);
  background: var(--field); border: 2px dashed var(--border); border-radius: 16px; padding: 16px 10px; font-size: 30px;
}
.empty-player p { margin: 2px 0; font-size: 14px; }
.empty-player .small { font-size: 12.5px; }

/* ── チャット ───────────────────────────────────────────── */
#messages {
  height: 280px; max-height: 45vh; min-height: 150px; overflow-y: auto; overscroll-behavior: contain;
  border: 1px solid var(--border); border-radius: 18px; padding: 11px 10px; background: var(--field);
}
.empty-chat { text-align: center; margin: 40px 10px; color: var(--muted); }
.message {
  position: relative; max-width: 84%; width: fit-content; padding: 8px 13px; margin: 3px 0 9px;
  background: var(--other); border-radius: 20px 20px 20px 7px; overflow-wrap: anywhere;
  box-shadow: var(--shadow-sm);
  animation: pop .16s ease-out;
}
.message.own { margin-left: auto; background: var(--own); border-radius: 20px 20px 7px 20px; }
/* 続きの発言は、見出しを出さず間隔も詰める（尻尾も出さない） */
.message.cont { margin-top: -5px; border-radius: 20px 20px 20px 12px; }
.message.own.cont { border-radius: 20px 20px 12px 20px; }
@keyframes pop { from { opacity: 0; transform: translateY(5px) scale(.98); } to { opacity: 1; transform: none; } }
.message-head, .message small { color: var(--muted); font-size: 11.5px; }
.message-head { margin-bottom: 1px; font-weight: 650; }
.message p { white-space: pre-wrap; margin: 2px 0; font-size: 15.5px; line-height: 1.5; }
.message small[hidden] { display: none; }
.chat-sep { margin: 12px 0; text-align: center; font-size: 11.5px; color: var(--muted); }
.chat-sep::before, .chat-sep::after { content: '───'; margin: 0 8px; opacity: .45; }
.composer { display: flex; align-items: flex-end; gap: 8px; }
.composer textarea { flex: 1 1 auto; min-height: 48px; max-height: 116px; border-radius: 24px; padding: 12px 16px; }
.composer button { flex: 0 0 auto; margin: 0; width: auto; min-width: 68px; padding: 10px 16px; }

.countdown { min-height: 60px; text-align: center; font-size: 24px; font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; }
.diagnostics dt { font-weight: 700; color: var(--accent); margin-top: 11px; font-size: 14px; }
.diagnostics dd { margin: 3px 0 11px; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; font-size: 14px; }

/* ── ドック ─────────────────────────────────────────────── */
.dock {
  position: fixed; z-index: 50; bottom: 0; left: 0; right: 0;
  border-top: 1px solid var(--border); background: var(--panel);
  padding: 9px max(12px, env(safe-area-inset-right)) calc(7px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  box-shadow: 0 -6px 26px rgba(160, 100, 130, .10);
}
.dock-inner { width: min(100%, 684px); margin: auto; }
.dock .primary { min-height: 52px; }
#quickNav { display: flex; gap: 8px; margin-top: 5px; }
.navbtn { flex: 1 1 auto; min-height: 44px; color: var(--text); background: var(--soft); border: 1px solid var(--border); box-shadow: none; font-weight: 650; font-size: 14.5px; }
.navbtn.chip { flex: 0 0 auto; min-width: 104px; font-variant-numeric: tabular-nums; }
.navbtn.chip[data-soon='1'] { color: var(--on-accent); background: var(--accent); border-color: var(--accent); }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--dockH) + 14px + env(safe-area-inset-bottom));
  width: min(calc(100% - 26px), 640px); z-index: 60;
  color: var(--text); background: var(--panel); padding: 12px 16px;
  border: 1px solid var(--accent); border-radius: 18px; box-shadow: var(--shadow);
  pointer-events: none; overflow-wrap: anywhere; font-size: 14.5px;
}
footer { padding: 4px 4px 18px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }

/* ══ 観る面 ═══════════════════════════════════════════════
   動画とチャットを、スクロールせずに同時に。 */
body.inroom { overflow: hidden; height: 100dvh; display: flex; flex-direction: column; }
body.inroom .topbar { position: static; flex: 0 0 auto; }
body.inroom .topbar-inner { padding-top: calc(6px + env(safe-area-inset-top)); padding-bottom: 6px; }
body.inroom h1 { font-size: 17px; }
body.inroom h1 span:not(.mark) { display: none; }
body.inroom main { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; overflow: hidden; padding-top: 7px; padding-bottom: 0; }
body.inroom #journey, body.inroom #entrance { display: none; }
body.inroom .toast { top: calc(52px + env(safe-area-inset-top)); bottom: auto; }
body.inroom #room { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; padding-bottom: calc(var(--dockH) + 5px); }

#videoCard.watchcard { position: relative; flex: 0 0 auto; padding: 7px; margin-bottom: 7px; }
#videoCard.watchcard #seek { min-height: 26px; margin-top: 0; }
#videoCard.watchcard #videoStatus { display: none; }
#videoCard.watchcard.needshelp #videoStatus { display: block; margin: 3px 2px 0; }

/* 画面の大きさ 3段階 */
#videoCard.size-small .playerbox { aspect-ratio: auto; height: 118px; }
#videoCard.size-small .empty-player { min-height: 88px; font-size: 22px; }
/* ★ 「音だけ」（高さ 0）は入れられない——YouTube Developer Policies III.I.9 は
   「ユーザーが見ている画面に表示されていないプレイヤーからの再生」を禁じている。
   いちばん小さくしても、プレイヤーは見えたままにする。 */
#videoCard.size-mini .playerbox { aspect-ratio: auto; height: 76px; }
#videoCard.size-mini .empty-player { min-height: 64px; font-size: 18px; }
#videoCard.size-mini .empty-player p { font-size: 12.5px; }

.watchbar { display: flex; align-items: center; gap: 4px; margin-top: 6px; }
.watchbar button { min-height: 40px; padding: 0 10px; flex: 0 0 auto; font-size: 14px; box-shadow: none; font-weight: 650; }
.watchbar #position {
  flex: 1 1 auto; float: none; text-align: center; font-size: 12px; white-space: nowrap;
  letter-spacing: -.01em; padding: 0 2px; font-weight: 600;
}

/* 音量の小窓 */
/* 動画の上に重ねると、画面が小さいときに上へはみ出す（実測で確認）。
   親指の届く下側に、画面に対して固定で出す。 */
.pop {
  position: fixed; left: 10px; right: 10px; z-index: 65;
  bottom: calc(var(--dockH) + 10px + env(safe-area-inset-bottom));
  max-height: 58vh; overflow-y: auto; overscroll-behavior: contain;
  width: auto; max-width: 700px; margin: auto;
  background: var(--panel); border: 1px solid var(--accent); border-radius: var(--r);
  padding: 13px 15px 8px; box-shadow: var(--shadow);
}
.pop-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 2px; }
.pop-head button { min-height: 38px; padding: 0 14px; font-size: 14px; }
.pop label { margin: 8px 0 2px; }
.pop input[type='range'] { min-height: 38px; }
.pop .small { margin: 2px 0 6px; }

#chatCard.chatcard { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; margin-bottom: 0; padding: 9px; }
#chatCard.chatcard #messages { flex: 1 1 auto; height: auto; max-height: none; min-height: 0; }
#chatCard.chatcard form { margin: 7px 0 0; }
#chatCard.chatcard #chatStatus { margin: 5px 2px 0; }

/* 道具箱 */
.sheet { position: fixed; inset: 0; z-index: 70; background: var(--bg); display: flex; flex-direction: column; overflow: hidden; }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: calc(9px + env(safe-area-inset-top)) 16px 9px;
  background: linear-gradient(180deg, var(--soft), var(--panel)); border-bottom: 1px solid var(--border);
}
.sheet-head h2 { margin: 0; font-size: 18px; }
.sheet-head button { min-height: 42px; flex: 0 0 auto; }
.sheet-body {
  flex: 1 1 auto; overflow-y: auto; overscroll-behavior: contain;
  padding: 13px max(12px, env(safe-area-inset-right)) calc(26px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  width: min(100%, 720px); margin: auto;
}
.sheet-body .card:last-of-type { margin-bottom: 0; }

@media (min-width: 900px) and (orientation: landscape) {
  body.inroom #room { flex-direction: row; gap: 11px; }
  #videoCard.watchcard { flex: 1 1 62%; align-self: flex-start; }
  #chatCard.chatcard { flex: 1 1 38%; }
}
@media (max-width: 360px) {
  .card { padding: 13px; }
  .topbar-inner { padding-left: 12px; padding-right: 12px; }
  .row > button, .row > .btnlink { flex-basis: 110px; padding-left: 10px; padding-right: 10px; }
  .watchbar button { padding: 0 7px; font-size: 13px; }
  .watchbar #position { font-size: 11px; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .message { animation: none; }
}

/* ── YouTube の検索結果 ─────────────────────────────────── */
.urlrow { display: flex; gap: 8px; align-items: stretch; }
.urlrow input { flex: 1 1 auto; }
.urlrow button { flex: 0 0 auto; width: auto; min-width: 86px; margin: 0; }
.results { list-style: none; margin: 10px 0 0; padding: 0; }
.results li { margin: 0 0 8px; }
.results button {
  display: flex; align-items: center; gap: 11px; width: 100%; text-align: left;
  padding: 8px; min-height: 0; border-radius: 16px; font-weight: 500;
  color: var(--text); background: var(--field); border: 1px solid var(--border); box-shadow: none;
}
.results img { flex: 0 0 auto; width: 104px; height: 58px; object-fit: cover; border-radius: 10px; background: #000; }
.results .rtitle { font-size: 14.5px; font-weight: 650; line-height: 1.35; overflow-wrap: anywhere; }
.results .rchan { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.results .rbody { min-width: 0; }
