/*
 * 画面全体の見た目。スマホで片手で使う前提で、押す場所は大きく、文字は読みやすく。
 * 色は変数にまとめ、端末がダークモードなら暗い配色に切り替える。
 */
:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #1c2333;
  --muted: #677086;
  --border: #e1e5ee;
  --accent: #4f46e5;
  --accent-soft: #eef0ff;
  --accent-text: #ffffff;
  --good: #16a34a;
  --good-soft: #e8f7ee;
  --hard: #d97706;
  --hard-soft: #fdf3e3;
  --again: #dc2626;
  --again-soft: #fdecec;
  --code-bg: #f6f8fc;
  --shadow: 0 1px 2px rgba(20, 30, 60, .05), 0 4px 14px rgba(20, 30, 60, .06);
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1320;
    --card: #181d2d;
    --text: #e7eaf3;
    --muted: #97a0b8;
    --border: #2a3147;
    --accent: #8b85ff;
    --accent-soft: #24244a;
    --accent-text: #0f1320;
    --good: #4ade80;
    --good-soft: #15301f;
    --hard: #fbbf24;
    --hard-soft: #352a12;
    --again: #f87171;
    --again-soft: #3a1a1d;
    --code-bg: #11162a;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif;
  line-height: 1.75;
  -webkit-text-size-adjust: 100%;
}

main { max-width: 720px; margin: 0 auto; padding: 16px 16px 48px; }
main.narrow { max-width: 400px; padding-top: 56px; }

h1 { font-size: 1.35rem; margin: 4px 0 14px; }
h2 { font-size: 1.05rem; margin: 28px 0 10px; display: flex; align-items: center; gap: 8px; }
h2.first { margin-top: 8px; }
a { color: var(--accent); }

/* ---- ヘッダー ---- */
.site-header {
  position: sticky; top: 0; z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.site-header-inner {
  max-width: 720px; margin: 0 auto; padding: 10px 16px;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
}
.brand { font-weight: 800; text-decoration: none; color: var(--text); letter-spacing: .01em; }
.site-nav { display: flex; align-items: center; gap: 14px; font-size: .9rem; }
.site-nav a { text-decoration: none; color: var(--muted); }
.site-nav a:hover { color: var(--accent); }
.site-nav form { margin: 0; }

/* ---- 共通の部品 ---- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 14px;
}
.stack { display: flex; flex-direction: column; gap: 12px; }
.muted { color: var(--muted); font-size: .88rem; margin: 0 0 4px; }
.small { font-size: .82rem; }
.big { font-size: 1.1rem; }
.text { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0 0 14px; }
.answer { font-weight: 700; }
.block { display: block; width: 100%; }

pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  overflow-x: auto;
  font-size: .84rem;
  line-height: 1.55;
  margin: 0 0 14px;
}
code { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; }

label { display: flex; flex-direction: column; gap: 6px; font-size: .92rem; }
label.inline { flex-direction: row; align-items: center; gap: 8px; }

input[type=text], input[type=password], textarea {
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
  width: 100%;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

button, .button {
  font: inherit; font-weight: 600; display: inline-block; text-align: center; text-decoration: none;
  border: 1px solid var(--border); border-radius: 12px; padding: 12px 18px;
  background: var(--card); color: var(--text); cursor: pointer;
  transition: transform .05s ease, background .15s ease;
}
button:active, .button:active { transform: scale(.98); }
button:disabled { opacity: .6; }
.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.link-button { border: none; background: none; padding: 0; color: var(--muted); font-weight: 400; font-size: .9rem; }

.notice {
  background: var(--accent-soft); border-radius: 12px; padding: 10px 14px; margin: 0 0 14px;
}
.notice.error { background: var(--again-soft); color: var(--again); }

/* 帯グラフ(進み具合・正答率) */
.bar { display: block; height: 6px; border-radius: 99px; background: var(--border); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.bar > span.weak { background: var(--again); }
.bar > span.strong { background: var(--good); }

/* ---- トップ ---- */
/* 今日解いた数。1行に「ラベル・数・○△× の内訳」を並べる */
.today {
  display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-top: 4px;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 12px 16px;
}
.today-label { font-size: .85rem; color: var(--muted); }
.today-count { font-size: 1.6rem; font-weight: 800; line-height: 1.2; }
.today-count small { font-size: .85rem; font-weight: 700; margin-left: 2px; }
.today-results { display: flex; gap: 10px; margin-left: auto; font-weight: 700; font-size: .9rem; }
.today-results .good { color: var(--good); }
.today-results .hard { color: var(--hard); }
.today-results .again { color: var(--again); }
.today-review {
  flex-basis: 100%; text-align: center; text-decoration: none; font-weight: 700; font-size: .9rem;
  padding: 10px; border-radius: 10px; background: var(--accent-soft); color: var(--accent);
}
.filters { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 6px; }
.filter {
  display: flex; flex-direction: column; gap: 2px; text-decoration: none; color: var(--text);
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 12px;
}
.filter-name { font-size: .78rem; color: var(--muted); }
.filter-count { font-size: 1.6rem; font-weight: 800; line-height: 1.2; }
.filter.due .filter-count { color: var(--accent); }
.filter.wrong .filter-count { color: var(--again); }
.filter.marked .filter-count { color: var(--hard); }

.level-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.level-1 { background: var(--good); }
.level-2 { background: var(--hard); }
.level-3 { background: var(--again); }

/* 難易度順 / 分野別 の切り替え。ラジオボタン本体は見えなくして、ラベルをボタンのように見せる */
.tabs { margin-top: 18px; }
.tabs > input { position: absolute; opacity: 0; pointer-events: none; }
.tabs > label {
  display: inline-block; padding: 8px 16px; margin-right: 6px; border-radius: 99px;
  border: 1px solid var(--border); background: var(--card); color: var(--muted);
  font-weight: 700; font-size: .9rem; cursor: pointer;
}
.tabs > input:checked + label { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.tabs > input:focus-visible + label { outline: 2px solid var(--accent); outline-offset: 2px; }
.tab-panel { display: none; }
#view-level:checked ~ .panel-level, #view-category:checked ~ .panel-category { display: block; }

.sections { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.section {
  display: flex; flex-direction: column; gap: 8px;
  text-decoration: none; color: var(--text);
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px 16px;
}
.section-row { display: flex; justify-content: space-between; align-items: center; }
.section-name { font-weight: 700; }
.section-stats { display: flex; gap: 12px; color: var(--muted); font-size: .9rem; }
.section-stats .wrong { color: var(--again); font-weight: 700; }

/* ---- 問題・答え合わせ ---- */
.question-bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.question-bar > a { text-decoration: none; font-weight: 700; }
.question-bar form { margin: 0; }
.mark { padding: 6px 12px; font-size: .88rem; border-radius: 99px; }
.mark.on { color: var(--hard); border-color: var(--hard); background: var(--hard-soft); }

/* 4択の選択肢。押すとそのまま答え合わせ。長い文でも折り返して全文読めるようにする */
button.choice {
  text-align: left; white-space: normal; line-height: 1.6; font-weight: 500;
  padding: 14px 16px; width: 100%;
}
button.choice:active { border-color: var(--accent); background: var(--accent-soft); }

.result { font-size: 1.15rem; font-weight: 800; margin: 0 0 10px; padding: 8px 12px; border-radius: 10px; }
.result.good { color: var(--good); background: var(--good-soft); }
.result.again { color: var(--again); background: var(--again-soft); }

.grade-buttons { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.grade-buttons button {
  color: #fff; border: none; font-weight: 800; font-size: 1.4rem;
  display: flex; flex-direction: column; align-items: center; padding: 12px 4px;
}
.grade-buttons small { font-size: .74rem; font-weight: 500; }
.grade-buttons .good { background: var(--good); }
.grade-buttons .hard { background: var(--hard); }
.grade-buttons .again { background: var(--again); }
/* Gemini の判定と同じボタン。色では見分けにくい人もいるので、枠で示す */
.grade-buttons button.suggested { outline: 3px solid var(--text); outline-offset: 2px; }

/* Gemini の判定(提案) */
.grading { border: 1px solid var(--border); border-radius: 12px; padding: 10px 14px; margin: 0 0 14px; }
.grading.good { border-color: var(--good); background: var(--good-soft); }
.grading.hard { border-color: var(--hard); background: var(--hard-soft); }
.grading.again { border-color: var(--again); background: var(--again-soft); }
.grading-title { font-weight: 800; margin: 0 0 6px; }

/* Gemini とのやり取り */
.asks-title { font-size: .95rem; margin: 22px 0 10px; padding-top: 14px; border-top: 1px solid var(--border); }
.asks { list-style: none; padding: 0; margin: 0 0 14px; display: flex; flex-direction: column; gap: 12px; }
.asks li { border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.asks li.latest { border-color: var(--accent); background: var(--accent-soft); }
.ask-label { font-weight: 800; color: var(--accent); margin: 0; font-size: .85rem; }
.ask-message { font-weight: 700; margin-bottom: 8px; }
.ask-answer { margin-bottom: 0; }
.badge.new { color: var(--accent-text); background: var(--accent); margin-right: 6px; }

/* ---- 周の結果 ---- */
.lap-progress { display: flex; gap: 12px; align-items: center; }
.lap-title { margin-bottom: 4px; }
.lap-score { font-size: 2.6rem; font-weight: 800; margin: 0; color: var(--accent); }
.lap-counts { display: flex; gap: 12px; font-weight: 800; margin: 4px 0 8px; }
.lap-counts .good { color: var(--good); }
.lap-counts .hard { color: var(--hard); }
.lap-counts .again { color: var(--again); }
.lap-diff { font-weight: 800; margin: 10px 0 2px; }
.lap-diff.up { color: var(--good); }
.lap-diff.down { color: var(--again); }
.lap-groups, .lap-misses, .lap-history { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.lap-groups li { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.lap-groups li .small { grid-column: 1 / -1; }
.lap-group-name { font-weight: 700; }
.lap-group-score { font-weight: 800; }
.lap-misses a, .lap-history a { display: block; text-decoration: none; color: inherit; border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; }
.lap-mark { font-weight: 800; margin-right: 6px; }
.lap-mark.again { color: var(--again); }
.lap-mark.hard { color: var(--hard); }
.lap-history a { display: flex; gap: 12px; align-items: center; }
.lap-history li.current a { border-color: var(--accent); background: var(--accent-soft); }

/* ---- 得意・苦手 ---- */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.tile { display: flex; flex-direction: column; align-items: center; text-align: center; }
.tile-value { font-size: 1.7rem; font-weight: 800; line-height: 1.2; }
.tile-label { font-size: .76rem; color: var(--muted); }

.split-bar { display: flex; height: 10px; border-radius: 99px; overflow: hidden; margin-bottom: 6px; background: var(--border); }
.split-bar .good { background: var(--good); }
.split-bar .hard { background: var(--hard); }
.split-bar .again { background: var(--again); }

.category-list, .weak-list { list-style: none; padding: 0; margin: 0; }
.category { padding: 14px 16px; }
.category-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.category-name { font-weight: 700; }
.category-rate { margin-left: auto; font-weight: 800; }
.category .bar { margin-bottom: 6px; }

.badge { font-size: .72rem; font-weight: 700; padding: 1px 8px; border-radius: 99px; }
.badge.weak { color: var(--again); background: var(--again-soft); }
.badge.strong { color: var(--good); background: var(--good-soft); }

.weak-list .card { padding: 0; }
.weak-list a { display: flex; flex-direction: column; gap: 2px; padding: 14px 16px; text-decoration: none; color: var(--text); }
.weak-question {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  font-weight: 600;
}
.again-text { color: var(--again); font-weight: 700; }

@media (max-width: 380px) {
  .site-nav { gap: 10px; font-size: .82rem; }
  .filter-count, .tile-value { font-size: 1.35rem; }
}
