:root {
  --bg: #fbfaf7;
  --fg: #2b2b2b;
  --muted: #666;
  --warm: #f08a3c;
  --cool: #3c8af0;
  --danger: #b3261e;
  --card: #fff;
  --line: #ddd;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Hiragino Sans", sans-serif;
  font-size: 18px;
}

main { max-width: 960px; margin: 0 auto; padding: 16px; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; margin-top: 1.6em; }
.lead { font-size: 1.2rem; }
.note { color: var(--muted); }
.warn { color: var(--danger); }

button {
  font: inherit;
  min-height: 56px;
  padding: 0 24px;
  border-radius: 12px;
  border: 2px solid var(--fg);
  background: var(--card);
  cursor: pointer;
}
button.primary { background: var(--fg); color: var(--bg); }
button.danger { border-color: var(--danger); color: var(--danger); margin-top: 1em; }
button:disabled { opacity: 0.4; cursor: not-allowed; }

.join-url { word-break: break-all; font-size: 1.1rem; }
.role-list, .request-list { list-style: none; padding: 0; }
.role-list li, .request-list li {
  display: flex; gap: 12px; align-items: center; justify-content: space-between;
  padding: 8px 12px; margin-bottom: 8px; background: var(--card); border: 1px solid var(--line); border-radius: 10px;
}

/* 子どもの画面：画面全体がひとつの大きな参加エリア（対応表 1・3）。
   A は左（暖色）、B は右（寒色）で、色だけでなく位置と動きでも区別する（対応表 7）。 */
#child {
  position: fixed;
  inset: 0;
}
.stage {
  position: absolute;
  inset: 0;
  background: #1f2433;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  outline: none;
}
.stage:focus-visible { box-shadow: inset 0 0 0 6px rgba(255, 255, 255, 0.6); }

.light, .spark {
  position: absolute;
  bottom: 12%;
  width: min(28vw, 40vh);
  aspect-ratio: 1;
  border-radius: 50%;
  pointer-events: none;
}
.light { opacity: 0.2; transition: opacity 0.8s ease; }
.light-a, .spark-a { left: 6%; }
.light-b, .spark-b { right: 6%; }
.light-a { background: radial-gradient(circle, var(--warm), transparent 70%); }
.light-b { background: radial-gradient(circle, var(--cool), transparent 70%); }

/* 対応表 5：自分の光（参加済みで相手を待っている）は、明るさがゆっくり上下する呼吸で保持を示す */
.light.held { animation: breathe 4s ease-in-out infinite; }
@keyframes breathe {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 0.95; }
}

/* 対応表 6：相手の光（相手が待っている）は、明るさは一定のまま、そっと左右に揺れて誘う */
.light.inviting { opacity: 0.85; animation: sway 5s ease-in-out infinite; }
@keyframes sway {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  75% { transform: translateX(8px); }
}

/* 対応表 4：入力の瞬間の小さな光の反応。保持の動きとは別の要素なので、待機中でも必ず見える。
   明るさは app.js が Web Animations で付ける（連続入力でも暗転を挟まない）。 */
.spark {
  opacity: 0;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.85) 0%, rgba(255, 255, 255, 0.35) 30%, transparent 55%);
}

/* 虹（案A）：A の参加で暖色の弧が左から、B の参加で寒色の弧が右から、ゆっくり描かれる。
   完成した虹は薄い層として後ろに残り、少し大きくなって二重・三重に見える（最大3枚、古いものから消える）。 */
.rainbows {
  position: absolute;
  left: 50%;
  bottom: 18%;
  width: 70%;
  aspect-ratio: 2 / 1;
  transform: translateX(-50%);
}
.rainbow {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  transform-origin: 50% 100%;
  transition: opacity 2s ease, transform 2s ease;
}
.rainbow path {
  fill: none;
  stroke-width: 10;
  stroke-linecap: butt;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  transition: stroke-dashoffset 2.8s ease-in-out;
}
.rainbow .warm:nth-child(2), .rainbow .cool:nth-child(5) { transition-delay: 0.35s; }
.rainbow .warm:nth-child(3), .rainbow .cool:nth-child(6) { transition-delay: 0.7s; }
.rainbow .cool:nth-child(7) { transition-delay: 1.05s; }
.rainbow.warm .warm, .rainbow.cool .cool, .rainbow.layer path { stroke-dashoffset: 0; transition-delay: 0s; }
.rainbow.warm .warm:nth-child(2), .rainbow.cool .cool:nth-child(5) { transition-delay: 0.35s; }
.rainbow.warm .warm:nth-child(3), .rainbow.cool .cool:nth-child(6) { transition-delay: 0.7s; }
.rainbow.cool .cool:nth-child(7) { transition-delay: 1.05s; }
.rainbow.layer path { transition-delay: 0s; }
.rainbow[data-depth="1"] { opacity: 0.4; transform: scale(1.05); }
.rainbow[data-depth="2"] { opacity: 0.26; transform: scale(1.1); }
.rainbow[data-depth="3"] { opacity: 0.14; transform: scale(1.15); }
.rainbow.fading { opacity: 0; transform: scale(1.2); }
.rainbows.no-anim .rainbow, .rainbows.no-anim .rainbow path { transition: none; }

/* 共同変化（初期版は1種類）：虹の上に光の輪が広がる。点滅はしない。 */
.pulse {
  position: absolute;
  left: 50%;
  bottom: 18%;
  width: 70%;
  aspect-ratio: 1;
  border-radius: 50%;
  transform: translate(-50%, 50%) scale(0.2);
  background: radial-gradient(circle, rgba(255, 255, 255, 0.55), transparent 65%);
  opacity: 0;
  pointer-events: none;
}
.pulse.play { animation: pulse 1.6s ease-out; }
@keyframes pulse {
  0% { opacity: 0.9; transform: translate(-50%, 50%) scale(0.2); }
  100% { opacity: 0; transform: translate(-50%, 50%) scale(1.3); }
}

.child-status {
  position: absolute;
  left: 0;
  right: 0;
  bottom: max(16px, env(safe-area-inset-bottom));
  margin: 0;
  font-size: 1.3rem;
  text-align: center;
  color: rgba(255, 255, 255, 0.75);
  pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
  .light.held, .light.inviting { animation: none; opacity: 0.9; }
  .rainbow, .rainbow path { transition: none; }
  .pulse.play { animation-duration: 0.01s; }
}

/* 先生画面：読み上げのオン／オフ */
.toggle { display: flex; gap: .6em; align-items: flex-start; font-size: 1.05rem; line-height: 1.5; }
.toggle input { width: 1.4em; height: 1.4em; flex: none; margin-top: .15em; }

/* 先生画面（対応表 10）：操作部品を大きく、キーボードだけで操作でき、フォーカスがはっきり見える。
   子ども画面には影響しない（#teacher の中だけ）。 */
#teacher button {
  min-height: 64px;
  padding: 0 28px;
  font-size: 1.15rem;
  font-weight: 600;
}
#teacher .role-list li, #teacher .request-list li { padding: 12px 16px; flex-wrap: wrap; }
#teacher .role-list li > span, #teacher .request-list li > span { font-size: 1.15rem; font-weight: 600; flex: 1 1 10em; }
#teacher .request-list li button { flex: 1 1 12em; }
#teacher .join-url { font-size: 1.2rem; }
#teacher .join-url a { display: inline-block; padding: 8px 4px; }
#teacher .toggle { font-size: 1.15rem; }
#teacher .toggle input { width: 1.8em; height: 1.8em; margin-top: 0.05em; }
#teacher :focus-visible {
  outline: 4px solid var(--cool);
  outline-offset: 3px;
  border-radius: 8px;
}
#teacher h1:focus-visible { outline-offset: 6px; }
/* 誤操作防止：活動を終えるボタンは、他の操作から離し、区切り線の下に置く */
#teacher .end-area { margin-top: 3em; padding-top: 1.5em; border-top: 2px solid var(--line); }
#teacher #end-room { margin-top: 0; }
@media (max-width: 600px) {
  #teacher .role-list li button, #teacher .request-list li button { width: 100%; }
}
