/* ===== G-Compass！ styles（設計書 §8 デザイントークン） ===== */
:root {
  --primary: #FF8A3D;
  --primary-deep: #E06A1B;
  --primary-grad: linear-gradient(135deg, #FF8A3D, #FF7A22);
  --ok: #22C55E;
  --ok-deep: #16A34A;
  --ng: #EF4444;

  --bg: #FFF8F2;
  --card: #FFFFFF;
  --ink: #1F2937;
  --sub: #9C8A78;
  --line: #F0E2D2;
  --soft: #F9F4EC;
  --chip-bg: #FFEDD9;
  --seg-bg: #F1E4D6;
  --shadow: 0 4px 16px rgba(0,0,0,.08);
  --shadow-sm: 0 2px 6px rgba(80,50,20,.06);

  --r-card: 20px;
  --r-btn: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111827; --card: #1F2937; --ink: #F9FAFB; --sub: #9CA3AF;
    --line: #374151; --soft: #374151; --chip-bg: #3A2A1A; --seg-bg: #26303f;
    --shadow: 0 4px 16px rgba(0,0,0,.35); --shadow-sm: 0 2px 6px rgba(0,0,0,.25);
  }
}
:root[data-theme="light"] {
  --bg: #FFF8F2; --card: #FFFFFF; --ink: #1F2937; --sub: #9C8A78;
  --line: #F0E2D2; --soft: #F9F4EC; --chip-bg: #FFEDD9; --seg-bg: #F1E4D6;
  --shadow: 0 4px 16px rgba(0,0,0,.08); --shadow-sm: 0 2px 6px rgba(80,50,20,.06);
}
:root[data-theme="dark"] {
  --bg: #111827; --card: #1F2937; --ink: #F9FAFB; --sub: #9CA3AF;
  --line: #374151; --soft: #374151; --chip-bg: #3A2A1A; --seg-bg: #26303f;
  --shadow: 0 4px 16px rgba(0,0,0,.35); --shadow-sm: 0 2px 6px rgba(0,0,0,.25);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, "Hiragino Sans", "Hiragino Kaku Gothic ProN", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
  overscroll-behavior: none;
  touch-action: manipulation;
}
button { font-family: inherit; cursor: pointer; }
.num { font-variant-numeric: tabular-nums; }

/* ===== app container / screens ===== */
#app {
  max-width: 440px;
  margin: 0 auto;
  min-height: 100dvh;
  position: relative;
}
.screen {
  display: none;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  padding:
    calc(env(safe-area-inset-top) + 14px)
    calc(env(safe-area-inset-right) + 16px)
    calc(env(safe-area-inset-bottom) + 18px)
    calc(env(safe-area-inset-left) + 16px);
}
.screen.active { display: flex; }
/* ホームは小型端末で内容が溢れたらスクロール許可。他画面は内部にスクロール領域を持つ */
#screen-home { overflow-y: auto; }

.applogo {
  font-size: 14px; font-weight: 800; color: var(--primary-deep);
  letter-spacing: .03em; padding: 0 2px 10px; display: flex;
  align-items: center; justify-content: space-between;
}
.applogo .theme-toggle {
  font-size: 16px; background: none; border: none; padding: 4px 6px; color: var(--sub);
}
.sec-label {
  font-size: 11px; font-weight: 800; color: var(--sub);
  letter-spacing: .1em; margin: 16px 2px 8px;
}

/* ===== S1 home ===== */
.countdown {
  background: linear-gradient(135deg, #FF8A3D, #FFA45C);
  color: #fff; border-radius: 16px; padding: 13px 16px;
  display: flex; justify-content: space-between; align-items: center;
  box-shadow: 0 4px 14px rgba(255,138,61,.35);
}
.countdown .l { font-size: 11px; opacity: .92; font-weight: 600; }
.countdown .n { font-size: 21px; font-weight: 800; }
.countdown .n em { font-style: normal; font-size: 12px; font-weight: 700; margin-left: 1px; }
.streak {
  font-size: 12px; font-weight: 700; background: rgba(255,255,255,.22);
  padding: 6px 10px; border-radius: 999px; white-space: nowrap;
}

.subj3 { display: flex; gap: 8px; }
.subj {
  flex: 1; background: var(--card); border-radius: 16px; padding: 12px 6px 10px;
  text-align: center; box-shadow: var(--shadow-sm);
  border: 2px solid transparent; position: relative;
  transition: transform .08s, border-color .12s, box-shadow .12s;
}
.subj:active { transform: scale(.97); }
.subj.sel { border-color: var(--primary); box-shadow: 0 4px 14px rgba(255,138,61,.25); }
.subj.empty { opacity: .55; }
.subj .ic { font-size: 20px; }
.subj .nm { font-size: 13px; font-weight: 800; margin-top: 3px; }
.subj .st { font-size: 9.5px; color: var(--sub); margin-top: 3px; }
.subj .check {
  position: absolute; top: -7px; right: -5px; width: 19px; height: 19px; border-radius: 50%;
  background: var(--primary); color: #fff; font-size: 11px; line-height: 19px; font-weight: 800;
}
.subj4 { display: flex; gap: 6px; margin-top: 8px; }
.subj4 .mini {
  flex: 1; background: var(--card); border-radius: 12px; padding: 9px 2px; text-align: center;
  font-size: 11.5px; font-weight: 700; color: var(--ink); box-shadow: var(--shadow-sm);
  border: 2px solid transparent; transition: transform .08s, border-color .12s;
}
.subj4 .mini:active { transform: scale(.96); }
.subj4 .mini.sel { border-color: var(--primary); }
.subj4 .mini small { display: block; font-size: 8.5px; color: var(--sub); margin-top: 2px; font-weight: 600; }

.seg { display: flex; background: var(--seg-bg); border-radius: 12px; padding: 3px; }
.seg button {
  flex: 1; text-align: center; font-size: 13px; font-weight: 700; padding: 8px 0;
  color: var(--sub); border-radius: 10px; border: none; background: transparent;
}
.seg button.on { background: var(--card); color: var(--primary-deep); box-shadow: var(--shadow-sm); }

.subbtns { display: flex; gap: 8px; margin-top: 10px; }
.subbtn {
  flex: 1; background: var(--card); border: 1.5px solid var(--line); border-radius: 12px;
  font-size: 12px; font-weight: 700; color: var(--ink); padding: 11px 4px; text-align: center;
  position: relative;
}
.subbtn:disabled { opacity: .45; }
.subbtn .badge {
  position: absolute; top: -7px; right: -4px; background: var(--ng); color: #fff;
  font-size: 9.5px; font-weight: 800; border-radius: 999px; padding: 2px 6px;
}
.row-actions { display: flex; gap: 8px; margin-top: 10px; }
.linkbtn {
  flex: 1; background: none; border: none; color: var(--sub);
  font-size: 12.5px; font-weight: 700; padding: 8px; text-align: center;
}

.cta {
  margin-top: auto; background: var(--primary-grad);
  color: #fff; text-align: center; font-size: 16px; font-weight: 800;
  padding: 16px; border-radius: 16px; border: none; width: 100%;
  box-shadow: 0 6px 18px rgba(255,122,34,.4);
}
.cta:active { filter: brightness(.96); }
.cta:disabled { background: #cbb9a6; box-shadow: none; }

/* ===== S2/S3 quiz ===== */
.qtop { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; gap: 8px; }
.qtop .backbtn { background: none; border: none; color: var(--sub); font-size: 18px; padding: 2px 6px 2px 0; }
.dots { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.dots i { width: 13px; height: 5px; border-radius: 3px; background: var(--line); }
.dots i.done { background: var(--primary); }
.dots i.ng { background: var(--ng); }
.combo { font-size: 13px; font-weight: 800; color: var(--primary-deep); min-width: 34px; text-align: right; }
.qcount { font-size: 12px; color: var(--sub); font-weight: 700; }

.flipbox { position: relative; flex: 1; perspective: 1000px; min-height: 0; margin-bottom: 12px; }
.qcard {
  position: absolute; inset: 0;
  transform-style: preserve-3d; transition: transform .4s cubic-bezier(.2,.8,.2,1);
}
.flipbox.flipped .qcard { transform: rotateY(180deg); }
.face {
  position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  background: var(--card); border-radius: var(--r-card); box-shadow: var(--shadow);
  padding: 18px 16px; display: flex; flex-direction: column; overflow: hidden;
}
.face.back { transform: rotateY(180deg); }
.chip {
  align-self: flex-start; font-size: 10.5px; font-weight: 800; color: var(--primary-deep);
  background: var(--chip-bg); border-radius: 999px; padding: 4px 11px; letter-spacing: .04em;
}
.qtext {
  font-size: 19px; font-weight: 700; line-height: 1.7; margin-top: 14px;
  display: flex; align-items: center; flex: 1;
}
.qtext.small { font-size: 16.5px; }
.qtext.xsmall { font-size: 14.5px; }
.qsrc { font-size: 9.5px; color: var(--sub); margin-top: 8px; }

.choices { display: flex; flex-direction: column; gap: 9px; }
.choice {
  background: var(--card); border: 1.5px solid var(--line); border-radius: var(--r-btn);
  padding: 0 14px; min-height: 56px; font-size: 15.5px; font-weight: 700;
  display: flex; gap: 11px; align-items: center; text-align: left; width: 100%;
  color: var(--ink); box-shadow: var(--shadow-sm);
  transition: transform .07s, border-color .12s, background .12s;
}
.choice:active { transform: scale(.985); }
.choice .k {
  width: 23px; height: 23px; border-radius: 50%; background: var(--seg-bg); color: var(--primary-deep);
  font-size: 11px; font-weight: 800; text-align: center; line-height: 23px; flex-shrink: 0;
}
.choice .tx { flex: 1; }
.choice.correct { border-color: var(--ok); background: rgba(34,197,94,.10); }
.choice.correct .k { background: var(--ok); color: #fff; }
.choice.wrong { border-color: var(--ng); background: rgba(239,68,68,.10); }
.choice.wrong .k { background: var(--ng); color: #fff; }
.choice:disabled { opacity: 1; }

/* answer back face */
.face.back.ok { box-shadow: 0 0 0 3px var(--ok), 0 8px 26px rgba(34,197,94,.35); }
.face.back.ng { box-shadow: 0 0 0 3px var(--ng), 0 8px 26px rgba(239,68,68,.30); }
.mark { text-align: center; }
.mark .icon { font-size: 40px; line-height: 1; margin: 2px 0 4px; }
.praise { text-align: center; font-size: 19px; font-weight: 800; }
.praise.ok { color: var(--ok-deep); }
.praise.ng { color: var(--ng); }
.praise small { display: block; font-size: 12px; color: var(--primary-deep); font-weight: 800; margin-top: 5px; }
.ansline { text-align: center; font-size: 16px; font-weight: 800; margin-top: 12px; }
.ansline b { color: var(--primary-deep); }
.expl {
  margin-top: 12px; background: var(--soft); border-radius: 12px; padding: 12px 13px;
  font-size: 14px; line-height: 1.8; color: var(--ink); overflow-y: auto;
}
.expl b { color: var(--primary-deep); }
.tapnext { margin-top: auto; text-align: center; font-size: 11.5px; color: var(--sub); font-weight: 700; padding-top: 10px; }

/* ===== S4 result ===== */
.rtitle { text-align: center; font-size: 18px; font-weight: 800; margin: 6px 0 2px; }
.rsub { text-align: center; font-size: 12px; color: var(--sub); font-weight: 600; }
.ringbox { display: flex; justify-content: center; margin: 16px 0 6px; position: relative; }
.ring { transform: rotate(-90deg); }
.ring .bgc { stroke: var(--seg-bg); }
.ring .fgc { stroke: var(--primary); stroke-linecap: round; transition: stroke-dashoffset 1s cubic-bezier(.2,.8,.2,1); }
.ringlbl { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ringlbl .pct { font-size: 30px; font-weight: 800; }
.ringlbl .rank { font-size: 12px; font-weight: 800; color: var(--primary-deep); }
.rmsg { text-align: center; font-size: 13px; font-weight: 700; color: var(--ink); margin: 4px 0 2px; }
.rstats { display: flex; gap: 8px; margin: 12px 0 4px; }
.rstat { flex: 1; background: var(--card); border-radius: 12px; text-align: center; padding: 10px 2px; box-shadow: var(--shadow-sm); }
.rstat .v { font-size: 16px; font-weight: 800; }
.rstat .l { font-size: 9.5px; color: var(--sub); font-weight: 700; margin-top: 3px; }
.misslist { margin-top: 10px; overflow-y: auto; flex: 1; min-height: 0; }
.misslist .empty-note { text-align: center; color: var(--sub); font-size: 13px; font-weight: 700; padding: 20px 0; }
.miss {
  background: var(--card); border-left: 3px solid var(--ng); border-radius: 10px;
  padding: 10px 12px; font-size: 12.5px; font-weight: 700; color: var(--ink); margin-bottom: 7px;
  box-shadow: var(--shadow-sm); width: 100%; text-align: left;
}
.miss small { display: block; color: var(--sub); font-size: 9.5px; font-weight: 600; margin-top: 3px; }
.miss .m-expl { display: none; margin-top: 7px; font-size: 11.5px; font-weight: 600; line-height: 1.7; color: var(--sub); }
.miss.open .m-expl { display: block; }
.retry {
  margin-top: 10px; background: var(--primary-grad); color: #fff;
  text-align: center; font-size: 15px; font-weight: 800; padding: 14px; border-radius: var(--r-btn);
  border: none; width: 100%; box-shadow: 0 5px 16px rgba(255,122,34,.4);
}
.gohome { text-align: center; font-size: 13px; color: var(--sub); font-weight: 700; margin-top: 12px; background: none; border: none; padding: 6px; }

/* ===== S5 stats ===== */
.stat-h { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.stat-h .backbtn { background: none; border: none; color: var(--sub); font-size: 18px; padding: 4px 6px 4px 0; }
.stat-h h2 { font-size: 17px; font-weight: 800; margin: 0; }
.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 9px; }
.bar-row .bl { width: 42px; font-size: 12px; font-weight: 800; flex-shrink: 0; }
.bar-track { flex: 1; height: 18px; background: var(--seg-bg); border-radius: 9px; overflow: hidden; position: relative; }
.bar-fill { height: 100%; background: var(--primary); border-radius: 9px; }
.bar-row .bv { font-size: 11px; color: var(--sub); font-weight: 700; width: 62px; text-align: right; flex-shrink: 0; }
.worst { display: flex; align-items: center; gap: 8px; background: var(--card); border-radius: 12px; padding: 11px 13px; margin-bottom: 7px; box-shadow: var(--shadow-sm); width: 100%; border: none; text-align: left; }
.worst .wc { flex: 1; font-size: 13px; font-weight: 800; color: var(--ink); }
.worst .wp { font-size: 13px; font-weight: 800; color: var(--ng); }
.worst .wgo { font-size: 10px; color: var(--sub); font-weight: 700; }
.daybars { display: flex; align-items: flex-end; gap: 3px; height: 88px; margin: 8px 0 4px; }
.daybar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; height: 100%; justify-content: flex-end; }
.daybar .col { width: 100%; background: var(--primary); border-radius: 3px 3px 0 0; min-height: 2px; }
.daybar .dl { font-size: 7.5px; color: var(--sub); font-weight: 700; }
.scroll-y { overflow-y: auto; flex: 1; min-height: 0; -webkit-overflow-scrolling: touch; }
.empty-big { text-align: center; color: var(--sub); font-size: 13.5px; font-weight: 700; padding: 40px 20px; line-height: 1.9; }

/* ===== confetti ===== */
#confetti {
  position: fixed; inset: 0; width: 100%; height: 100%;
  pointer-events: none; z-index: 100; display: none;
}
#confetti.on { display: block; }

/* flash overlay for wrong answer */
.flash-ng {
  position: fixed; inset: 0; background: var(--ng); opacity: 0; pointer-events: none; z-index: 90;
  animation: flashng .35s ease-out;
}
@keyframes flashng { 0% { opacity: .22; } 100% { opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  .qcard { transition: none; }
  .ring .fgc { transition: none; }
  .flash-ng { animation: none; }
}
