:root {
  --bg: #fbf3e4;
  --card: #fffaf0;
  --ink: #3a2a1c;
  --muted: #8a7460;
  --line: #e6d5bd;
  --accent: #e8590c;
  --accent-dark: #c2410c;
  --ok: #2f9e44;
  --note-yellow: #fff3a8;
  --note-pink: #ffd3e0;
  --note-blue: #cfe6ff;
  --note-green: #d3f2d1;
  --note-orange: #ffdcb8;
  --note-purple: #e6d8ff;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: "Hiragino Sans", "Yu Gothic UI", "Noto Sans JP", system-ui, sans-serif;
  line-height: 1.55;
}
button, input, select, textarea { font: inherit; color: inherit; }
.btn {
  font-weight: 700;
  padding: 8px 16px;
  border: 2px solid var(--ink);
  border-radius: 10px;
  background: var(--card);
  cursor: pointer;
}
.btn:hover { background: #fff; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.primary { background: var(--ink); color: var(--card); }
.btn.danger { background: var(--accent); border-color: var(--accent-dark); color: #fff; }
.btn.small { padding: 4px 10px; font-size: 0.85rem; border-width: 1px; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.error { color: var(--accent-dark); }
input, select, textarea {
  padding: 6px 8px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 7px;
}

/* ---- 学生の画面 ---- */
.s-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  border-bottom: 2px solid var(--line);
  background: var(--card);
}
.s-bar .me { font-weight: 700; font-size: 1.05rem; }
.s-bar .phase { margin-left: auto; font-weight: 700; }
.s-bar .timer { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; min-width: 4ch; text-align: right; }
.s-bar .timer.soon { color: var(--accent-dark); }

.s-main { display: grid; grid-template-columns: minmax(0, 1fr) min(400px, 34vw); height: calc(100vh - 58px); }
.s-left { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.s-theme { margin: 0; padding: 8px 20px 0; color: var(--muted); }
.s-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px 20px; }
.s-tools input[type=text] { flex: 1; min-width: 220px; }
.swatches { display: flex; gap: 4px; }
.swatch { width: 24px; height: 24px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; padding: 0; }
.swatch[aria-pressed=true] { border-color: var(--ink); }

.board-wrap { flex: 1; min-height: 0; overflow: auto; padding: 0 20px 20px; }
.s-help { margin: -4px 20px 8px; }
.s-tools .sep { width: 8px; }
/* ボード（board.js）。外側の箱が表示の大きさ、中のボードは 1600×1000 を縮小して描く */
.board-host { position: relative; }
.board {
  position: absolute;
  left: 0;
  top: 0;
  width: 1600px;
  height: 1000px;
  transform-origin: 0 0;
  background-color: #fff;
  background-image: radial-gradient(#e9dcc6 1.2px, transparent 1.2px);
  background-size: 24px 24px;
  border: 2px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}
.frame-layer, .note-layer { position: absolute; inset: 0; pointer-events: none; }
.frame-layer { z-index: 1; }
.note-layer { z-index: 3; }
.link-layer { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 2; pointer-events: none; color: #7a6650; }
.link .hit { fill: none; stroke: transparent; stroke-width: 18; pointer-events: stroke; cursor: pointer; }
.link .line { fill: none; stroke: #7a6650; stroke-width: 2.5; }
.link.selected .line { stroke: var(--accent); stroke-width: 3.5; }
.link-layer .temp { stroke: var(--accent); stroke-width: 2.5; stroke-dasharray: 7 5; }
.link-del {
  position: absolute; z-index: 4; width: 24px; height: 24px; padding: 0; border: none; border-radius: 50%;
  background: var(--accent); color: #fff; font-weight: 700; cursor: pointer; line-height: 24px;
}
.frame {
  position: absolute;
  pointer-events: auto;
  border: 2px dashed #b9a585;
  border-radius: 10px;
  background: rgba(255, 250, 240, 0.55);
}
.frame.dragging { border-color: var(--accent); }
.frame-bar {
  display: flex; align-items: center; gap: 6px; height: 36px; padding: 0 10px;
  background: rgba(230, 213, 189, 0.65); border-radius: 8px 8px 0 0; cursor: grab; font-weight: 700;
}
.board.mini .frame-bar { cursor: default; }
.frame-title { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.frame-title input { width: 100%; padding: 2px 6px; font-weight: 700; }
.frame .del { border: none; background: none; cursor: pointer; color: rgba(58, 42, 28, 0.5); font-size: 1.1rem; display: none; }
.frame-bar:hover .del { display: block; }
.frame-resize {
  position: absolute; right: -7px; bottom: -7px; width: 16px; height: 16px;
  background: #fff; border: 2px solid #b9a585; border-radius: 4px; cursor: nwse-resize;
}
.note {
  position: absolute;
  width: 170px;
  min-height: 96px;
  padding: 10px 12px 22px;
  border-radius: 4px;
  box-shadow: 0 2px 6px rgba(58, 42, 28, 0.18);
  cursor: grab;
  user-select: none;
  touch-action: none;
  font-size: 1.05rem;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.note.dragging { cursor: grabbing; box-shadow: 0 8px 18px rgba(58, 42, 28, 0.28); z-index: 5; }
.note .by { position: absolute; left: 12px; bottom: 4px; font-size: 0.72rem; color: rgba(58, 42, 28, 0.6); }
.note .del {
  position: absolute; right: 2px; top: 0; border: none; background: none; cursor: pointer;
  color: rgba(58, 42, 28, 0.45); font-size: 1rem; padding: 2px 6px; display: none;
}
.note:hover .del { display: block; }
.note { pointer-events: auto; }
.note .handle {
  position: absolute; right: -9px; top: 50%; width: 16px; height: 16px; margin-top: -8px;
  border-radius: 50%; background: var(--accent); border: 2px solid #fff; cursor: crosshair; display: none;
}
.note:hover .handle, .note .handle.dragging { display: block; }
.note textarea { width: 100%; min-height: 70px; border: none; background: transparent; padding: 0; resize: none; }
.note.yellow { background: var(--note-yellow); }
.note.pink { background: var(--note-pink); }
.note.blue { background: var(--note-blue); }
.note.green { background: var(--note-green); }
.note.orange { background: var(--note-orange); }
.note.purple { background: var(--note-purple); }

.s-side { display: flex; flex-direction: column; min-height: 0; border-left: 2px solid var(--line); background: var(--card); }
.ai-head { display: flex; gap: 14px; padding: 12px 16px 8px; border-bottom: 1px solid var(--line); }
.ai-head .who { display: flex; align-items: center; gap: 8px; }
.ai-head img { width: 44px; height: 44px; image-rendering: pixelated; }
.ai-head .name { font-weight: 700; line-height: 1.2; }
.ai-head .role { font-size: 0.75rem; color: var(--muted); }
.ai-head .state { font-size: 0.75rem; color: var(--accent-dark); min-height: 1.1em; }
.messages { flex: 3; min-height: 0; overflow-y: auto; padding: 12px 16px; }
.msg { display: flex; gap: 8px; margin-bottom: 12px; }
.msg img { width: 34px; height: 34px; image-rendering: pixelated; flex: none; }
.msg .body { background: #fff; border: 1.5px solid var(--ink); border-radius: 12px; padding: 8px 12px; }
.msg .name { font-size: 0.75rem; font-weight: 700; color: var(--muted); }
.msg.private .body { border-color: var(--accent); background: #fff3ea; }
.msg.fresh .body { animation: fresh 2.6s ease-out; } /* 新しく届いたメッセージを少しの間目立たせる */
@keyframes fresh { 0%, 35% { background: #ffe3cc; box-shadow: 0 0 0 4px rgba(232, 89, 12, 0.35); } }
.msg.private .name::after { content: "（あなたにだけ表示）"; color: var(--accent-dark); font-weight: 400; }
.messages .empty { color: var(--muted); }
.transcript { flex: 2; min-height: 0; overflow-y: auto; padding: 8px 16px 12px; border-top: 1px solid var(--line); font-size: 0.9rem; }
.transcript h2 { font-size: 0.85rem; color: var(--muted); margin: 4px 0 6px; }
.transcript p { margin: 0 0 4px; display: grid; grid-template-columns: 4.5em 1fr; column-gap: 6px; }
.transcript .who { font-weight: 700; overflow-wrap: anywhere; }
.transcript .unclear { color: #a89a8a; font-style: italic; }

.join { max-width: 520px; margin: 10vh auto; padding: 28px; background: var(--card); border: 2px solid var(--line); border-radius: 16px; }
.join h1 { font-size: 1.3rem; margin: 0 0 12px; }
.join .seats { display: grid; gap: 8px; margin-top: 12px; }
.join .group { border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.join .group h2 { font-size: 1rem; margin: 0 0 6px; }
.join .group .row { display: flex; flex-wrap: wrap; gap: 6px; }
.join .btn.taken { border-style: dashed; color: var(--muted); font-weight: 400; }

/* ---- 研究者の画面 ---- */
.a-bar { display: flex; align-items: center; gap: 12px; padding: 12px 20px; border-bottom: 2px solid var(--line); background: var(--card); }
.a-bar h1 { font-size: 1.15rem; margin: 0; }
.a-bar .spacer { flex: 1; }
.a-main { padding: 16px 20px 60px; }
.join-info { display: flex; flex-wrap: wrap; gap: 18px; align-items: center; padding: 12px 16px; margin-bottom: 16px;
  background: #fff; border: 2px dashed var(--line); border-radius: 12px; }
.join-info .url { font-size: 1.3rem; font-weight: 700; }
.join-info .code { font-size: 1.6rem; font-weight: 700; letter-spacing: 0.15em; }
.form-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; margin-bottom: 12px; }
.form-row label { display: flex; flex-direction: column; font-size: 0.8rem; color: var(--muted); gap: 2px; }
.form-row label.check { flex-direction: row; align-items: center; gap: 6px; color: var(--ink); font-size: 0.9rem; }
.form-row .wide { min-width: 360px; }
.groups { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
@media (max-width: 1100px) { .groups { grid-template-columns: minmax(0, 1fr); } }
.gcard h2 select { flex: 1; min-width: 0; font-size: 0.85rem; font-weight: 400; }
.seat-row .btn { white-space: nowrap; }
.gcard { background: var(--card); border: 2px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.gcard h2 { display: flex; align-items: center; gap: 10px; font-size: 1.05rem; margin: 0 0 8px; }
.gcard h2 .tag { font-size: 0.75rem; font-weight: 400; color: var(--muted); }
.gcard h2 .right { margin-left: auto; display: flex; gap: 6px; }
.seat-row { display: grid; grid-template-columns: 1.6em 8em minmax(0, 1fr) 3.4em auto 5em; gap: 6px; align-items: center; margin-bottom: 4px; }
.seat-row b { text-align: center; }
.meter { height: 10px; background: #f0e4cf; border-radius: 5px; overflow: hidden; }
.meter > div { height: 100%; width: 0; background: var(--muted); }
.meter.active > div { background: var(--ok); }
.live-row { display: grid; grid-template-columns: 1.6em 6em minmax(0, 1fr) 4.5em; gap: 6px; align-items: center; margin-bottom: 4px; }
.share { height: 10px; background: #f0e4cf; border-radius: 5px; overflow: hidden; }
.share > div { height: 100%; width: 0; background: var(--accent); transition: width 0.4s; }
.presence { width: 10px; height: 10px; border-radius: 50%; background: var(--line); display: inline-block; }
.presence.on { background: var(--ok); }
.log { height: 170px; overflow-y: auto; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; font-size: 0.85rem; margin-top: 8px; }
.log p { margin: 0 0 3px; }
.log .ai { color: var(--accent-dark); }
.log .private { font-style: italic; }
.log .unclear { color: #a89a8a; }
.log .board-ev { color: #4f6a8f; }
.gstat { display: flex; gap: 14px; flex-wrap: wrap; font-size: 0.85rem; color: var(--muted); margin-top: 6px; }
.gstat strong { color: var(--ink); }
.devices { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 4px 16px; margin: 8px 0 14px; }
.devices .dev { display: grid; grid-template-columns: minmax(0, 1fr) 90px 4em; gap: 6px; align-items: center; font-size: 0.85rem; }
.devices .dev .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.warnings p { margin: 0 0 4px; color: var(--accent-dark); font-size: 0.85rem; }
section h2.sec { font-size: 1rem; margin: 18px 0 8px; padding-bottom: 4px; border-bottom: 1px solid var(--line); }
.test-links { margin: 0 0 12px; padding: 8px 12px; background: #fff; border: 1px dashed var(--line); border-radius: 10px; }
.test-links p { margin: 6px 0 0; }
.test-links a { color: var(--accent-dark); font-weight: 700; }
details summary { cursor: pointer; color: var(--muted); }

/* 研究者の画面で見るホワイトボード（見るだけ） */
.board-view { margin-top: 8px; }
.board-view summary { font-size: 0.85rem; }
.mini-wrap { margin-top: 6px; overflow: hidden; }
.board.mini .note { cursor: default; box-shadow: 0 1px 3px rgba(58, 42, 28, 0.18); }
.overlay { position: fixed; inset: 0; z-index: 40; display: flex; flex-direction: column; background: var(--bg); }
.overlay-bar { display: flex; align-items: center; gap: 14px; padding: 10px 20px; border-bottom: 2px solid var(--line); background: var(--card); }
.overlay-bar .spacer { flex: 1; }
.overlay-wrap { flex: 1; min-height: 0; overflow: auto; padding: 10px; }
.overlay-wrap .board-host { margin: 0 auto; }
.overlay .board .note, .overlay .board .frame-bar { cursor: default; }

/* ---- 投票 ---- */
.vote-setup, .vote-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px;
  margin: 0 20px 8px; padding: 8px 12px; border: 2px solid var(--accent); border-radius: 10px; background: #fff;
}
.vote-setup { align-items: end; }
.vote-setup label { display: flex; flex-direction: column; gap: 2px; font-size: 0.8rem; color: var(--muted); }
.vote-setup .muted { flex-basis: 100%; }
.vote-bar.open { background: #fff3ea; }
.vote-bar .left { font-weight: 700; color: var(--accent-dark); }
.vote-bar .who { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 0.85rem; color: var(--muted); }
.vote-bar .who .done { color: var(--ok); font-weight: 700; }
.vote-bar .spacer { flex: 1; }
.vote-bar .hint { flex-basis: 100%; margin: 0; color: var(--muted); }
.vote-bar .results { display: flex; flex-wrap: wrap; flex-basis: 100%; gap: 2px 24px; margin: 0; padding: 0; list-style: none; }
.vote-bar .results li { white-space: nowrap; }
.vote-bar .rank { margin-right: 6px; font-size: 0.8rem; color: var(--muted); }
.vote-bar .count { margin-left: 6px; font-weight: 700; color: var(--accent-dark); }
.linkish {
  max-width: 16em; padding: 0; border: none; background: none; cursor: pointer; vertical-align: bottom;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-decoration: underline dotted;
}
.note .badge {
  position: absolute; left: -12px; top: -15px; min-width: 24px; height: 24px; padding: 0 7px; border-radius: 12px;
  background: var(--accent); color: #fff; font-size: 0.82rem; font-weight: 700; line-height: 24px; text-align: center;
  box-shadow: 0 1px 4px rgba(58, 42, 28, 0.3);
}
.note .badge.tally { background: #7a6650; } /* 研究者の画面での途中経過 */
.board.voting .note.votable { cursor: pointer; }
.board.voting .note.out { opacity: 0.4; }
.note.voted { box-shadow: 0 0 0 3px var(--accent), 0 2px 6px rgba(58, 42, 28, 0.18); }
.note.winner { box-shadow: 0 0 0 4px var(--accent), 0 6px 16px rgba(232, 89, 12, 0.35); }
.frame.vote-scope { border-style: solid; border-color: var(--accent); }
.note.flash { animation: flash 0.6s ease 3; }
@keyframes flash { 50% { transform: scale(1.07); box-shadow: 0 0 0 6px rgba(232, 89, 12, 0.5); } }

/* ---- ほかの人のカーソル・書き直し中・ドラッグ中 ---- */
.cursor-layer { position: absolute; inset: 0; z-index: 8; pointer-events: none; overflow: hidden; }
.peer-cursor {
  position: absolute; left: 0; top: 0; transform-origin: 0 0;
  transition: transform 0.12s linear, opacity 0.5s; will-change: transform;
}
.peer-cursor svg { display: block; filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.3)); }
.peer-cursor path { fill: var(--peer); stroke: #fff; stroke-width: 1.5; stroke-linejoin: round; }
.peer-cursor .peer-name {
  position: absolute; left: 15px; top: 17px; padding: 1px 7px; border-radius: 7px; white-space: nowrap;
  background: var(--peer); color: #fff; font-size: 12px; font-weight: 700; line-height: 1.5;
}
.peer-cursor.idle { opacity: 0; }
.note[data-peer] { box-shadow: 0 0 0 3px var(--peer), 0 6px 14px rgba(58, 42, 28, 0.22); }
.frame[data-peer] { border-style: solid; border-color: var(--peer); }
.note[data-peer-drag] { z-index: 4; }
.peer-tag {
  position: absolute; right: -3px; top: -26px; z-index: 6; padding: 1px 8px; border-radius: 7px; white-space: nowrap;
  background: var(--peer); color: #fff; font-size: 0.82rem; font-weight: 700; line-height: 1.6; pointer-events: none;
}
.frame > .peer-tag { top: -27px; right: 0; }
.note[data-preview] .text { color: #5c4a38; }
.members { display: flex; gap: 8px; font-size: 0.85rem; }
.members .m { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); }
.members .m::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--c); opacity: 0.25; }
.members .m.on { color: var(--ink); }
.members .m.on::before { opacity: 1; }

/* 付箋の操作のしやすさ */
.board-empty {
  position: absolute; left: 50%; top: 45%; z-index: 0; transform: translate(-50%, -50%); pointer-events: none;
  font-size: 30px; font-weight: 700; color: rgba(138, 116, 96, 0.45); white-space: nowrap;
}
.note.editing { z-index: 6; box-shadow: 0 0 0 3px var(--accent), 0 8px 18px rgba(58, 42, 28, 0.25); cursor: text; }
.note textarea::placeholder { font-size: 0.8rem; color: rgba(58, 42, 28, 0.45); }
.note.selected .handle { display: block; } /* 選んだ付箋には、つなぐための ● をいつも出す */
.note .handle { width: 18px; height: 18px; margin-top: -9px; right: -10px; }
.board.linking .note { cursor: crosshair; }
.note.link-source { outline: 3px dashed var(--accent); outline-offset: 3px; }
.swatch-ghost {
  position: fixed; z-index: 60; width: 120px; height: 78px; margin: -39px 0 0 -60px; border-radius: 4px; pointer-events: none;
  box-shadow: 0 8px 18px rgba(58, 42, 28, 0.3); opacity: 0.9;
}
.swatches .swatch { cursor: grab; }

/* 付箋をクリックしたときの道具 */
.note.selected { outline: 2px solid var(--ink); outline-offset: 3px; }
.note-tools {
  position: absolute; z-index: 7; display: flex; align-items: center; gap: 6px; padding: 6px 8px; white-space: nowrap;
  background: #fff; border: 1.5px solid var(--ink); border-radius: 10px; box-shadow: 0 4px 12px rgba(58, 42, 28, 0.2);
  transform-origin: 0 100%;
}
.note-tools.below { transform-origin: 0 0; }
.note-tools .swatch { width: 22px; height: 22px; }
.board:has(.note.dragging) .note-tools { display: none; }

/* 終わったあと（見るだけ） */
.board.locked .note, .board.locked .frame-bar { cursor: default; }
.board.locked .del, .board.locked .handle, .board.locked .frame-resize { display: none !important; }

/* 研究者の画面で大きく出したボードの印刷（A4横） */
@media print {
  @page { size: A4 landscape; margin: 10mm; }
  body { background: #fff; min-height: 0; }
  body:has(#overlay:not([hidden])) > :not(#overlay) { display: none !important; }
  .overlay { position: static; display: block; background: #fff; }
  .overlay-bar { border: none; background: #fff; padding: 0 0 6px; }
  .overlay-wrap { overflow: visible; padding: 0; }
  .overlay-wrap .board-host { break-inside: avoid; page-break-inside: avoid; overflow: hidden; }
  .no-print, .cursor-layer, .peer-tag { display: none !important; }
  .board { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
}

.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 50; transform: translateX(-50%); max-width: min(560px, 90vw);
  padding: 10px 16px; border-radius: 10px; background: var(--ink); color: var(--card); font-size: 0.95rem;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
}
