* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  background: #fdf8f4;
  min-height: 100vh;
  padding: 20px 16px 40px;
  color: #1e293b;
}
.container { max-width: 1040px; margin: 0 auto; }

/* ===== 共通 ===== */
.card {
  background: #fff;
  border-radius: 20px;
  border: 1px solid #e2e8f0;
  padding: 24px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.06);
}
.chip-group { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 5px 12px; border-radius: 999px;
  font-size: 11px; font-weight: 700; border: none; cursor: pointer;
  background: #f1f5f9; color: #64748b; transition: all .15s;
}
.chip:hover { background: #e2e8f0; }
.chip.active { background: #f97316; color: #fff; }
.chip-sm {
  padding: 5px 12px; border-radius: 999px;
  font-size: 11px; font-weight: 700; border: none; cursor: pointer;
  background: #f1f5f9; color: #64748b; transition: all .15s;
}
.chip-sm:hover { background: #e2e8f0; }
.chip-sm.active { background: #f97316; color: #fff; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field-label { font-size: 11px; font-weight: 700; color: #94a3b8; }
.select {
  background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 12px;
  padding: 10px 16px; font-size: 13px; font-weight: 700; color: #1e293b;
  outline: none; cursor: pointer; max-width: 360px; width: 100%;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2.5'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; padding-right: 36px;
}
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 9px; border: none; border-radius: 14px;
  font-size: 11px; font-weight: 900; cursor: pointer; transition: all .15s;
}
.btn:disabled { opacity: 0.65; cursor: not-allowed; }
.btn-primary { background: #f87171; color: #fff; box-shadow: 0 4px 16px rgba(248,113,113,.25); padding: 15px; font-size: 14px; }
.btn-primary:hover:not(:disabled) { background: #ef4444; }
.btn-orange { background: #f97316; color: #fff; }
.btn-orange:hover:not(:disabled) { background: #ea6c0a; }
.btn-white { background: #fff; color: #64748b; border: 1px solid #e2e8f0; font-size: 10px; padding: 9px; }
.btn-white:hover { background: #f8fafc; }
.btn-red { background: #ef4444; color: #fff; font-size: 10px; padding: 8px; }
.btn-red:hover { background: #dc2626; }
.spinner {
  width: 18px; height: 18px;
  border: 2.5px solid rgba(255,255,255,.3); border-top-color: #fff;
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.hidden { display: none !important; }
.fade-in { animation: fadeIn .25s ease; }
@keyframes fadeIn { from { opacity:0; transform: translateY(8px); } to { opacity:1; transform: translateY(0); } }

/* ===== セレクター ===== */
.widget-title {
  display: flex; align-items: center; gap: 8px;
  font-size: 16px; font-weight: 900; margin-bottom: 20px;
}
.dot { width: 10px; height: 10px; background: #f97316; border-radius: 50%; display: inline-block; }
.detail-toggle {
  background: #f1f5f9; border: 1px solid #e2e8f0; border-radius: 10px; cursor: pointer;
  font-size: 11px; font-weight: 700; color: #64748b;
  display: flex; align-items: center; justify-content: center; gap: 5px;
  padding: 7px 14px; margin-bottom: 4px; width: 100%;
  transition: background .15s, color .15s;
}
.detail-toggle:hover { background: #e2e8f0; color: #334155; }
.detail-toggle.open { background: #e2e8f0; color: #334155; }
.detail-toggle .arrow { transition: transform .2s; display: inline-block; }
.detail-toggle.open .arrow { transform: rotate(180deg); }
.detail-panel {
  border-top: 1px solid #f1f5f9; padding-top: 14px; margin-top: 4px;
  display: grid; grid-template-columns: 1fr 1fr; gap: 14px;
}
.detail-field { display: flex; align-items: center; gap: 8px; }
.detail-field-label { font-size: 11px; font-weight: 700; color: #94a3b8; width: 72px; flex-shrink: 0; }
.select-sm {
  background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 10px;
  padding: 6px 12px; font-size: 12px; font-weight: 700; color: #1e293b; outline: none; cursor: pointer;
}
@media (max-width:480px) {
  .detail-panel { grid-template-columns: 1fr; }
  body { font-size: 13px; }
  .widget-title { font-size: 14px; }
  .field-label { font-size: 10px; }
  .chip { font-size: 9px; padding: 3px 7px; }
  .chip-sm { font-size: 10px; padding: 4px 9px; }
  .detail-toggle { font-size: 10px; padding: 6px 12px; }
  .detail-field-label { font-size: 10px; width: 60px; }
  .btn { font-size: 12px; padding: 10px; }
  .btn-primary { font-size: 14px; padding: 15px; }
  .btn-save-data { font-size: 12px; padding: 10px; }
  #next-btn { font-size: 13px; padding: 12px; }
  .question-text { font-size: 14px; }
  .opt-btn { font-size: 13px; padding: 12px 14px; }
  .quiz-timer { font-size: 14px; }
  .coverage-title { font-size: 10px; }
  .coverage-year { font-size: 9px; }
  .coverage-pct { font-size: 10px; }
  .result-stat .num { font-size: 22px; }
  .review-q { font-size: 12px; }
  .review-exp { font-size: 11px; }
  .card { padding: 16px; }
}

/* データ保存ボタン */
.btn-save-data {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 9px; border-radius: 14px;
  font-size: 11px; font-weight: 900;
  background: linear-gradient(135deg, #f97316, #fb923c);
  color: #fff;
  box-shadow: 0 4px 16px rgba(249,115,22,.3);
  transition: opacity .15s;
}
.btn-save-data:hover { opacity: .88; }

/* 出題率ボックス */
.coverage-box {
  background: #fffaf5;
  border: 1px solid #fde8cc;
  border-radius: 16px;
  padding: 12px 14px;
}
.coverage-title {
  font-size: 11px; font-weight: 900; color: #c2410c; margin-bottom: 8px;
  display: flex; flex-direction: column; gap: 3px;
}
.coverage-title-top {
  display: flex; align-items: center; gap: 6px;
}
.coverage-row {
  display: flex; align-items: center; gap: 8px; margin-bottom: 5px;
}
.coverage-row:last-child { margin-bottom: 0; }
.coverage-year { font-size: 10px; font-weight: 700; color: #64748b; width: 40px; flex-shrink: 0; }
.coverage-bar-wrap { flex: 1; height: 7px; background: #fde8cc; border-radius: 999px; overflow: hidden; }
.coverage-bar { height: 100%; border-radius: 999px; background: linear-gradient(90deg, #fb923c, #fdba74); transition: width .6s ease; }
.coverage-pct { font-size: 11px; font-weight: 900; color: #ea580c; width: 40px; text-align: right; flex-shrink: 0; }
.coverage-subject-tabs { display: flex; gap: 6px; margin-bottom: 8px; }
.coverage-subject-tab {
  padding: 3px 10px; border-radius: 999px; font-size: 10px; font-weight: 700;
  border: 1px solid #fde8cc; background: #fff; color: #94a3b8; cursor: pointer;
}
.coverage-subject-tab.active { background: #f97316; color: #fff; border-color: #f97316; }

/* ===== スケルトン ===== */
@keyframes shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position:  200% 0; }
}
.skeleton {
  background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 50%, #f1f5f9 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite linear;
  border-radius: 4px;
  display: inline-block;
}
.skel-chip   { height: 27px; border-radius: 999px; }
.skel-year   { width: 36px; height: 13px; flex-shrink: 0; }
.skel-bar    { flex: 1; height: 7px; border-radius: 999px; }
.skel-pct    { width: 34px; height: 13px; flex-shrink: 0; }

/* 単元アコーディオン */
.unit-chips-wrap {
  overflow: hidden;
  transition: max-height .3s ease;
}
.unit-chips-wrap.collapsed { mask-image: linear-gradient(to bottom, black 60%, transparent 100%); }
.unit-more-btn {
  background: none; border: 1px solid #e2e8f0; border-radius: 999px; cursor: pointer;
  font-size: 11px; font-weight: 700; color: #94a3b8;
  display: flex; align-items: center; justify-content: center; gap: 3px;
  margin: 6px auto 0; padding: 5px 20px;
  transition: color .15s, border-color .15s;
}
.unit-more-btn:hover { color: #64748b; border-color: #cbd5e1; }
.unit-more-arrow { transition: transform .2s; display: inline-block; }
.unit-more-arrow.open { transform: rotate(180deg); }

/* ===== クイズ ===== */
#screen-quiz .card { padding: 0; overflow: hidden; }
.quiz-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px; border-bottom: 1px solid #f1f5f9; background: #f8fafc;
}
.quiz-pos { font-size: 11px; font-weight: 700; color: #94a3b8; }
.quiz-timer { display: flex; align-items: center; gap: 4px; font-size: 13px; font-weight: 900; color: #475569; }
.quiz-timer.urgent { color: #ef4444; }
.timer-bar-wrap { height: 3px; background: #f1f5f9; }
.timer-bar { height: 100%; background: #f97316; transition: width .9s linear; }
.quiz-body { padding: 12px 14px; }
.tags { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.tag {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 10px; font-weight: 700;
}
.tag-freq-hot { background: #fee2e2; color: #ef4444; }
.tag-freq-mid { background: #ffedd5; color: #ea580c; }
.tag-year { background: #dbeafe; color: #2563eb; }
.tag-unit { background: #f1f5f9; color: #64748b; }
.tag-grade { background: #f1f5f9; color: #64748b; }
.tag-acc { background: #d1fae5; color: #059669; display: flex; align-items: center; gap: 3px; }
.question-text { font-size: 14px; font-weight: 700; line-height: 1.6; margin-bottom: 10px; }
.options { display: grid; gap: 6px; }
.opt-btn {
  padding: 10px 13px; border-radius: 11px; border: 2px solid #e2e8f0;
  font-size: 13px; font-weight: 700; text-align: left; cursor: pointer;
  background: #fff; color: #334155; transition: all .12s;
}
.opt-btn:hover:not(:disabled) { border-color: #f97316; background: #fff7ed; }
.opt-btn:disabled { cursor: default; }
.opt-btn.correct { border-color: #10b981; background: #ecfdf5; color: #065f46; }
.opt-btn.wrong   { border-color: #fca5a5; background: #fff1f1; color: #fca5a5; }
.opt-btn.dim     { border-color: #f1f5f9; background: #f8fafc; color: #cbd5e1; opacity: .6; }
.answer-feedback { margin-top: 10px; padding-top: 10px; border-top: 1px solid #f1f5f9; animation: fadeIn .2s; }
.feedback-label { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 900; margin-bottom: 8px; }
.feedback-label.ok  { color: #10b981; }
.feedback-label.ng  { color: #ef4444; }
.feedback-label.to  { color: #ef4444; }
.explanation { background: #f8fafc; border-radius: 10px; padding: 10px 12px; font-size: 12px; color: #475569; line-height: 1.6; margin-bottom: 10px; }

/* ===== リザルト ===== */
.result-card {
  border-radius: 18px; border: 1px solid; padding: 16px; margin-bottom: 12px;
}
.result-great { background: linear-gradient(135deg,#ecfdf5,#d1fae5); border-color: #6ee7b7; }
.result-ok    { background: linear-gradient(135deg,#fffbeb,#fef3c7); border-color: #fcd34d; }
.result-ng    { background: linear-gradient(135deg,#f8fafc,#f1f5f9); border-color: #cbd5e1; }
.result-message { font-size: 11px; font-weight: 700; color: #475569; text-align: center; margin-bottom: 10px; }
.result-stats { display: flex; justify-content: center; gap: 16px; margin-bottom: 14px; }
.result-stat { text-align: center; }
.result-stat .num { font-size: 22px; font-weight: 900; color: #1e293b; }
.result-stat .num span { font-size: 12px; font-weight: 700; color: #94a3b8; }
.result-stat .lbl { font-size: 10px; font-weight: 700; color: #94a3b8; }
.result-stat + .result-stat { border-left: 1px solid #e2e8f0; padding-left: 16px; }
.mistakes-box {
  background: #fff1f2; border: 1px solid #fecaca; border-radius: 12px; padding: 10px; margin-bottom: 10px;
}
.mistakes-box .box-title { display: flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 900; color: #dc2626; margin-bottom: 4px; }
.mistakes-box .box-sub { font-size: 10px; font-weight: 700; color: #ef4444; margin-bottom: 8px; }
.hard-box {
  background: #f0fdf4; border: 1px solid #bbf7d0; border-radius: 12px; padding: 10px; margin-bottom: 10px;
}
.hard-box .box-title { display: flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 900; color: #059669; margin-bottom: 8px; }
.mistake-item, .hard-item {
  display: flex; flex-direction: column; gap: 4px;
  background: #fff; border-radius: 10px; padding: 8px 10px; margin-bottom: 5px;
  border: 1px solid #fecaca;
}
.mistake-item .tag, .hard-item .tag { align-self: flex-start; }
.hard-item { border-color: #bbf7d0; }
.item-q { font-size: 11px; font-weight: 700; color: #334155; line-height: 1.5; }
.btn-row { display: flex; gap: 8px; }
.btn-row .btn { flex: 1; }

/* 振り返り */
.review-toggle {
  width: 100%; display: flex; align-items: center; justify-content: space-between;
  padding: 9px 12px; background: none; border: none; cursor: pointer;
  font-size: 11px; font-weight: 900; color: #475569;
}
.review-toggle:hover { background: #f8fafc; }
.review-arrow { transition: transform .2s; }
.review-arrow.open { transform: rotate(180deg); }
.review-list { border-top: 1px solid #f1f5f9; }
.review-item {
  display: flex; gap: 8px; align-items: flex-start;
  padding: 10px 14px; border-bottom: 1px solid #f1f5f9;
}
.review-icon { width: 16px; height: 16px; flex-shrink: 0; margin-top: 1px; }
.review-q { font-size: 11px; font-weight: 700; color: #334155; margin-bottom: 3px; line-height: 1.5; }
.review-ans { font-size: 10px; color: #94a3b8; }
.review-ans .correct-ans { color: #059669; font-weight: 700; }
.review-ans .wrong-ans   { color: #ef4444; font-weight: 700; }
.review-acc { font-size: 10px; color: #94a3b8; margin-top: 3px; display: flex; align-items: center; gap: 3px; }
.review-exp { background: #f8fafc; border-radius: 8px; padding: 8px 10px; font-size: 11px; color: #475569; line-height: 1.5; margin-top: 6px; }