:root {
  --bg: #f6f9ff;
  --surface: #ffffff;
  --surface-soft: #f8fbff;
  --text: #1e293b;
  --muted: #64748b;
  --line: #dbe7ff;
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --ok: #059669;
  --warn: #dc2626;
  --radius: 14px;
}
* { box-sizing: border-box; }
html { width: 100%; max-width: 100vw; overflow-x: hidden; }
body { margin: 0; position: relative; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans JP", sans-serif; background: var(--bg); color: var(--text); overflow-x: hidden; max-width: 100vw; }
.app { max-width: 1280px; margin: 0 auto; padding: 20px 16px 28px; overflow-x: hidden; }
.header { display:flex; justify-content:space-between; align-items:center; margin-bottom: 16px; }
.brand { font-size: 1.25rem; font-weight: 800; color: #152b66; }
.view { display:none; }
.view.active { display:block; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 10px 30px rgba(37,99,235,0.06); }
.hero { padding: 40px 32px; display:grid; gap:20px; background:linear-gradient(135deg, #eef4ff 0%, #e4edff 100%); }
.hero h1 { margin:0; font-size: clamp(1.5rem, 2.6vw, 2.2rem); }
.hero p { margin:0; color: var(--muted); }
.university-card-list { display:flex; flex-direction:column; gap:10px; }
.university-card { display:flex; align-items:center; gap:14px; background:#fff; border:1px solid #bfd3ff; border-radius:12px; padding:14px 18px; }
.university-card-name { font-weight:600; font-size:1rem; min-width:120px; }
.university-card-tracks { display:flex; gap:8px; flex-wrap:wrap; }
.track-btn { padding:8px 18px; font-size:0.9rem; }
select, input, button { border-radius: 10px; border:1px solid #bfd3ff; font: inherit; }
select, input { width:100%; padding: 11px 12px; background:#fff; }
button { padding: 11px 16px; cursor:pointer; }
.primary { background: var(--brand); color: #fff; border-color:var(--brand); }
.primary:hover { background: var(--brand-dark); }
.secondary { background:#fff; color: var(--brand-dark); }
.catalog { margin-top: 16px; padding: 16px; }
.catalog-head { display:flex; justify-content:space-between; align-items:center; gap:10px; }

.catalog-title { margin:0; font-size:1.05rem; color:#1e3a8a; }
.catalog-subtitle { margin:4px 0 0; font-size:0.88rem; color:var(--muted); }
.year-nav { margin-top: 14px; display:flex; flex-direction:column; gap:8px; }
.decade-jumps { display:flex; flex-wrap:wrap; gap:6px; }
.decade-btn { padding: 6px 12px; font-size: 0.82rem; border-radius: 999px; }
.year-select { width: auto; min-width: 160px; padding: 8px 12px; font-size: 0.88rem; }
.year-list { margin-top: 14px; display:grid; gap:12px; }
.year-card { border:1px solid var(--line); background:var(--surface-soft); border-radius: 12px; padding: 12px; }
.year-title { margin:0 0 4px; font-size: 1.05rem; color:#1e3a8a; }
.year-meta { font-size:0.78rem; color:var(--muted); margin-bottom:10px; }
.problem-buttons { display:flex; flex-wrap:wrap; gap:8px; }
.problem-btn { background:#fff; border:1px solid #b8cdfd; color:#2346a6; padding:10px 14px; border-radius: 999px; font-size: 0.9rem; font-weight:600; }
.problem-btn:hover { background:#edf4ff; }

.practice-layout { display:grid; grid-template-columns: minmax(0,1fr); gap:16px; width: 100%; }
.practice-layout > * { min-width: 0; }
.problem-pane { padding: 16px; }
.meta { display:flex; flex-wrap:wrap; gap:8px; margin-bottom:10px; color:var(--muted); font-size:0.86rem; }
.pill { background:#edf4ff; border:1px solid #cddfff; color:#2452bf; border-radius:999px; padding:4px 10px; }
.img-wrap { background:#fff; border:1px solid var(--line); border-radius: 12px; padding: 12px; width: 100%; overflow: hidden; box-sizing: border-box; }
.problem-pane { overflow: hidden; }
.no-image-notice { padding: 12px 4px; color: var(--muted); font-size: 0.88rem; line-height: 1.7; }
.no-image-notice p { margin: 0 0 6px; }
.btn-search-problem { margin-top: 10px; padding: 7px 16px; background: #2452bf; color: #fff; border: none; border-radius: 8px; font-size: 0.88rem; cursor: pointer; }
.btn-search-problem:hover { background: #1a3ea0; }
#image-modal { position:fixed; inset:0; background:rgba(0,0,0,0.92); z-index:9999; display:flex; align-items:center; justify-content:center; overflow:auto; touch-action:pan-x pan-y; }
#image-modal.hidden { display:none; }
#image-modal-img { max-width:100%; max-height:100%; object-fit:contain; touch-action:pinch-zoom; }
#image-modal-close { position:fixed; top:12px; right:16px; background:rgba(255,255,255,0.15); color:#fff; border:none; border-radius:50%; width:36px; height:36px; font-size:1.1rem; cursor:pointer; display:flex; align-items:center; justify-content:center; }
.pane-actions { margin-top:14px; display:flex; gap:8px; align-items:center; justify-content:space-between; flex-wrap:wrap; }
.pane-nav { display:flex; gap:8px; flex-wrap:wrap; }

.study-pane { display:flex; flex-direction:column; min-height:50vh; }
.tabs { display:flex; padding:8px; gap:4px; background:#f0f5ff; border-radius:12px 12px 0 0; }
.tab-btn { flex:1; border:none; background:transparent; padding:9px 12px; color:var(--muted); font-weight:700; border-radius:8px; transition:background 0.15s; }
.tab-btn.active { color:#fff; background:var(--brand); box-shadow:0 2px 6px rgba(37,99,235,0.25); }
.tab-content { display:none; padding:16px; overflow-x: hidden; overflow-y: auto; }
.exp-reveal-btn { width: 100%; margin-bottom: 10px; font-weight: 600; }
.tab-content.active { display:block; }
#tab-qa.active { display:flex; flex-direction:column; }
.status { background:#f8fbff; border:1px solid var(--line); color:var(--muted); border-radius:10px; padding:10px; margin-bottom:10px; white-space: pre-wrap; }
.error { border-color:#fecaca; color:var(--warn); background:#fef2f2; }
.upload { border:2px dashed #c6d8ff; border-radius:10px; padding:18px; text-align:center; background:#f8fbff; cursor:pointer; }
.upload:hover { border-color:var(--brand); }
.upload.drag-over { border-color:var(--brand); background:#eff6ff; }
#preview-list { display:flex; flex-wrap:wrap; gap:8px; margin-top:10px; }
.preview-item { position:relative; display:inline-block; }
.preview-item img { max-width:180px; max-height:180px; border-radius:8px; display:block; }
.remove-preview { position:absolute; top:4px; right:4px; background:rgba(0,0,0,0.55); color:#fff; border:none; border-radius:50%; width:22px; height:22px; cursor:pointer; font-size:12px; line-height:1; display:flex; align-items:center; justify-content:center; }
.remove-preview:hover { background:rgba(200,0,0,0.8); }
.chat-history { flex:1; min-height:220px; border:1px solid var(--line); border-radius:10px; padding:10px; display:flex; flex-direction:column; gap:8px; overflow:auto; background:#fdfefe; }
.chat-msg { max-width:88%; padding:10px; border-radius:10px; font-size:0.9rem; white-space:pre-wrap; }
.chat-msg.user { align-self:flex-end; background:var(--brand); color:#fff; }
.chat-msg.ai { align-self:flex-start; background:#eef4ff; color:#1e3a8a; }
.chat-input { display:flex; gap:8px; margin-top:10px; }
.chat-input input { border-radius:20px; padding:10px 16px; background:#f8fbff; }
#btn-send-chat { border-radius:20px; flex-shrink:0; }
.chat-mode-selector { display:flex; gap:6px; margin-bottom:8px; }
.mode-btn { flex:1; padding:6px 4px; border:1px solid var(--line); border-radius:6px; background:#f8fbff; color:var(--muted); cursor:pointer; font-size:0.82rem; }
.mode-btn.active { background:var(--brand); color:#fff; border-color:var(--brand); }
.mode-btn:disabled { opacity:0.5; cursor:default; }
.grade-result-item { display:grid; gap:3px; background:#f8fbff; border:1px solid var(--line); border-radius:10px; padding:10px; margin-bottom:10px; }
.grade-result-key { font-size:.75rem; font-weight:700; color:var(--brand); letter-spacing:.03em; }
.grade-result-val { line-height:1.7; color:var(--text); }
.grade-list { margin:4px 0 0 0; padding-left:18px; }
.grade-list li { margin-bottom:6px; line-height:1.7; }
.grade-clarification { margin-top: 12px; border: 1px solid #bfd3ff; border-radius: 12px; background: #f8fbff; padding: 14px; display: grid; gap: 10px; }
.grade-clarification-label { font-size: 0.78rem; font-weight: 700; letter-spacing: 0.04em; color: var(--brand); }
.grade-clarification-reason { color: #1e3a8a; line-height: 1.7; font-weight: 600; }
.grade-clarification-prompt { color: var(--text); line-height: 1.7; }
.grade-clarification textarea { min-height: 92px; resize: vertical; border-radius: 10px; padding: 10px 12px; background: #fff; }
.grade-clarification-note { font-size: 0.84rem; color: var(--muted); line-height: 1.6; }

.chat-msg .katex-display { margin: 0.5em 0; overflow-x: auto; }

.md-content { line-height: 1.8; color: var(--text); overflow-wrap: break-word; word-break: break-word; min-width: 0; }
.md-content h1, .md-content h2, .md-content h3 { margin: 1.2em 0 0.4em; color: #1e3a8a; }
.md-content h2 { font-size: 1.05rem; border-bottom: 1px solid var(--line); padding-bottom: 4px; }
.md-content h3 { font-size: 0.97rem; }
.md-content p { margin: 0.6em 0; }
.md-content ul, .md-content ol { padding-left: 1.4em; margin: 0.4em 0; }
.md-content li { margin-bottom: 4px; }
.md-content strong { color: #1e293b; }
.md-content .katex-display { margin: 0.8em 0; overflow-x: auto; max-width: 100%; }
.md-content .katex { max-width: 100%; }
.md-content table { display: block; overflow-x: auto; max-width: 100%; border-collapse: collapse; }
.md-content table th, .md-content table td { border: 1px solid var(--line); padding: 6px 10px; }
.katex-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: calc(100vw - 60px); padding: 0.3em 0; }

.hidden { display:none !important; }
body.auth-pending .app { display:none; }
#auth-loading { min-height:100vh; display:flex; align-items:center; justify-content:center; color:#334155; font-weight:700; }
.header-right { display:flex; align-items:center; gap:8px; }
.user-chip { background:#eef4ff; border:1px solid #cddfff; color:#1e3a8a; padding:6px 10px; border-radius:999px; font-size:0.8rem; font-weight:600; }

@media (max-width: 1024px) {
  .study-pane { min-height: auto; overflow: hidden; }
  .tab-content { max-width: 100%; }
}
@media (max-width: 760px) {
  .university-card { flex-direction:column; align-items:flex-start; }
  .hero { padding:20px; }
}
/* Spinner */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner { display:inline-block; width:13px; height:13px; border:2px solid #dbe7ff; border-top-color:var(--brand); border-radius:50%; animation:spin 0.75s linear infinite; vertical-align:middle; margin-right:6px; }

/* Problem attempt badges */
.problem-btn.solved { border-color:#86efac; color:#15803d; background:#f0fdf4; }
.problem-btn.solved::after { content:' ✓'; font-size:0.8em; }
.problem-btn.attempted { border-color:#fed7aa; color:#c2410c; background:#fff7ed; }
.problem-btn.attempted::after { content:' △'; font-size:0.8em; }

/* Explanation TOC */
.exp-toc { background:#f8fbff; border:1px solid var(--line); border-radius:10px; padding:10px 14px; margin-bottom:14px; }
.exp-toc-title { font-size:0.75rem; font-weight:700; color:var(--muted); margin:0 0 6px; letter-spacing:0.05em; }
.exp-toc-list { margin:0; padding:0; list-style:none; display:flex; flex-wrap:wrap; gap:4px 16px; }
.exp-toc-list li.h3 { padding-left:10px; }
.exp-toc-list a { color:var(--brand); text-decoration:none; font-size:0.84rem; }
.exp-toc-list a:hover { text-decoration:underline; }

/* ── モード選択 ─────────────────── */
.mode-selector { display:flex; gap:12px; flex-wrap:wrap; }
.mode-card { flex:1; min-width:180px; text-align:left; padding:16px 18px; background:#fff; border:2px solid var(--line); border-radius:14px; cursor:pointer; transition:border-color 0.15s, box-shadow 0.15s; }
.mode-card:hover { border-color:var(--brand); box-shadow:0 2px 10px rgba(37,99,235,0.12); }
.mode-card.active { border-color:var(--brand); background:#eef4ff; box-shadow:0 2px 10px rgba(37,99,235,0.15); }
.mode-card-title { font-size:1rem; font-weight:700; color:var(--brand); margin-bottom:4px; }
.mode-card-desc { font-size:0.82rem; color:var(--muted); }

/* ── 基礎問題カタログ ────────────── */
/* ── 基礎問題 科目アコーディオン (案A) ── */
.basic-subject-card { flex-direction:column; align-items:stretch; }
.basic-subject-header { display:flex; align-items:center; gap:14px; }
.basic-subject-expand-btn { margin-left:auto; white-space:nowrap; }
.basic-subject-panel { margin-top:12px; display:grid; gap:12px; }

.basic-unit-list { margin-top:14px; display:grid; gap:14px; }
.basic-unit-section { border:1px solid var(--line); background:var(--surface-soft); border-radius:12px; padding:12px 14px; }
.basic-unit-title { margin:0 0 10px; font-size:1rem; color:#1e3a8a; font-weight:700; }
.basic-topic-buttons { display:flex; flex-wrap:wrap; gap:8px; }
.basic-topic-btn { background:#fff; border:1px solid #b8cdfd; color:#2346a6; padding:8px 14px; border-radius:999px; font-size:0.88rem; font-weight:600; cursor:pointer; }
.basic-topic-btn:hover { background:#edf4ff; }

/* ── 基礎問題 問題画像 ───────────── */
#problem-image { max-width:100%; display:block; border-radius:8px; }

/* ── マイリスト チェックボックス ── */
.mylist-check { display:inline-flex; align-items:center; gap:5px; font-size:.85rem; color:#1d4ed8; cursor:pointer; user-select:none; padding:6px 12px; border:1px solid #bfd3ff; border-radius:8px; background:#fff; font-weight:600; }
.mylist-check input[type="checkbox"] { width:15px; height:15px; cursor:pointer; accent-color:#2563eb; flex-shrink:0; }

@media (max-width: 640px) {
  .header { flex-direction: column; align-items: flex-start; gap: 6px; }
  .header-right { flex-wrap: wrap; gap: 4px; }
  .header-right a, .header-right button { padding: 6px 8px; font-size: 0.82rem; }
  .user-chip { max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
