/* 土台 */
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; }
img { max-width: 100%; }

/* レイアウト: 運用ノートのような 2 段組。左に行動の一覧、右に「手元のメモ」(時系列の記録)。上に時計と操作 */
:root {
  --bg: #eceff0;
  --surface: #ffffff;
  --sunken: #f5f7f7;
  --ink: #1a2326;
  --muted: #5a676b;
  --line: #d2d9db;
  --accent: #245e73;
  --accent-ink: #ffffff;
  --accent-soft: #dcebf0;
  --ok: #2e7440;
  --ok-soft: #e1f0e4;
  --warn: #9a5a12;
  --warn-soft: #f6ead9;
  --bad: #a8321f;
  --bad-soft: #f7e1dc;
  --code-bg: #f0f3f4;
  --font-display: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", system-ui, sans-serif;
  --font-body: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", system-ui, sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --radius: 6px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111719; --surface: #182124; --sunken: #141c1f; --ink: #e3eaec; --muted: #9aa8ac; --line: #2c393d;
    --accent: #6fb3cb; --accent-ink: #0d1719; --accent-soft: #1d3540;
    --ok: #7cc48d; --ok-soft: #1b3122; --warn: #e0a55a; --warn-soft: #36291a; --bad: #ef8a76; --bad-soft: #3a1f1a;
    --code-bg: #1f2a2e; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111719; --surface: #182124; --sunken: #141c1f; --ink: #e3eaec; --muted: #9aa8ac; --line: #2c393d;
  --accent: #6fb3cb; --accent-ink: #0d1719; --accent-soft: #1d3540;
  --ok: #7cc48d; --ok-soft: #1b3122; --warn: #e0a55a; --warn-soft: #36291a; --bad: #ef8a76; --bad-soft: #3a1f1a;
  --code-bg: #1f2a2e; color-scheme: dark;
}
* { box-sizing: border-box; }
body { background: var(--bg); color: var(--ink); font-family: var(--font-body); font-size: 15px; line-height: 1.7; }
.wrap { max-width: 1180px; margin: 0 auto; padding-inline: 16px; padding-block: 16px 48px; }
h1, h2, h3 { font-family: var(--font-display); line-height: 1.35; text-wrap: balance; margin: 0; }
h1 { font-size: 1.5rem; font-weight: 900; letter-spacing: .02em; }
h2 { font-size: 1.15rem; font-weight: 700; }
h3 { font-size: 1rem; font-weight: 700; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.label { font-size: .75rem; letter-spacing: .08em; color: var(--muted); font-weight: 700; }

/* ヘッダー */
.top { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; padding-bottom: 14px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.top .sub { color: var(--muted); font-size: .85rem; }
.tabs, .tabs-list { display: flex; gap: 4px; }
.tab { border: 1px solid var(--line); background: var(--surface); padding: 6px 14px; border-radius: var(--radius); font-size: .9rem; }
.tab[aria-selected="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }

/* 共通の部品 */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.btn { border: 1px solid var(--line); background: var(--surface); padding: 8px 14px; border-radius: var(--radius); }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.pill { display: inline-block; font-size: .75rem; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.pill.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
pre { font-family: var(--font-mono); font-size: .8rem; line-height: 1.6; background: var(--code-bg); padding: 10px 12px; border-radius: 4px; margin: 0; overflow-x: auto; white-space: pre; }
ul.plain { margin: 0; padding-left: 1.2em; }
input[type="text"], select, textarea { background: var(--sunken); border: 1px solid var(--line); border-radius: 4px; padding: 7px 10px; width: 100%; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend { padding: 0; }

/* 開始画面 */
.start-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.card-text { max-width: 68ch; }
.card-text h3 { margin-top: 6px; }
.card-text ul { margin: 4px 0 0; padding-left: 1.2em; }
.choice { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--sunken); }
.choice input { margin-top: 5px; }

/* 演習画面 */
.hud { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center; justify-content: space-between; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 14px; }
.clock { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: 1.35rem; font-weight: 500; letter-spacing: .02em; }
.clock.late { color: var(--bad); }
.play-grid { display: grid; grid-template-columns: minmax(0, 400px) minmax(0, 1fr); gap: 14px; align-items: start; }
.cats { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 10px; }
.cat { border: 1px solid var(--line); background: var(--sunken); padding: 4px 10px; border-radius: 999px; font-size: .85rem; }
.cat[aria-selected="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--ink); font-weight: 700; }
.actions { display: flex; flex-direction: column; gap: 6px; }
.act { text-align: left; border: 1px solid var(--line); background: var(--surface); padding: 9px 12px; border-radius: var(--radius); display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.act:hover { border-color: var(--accent); }
.act .side { display: flex; gap: 8px; align-items: center; }
.act .done, .act .cost { font-size: .72rem; color: var(--muted); white-space: nowrap; }
.clock-row { display: flex; align-items: baseline; gap: 8px; }
.clock-rest { color: var(--muted); }
.clock-rest.soon { color: var(--warn); font-weight: 700; }
.clock-flash { font-size: .8rem; color: var(--warn); font-weight: 700; }
.pending { margin-top: 10px; padding: 8px 12px; border: 1px dashed var(--line); border-radius: var(--radius); justify-content: space-between; }
.sent-mark { color: var(--muted); margin-left: 6px; }
.sent-mark.mine { color: var(--warn); }
.paused-cover { position: fixed; inset: 0; z-index: 50; background: rgba(10, 16, 18, .7); display: flex; align-items: center; justify-content: center; padding: 16px; }
.note-box { margin-bottom: 10px; }
.note-box textarea { width: 100%; }
.entry.note { border-left: 3px solid var(--ok); }
.toast { margin-top: 8px; padding: 6px 12px; border-radius: var(--radius); background: var(--ok-soft); color: var(--ok); }
.act.new { border-left: 3px solid var(--accent); }
.feed { display: flex; flex-direction: column; gap: 10px; }
.entry { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.entry .meta { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.entry .t { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: .8rem; color: var(--muted); }
.entry .who { font-weight: 700; }
.entry.reply { border-left: 3px solid var(--accent); }
.entry.sys { background: var(--sunken); }
.empty { color: var(--muted); padding: 20px; text-align: center; border: 1px dashed var(--line); border-radius: var(--radius); }

/* ダイアログ */
.overlay { position: fixed; inset: 0; background: rgba(10, 16, 18, .55); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 20; }
.dialog { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); max-width: 640px; width: 100%; max-height: 90vh; overflow: auto; padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.opt { display: flex; gap: 8px; align-items: flex-start; padding: 6px 0; }
.opt input { margin-top: 6px; }
.judge { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.judge-row { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg label { border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px; font-size: .85rem; display: flex; gap: 6px; align-items: center; background: var(--sunken); }

/* 結果 */
.verdict { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.verdict .big { font-family: var(--font-display); font-weight: 900; font-size: 1.4rem; }
.verdict .big.ok { color: var(--ok); }
.verdict .big.warn { color: var(--warn); }
.verdict .big.bad { color: var(--bad); }
.checks { display: flex; flex-direction: column; gap: 6px; }
.check { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 10px; align-items: baseline; }
.trace { width: 100%; border-collapse: collapse; font-size: .85rem; }
.trace th, .trace td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.trace td.t { font-family: var(--font-mono); font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--muted); }
.scroll { overflow-x: auto; }
.rec { display: flex; flex-direction: column; gap: 10px; }
.rec-head { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; align-items: center; }
details > summary { cursor: pointer; }
.rec > summary { list-style: none; }
.rec > summary::-webkit-details-marker { display: none; }
.rec > summary .rec-head > :first-child::before { content: "▸"; color: var(--muted); }
.rec[open] > summary .rec-head > :first-child::before { content: "▾"; }

@media (max-width: 860px) {
  .start-grid, .play-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (prefers-reduced-motion: no-preference) {
  .entry.fresh { animation: pop .35s ease-out; }
  @keyframes pop { from { transform: translateY(-4px); background: var(--accent-soft); } to { transform: none; } }
}
.dialog .card-text ul { margin: 4px 0 0; padding-left: 1.2em; }
.big-label { font-family: var(--font-display); font-size: 1.2rem; font-weight: 700; }
.btn.danger { border-color: var(--bad); color: var(--bad); }
.coach { position: fixed; z-index: 40; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); left: 16px; margin-inline: auto; max-width: 560px; background: var(--ink); color: var(--bg); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; box-shadow: 0 6px 24px rgba(0,0,0,.25); }
.coach .coach-meta { font-size: .75rem; letter-spacing: .06em; opacity: .75; }
.coach .btn { background: transparent; color: var(--bg); border-color: color-mix(in srgb, var(--bg) 40%, transparent); }
.coach .btn.primary { background: var(--bg); color: var(--ink); border-color: var(--bg); }
.coach-hl { outline: 3px solid var(--warn) !important; outline-offset: 3px; position: relative; z-index: 1; }
@media (prefers-reduced-motion: no-preference) { .coach-hl { animation: coachpulse 1.4s ease-in-out infinite; } @keyframes coachpulse { 50% { outline-color: transparent; } } }
.tutorial-note { border: 1px dashed var(--line); border-radius: var(--radius); padding: 10px 12px; background: var(--sunken); }
body.coaching .wrap { padding-bottom: 180px; }
.coach .coach-row { flex-wrap: nowrap; }
.coach .coach-quit { margin-left: auto; }
.coach .coach-nudge { font-size: .85rem; font-weight: 700; color: var(--warn-soft); }
/* 練習の案内が出ているあいだは、窓を案内の箱の上に収める(送るボタンなどが箱に隠れないように) */
body.coaching .overlay { align-items: flex-start; padding-bottom: calc(var(--coach-h, 160px) + 32px); }
body.coaching .dialog { max-height: calc(100vh - var(--coach-h, 160px) - 64px); }

/* サーバー版で足したもの */
.err { color: var(--bad); }
.notice { background: var(--warn-soft); color: var(--warn); padding: 8px 12px; border-radius: var(--radius); }
.gap-6 { gap: 6px; }
.between { justify-content: space-between; }
.mb-8 { margin-bottom: 8px; }
.hidden { display: none !important; }
textarea { background: var(--sunken); border: 1px solid var(--line); border-radius: 4px; padding: 7px 10px; width: 100%; font: inherit; color: inherit; }
.btn.small { padding: 2px 8px; font-size: .8rem; }
.stages { list-style: none; padding: 0; margin: 4px 0; display: flex; flex-direction: column; gap: 6px; }
.stages .stage { display: flex; gap: 10px; align-items: center; padding: 6px 10px; border: 1px solid var(--line); border-radius: var(--radius); }
.stages .stage > :first-child { flex: 1; }
.stages .stage.current { border-color: var(--warn); }
.stages .stage.done { opacity: .75; }
.tab[aria-current="page"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
a.tab { text-decoration: none; color: inherit; }
input.narrow, input[type=number] { width: 6em; }
h3.step { font-size: .95rem; margin: 0; }
.preview { border-top: 1px dashed var(--line); padding-top: 10px; }
button.linklike { background: none; border: 0; padding: 0; color: inherit; font: inherit; text-decoration: underline; cursor: pointer; text-align: left; }
@media print {
  .top nav, .no-print, .tabs, button { display: none !important; }
  .panel { border: 0; padding: 4px 0; }
  details:not([open]) > :not(summary) { display: block; }
}
a.pill { text-decoration: none; }
textarea.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .82rem; line-height: 1.45; white-space: pre; tab-size: 2; }
.btn.star { font-size: 1rem; line-height: 1; padding: 2px 6px; color: var(--warn, #b8860b); }
.glossary dl { margin: 0; }
.glossary dt { font-weight: 700; margin-top: 8px; }
.glossary dd { margin: 2px 0 0 1em; }
