:root {
  --bg: #f3f4f1; --panel: #ffffff; --text: #1c2321; --muted: #66706c; --border: #d9ddd8;
  --accent: #1f7a4d; --home: #1d4ed8; --away: #dc2626; --note: #fff7d6; --note-border: #e6cf7a;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #14181a; --panel: #1e2427; --text: #e8ecea; --muted: #98a39e; --border: #333c40; --accent: #3fae77;
          --note: #3a3420; --note-border: #6b5d2a; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
  display: flex; flex-direction: column;
}
header {
  display: flex; align-items: center; gap: 12px 16px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--border);
}
h1 { font-size: 16px; margin: 0; overflow-wrap: anywhere; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button {
  border: 0; background: transparent; color: var(--text); padding: 6px 14px; font: inherit; cursor: pointer;
}
.seg button + button { border-left: 1px solid var(--border); }
.seg button[aria-pressed="true"] { background: var(--accent); color: #fff; font-weight: 600; }
.seg button:disabled { cursor: default; }
.seg button:disabled:not([aria-pressed="true"]) { color: var(--muted); opacity: .5; }
.seg.full { display: flex; }
.seg.full button { flex: 1; padding: 6px 4px; }
.spacer { flex: 1; }
#banner {
  display: none; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 8px 16px; background: var(--note); border-bottom: 1px solid var(--note-border); font-size: 13px;
}
#banner.show { display: flex; }
main { flex: 1; min-height: 0; display: flex; gap: 16px; padding: 16px; }
.stage { flex: 1; min-width: 0; position: relative; }
#pitch { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; user-select: none; -webkit-user-select: none; }
aside { width: 300px; flex-shrink: 0; display: flex; flex-direction: column; gap: 12px; overflow-y: auto; }
#side { display: flex; flex-direction: column; gap: 12px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 12px; }
.card h2 { font-size: 14px; margin: 0 0 8px; display: flex; align-items: center; gap: 8px; }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
label { display: block; font-size: 12px; color: var(--muted); margin: 8px 0 4px; }
select, input[type="text"], textarea {
  width: 100%; padding: 6px 8px; font: inherit; color: var(--text);
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
}
textarea { resize: vertical; min-height: 44px; display: block; }
input[type="range"] { width: 100%; }
.row { display: flex; gap: 6px; }
.row > :first-child { flex: 1; min-width: 0; }
.row.even { flex-wrap: wrap; }
.row.even > * { flex: 1 1 auto; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.btn {
  padding: 6px 10px; font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 6px; cursor: pointer; white-space: nowrap;
  text-decoration: none; display: inline-block; text-align: center;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  min-width: 32px; padding: 4px 8px; font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 999px; cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
details { margin-top: 10px; }
summary { cursor: pointer; font-size: 12px; color: var(--muted); }
.msg { font-size: 12px; min-height: 18px; margin-top: 4px; color: var(--away); }
.ok { font-size: 12px; margin-top: 4px; color: var(--accent); }
.hint { font-size: 12px; color: var(--muted); margin: 0; }
.hint + .hint { margin-top: 6px; }
.who { font-size: 18px; font-weight: 700; margin: 4px 0; overflow-wrap: anywhere; }
.question { margin: 4px 0 10px; }
.answer {
  background: var(--note); border: 1px solid var(--note-border); border-radius: 8px;
  padding: 10px; margin-bottom: 8px; white-space: pre-wrap; font-size: 15px; overflow-wrap: anywhere;
}
label.sel { color: var(--accent); font-weight: 700; }
.player, .ball { cursor: grab; }
.handle { cursor: crosshair; }
.dragging { cursor: grabbing; }

/* ---- アカウント・ノート ---- */
#account { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
#account:empty { display: none; }
#account.attn { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 6px; }
.avatar { width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0; background: var(--border); }
.uname { max-width: 10em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#noteBar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 0; }
#noteTitle { width: 15em; max-width: 100%; font-weight: 600; background: transparent; border-color: transparent; cursor: pointer; }
#noteTitle:hover { border-color: var(--border); }
#noteTitle:focus { background: var(--bg); border-color: var(--border); cursor: text; }
#saveState { font-size: 12px; color: var(--muted); }
#saveState.err { color: var(--away); }
#saveState.done { color: var(--accent); }
.share-item { border-top: 1px solid var(--border); padding-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.share-name { font-size: 12px; font-weight: 600; overflow-wrap: anywhere; }
dialog {
  width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 24px); padding: 16px; overflow-y: auto;
  color: var(--text); background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
}
dialog::backdrop { background: rgba(0, 0, 0, .45); }
.dlg-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.dlg-head h2 { font-size: 16px; margin: 0; flex: 1; }
.note-item { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 10px 0; border-bottom: 1px solid var(--border); }
.note-main { flex: 1; min-width: 150px; }
.note-title { font-weight: 600; overflow-wrap: anywhere; }
.note-acts { display: flex; gap: 6px; flex-wrap: wrap; }
.new-note > select { width: auto; }
#toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 10;
  max-width: calc(100vw - 24px); padding: 10px 14px; font-size: 13px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 4px 16px rgba(0, 0, 0, .25);
}

/* ---- 共有ページ（閲覧専用） ---- */
.viewer #pitch { touch-action: auto; }   /* 駒を動かせないので、ボードの上でもページをスクロールできるようにする */
.viewer .player, .viewer .ball { cursor: default; }
.viewer .player.pick { cursor: pointer; }
.notice { margin: 40px auto; max-width: 420px; text-align: center; align-self: flex-start; }
.notice p { margin: 0 0 12px; }
.ad-slot { margin-top: auto; min-height: 250px; flex-shrink: 0; }

@media (max-width: 760px) {
  body { height: auto; }
  main { flex-direction: column; padding: 12px; }
  .stage { height: 78vh; flex: none; }
  aside { width: 100%; overflow: visible; }
  #noteBar { width: 100%; }
  #noteTitle { flex: 1; width: auto; min-width: 8em; }
  /* 共有ページの広告枠はボードのすぐ下に置く */
  .viewer aside { display: contents; }
  .viewer .ad-slot { order: 1; margin-top: 0; min-height: 100px; }
  .viewer #side { order: 2; }
}

.account-zone {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin-top: 16px; padding-top: 10px; border-top: 1px solid var(--border); font-size: 12px;
}
.account-zone a, footer a { color: var(--muted); }
.account-zone .btn { font-size: 12px; color: var(--muted); }
footer { padding: 4px 16px 8px; font-size: 12px; text-align: right; }
