/* app.css — 第一段階の実験UI
 *
 * ■ 色の方針（極力少なく）
 *   無彩色（グレー）＋ 有彩色2つ だけで組む。
 *     --accent  いま手を動かす場所（進行中のステップ・主ボタン・進捗）
 *     --error   エラーが出ていること
 *   成功は緑を足さず、無彩色の濃淡で表す。
 *   唯一の例外が「実績バッジ」。報酬条件でしか出ない。
 *   画面からほかの色を抜いたことで、報酬が鳴る瞬間だけが色を持つ。
 *   これは実験の操作そのものなので、意図してそうしている。
 *
 * ■ デザインの四原則
 *   近接  見出し＋中身を <section class="pane"> でひとかたまりにし、
 *         かたまりの間を広く、中は狭くする
 *   整列  左の文字はすべて同じ左端（--gut）から始める。中央揃えは使わない
 *   反復  見出し＝pane-head、本文13px、余白は4の倍数、角丸6px、
 *         ボタンは主＝塗り／従＝線 の2種類だけ
 *   強弱  一番強いのは「いまやること」の見出し（20px太字）。
 *         次が主ボタン。ほかは意図的に弱くして競合させない
 */

* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* 無彩色 */
  --bg:      #f2f2f0;
  --surface: #ffffff;
  --line:    #dcdcd8;
  --line-2:  #ebebe7;
  --ink:     #1c1c1a;
  --ink-2:   #5d5d58;
  --ink-3:   #8c8c86;

  /* 有彩色は2つだけ */
  --accent:  #2f5fd0;
  --accent-bg: #eaf0fc;
  --error:   #b3372c;
  --error-bg:  #fbeceb;

  /* 寸法。4の倍数でそろえる */
  --gut: 20px;
  --r: 6px;
}

html, body {
  height: 100%; overflow: hidden;
  font-family: 'Hiragino Sans', 'Noto Sans JP', system-ui, sans-serif;
  font-size: 13px; line-height: 1.8;
  background: var(--bg); color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
#app { display: flex; flex-direction: column; height: 100vh; }
[hidden] { display: none !important; }

/* ───────── ヘッダー ───────── */
#header {
  display: flex; align-items: center; gap: 12px;
  padding: 0 var(--gut); height: 44px; flex-shrink: 0;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.logo { font-size: 13px; font-weight: 700; }
#pid-label { font-size: 12px; color: var(--ink-3); }
#timer-display {
  margin-left: auto; font-size: 13px; color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}
#timer-display.low { color: var(--error); font-weight: 700; }

/* ───────── いまやること ───────── */
#goal-bar {
  padding: 16px var(--gut) 14px; flex-shrink: 0;
  background: var(--surface); border-bottom: 1px solid var(--line);
}

/* ステップ：いまどちらをやっているかを常に見せる */
#steps { display: flex; gap: 8px; list-style: none; margin-bottom: 10px; }
.step {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--ink-3);
  padding: 3px 10px 3px 4px; border-radius: 999px;
  border: 1px solid transparent;
}
.step .num {
  display: grid; place-items: center;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--line-2); color: var(--ink-3);
  font-size: 11px; font-weight: 700;
}
.step.on { color: var(--accent); background: var(--accent-bg); border-color: var(--accent); }
.step.on .num { background: var(--accent); color: #fff; }
.step.done { color: var(--ink-2); }
.step.done .num { background: var(--ink-2); color: #fff; }

/* 画面でいちばん強い要素。ここだけ 20px */
#goal-text { font-size: 20px; font-weight: 700; line-height: 1.5; letter-spacing: .01em; }
#goal-text b { color: var(--accent); }
/* これから出すエラーの説明。目標より弱く、操作の案内より強い */
#goal-about {
  font-size: 13px; color: var(--ink); margin-top: 6px;
  padding: 8px 11px; border-radius: var(--r);
  background: var(--accent-bg); max-width: 70ch;
}
#goal-about:empty { display: none; }
/* 公式ドキュメントからそのまま引いているので、出典を添える */
#goal-cite, #lesson-cite {
  font-size: 11px; color: var(--ink-3); margin-top: 4px;
}
#goal-cite:empty, #lesson-cite:empty { display: none; }
#goal-note { font-size: 13px; color: var(--ink-2); margin-top: 6px; min-height: 1.8em; }

#progress-row { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
#progress-label { font-size: 12px; color: var(--ink-3); white-space: nowrap; }
#progress-track {
  flex: 1; max-width: 220px; height: 4px; border-radius: 2px;
  background: var(--line-2); overflow: hidden;
}
#progress-fill { display: block; height: 100%; width: 0; background: var(--accent); transition: width .35s ease; }

/* ───────── 本体 ───────── */
#main { display: flex; flex: 1; overflow: hidden; }
#left { display: flex; flex-direction: column; flex: 1; min-width: 0; }

/* 見出しの作りは左右で共通にする（反復） */
.pane-head {
  display: flex; align-items: baseline; gap: 10px;
  padding: 10px var(--gut) 6px;
}
.pane-head h2 {
  font-size: 11px; font-weight: 700; letter-spacing: .08em;
  color: var(--ink-3);
}
#task-theme { font-size: 12px; color: var(--ink-2); }
#run-count-inline { margin-left: auto; font-size: 12px; color: var(--ink-3); }

#editor-container {
  flex: 1; overflow: hidden;
  margin: 0 var(--gut) 0; border: 1px solid var(--line);
  border-radius: var(--r); background: var(--surface);
}
.CodeMirror {
  height: 100% !important; font-size: 15px; line-height: 1.85;
  font-family: 'SF Mono', Menlo, Consolas, monospace;
  background: transparent; color: var(--ink);
  border-radius: var(--r);
}
.CodeMirror-gutters { background: transparent; border-right: 1px solid var(--line-2); }
.CodeMirror-linenumber { color: var(--ink-3); }
.CodeMirror-cursor { border-left: 2px solid var(--ink); }
.CodeMirror-selected { background: var(--accent-bg) !important; }
/* 構文色も2色に抑える。読む助けになる分だけ残す */
.cm-keyword, .cm-builtin { color: var(--accent); }
.cm-string, .cm-number  { color: var(--ink-2); }
.cm-comment { color: var(--ink-3); font-style: italic; }
.cm-def, .cm-variable, .cm-operator, .cm-punctuation { color: var(--ink); }

/* ───────── 操作 ───────── */
#footer {
  display: flex; align-items: center; gap: 10px;
  padding: 12px var(--gut); flex-shrink: 0;
}
#assist { display: flex; gap: 8px; margin-left: auto; }

/* ボタンは2種類だけ（反復）。主＝塗り、従＝線 */
button {
  font-family: inherit; font-size: 13px; cursor: pointer;
  border-radius: var(--r); border: 1px solid var(--line);
  background: var(--surface); color: var(--ink-2);
  padding: 9px 14px; transition: background .15s, border-color .15s;
}
button:hover:not(:disabled) { border-color: var(--ink-3); color: var(--ink); }
button:disabled { color: var(--ink-3); background: var(--bg); cursor: not-allowed; }
button.primary {
  background: var(--accent); border-color: var(--accent); color: #fff;
  font-weight: 700; font-size: 15px; padding: 11px 32px;
}
button.primary:hover:not(:disabled) { background: #27509f; border-color: #27509f; color: #fff; }
button.primary:disabled { background: var(--ink-3); border-color: var(--ink-3); color: #fff; opacity: .5; }
#hint-kbd { font-size: 12px; color: var(--ink-3); }

/* ───────── 右の列 ───────── */
#right {
  display: flex; flex-direction: column;
  width: 340px; flex-shrink: 0;
  background: var(--surface); border-left: 1px solid var(--line);
  overflow-y: auto;
}
.pane { flex-shrink: 0; border-bottom: 1px solid var(--line-2); padding-bottom: 14px; }
.pane:last-of-type { border-bottom: none; }

/* 実行結果：まず一行で状態を言い、そのあとに詳細を出す */
#result-status {
  margin: 0 var(--gut) 8px; padding: 9px 11px;
  border-radius: var(--r); font-size: 13px;
  background: var(--bg); color: var(--ink-2);
}
#result-status.is-error { background: var(--error-bg); color: var(--error); font-weight: 700; }
#result-status.is-ok    { background: var(--accent-bg); color: var(--accent); font-weight: 700; }
#result-box {
  margin: 0 var(--gut); padding: 10px 11px;
  border: 1px solid var(--line); border-radius: var(--r);
  font-family: 'SF Mono', Menlo, Consolas, monospace; font-size: 12px;
  line-height: 1.7; white-space: pre-wrap; word-break: break-word;
  max-height: 180px; overflow-y: auto; color: var(--ink);
}
#result-box:empty { display: none; }
#traceback-box { margin: 8px var(--gut) 0; }
#traceback-box summary {
  font-size: 12px; color: var(--ink-2); cursor: pointer;
  list-style: none; padding: 2px 0;
}
#traceback-box summary::-webkit-details-marker { display: none; }
#traceback-box summary::before { content: '＋ '; color: var(--ink-3); }
#traceback-box[open] summary::before { content: '− '; }
#traceback-box summary:hover { color: var(--accent); }
#traceback {
  margin-top: 6px; padding: 9px 10px;
  border: 1px solid var(--line); border-radius: var(--r); background: var(--bg);
  font-family: 'SF Mono', Menlo, Consolas, monospace; font-size: 11.5px;
  white-space: pre-wrap; word-break: break-word;
  max-height: 170px; overflow: auto; color: var(--ink-2);
}

#lesson-cite { margin: 0 var(--gut); }
#lesson-box {
  margin: 0 var(--gut); padding: 11px 12px;
  background: var(--bg); border-radius: var(--r);
  font-size: 12.5px; line-height: 1.8;
}

/* 進み具合 */
#plain-progress { margin: 0 var(--gut); font-size: 15px; }
#plain-progress .n { font-size: 28px; font-weight: 700; margin-right: 2px; }
#badge-grid { margin: 0 var(--gut); display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.badge-card {
  border: 1px solid var(--line); border-radius: var(--r);
  padding: 12px 8px; text-align: center; background: var(--surface);
}
.badge-card.earned { border-color: var(--accent); background: var(--accent-bg); animation: pop .3s ease; }
.badge-card.locked { color: var(--ink-3); background: var(--bg); }
.badge-card .be { font-size: 22px; line-height: 1.2; }
.badge-card.locked .be { opacity: .35; filter: grayscale(1); }
.badge-card .bn { font-size: 12px; font-weight: 700; margin-top: 3px; line-height: 1.4; }
.badge-card .bt { font-size: 10px; color: var(--ink-3); font-family: monospace; }
@keyframes pop { from { transform: scale(.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* 右の列が長くなっても画面外に出ないように下端に貼りつける。
   ただし自発的に続けた時間を測るので、目立たせはしない */
#finish-btn {
  position: sticky; bottom: 0; z-index: 1;
  margin: auto var(--gut) 0; flex-shrink: 0;
  box-shadow: 0 -12px 16px -8px var(--surface);
}
#right::after { content: ''; display: block; height: var(--gut); flex-shrink: 0; }

/* ───────── 実績解除 ───────── */
#overlay { position: fixed; inset: 0; background: rgba(28,28,26,.45); z-index: 90; display: none; }
#overlay.show { display: block; }
/* エラー文を隠さないよう、画面中央ではなく上寄りに置く */
#badge-popup {
  position: fixed; top: 96px; left: 50%;
  transform: translate(-50%, -8px) scale(.94); opacity: 0; pointer-events: none;
  background: var(--surface); border: 2px solid var(--accent); border-radius: 14px;
  padding: 26px 40px; text-align: center; z-index: 100; min-width: 250px;
  box-shadow: 0 12px 40px rgba(28,28,26,.18);
  transition: transform .25s cubic-bezier(.34,1.3,.64,1), opacity .2s;
}
#badge-popup.show { transform: translate(-50%, 0) scale(1); opacity: 1; pointer-events: auto; cursor: pointer; }
#bp-label { font-size: 11px; font-weight: 700; letter-spacing: .1em; color: var(--accent); }
#bp-emoji { font-size: 46px; line-height: 1.2; margin: 10px 0 4px; }
#bp-name  { font-size: 18px; font-weight: 700; }
#bp-type  { font-size: 12px; color: var(--ink-3); font-family: monospace; }
#bp-progress { font-size: 12px; color: var(--ink-2); margin-top: 8px; }

/* ───────── 全画面シート（開始・測定・終了） ───────── */
.sheet-layer {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: flex-start; justify-content: center;
  background: var(--bg); padding: 24px; overflow-y: auto;
}
/* align-items:center だと、中身が画面より高いときに上が切れて読めなくなる。
   flex-start ＋ margin:auto なら、余裕があるときだけ中央にそろう */
.sheet {
  margin: auto 0;
  width: 100%; max-width: 540px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 28px 32px 30px;
}
.sheet h1 { font-size: 19px; font-weight: 700; margin-bottom: 6px; }
.sheet .lead { font-size: 13px; color: var(--ink-2); margin-bottom: 18px; }
.sheet h2 {
  font-size: 11px; font-weight: 700; letter-spacing: .08em;
  color: var(--ink-3); margin: 22px 0 8px;
}
.sheet p { margin: 8px 0; }
.sheet ol, .sheet ul { margin: 8px 0 8px 1.5em; }
.sheet li { margin: 4px 0; }
.sheet code {
  font-family: Menlo, monospace; font-size: 12px;
  background: var(--bg); border: 1px solid var(--line);
  padding: 0 4px; border-radius: 3px;
}
.sheet button { width: 100%; margin-top: 22px; }
.sheet button + button { margin-top: 10px; }

.ptable { width: 100%; border-collapse: collapse; font-size: 13px; }
.ptable th {
  text-align: left; width: 36%; font-weight: 400; color: var(--ink-3);
  padding: 7px 10px 7px 0; border-bottom: 1px solid var(--line-2); vertical-align: top;
}
.ptable td { padding: 7px 0; border-bottom: 1px solid var(--line-2); }
.ptable .bad { color: var(--error); }

.status { margin: 16px 0; padding: 11px 13px; border-radius: var(--r); font-size: 13px; }
.status.wait { background: var(--bg); color: var(--ink-2); }
.status.ok   { background: var(--accent-bg); color: var(--accent); }
.status.bad  { background: var(--error-bg); color: var(--error); }
.status.dev  { background: var(--bg); color: var(--ink); border: 1px dashed var(--ink-3); }

/* 手順の図解（はじめての人向け） */
.howto { display: flex; gap: 10px; margin: 12px 0 4px; }
.howto-step {
  flex: 1; padding: 12px 10px; border: 1px solid var(--line);
  border-radius: var(--r); background: var(--bg);
}
.howto-step .n {
  display: grid; place-items: center; width: 20px; height: 20px;
  border-radius: 50%; background: var(--accent); color: #fff;
  font-size: 11px; font-weight: 700; margin-bottom: 6px;
}
.howto-step .t { font-size: 13px; font-weight: 700; }
.howto-step .d { font-size: 12px; color: var(--ink-2); line-height: 1.7; }

/* 事前アンケートの選択肢 */
.choice-group { margin: 20px 0 0; }
.choices { display: flex; flex-wrap: wrap; gap: 6px; }
.sheet .choice {
  width: auto; margin-top: 0; padding: 9px 14px;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: 999px;
  font-size: 13px; font-weight: 400;
}
.sheet .choice:hover { border-color: var(--accent); color: var(--accent); }
.sheet .choice.on {
  background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700;
}

/* 測定 */
.scale { margin: 22px 0 0; }
.scale-q { font-size: 14px; margin-bottom: 10px; }
.scale-row { display: flex; gap: 4px; }
.sheet .scale-btn {
  flex: 1 1 0; width: auto; min-width: 0; margin-top: 0;
  padding: 12px 0; font-size: 14px; font-weight: 400;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); font-variant-numeric: tabular-nums;
}
.sheet .scale-btn:hover { border-color: var(--accent); color: var(--accent); }
.sheet .scale-btn.on {
  background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700;
}
.anchors {
  display: flex; justify-content: space-between; gap: 10px;
  margin-top: 6px; font-size: 11px; color: var(--ink-3);
}
.anchors span:nth-child(2) { text-align: center; }
.anchors span:last-child { text-align: right; }

/* ヒント・答えの表示 */
.reveal { }
.reveal .rl {
  display: block; font-size: 11px; letter-spacing: .06em;
  color: var(--ink-3); margin-bottom: 4px;
}

/* ── 同意とネタばらし（リンクで配るときに使う） ───────────── */
.consent-box {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 14px 16px;
  margin: 0 0 16px;
  max-height: 46vh;
  overflow-y: auto;
  background: var(--bg);
  font-size: 13px;
  line-height: 1.8;
}
.consent-box h2 { font-size: 13px; margin: 14px 0 4px; }
.consent-box h2:first-child { margin-top: 0; }
.consent-box ul { margin: 0 0 8px; padding-left: 1.2em; }

.agree-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  margin-bottom: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
}
.agree-row:hover { background: var(--bg); }
.agree-row input { margin-top: 3px; width: 16px; height: 16px; flex: none; }
.agree-row span { font-size: 13px; line-height: 1.6; }

.decline {
  background: none;
  border: none;
  color: var(--ink-2);
  text-decoration: underline;
  font-size: 12px;
  cursor: pointer;
  padding: 8px;
  margin-top: 4px;
}
