/* ============================================================
   よすが練習アプリ 共通デザインシステム（3アプリ統一トークン）
   ナウキャスト練習 = アクセント #81c784（launcherと一致）
   ============================================================ */
:root {
  --bg: #0e1116;
  --surface: #161b22;
  --surface-2: #1d242e;
  --surface-3: #252e3a;
  --border: #2b333f;
  --text: #e6edf3;
  --text-dim: #9aa7b6;
  --accent: #81c784;
  --accent-ink: #06150a;
  --green: #3fb950;
  --red: #ff5d5d;
  --danger: #f0533f;
  --radius: 8px;
  --radius-sm: 6px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .45);
  --font: 'Segoe UI', 'Yu Gothic UI', 'Meiryo UI', sans-serif;
}

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

body {
  font-family: var(--font);
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(129, 199, 132, .06), transparent 60%),
    var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  position: relative;
}

/* ── Screen switching ── */
.screen { display: none; position: absolute; inset: 0; flex-direction: column; }
.screen.active { display: flex; animation: screen-fade .28s ease; }
@keyframes screen-fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ── Buttons ── */
button {
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 7px 16px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  transition: filter .15s, background .15s, border-color .15s, transform .08s;
  white-space: nowrap;
}
button:active { transform: translateY(1px); }
button:disabled { opacity: .4; cursor: default; }
.btn-primary   { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover:not(:disabled)   { filter: brightness(1.08); }
.btn-secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { border-color: var(--text-dim); }
.btn-success   { background: var(--green); color: #04140a; }
.btn-success:hover:not(:disabled)   { filter: brightness(1.08); }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled)    { filter: brightness(1.08); }

/* ════════ LOADING ════════ */
#screen-loading { align-items: center; justify-content: center; gap: 20px; }
#screen-loading h1 { font-size: 26px; color: var(--accent); letter-spacing: 1px; }
.progress-bar-container {
  width: 60%;
  max-width: 460px;
  height: 14px;
  background: var(--surface-3);
  border-radius: 999px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #c3edc5);
  transition: width .3s ease;
  border-radius: 999px;
}
#loading-percent { font-size: 16px; color: var(--text-dim); }

/* ════════ MENU ════════ */
#screen-menu { align-items: center; justify-content: center; gap: 26px; }
#screen-menu h1 { font-size: 28px; color: var(--text); letter-spacing: 1px; }
#screen-menu h1::after {
  content: ""; display: block; width: 56px; height: 3px;
  margin: 12px auto 0; border-radius: 3px; background: var(--accent);
}
.menu-options { display: flex; flex-direction: column; gap: 10px; min-width: 320px; }
.menu-options label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  cursor: pointer;
  padding: 12px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-dim);
  transition: border-color .15s, color .15s, background .15s;
}
.menu-options label:hover { border-color: var(--accent); }
.menu-options input[type="radio"] { width: 16px; height: 16px; cursor: pointer; accent-color: var(--accent); }
.menu-options label:has(input:checked) {
  border-color: var(--accent); color: var(--text); background: var(--surface-3);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.menu-buttons { display: flex; gap: 16px; margin-top: 6px; }
.menu-buttons button { padding: 11px 28px; font-size: 15px; }

/* ════════ PRACTICE ════════ */
#screen-practice { background: var(--bg); }

.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;
}

#problem-label { font-size: 13px; font-weight: 700; color: var(--accent); margin-right: 4px; white-space: nowrap; }

.tool-btn {
  background: var(--surface-2);
  color: var(--text);
  padding: 6px 12px;
  font-size: 12px;
  border: 1px solid var(--border);
}
.tool-btn:hover:not(:disabled) { border-color: var(--text-dim); }
.tool-btn.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.tool-btn.pasting { background: #b05020; color: #fff; border-color: #b05020; animation: pulse 1s infinite; }
@keyframes pulse { 0%,100%{ opacity:1 } 50%{ opacity:.7 } }

.color-btn[data-color="#ff4444"] { color: #ff5d5d; border-color: #5a2a2a; }
.color-btn[data-color="#00cfff"] { color: #45d0ff; border-color: #234a5a; }
.color-btn[data-color="#ffdd44"] { color: #ffdd66; border-color: #5a522a; border-style: dashed; }
.color-btn.active[data-color="#ff4444"] { background: #ff5d5d; color: #1a0606; border-color: #ff5d5d; }
.color-btn.active[data-color="#00cfff"] { background: #45d0ff; color: #04121c; border-color: #45d0ff; }
.color-btn.active[data-color="#ffdd44"] { background: #ffdd66; color: #1a1606; border-color: #ffdd66; }

.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;
  padding: 0;
}
.help-fab:hover { color: var(--accent); border-color: var(--accent); }

#btn-end { margin-left: auto; background: var(--surface-2); color: var(--text); border-color: var(--border); }
#btn-end:hover { border-color: var(--danger); color: var(--danger); }

/* Canvas area */
.canvas-container { position: relative; flex: 1; overflow: hidden; background: #08090f; }
#chart-image {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: contain; user-select: none; pointer-events: none; display: block;
}
#drawing-canvas { position: absolute; inset: 0; width: 100%; height: 100%; cursor: crosshair; display: block; touch-action: none; }

/* Bottom bar */
.bottom-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}
#page-indicator { font-size: 12px; color: var(--text-dim); flex-shrink: 0; }
#btn-view-answer { margin-left: 8px; }
.comment-input {
  flex: 1;
  min-width: 120px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 12px;
  font-family: inherit;
}
.comment-input:focus { outline: none; border-color: var(--accent); }

/* ════════ ANSWER COMPARISON ════════ */
#screen-answer { background: var(--bg); }
.answer-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}
#answer-problem-label { font-size: 14px; font-weight: 700; color: var(--accent); }
.answer-comment {
  display: none;
  padding: 5px 14px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  color: #ffdd66;
  flex-shrink: 0;
}
.page-tabs { display: flex; gap: 4px; }
.page-tab {
  background: var(--surface-2);
  color: var(--text-dim);
  border: 1px solid var(--border);
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
}
.page-tab:hover { border-color: var(--text-dim); }
.page-tab.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.judge-btn { padding: 7px 16px; font-size: 13px; font-weight: 700; }
.judge-btn.correct   { background: var(--green); color: #04140a; }
.judge-btn.incorrect { background: var(--danger); color: #fff; }

/* 重ねて比較 トグル＆スライダー */
.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; }

#btn-view-stats { margin-left: auto; }

.comparison-area { display: flex; flex: 1; gap: 2px; overflow: hidden; padding: 4px; position: relative; }
.panel { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.panel h3 { font-size: 12px; color: var(--text-dim); text-align: center; padding: 4px 0 6px; flex-shrink: 0; font-weight: 600; }
.panel-inner { position: relative; flex: 1; background: #08090f; overflow: hidden; border-radius: 4px; }
.panel-inner img, .panel-inner canvas {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; display: block;
}
#snapshot-canvas { pointer-events: none; }

/* 重ねて比較モード: 自分パネルを解答パネルに重ねて不透明度を可変 */
.comparison-area.overlay .panel { position: absolute; inset: 4px; }
.comparison-area.overlay .panel h3 { display: none; }
.comparison-area.overlay .panel:first-child { z-index: 2; opacity: var(--my-op, .55); }
.comparison-area.overlay .panel:last-child { z-index: 1; }

/* ════════ 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, .5);
  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; } }

.ta-page-tab {
  background: var(--surface-2);
  color: var(--text-dim);
  border: 1px solid var(--border);
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
}
.ta-page-tab.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* ════════ STATISTICS ════════ */
#screen-stats { align-items: center; justify-content: center; gap: 22px; }
#screen-stats h1 { font-size: 24px; color: var(--text); }
.stats-summary { text-align: center; }
.stat-rate { font-size: 60px; font-weight: 800; color: var(--accent); }
.stat-count { font-size: 20px; color: var(--text-dim); margin-top: 4px; }
.incorrect-list {
  text-align: center; max-width: 600px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 18px;
}
.incorrect-list h3 { font-size: 13px; color: var(--text-dim); margin-bottom: 8px; }
#incorrect-numbers { font-size: 14px; color: var(--danger); line-height: 1.7; }
.stats-buttons { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.stats-buttons button { padding: 11px 22px; }

/* ════════ SCORE HISTORY ════════ */
#screen-history { align-items: center; gap: 16px; padding: 24px; overflow-y: auto; }
#screen-history h1 { font-size: 24px; color: var(--text); }
.history-list { width: 100%; max-width: 860px; display: flex; flex-direction: column; gap: 8px; }
.history-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 13px;
}
.history-item:hover { border-color: var(--text-dim); }
.history-item .h-datetime { color: var(--text-dim); font-size: 11px; margin-bottom: 4px; }
.history-item .h-rate { font-size: 22px; font-weight: 800; color: var(--accent); }
.history-item .h-count { color: var(--text-dim); margin-left: 8px; }
.history-item .h-incorrect { color: #ffdd66; font-size: 12px; margin-top: 4px; }

/* ════════ 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: 440px;
  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;
}
