/* ============================================================
   よすが練習アプリ 共通デザインシステム（3アプリ統一トークン）
   シナリオ構築練習 = アクセント #ffb74d（launcherと一致）
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0e1116;
  --surface: #161b22;
  --panel: #161b22;       /* 後方互換 */
  --surface-2: #1d242e;
  --panel2: #1d242e;      /* 後方互換 */
  --surface-3: #252e3a;
  --border: #2b333f;
  --text: #e6edf3;
  --text-dim: #9aa7b6;
  --accent: #ffb74d;
  --accent-ink: #211200;
  --red: #ff5d5d;
  --cyan: #45d0ff;
  --yellow: #ffdd66;
  --green: #3fb950;
  --purple: #b07cff;
  --danger: #f0533f;
  --gold: #ffb74d;
  --radius: 8px;
  --radius-sm: 6px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .45);
  --font: 'Segoe UI', 'Yu Gothic UI', 'Meiryo UI', sans-serif;
}

body {
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(255, 183, 77, .06), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  height: 100vh;
  overflow: hidden;
}

.screen { display: none; width: 100vw; height: 100vh; }
.screen.active { display: flex; animation: screen-fade .28s ease; }
@keyframes screen-fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ─── Loading Screen ─── */
#loading-screen { flex-direction: column; align-items: center; justify-content: center; gap: 24px; }
.loading-title { font-size: 22px; font-weight: 600; color: var(--accent); letter-spacing: 2px; }
.progress-wrap {
  width: 420px;
  background: var(--surface-3);
  border-radius: 999px;
  border: 1px solid var(--border);
  height: 18px;
  overflow: hidden;
}
.progress-bar { height: 100%; background: linear-gradient(90deg, var(--accent), #ffd99a); transition: width .3s; width: 0%; }
.progress-label { font-size: 13px; color: var(--text-dim); }

/* ─── Menu Screen ─── */
#menu-screen { flex-direction: column; align-items: center; justify-content: center; gap: 30px; }
.menu-title { font-size: 26px; font-weight: 700; color: var(--text); letter-spacing: 2px; }
.menu-title::after {
  content: ""; display: block; width: 56px; height: 3px;
  margin: 12px auto 0; border-radius: 3px; background: var(--accent);
}
.menu-subtitle { color: var(--text-dim); font-size: 13px; margin-top: -16px; }

.order-group { display: flex; gap: 14px; }
.radio-btn {
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface-2);
  color: var(--text-dim);
  cursor: pointer;
  font-size: 14px;
  transition: all .18s;
  user-select: none;
}
.radio-btn:hover { border-color: var(--accent); }
.radio-btn.selected {
  border-color: var(--accent);
  color: var(--text);
  background: var(--surface-3);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.menu-btns { display: flex; gap: 16px; }

.btn {
  padding: 11px 28px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  transition: filter .15s, background .15s, border-color .15s, transform .08s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--text-dim); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.08); }
.btn-success { background: var(--green); color: #04140a; }
.btn-success:hover { filter: brightness(1.08); }
.btn-purple { background: var(--purple); color: #fff; }
.btn-purple:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .4; cursor: not-allowed; filter: none; }

/* ─── Practice Screen ─── */
#practice-screen { flex-direction: column; overflow: hidden; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
  min-height: 46px;
}
.toolbar-label { font-size: 13px; font-weight: 700; color: var(--accent); white-space: nowrap; }
.toolbar-sep { width: 1px; height: 26px; background: var(--border); margin: 0 4px; }

.tool-btn {
  padding: 6px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  transition: all .15s;
  white-space: nowrap;
}
.tool-btn:hover { border-color: var(--text-dim); }
.tool-btn:disabled { opacity: .4; cursor: not-allowed; }

.tool-btn.active-red   { border-color: var(--red);    color: var(--red);    background: #3a1414; }
.tool-btn.active-cyan  { border-color: var(--cyan);   color: var(--cyan);   background: #102530; }
.tool-btn.active-dot   { border-color: var(--yellow); color: var(--yellow); background: #2e2814; }
.tool-btn.active-brush { border-color: var(--yellow); color: var(--yellow); background: #2e2814; }
.tool-btn.active-erase { border-color: var(--text-dim); color: var(--text); background: var(--surface-3); }
.tool-btn.active-select{ border-color: var(--purple); color: var(--purple); background: #251a35; }
.tool-btn.active-copy  { border-color: var(--green);  color: var(--green);  background: #103020; }
.tool-btn.pasting      { border-color: #b05020; color: #fff; background: #b05020; animation: pulse 1s infinite; }
@keyframes pulse { 0%,100%{ opacity:1 } 50%{ opacity:.7 } }

.help-fab {
  width: 32px; height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-dim);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}
.help-fab:hover { color: var(--accent); border-color: var(--accent); }

.chart-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
  background: #08090f;
}

#chart-img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}

#draw-canvas { position: absolute; top: 0; left: 0; pointer-events: none; touch-action: none; }
.chart-container { position: relative; display: inline-block; line-height: 0; }

#draw-canvas.interactive { pointer-events: all; cursor: crosshair; }
#draw-canvas.select-mode { cursor: default; }
#draw-canvas.erase-mode  { cursor: cell; }
#draw-canvas.copy-mode   { cursor: ns-resize; }

/* ─── 分析メモ オーバーレイ ─── */
.memo-overlay {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 5;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 320px;
}
.memo-box {
  pointer-events: auto;
  background: rgba(14, 17, 22, .9);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  line-height: 1.4;
  overflow: hidden;
}
.memo-box-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 8px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  cursor: move;
  user-select: none;
}
.memo-box-title { font-size: 12px; font-weight: 600; color: var(--text); white-space: nowrap; }
.memo-head-btns { display: flex; align-items: center; gap: 2px; }
.memo-toggle, .memo-fontbtn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 5px;
  border-radius: 4px;
  font-family: inherit;
}
.memo-toggle:hover, .memo-fontbtn:hover { color: var(--text); border-color: var(--border); }
.memo-fontbtn { font-weight: 700; }
.memo-box.collapsed .memo-box-body { display: none; }
.memo-box-body { padding: 6px 8px; }
.memo-textarea {
  width: 280px;
  height: 110px;
  resize: vertical;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  line-height: 1.5;
  padding: 6px 8px;
}
.memo-textarea:focus { outline: none; border-color: var(--accent); }
.memo-ro-section { margin-bottom: 8px; }
.memo-ro-section:last-child { margin-bottom: 0; }
.memo-ro-label {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  color: var(--accent-ink);
  background: var(--accent);
  border-radius: 4px;
  padding: 1px 7px;
  margin-bottom: 3px;
}
.memo-ro-text {
  width: 280px;
  font-size: 13px;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 130px;
  overflow-y: auto;
}
.memo-ro-text.empty { color: var(--text-dim); font-style: italic; }

.bottom-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.bottom-nav { display: flex; gap: 10px; align-items: center; }
.page-indicator { color: var(--text-dim); font-size: 13px; }

/* ─── Comparison Screen ─── */
#comparison-screen, #ta-review-screen { flex-direction: column; }

/* ─── Time Attack ─── */
.ta-timer {
  position: fixed;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  pointer-events: none;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 22px;
  font-weight: 800;
  padding: 6px 22px;
  border-radius: 999px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .6);
  letter-spacing: 1px;
  font-variant-numeric: tabular-nums;
}
.ta-timer.warning { background: var(--danger); color: #fff; animation: ta-blink 1s steps(2, start) infinite; }
@keyframes ta-blink { 50% { opacity: .55; } }

.comparison-header {
  display: flex;
  align-items: center;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  gap: 14px;
  flex-shrink: 0;
  flex-wrap: wrap;
}
.comp-prob-label { font-size: 14px; color: var(--text-dim); }
.comp-prob-num { font-size: 16px; font-weight: 700; color: var(--accent); }

.page-tabs { display: flex; gap: 6px; }
.page-tab {
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-dim);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}
.page-tab:hover { border-color: var(--text-dim); }
.page-tab.active { border-color: var(--accent); color: var(--accent-ink); background: var(--accent); }

/* 重ねて比較 トグル＆スライダー */
.cmp-ctrl { display: flex; align-items: center; gap: 8px; }
.cmp-toggle.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.cmp-slider { width: 130px; accent-color: var(--accent); cursor: pointer; display: none; }
.cmp-slider.show { display: inline-block; }
.cmp-slider-label { font-size: 12px; color: var(--text-dim); display: none; }
.cmp-slider-label.show { display: inline; }

.comparison-body { flex: 1; display: flex; overflow: hidden; position: relative; }
.comp-pane { flex: 1; display: flex; flex-direction: column; overflow: hidden; border-right: 1px solid var(--border); }
.comp-pane:last-child { border-right: none; }
.comp-pane-label {
  padding: 6px 12px;
  font-size: 12px;
  color: var(--text-dim);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.comp-img-wrap { flex: 1; display: flex; align-items: center; justify-content: center; overflow: hidden; background: #08090f; }
.comp-img-wrap img { max-width: 100%; max-height: 100%; object-fit: contain; }

/* 重ねて比較モード: 自分の描画を解答に重ねて不透明度を可変 */
.comparison-body.overlay .comp-pane { position: absolute; inset: 0; border-right: none; }
.comparison-body.overlay .comp-pane-label { display: none; }
.comparison-body.overlay .comp-pane:first-child { z-index: 2; opacity: var(--my-op, .55); }
.comparison-body.overlay .comp-pane:last-child { z-index: 1; }

.comparison-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 10px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* ─── Summary Screen ─── */
#summary-screen { flex-direction: column; align-items: center; justify-content: center; gap: 24px; }
.summary-title { font-size: 22px; font-weight: 700; color: var(--text); }
.summary-stats { display: flex; gap: 36px; }
.stat-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 32px;
  gap: 6px;
  box-shadow: var(--shadow);
}
.stat-label { font-size: 12px; color: var(--text-dim); }
.stat-value { font-size: 38px; font-weight: 800; color: var(--accent); }

.incorrect-list {
  max-width: 480px;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.incorrect-list-title { font-size: 12px; color: var(--text-dim); margin-bottom: 8px; }
.incorrect-nums { display: flex; flex-wrap: wrap; gap: 6px; }
.incorrect-tag {
  padding: 3px 10px;
  background: #3a1414;
  border: 1px solid var(--danger);
  color: var(--red);
  border-radius: 4px;
  font-size: 12px;
}
.summary-btns { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }

/* ─── History Screen ─── */
#history-screen { flex-direction: column; }
.history-header {
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 20px;
}
.history-title { font-size: 16px; font-weight: 700; color: var(--accent); }
.history-body { flex: 1; overflow-y: auto; padding: 16px; }
.history-body::-webkit-scrollbar { width: 6px; }
.history-body::-webkit-scrollbar-track { background: var(--bg); }
.history-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.history-row {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
}
.history-row:hover { border-color: var(--text-dim); }
.hist-datetime { font-size: 12px; color: var(--text-dim); min-width: 130px; }
.hist-rate { font-size: 22px; font-weight: 800; color: var(--accent); min-width: 70px; }
.hist-count { font-size: 13px; color: var(--text); min-width: 80px; }
.hist-incorrect { font-size: 11px; color: var(--text-dim); flex: 1; }
.empty-msg { color: var(--text-dim); text-align: center; padding: 40px; }

/* ─── Help モーダル（共通） ─── */
.help-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(0, 0, 0, .6);
  align-items: center;
  justify-content: center;
  animation: screen-fade .2s ease;
}
.help-overlay.show { display: flex; }
.help-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 26px 30px;
  width: 460px;
  max-width: 92vw;
  box-shadow: var(--shadow);
}
.help-modal h3 { color: var(--accent); font-size: 18px; margin-bottom: 16px; display: flex; align-items: center; justify-content: space-between; }
.help-modal h3 .help-close { background: none; border: none; color: var(--text-dim); font-size: 22px; cursor: pointer; line-height: 1; }
.help-modal h3 .help-close:hover { color: var(--text); }
.help-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px dashed var(--border); }
.help-row:last-child { border-bottom: none; }
.help-row span { color: var(--text); font-size: 14px; }
.help-row kbd {
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 3px 9px;
  font-size: 12px;
  font-family: inherit;
  color: var(--text);
  white-space: nowrap;
}
