:root {
  --bg: #15171c;
  --panel: #1d2027;
  --line: #2e333d;
  --text: #e8eaf0;
  --muted: #9aa1ad;
  --accent: #6aa8ff;
  --warn: #ffb35c;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  display: flex;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.6 "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
}

#stage {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
#view {
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 6px;
  /* 透過のときだけ見える市松模様 */
  background: repeating-conic-gradient(#2a2d34 0 25%, #22252b 0 50%) 0 0 / 24px 24px;
}
#status {
  position: absolute;
  left: 50%;
  top: 24px;
  transform: translateX(-50%);
  max-width: 80%;
  padding: 8px 14px;
  border-radius: 6px;
  background: rgba(0, 0, 0, .75);
  color: #fff;
}
#status.error { background: #8a2b2b; }
#streamHint { display: none; }

#panel {
  width: 340px;
  flex: none;
  overflow-y: auto;
  background: var(--panel);
  border-left: 1px solid var(--line);
  padding: 12px 16px 32px;
}
h1 { font-size: 18px; margin: 4px 0 8px; }
h1 span { font-size: 12px; color: var(--muted); font-weight: normal; margin-left: 4px; }
h2 { font-size: 14px; margin: 0 0 8px; }
section { border-top: 1px solid var(--line); padding: 14px 0; }
.note { color: var(--muted); font-size: 12px; margin: 6px 0; }
.note.warn { color: var(--warn); }

button, select, input[type=color] {
  width: 100%;
  margin: 4px 0;
  padding: 7px 10px;
  /* パネル（#1d2027）の上で埋もれないよう、背景を一段明るくし、枠線もはっきりさせる */
  border: 1px solid #6a7489;  /* パネルとのコントラスト比 3.5:1 */
  border-radius: 6px;
  background: #313744;
  color: var(--text);
  font: inherit;
  cursor: pointer;
}
input[type=color] { height: 34px; padding: 2px; }
button:hover:not(:disabled), select:hover:not(:disabled) { border-color: var(--accent); }
button:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
select option { background: #262a32; color: var(--text); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: #2c4f86; border-color: #3a65a8; }

.slots { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 6px;
  border: 1px dashed var(--line);
  border-radius: 6px;
  text-align: center;
  font-size: 12px;
  cursor: pointer;
}
.slot.drag { border-color: var(--accent); background: #232a36; }
.slot img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
  background: repeating-conic-gradient(#2a2d34 0 25%, #22252b 0 50%) 0 0 / 12px 12px;
  border-radius: 4px;
}
.slot img:not([src]) { visibility: hidden; }
.slot small { display: block; color: var(--muted); font-size: 11px; }
.slot { position: relative; }
.slot input { display: none; }
.slot .clear {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 22px;
  height: 22px;
  margin: 0;
  padding: 0;
  border-radius: 50%;
  line-height: 1;
  background: rgba(0, 0, 0, .7);
}
.slots.vowels { grid-template-columns: repeat(5, 1fr); gap: 6px; }
.slots.vowels .slot { padding: 4px; }
.slot.wide { flex-direction: row; text-align: left; margin: 4px 0; }
.slot.wide img { width: 64px; flex: none; }

/* 無料版・高機能版の切り替え */
body:not(.pro) .pro-only { display: none !important; }
body.pro .free-only { display: none !important; }
.title { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.title h1 { margin: 4px 0; }
#planName { padding: 1px 8px; border-radius: 10px; background: #2a2e36; }
body.pro #planName { background: #6b4bc8; color: #fff; }
.pro-switch { width: auto; flex: none; font-size: 12px; padding: 5px 10px; border-color: #6b4bc8; }
body.pro .pro-switch { border-color: var(--line); }

.row { display: flex; gap: 6px; }
.row button { flex: 1; font-size: 12px; padding: 5px 6px; }
.avatar-list { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0; }
.avatar-list button { width: auto; margin: 0; padding: 4px 10px; font-size: 12px; }
.avatar-list button.active { background: #6b4bc8; border-color: #8a6ee0; color: #fff; }
.toggle { text-align: left; }
.toggle::before { content: "○ "; color: var(--muted); }
.toggle.on { background: #24453a; border-color: #3f8f72; }
.toggle.on::before { content: "● "; color: #6fe0b4; }
.range output { color: var(--text); margin-left: 4px; }
.sub { margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--line); }
h3 { font-size: 13px; margin: 0 0 4px; }
#vowelNow { width: 1.5em; text-align: center; font-style: normal; font-weight: 700; color: var(--accent); }
input[type=text] {
  width: 100%;
  margin-top: 2px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #262a32;
  color: var(--text);
  font: inherit;
}

#regionTools { margin: 4px 0; padding: 8px 10px; border: 1px solid var(--accent); border-radius: 6px; }
body.editing #view { cursor: crosshair; }

#video {
  display: none;
  width: 100%;
  margin: 4px 0;
  border-radius: 6px;
  transform: scaleX(-1);
}
#video.on { display: block; }

.check { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.range { display: block; font-size: 12px; color: var(--muted); margin: 6px 0; }
.range input[type=range] { width: 100%; display: block; }
.range select, .range input[type=color] { margin-top: 2px; }

.meter-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.meter-row span { width: 1.5em; font-size: 12px; }
.meter { position: relative; flex: 1; height: 10px; border-radius: 5px; background: #2a2e36; overflow: hidden; }
.meter i { position: absolute; inset: 0 auto 0 0; width: 0; background: #557; }
.meter.on i { background: var(--accent); }
.meter b { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--warn); }

/* 配信画面：設定を隠して、キャンバスだけを全面に出す */
body.stream #panel { display: none; }
body.stream #stage { padding: 0; }
body.stream #view { width: 100vw; height: 100vh; max-width: none; max-height: none; object-fit: contain; border-radius: 0; background: none; }
body.stream #streamHint {
  display: block;
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 12px;
  border-radius: 6px;
  background: rgba(0, 0, 0, .6);
  color: #fff;
  font-size: 13px;
  transition: opacity .6s;
}
body.stream.hint-off #streamHint { opacity: 0; pointer-events: none; }

@media (max-width: 760px) {
  body { flex-direction: column; }
  #panel { width: auto; border-left: 0; border-top: 1px solid var(--line); }
}

/* Categorized background library */
.background-library { margin: 14px 0; }
.background-gallery { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:8px; }
.background-card { padding:5px; text-align:left; width:100%; min-width:0; border:2px solid transparent; }
.background-card img { display:block; width:100%; aspect-ratio:16/9; object-fit:cover; border-radius:6px; }
.background-card span { display:block; padding:6px 2px 2px; font-size:12px; }
.background-card[aria-pressed="true"] { border-color:#a46bd6; }
.background-card:focus-visible { outline:3px solid #a46bd6; outline-offset:2px; }

/* Collapsed by default; native details supports keyboard and screen readers. */
.character-picker { margin:12px 0; border:1px solid var(--border, #454552); border-radius:10px; padding:10px; }
.character-picker summary { cursor:pointer; font-size:13px; font-weight:600; }
.character-picker summary span { font-size:11px; font-weight:400; opacity:.7; margin-left:6px; }
.character-grid { display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); gap:10px 8px; margin-top:12px; }
.character-choice { min-width:0; }
button.character-card { display:flex; flex-direction:column; align-items:center; gap:5px; width:100%; padding:7px 3px; margin:0; font-size:12px; }
.character-card img { width:56px; height:56px; border-radius:50%; object-fit:cover; background:#eee7f4; }
.character-card span { overflow-wrap:anywhere; }
.character-message:empty { display:none; }
.character-message { font-size:11px; margin:5px 0 0; }

/* 右の設定欄の上部（タイトルと「配信画面にする」）は、スクロールしても見えるように固定する */
.panel-top {
  position: sticky;
  top: -12px;            /* #panel の上の余白ぶん */
  z-index: 5;
  margin: -12px -16px 8px;
  padding: 12px 16px 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 6px 12px -8px rgba(0, 0, 0, .6);
}
.panel-top #streamBtn { margin: 6px 0 0; }

/* カメラ・マイクの使用中：停止ボタンを赤くし、●を点滅させる */
button.live, button.primary.live { background: #8f2d34; border-color: #e0606a; color: #fff; }
button.live:hover:not(:disabled) { border-color: #ff9aa2; }
button.live::before { content: "● "; color: #ffb3b9; animation: livePulse 1.2s ease-in-out infinite; }
@keyframes livePulse { 50% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { button.live::before { animation: none; } }

/* 「キャラクターを追加」：折りたたみの見出しを、ボタンのように目立たせる */
.character-picker { border-color: #6aa8ff; background: rgba(106, 168, 255, .08); }
.character-picker summary { list-style: none; display: flex; align-items: center; flex-wrap: wrap; gap: 4px 8px; padding: 4px 2px; font-size: 14px; color: #cfe2ff; }
.character-picker summary::-webkit-details-marker { display: none; }
.character-picker summary::before { content: "＋"; display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: #3a65a8; color: #fff; font-size: 13px; }
.character-picker[open] summary::before { content: "－"; }
.character-picker summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
