/* =========================================================
   まなびクエスト  — モバイルファースト / タブレット / PC
   ========================================================= */
:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #f0f3fa;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-soft: #eef2ff;
  --accent: #f59e0b;
  --success: #10b981;
  --danger: #ef4444;
  --xp: linear-gradient(90deg, #818cf8, #c084fc);
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 2px 10px rgba(31, 41, 55, .06);
  --nav-h: 64px;
  --top-h: 56px;
  --side-w: 232px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Maru Gothic ProN", "Hiragino Sans", "BIZ UDPGothic", "Noto Sans JP", "Yu Gothic", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
img, canvas, svg { max-width: 100%; }
h1, h2, h3 { line-height: 1.35; margin: 0 0 .6em; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .8em; }
small, .muted { color: var(--muted); }
.nowrap { white-space: nowrap; }

/* ---------- 枠組み ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--top-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; color: var(--text); font-size: 1.05rem; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; background: var(--xp); color: #fff; font-size: 18px; }
.topbar .spacer { flex: 1; }
.top-user { display: flex; align-items: center; gap: 8px; color: var(--text); }
.top-user .avatar { font-size: 22px; }
.top-user .lv { font-size: .75rem; font-weight: 700; color: var(--primary-dark); background: var(--primary-soft); padding: 2px 8px; border-radius: 999px; }
.top-streak { font-weight: 700; color: #ea580c; font-size: .9rem; }

.layout { display: block; }
.main { padding: 16px 16px calc(var(--nav-h) + 24px); max-width: 1180px; margin: 0 auto; width: 100%; min-width: 0; }

/* スマホ: 下部タブバー */
.sidenav { display: none; }
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: .68rem; color: var(--muted); gap: 2px; text-decoration: none;
}
.tabbar a .ico { font-size: 1.35rem; line-height: 1; }
.tabbar a.active { color: var(--primary-dark); font-weight: 700; }

/* タブレット以上: 左サイドナビ */
@media (min-width: 768px) {
  .tabbar { display: none; }
  .layout { display: grid; grid-template-columns: var(--side-w) 1fr; }
  .sidenav {
    display: block; position: sticky; top: var(--top-h);
    height: calc(100vh - var(--top-h)); overflow-y: auto;
    padding: 16px 12px; background: var(--surface); border-right: 1px solid var(--border);
  }
  .sidenav a {
    display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px;
    color: var(--text); font-weight: 600; text-decoration: none; margin-bottom: 2px;
  }
  .sidenav a:hover { background: var(--surface-2); }
  .sidenav a.active { background: var(--primary-soft); color: var(--primary-dark); }
  .sidenav .ico { width: 24px; text-align: center; font-size: 1.15rem; }
  .sidenav .section { font-size: .72rem; color: var(--muted); margin: 14px 12px 6px; font-weight: 700; letter-spacing: .05em; }
  .main { padding: 24px 24px 40px; }
  h1 { font-size: 1.6rem; }
}
@media (min-width: 768px) and (max-width: 1023px) {
  :root { --side-w: 200px; }
}

/* ---------- 部品 ---------- */
.card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 16px; border: 1px solid rgba(0,0,0,.02);
}
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.card-head h2, .card-head h3 { margin: 0; }

.grid { display: grid; gap: 16px; }
.grid > .card { margin-bottom: 0; }
.grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
.stack > * + * { margin-top: 16px; }
@media (min-width: 600px) {
  .grid-3, .grid-4 { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 900px) {
  .grid-2 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(3, 1fr); }
  .grid-4 { grid-template-columns: repeat(4, 1fr); }
}
.mb-0 { margin-bottom: 0 !important; }
.mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 16px; min-height: 44px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-weight: 700; font-size: .95rem;
  cursor: pointer; text-decoration: none; font-family: inherit;
}
.btn:hover { text-decoration: none; background: var(--surface-2); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-danger { color: var(--danger); border-color: #fecaca; }
.btn-sm { min-height: 34px; padding: 6px 12px; font-size: .85rem; border-radius: 10px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .5; pointer-events: none; }
form.button_to { display: inline; }

.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px;
  font-size: .75rem; font-weight: 700; background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.chip-primary { background: var(--primary-soft); color: var(--primary-dark); }
.chip-success { background: #d1fae5; color: #047857; }
.chip-warn { background: #fef3c7; color: #b45309; }
.chip-danger { background: #fee2e2; color: #b91c1c; }

.flash { padding: 12px 16px; border-radius: 12px; margin-bottom: 16px; font-weight: 600; }
.flash-notice { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.flash-alert { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }

/* 進捗バー */
.bar { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 999px; background: var(--xp); transition: width .6s ease; }
.bar.thick { height: 14px; }
.bar.thin { height: 6px; }

/* ヒーロー（プレイヤーカード） */
.hero {
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 55%, #ec4899 100%);
  color: #fff; border-radius: 20px; padding: 18px; margin-bottom: 16px; box-shadow: 0 8px 24px rgba(99,102,241,.25);
}
.hero a { color: #fff; }
.hero .avatar-xl { font-size: 48px; line-height: 1; background: rgba(255,255,255,.2); width: 72px; height: 72px; display: grid; place-items: center; border-radius: 20px; flex: none; }
.hero .who { display: flex; gap: 14px; align-items: center; }
.hero .name { font-size: 1.2rem; font-weight: 800; }
.hero .title { opacity: .9; font-size: .85rem; }
.hero .bar { background: rgba(255,255,255,.25); margin-top: 6px; }
.hero .bar > span { background: #fde68a; }
.hero-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.hero-stats div { background: rgba(255,255,255,.15); border-radius: 12px; padding: 8px; text-align: center; }
.hero-stats b { display: block; font-size: 1.05rem; white-space: nowrap; }
@media (min-width: 600px) { .hero-stats b { font-size: 1.25rem; } }
.hero-stats small { color: rgba(255,255,255,.85); font-size: .7rem; }

/* 今日のミッション */
.mission { display: flex; align-items: center; gap: 12px; }
.mission .ring {
  --p: 0; width: 64px; height: 64px; border-radius: 50%; flex: none;
  background: conic-gradient(var(--success) calc(var(--p) * 1%), var(--surface-2) 0);
  display: grid; place-items: center;
}
.mission .ring span { background: var(--surface); width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: .85rem; }

/* パラメータ */
.params { display: grid; gap: 10px; }
.param { display: grid; grid-template-columns: 92px 1fr 36px; align-items: center; gap: 8px; font-size: .9rem; }
.param .label { font-weight: 700; white-space: nowrap; }
.param .val { text-align: right; font-weight: 800; color: var(--primary-dark); }

/* チャート */
.chart-box { position: relative; width: 100%; }
.chart-box.chart-radar { aspect-ratio: 1 / 1; max-width: 420px; margin: 0 auto; }
.chart-box.chart-bar { height: 420px; }
.chart-box.chart-line { height: 220px; }

/* ヒートマップ */
.heatmap { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 1fr); gap: 3px; overflow-x: auto; padding-bottom: 4px; }
.heatmap i { width: 13px; height: 13px; border-radius: 3px; background: #e5e7eb; display: block; }
.heatmap i.l1 { background: #c7d2fe; } .heatmap i.l2 { background: #a5b4fc; }
.heatmap i.l3 { background: #818cf8; } .heatmap i.l4 { background: #4f46e5; }
.heat-legend { display: flex; gap: 3px; align-items: center; font-size: .7rem; color: var(--muted); margin-top: 6px; }
.heat-legend i { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }

/* 教科タイル */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 600px) { .tiles { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1024px) { .tiles { grid-template-columns: repeat(4, 1fr); } }
.tile {
  display: block; background: var(--surface); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow);
  border-top: 5px solid var(--c, var(--primary)); color: var(--text); text-decoration: none;
}
.tile:hover { text-decoration: none; transform: translateY(-2px); transition: transform .15s; }
.tile .ico { font-size: 1.8rem; }
.tile .nm { font-weight: 800; margin: 4px 0; }
.tile .bar > span { background: var(--c, var(--primary)); }

/* 単元リスト */
.unit-list { list-style: none; padding: 0; margin: 0; }
.unit-list li { border-bottom: 1px solid var(--border); }
.unit-list li:last-child { border-bottom: none; }
.unit-item { display: flex; align-items: center; gap: 12px; padding: 12px 4px; color: var(--text); text-decoration: none; }
.unit-item:hover { text-decoration: none; background: var(--surface-2); border-radius: 10px; }
.unit-item .state { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; flex: none; font-size: 1rem; background: var(--surface-2); }
.unit-item .state.done { background: #d1fae5; }
.unit-item .state.wip { background: #fef3c7; }
.unit-item .body { flex: 1; min-width: 0; }
.unit-item .nm { font-weight: 700; }
.unit-item .meta { font-size: .78rem; color: var(--muted); }
.stars { color: var(--accent); letter-spacing: -1px; font-size: .8rem; }

/* 事象カード */
.phen { border-left: 4px solid var(--primary); background: var(--primary-soft); border-radius: 0 12px 12px 0; padding: 12px 14px; margin-bottom: 10px; }
.phen.solve { border-color: var(--success); background: #ecfdf5; }
.phen .scene { font-size: .75rem; font-weight: 700; color: var(--muted); }
.phen .ttl { font-weight: 800; margin: 2px 0 4px; }
.phen p { margin: 0; font-size: .9rem; }

/* ロードマップ */
.roadmap { list-style: none; margin: 0; padding: 0 0 0 8px; position: relative; }
.roadmap::before { content: ""; position: absolute; left: 25px; top: 12px; bottom: 12px; width: 3px; background: var(--border); border-radius: 3px; }
.roadmap li { position: relative; display: flex; gap: 14px; padding: 8px 0; }
.roadmap .node {
  position: relative; z-index: 1; flex: none; width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center; background: var(--surface); border: 3px solid var(--border); font-size: .9rem; font-weight: 800;
}
.roadmap li.done .node { border-color: var(--success); background: #d1fae5; }
.roadmap li.wip .node { border-color: var(--accent); background: #fef3c7; }
.roadmap li.goal .node { border-color: var(--primary); background: var(--primary); color: #fff; }
.roadmap .box { flex: 1; background: var(--surface-2); border-radius: 12px; padding: 10px 12px; min-width: 0; }
.roadmap .box.direct { background: var(--primary-soft); }
.roadmap .box a { font-weight: 700; }

/* 職業カード */
.career-card { display: flex; gap: 12px; align-items: flex-start; color: var(--text); text-decoration: none; }
.career-card:hover { text-decoration: none; }
.career-card .ico { font-size: 2rem; width: 48px; height: 48px; display: grid; place-items: center; background: var(--surface-2); border-radius: 14px; flex: none; }

/* フォーム */
.form { display: grid; gap: 14px; }
.field label { display: block; font-weight: 700; font-size: .9rem; margin-bottom: 4px; }
.field .hint { font-size: .78rem; color: var(--muted); }
input[type=text], input[type=password], input[type=email], input[type=number], input[type=date], input[type=url], input[type=search], select, textarea {
  width: 100%; padding: 11px 12px; min-height: 44px; border: 1px solid var(--border); border-radius: 12px;
  font-size: 16px; /* iOS のズーム防止 */ font-family: inherit; background: #fff; color: var(--text);
}
textarea { min-height: 90px; }
input:focus, select:focus, textarea:focus { outline: 3px solid var(--primary-soft); border-color: var(--primary); }
.errors { background: #fef2f2; color: #991b1b; border-radius: 12px; padding: 10px 14px; }
.errors ul { margin: 4px 0 0; padding-left: 20px; }
.form-row { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 600px) { .form-row { grid-template-columns: repeat(2, 1fr); } .form-row.three { grid-template-columns: repeat(3, 1fr); } }
.check-list { display: grid; gap: 6px; grid-template-columns: 1fr; }
@media (min-width: 600px) { .check-list { grid-template-columns: repeat(2, 1fr); } }
.check-list label { font-weight: 500; display: flex; gap: 8px; align-items: center; }

/* 理解度の選択（顔ボタン） */
.faces { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.faces input { position: absolute; opacity: 0; pointer-events: none; }
.faces label {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px; border-radius: 12px;
  border: 2px solid var(--border); cursor: pointer; font-size: .65rem; text-align: center; font-weight: 600; line-height: 1.3;
}
.faces label .f { font-size: 1.6rem; }
.faces input:checked + label { border-color: var(--primary); background: var(--primary-soft); }
.seg { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
@media (min-width: 600px) { .seg { grid-template-columns: repeat(4, 1fr); } }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label { border: 2px solid var(--border); border-radius: 12px; padding: 8px; text-align: center; cursor: pointer; font-weight: 700; font-size: .85rem; }
.seg input:checked + label { border-color: var(--primary); background: var(--primary-soft); color: var(--primary-dark); }

/* テーブル（スマホでは横スクロール） */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -16px; padding: 0 16px; }
table.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { padding: 10px 8px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.table th { font-size: .75rem; color: var(--muted); font-weight: 700; background: var(--surface-2); }
.table td.wrap { white-space: normal; min-width: 160px; }
.table tr:hover td { background: #fafbff; }

/* ランキング */
.rank { list-style: none; padding: 0; margin: 0; }
.rank li { display: flex; align-items: center; gap: 10px; padding: 10px 4px; border-bottom: 1px solid var(--border); }
.rank .no { width: 28px; text-align: center; font-weight: 800; color: var(--muted); }
.rank li:nth-child(1) .no { color: #d97706; } .rank li:nth-child(2) .no { color: #6b7280; } .rank li:nth-child(3) .no { color: #b45309; }
.rank .av { font-size: 1.5rem; }
.rank .nm { flex: 1; font-weight: 700; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.rank li.me { background: var(--primary-soft); border-radius: 10px; }

/* 統計タイル */
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 16px; }
@media (min-width: 900px) { .kpis { grid-template-columns: repeat(4, 1fr); } }
.kpi { background: var(--surface); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.kpi small { display: block; font-weight: 700; }
.kpi b { font-size: 1.5rem; }

/* バッジ */
.badges { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (min-width: 600px) { .badges { grid-template-columns: repeat(5, 1fr); } }
.badge-item { text-align: center; background: var(--surface-2); border-radius: 14px; padding: 12px 6px; }
.badge-item .ico { font-size: 2rem; }
.badge-item .nm { font-weight: 700; font-size: .8rem; }
.badge-item.locked { filter: grayscale(1); opacity: .45; }

/* ごほうびモーダル */
.reward-backdrop { position: fixed; inset: 0; background: rgba(17,24,39,.55); z-index: 100; display: grid; place-items: center; padding: 16px; animation: fade .2s; }
.reward { background: var(--surface); border-radius: 24px; padding: 24px; max-width: 360px; width: 100%; text-align: center; animation: pop .35s cubic-bezier(.2,1.4,.4,1); }
.reward .big { font-size: 3.2rem; }
.reward .xp { font-size: 2rem; font-weight: 900; background: var(--xp); -webkit-background-clip: text; background-clip: text; color: transparent; }
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ログイン画面 */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, #eef2ff, #fdf2f8); }
.auth-card { width: 100%; max-width: 420px; }
.auth-card .brand { justify-content: center; font-size: 1.4rem; margin-bottom: 8px; }

.pagination { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 12px; }
.pagination a, .pagination em, .pagination span.current, .pagination .page, .pagination .next, .pagination .prev, .pagination .first, .pagination .last { padding: 4px 4px; }
.pagination span a, .pagination span.current { display: inline-block; padding: 6px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); }
.pagination span.current { background: var(--primary); color: #fff; border-color: var(--primary); }

pre.code { background: #0f172a; color: #e2e8f0; padding: 12px; border-radius: 12px; overflow-x: auto; font-size: .78rem; line-height: 1.5; max-height: 420px; }
code { background: var(--surface-2); padding: 1px 6px; border-radius: 6px; font-size: .85em; }
.token-box { background: #fffbeb; border: 1px solid #fde68a; padding: 12px; border-radius: 12px; word-break: break-all; }
.empty { text-align: center; color: var(--muted); padding: 24px 8px; }
.empty .ico { font-size: 2.4rem; }
.tabs { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 12px; padding-bottom: 2px; }
.tabs a { padding: 6px 14px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); white-space: nowrap; font-weight: 700; font-size: .85rem; color: var(--text); }
.tabs a.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.legend-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; vertical-align: middle; }

/* ふりがな */
ruby rt { font-size: .55em; font-weight: 500; color: inherit; opacity: .85; letter-spacing: 0; }
.essence ruby, .ex-q ruby, .ex-steps ruby, .bubble ruby, .drill-q ruby { ruby-align: center; }
.top-toggle { border: 2px solid var(--border); background: var(--surface); color: var(--muted); border-radius: 999px; padding: 2px 10px; font-size: .78rem; font-weight: 700; cursor: pointer; line-height: 1.6; white-space: nowrap; }
.top-toggle.is-on { border-color: var(--primary); color: var(--primary); background: #eef2ff; }
.top-toggle rt { font-size: .6em; }
@media (max-width: 420px) { .top-toggle { padding: 2px 6px; font-size: .7rem; } }
