:root {
  --bg: #eef6fa;
  --sky: #c8e1ef;
  --ink: #22303a;
  --muted: #5b6b76;
  --accent: #e8a13a;
  --accent-dark: #b97a1e;
  --leaf: #f5c93f;
  --ok: #2e9e5b;
  --ng: #d9534f;
  --card: #ffffff;
  --line: #d5e4ec;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Noto Sans JP", "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic", "Yu Gothic UI", system-ui, sans-serif;
  line-height: 1.65;
  -webkit-text-size-adjust: 100%;
}

.app-header {
  background: var(--sky);
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 1px 6px rgba(34, 48, 58, 0.12);
}
.header-inner { display: flex; align-items: center; gap: 12px; max-width: 760px; margin: 0 auto; }
.header-icon { border-radius: 10px; }
.header-titles { flex: 1; min-width: 0; }
.header-titles h1 { font-size: 1.25rem; margin: 0; font-weight: 900; }
.header-sub { margin: 0; font-size: 0.8rem; color: var(--muted); }

.level-box { text-align: right; min-width: 118px; }
.level-main { font-weight: 900; font-size: 1.3rem; line-height: 1.1; }
.lv-label { font-size: 0.85rem; margin-right: 2px; }
.level-title { font-size: 0.72rem; color: var(--muted); }
.xp-bar { height: 6px; background: rgba(255,255,255,0.7); border-radius: 3px; overflow: hidden; margin: 3px 0 2px; }
.xp-fill { height: 100%; width: 0%; background: var(--accent); transition: width 0.4s; }
.xp-text { font-size: 0.68rem; color: var(--muted); }

.sync-status { max-width: 760px; margin: 4px auto 0; font-size: 0.72rem; color: var(--muted); min-height: 1em; text-align: right; }
.sync-status.offline { color: var(--accent-dark); }

main { max-width: 760px; margin: 0 auto; padding: 16px; }
footer { text-align: center; color: var(--muted); font-size: 0.75rem; padding: 8px 16px 32px; }

.unit { margin-bottom: 26px; }
.unit h2 { font-size: 1.05rem; margin: 0 0 10px; display: flex; align-items: center; gap: 8px; }
.unit-no { background: var(--leaf); border: 2px solid #8a6d1f; color: #4d3b08; border-radius: 999px; font-size: 0.75rem; font-weight: 900; padding: 1px 10px; }
.stage-list { display: grid; gap: 8px; }
.stage-btn {
  display: flex; align-items: center; gap: 10px; width: 100%;
  background: var(--card); border: 1.5px solid var(--line); border-radius: 14px;
  padding: 12px 14px; font: inherit; text-align: left; cursor: pointer; color: var(--ink);
}
.stage-btn:active { transform: scale(0.99); }
.stage-btn.locked { opacity: 0.55; cursor: not-allowed; }
.stage-num { font-weight: 900; background: var(--sky); border-radius: 8px; padding: 2px 9px; font-size: 0.85rem; white-space: nowrap; }
.stage-name { font-weight: 700; }
.stage-best { margin-left: auto; font-size: 0.8rem; color: var(--muted); white-space: nowrap; }
.badge-clear { background: var(--ok); color: #fff; border-radius: 999px; font-size: 0.7rem; font-weight: 700; padding: 1px 8px; }

.panel { background: var(--card); border: 1.5px solid var(--line); border-radius: 14px; margin-top: 8px; }
.panel summary { cursor: pointer; font-weight: 700; padding: 12px 14px; }
.panel-body { padding: 0 14px 14px; font-size: 0.9rem; }
.panel-body h2 { font-size: 0.95rem; margin: 16px 0 6px; }
.transfer-code { font-size: 1.05rem; font-weight: 900; letter-spacing: 0.06em; background: var(--bg); border: 1.5px dashed var(--accent); border-radius: 10px; padding: 10px; text-align: center; word-break: break-all; }
.code-label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 4px; }
#input-code { width: 100%; font: inherit; padding: 10px; border: 1.5px solid var(--line); border-radius: 10px; letter-spacing: 0.05em; }
.note { min-height: 1.2em; font-size: 0.85rem; }

.btn { font: inherit; font-weight: 700; border-radius: 999px; padding: 10px 20px; cursor: pointer; border: 1.5px solid var(--line); background: var(--card); color: var(--ink); }
.btn-main { background: var(--accent); border-color: var(--accent-dark); color: #fff; }
.btn-danger { color: var(--ng); border-color: var(--ng); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.btn-row.center { justify-content: center; }

.quiz-head { display: flex; align-items: center; gap: 12px; }
.quiz-meta { display: flex; flex-direction: column; font-size: 0.85rem; color: var(--muted); }
.quiz-meta #quiz-stage-name { font-weight: 700; color: var(--ink); font-size: 0.95rem; }
.progress-track { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; margin: 12px 0 4px; }
.progress-fill { height: 100%; width: 0%; background: var(--accent); transition: width 0.3s; }
.question { font-size: 1.12rem; line-height: 1.7; margin: 14px 0 16px; }
.choices { display: grid; gap: 10px; }
.choice {
  font: inherit; text-align: left; background: var(--card); color: var(--ink);
  border: 2px solid var(--line); border-radius: 14px; padding: 14px 16px; cursor: pointer; width: 100%;
}
.choice:active { transform: scale(0.99); }
.choice.correct { border-color: var(--ok); background: #e8f7ee; font-weight: 700; }
.choice.wrong { border-color: var(--ng); background: #fdecea; }
.choice:disabled { cursor: default; opacity: 0.95; }
.feedback { margin-top: 16px; background: var(--card); border: 1.5px solid var(--line); border-radius: 14px; padding: 14px 16px; }
.feedback-result { font-weight: 900; font-size: 1.05rem; margin: 0 0 4px; }
.feedback-result.ok { color: var(--ok); }
.feedback-result.ng { color: var(--ng); }
.feedback-exp { margin: 0 0 12px; font-size: 0.92rem; }

.result-card { background: var(--card); border: 1.5px solid var(--line); border-radius: 16px; padding: 20px 16px; text-align: center; }
.result-score { font-size: 2.6rem; font-weight: 900; margin: 0; }
.result-score-den { font-size: 1.2rem; color: var(--muted); }
.result-msg { font-weight: 700; margin: 4px 0; }
.result-xp { color: var(--accent-dark); font-weight: 700; margin: 4px 0 12px; min-height: 1.2em; }
.review { text-align: left; display: grid; gap: 8px; margin: 12px 0 16px; }
.review-item { border: 1.5px solid var(--line); border-radius: 10px; padding: 8px 12px; font-size: 0.85rem; }
.review-item .mark { font-weight: 900; }
.review-item .mark.ok { color: var(--ok); }
.review-item .mark.ng { color: var(--ng); }

@media (max-width: 480px) {
  .header-titles h1 { font-size: 1.05rem; }
  .level-box { min-width: 96px; }
}
