/* ============================================================
   よすが練習アプリ 共通デザインシステム（3アプリ統一トークン）
   ※アクセント色 --accent のみアプリごとに変える（launcherと一致）
   ライン練習 = #4fc3f7
   ============================================================ */
:root {
  --bg: #0e1116;
  --surface: #161b22;
  --surface-2: #1d242e;
  --surface-3: #252e3a;
  --border: #2b333f;
  --text: #e6edf3;
  --text-dim: #9aa7b6;
  --accent: #4fc3f7;
  --accent-ink: #04121c;
  --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 {
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(79, 195, 247, .06), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---- Screen switching (フェード遷移) ---- */
.screen { display: none; width: 100%; height: 100vh; 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 ---- */
.btn {
  padding: 10px 22px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  transition: filter .15s, transform .08s, background .15s, border-color .15s;
}
.btn:active { transform: translateY(1px); }
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .4; cursor: not-allowed; filter: none; }
.btn-primary   { background: var(--accent); color: var(--accent-ink); }
.btn-secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { border-color: var(--accent); }
.btn-success   { background: var(--green); color: #04140a; }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-sm        { padding: 6px 14px; font-size: 13px; }

/* ---- Loading ---- */
#screen-loading { align-items: center; justify-content: center; }
.loading-box {
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 48px 60px;
  border-radius: var(--radius);
  min-width: 360px;
  box-shadow: var(--shadow);
}
.loading-box h2 { font-size: 22px; margin-bottom: 20px; color: var(--accent); letter-spacing: 1px; }
.progress-bar-outer {
  background: var(--surface-3);
  border-radius: 999px;
  height: 12px;
  margin: 16px 0 8px;
  overflow: hidden;
}
.progress-bar-inner {
  background: linear-gradient(90deg, var(--accent), #9fe1ff);
  height: 100%;
  border-radius: 999px;
  transition: width .3s;
}
#loading-pct { color: var(--text-dim); font-size: 13px; }

/* ---- Menu ---- */
#screen-menu { align-items: center; justify-content: center; }
.menu-box {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 44px 52px;
  border-radius: 14px;
  text-align: center;
  min-width: 380px;
  box-shadow: var(--shadow);
}
.menu-box h1 {
  font-size: 26px;
  color: var(--text);
  margin-bottom: 6px;
  letter-spacing: 1px;
}
.menu-box h1::after {
  content: "";
  display: block;
  width: 56px;
  height: 3px;
  margin: 12px auto 0;
  border-radius: 3px;
  background: var(--accent);
}
.menu-section { margin-bottom: 24px; margin-top: 26px; }
.menu-section p { margin-bottom: 12px; color: var(--text-dim); font-size: 13px; }

/* 出題順をカード型ラジオに */
.order-select { display: flex; flex-direction: column; gap: 10px; margin-bottom: 22px; }
.order-select label {
  cursor: pointer;
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 10px;
  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;
}
.order-select label:hover { border-color: var(--accent); }
.order-select input[type="radio"] { accent-color: var(--accent); width: 16px; height: 16px; cursor: pointer; }
.order-select label:has(input:checked) {
  border-color: var(--accent);
  color: var(--text);
  background: var(--surface-3);
  box-shadow: inset 0 0 0 1px var(--accent);
}

/* ---- Practice ---- */
#screen-practice { overflow: hidden; }

.toolbar {
  background: var(--surface);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.problem-label { font-size: 14px; font-weight: 700; color: var(--accent); min-width: 150px; }

.tool-group { display: flex; align-items: center; gap: 6px; }

.color-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid var(--border);
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color .15s, transform .08s, box-shadow .15s;
}
.color-btn:active { transform: scale(.94); }
#tool-red    { background: #2a1414; color: #ff5d5d; }
#tool-cyan   { background: #102530; color: #45d0ff; }
#tool-dotted {
  background: #2a2614;
  color: #ffdd66;
  font-size: 11px;
  font-weight: 700;
  border-radius: var(--radius-sm);
  width: auto;
  padding: 0 12px;
  letter-spacing: 2px;
}
.color-btn.active { border-color: #fff; box-shadow: 0 0 0 3px rgba(255,255,255,.18); }

.tool-sep { width: 1px; background: var(--border); height: 24px; margin: 0 4px; flex-shrink: 0; }

/* ツールバー内の補助ボタン（取消/全消去/選択など）を統一 */
#btn-undo, #btn-clear, #tool-select, #btn-copy-line, #btn-delete-line {
  padding: 7px 14px;
  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: background .15s, border-color .15s, transform .08s;
}
#btn-undo:hover, #btn-clear:hover, #tool-select:hover,
#btn-copy-line:not([disabled]):hover, #btn-delete-line:not([disabled]):hover { border-color: var(--text-dim); }
#btn-undo:active, #btn-clear:active, #tool-select:active { transform: translateY(1px); }
#btn-undo, #btn-clear, #tool-select, #btn-copy-line, #btn-delete-line { white-space: nowrap; }
#btn-clear { color: var(--danger); }
#tool-select.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
#btn-copy-line { color: var(--text); }
#btn-copy-line:disabled, #btn-delete-line:disabled { opacity: .4; cursor: not-allowed; }
#btn-copy-line.pasting { background: #b05020; color: #fff; border-color: #b05020; animation: pulse 1s infinite; }
@keyframes pulse { 0%,100%{ opacity:1 } 50%{ opacity:.7 } }
#btn-delete-line { color: var(--danger); }

.btn-exit {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  margin-left: auto;
  padding: 7px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.btn-exit:hover { border-color: var(--danger); color: var(--danger); }

/* ヘルプボタン（ショートカット一覧） */
.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;
  flex-shrink: 0;
}
.help-fab:hover { color: var(--accent); border-color: var(--accent); }

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

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

#drawing-canvas { position: absolute; top: 0; left: 0; cursor: crosshair; touch-action: none; }

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

/* ---- Answer ---- */
#screen-answer { overflow: hidden; }

.answer-header {
  background: var(--surface);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}

#answer-label { font-size: 14px; font-weight: 700; color: var(--accent); }

.page-tabs { display: flex; gap: 4px; }
.page-tab {
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--text-dim);
  transition: background .15s, color .15s, border-color .15s;
}
.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 18px;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  transition: filter .15s, transform .08s;
}
.judge-btn:active { transform: translateY(1px); }
.judge-btn:hover { filter: brightness(1.08); }
.judge-btn.correct   { background: var(--green); color: #04140a; }
.judge-btn.incorrect { background: var(--danger); }

/* 重ねて比較 トグル＆スライダー */
.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-answer-tally { margin-left: auto; }

.answer-body {
  flex: 1;
  display: flex;
  gap: 2px;
  overflow: hidden;
  background: #08090f;
  position: relative;
}

.answer-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.answer-col-title {
  background: var(--surface);
  text-align: center;
  padding: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  flex-shrink: 0;
}

.answer-col img { flex: 1; object-fit: contain; max-width: 100%; max-height: 100%; display: block; min-height: 0; }

/* 重ねて比較モード: 2枚を重ねて自分側の不透明度を可変 */
.answer-body.overlay .answer-col { position: absolute; inset: 0; }
.answer-body.overlay .answer-col-title { display: none; }
.answer-body.overlay .answer-col:first-child { z-index: 2; opacity: var(--my-op, .55); }
.answer-body.overlay .answer-col:last-child { z-index: 1; }

/* ---- Tally ---- */
#screen-tally { align-items: center; justify-content: center; }
.tally-box {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 44px 56px;
  border-radius: 14px;
  text-align: center;
  min-width: 380px;
  max-width: 620px;
  box-shadow: var(--shadow);
}
.tally-box h2 { font-size: 22px; color: var(--text); margin-bottom: 16px; }
.tally-rate { font-size: 60px; font-weight: 800; color: var(--accent); margin: 10px 0; letter-spacing: 1px; }
#tally-counts { color: var(--text-dim); }
.tally-section { margin: 22px 0; text-align: left; }
.tally-section p:first-child { color: var(--text-dim); margin-bottom: 6px; font-size: 13px; }
.incorrect-list { font-size: 14px; color: var(--danger); line-height: 1.8; word-break: break-all; }
.tally-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 24px; align-items: stretch; }

/* ---- 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; } }
#screen-ta-review #ta-review-label { font-size: 14px; font-weight: 700; color: var(--accent); }

/* ---- History ---- */
#screen-history { overflow: hidden; padding: 28px; }
.history-box { display: flex; flex-direction: column; height: 100%; max-width: 980px; margin: 0 auto; width: 100%; }
.history-box h2 { font-size: 22px; color: var(--text); margin-bottom: 18px; }
.history-table-wrap { flex: 1; overflow-y: auto; margin-bottom: 16px; border: 1px solid var(--border); border-radius: var(--radius); }
#history-table { width: 100%; border-collapse: collapse; font-size: 14px; }
#history-table th { background: var(--surface); padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--border); color: var(--text-dim); position: sticky; top: 0; }
#history-table td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
#history-table tr:hover td { background: var(--surface-2); }
#history-empty { 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: 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;
}
