/* 配色は VVF ケーブルの電線の色から：黒（非接地側）、白（接地側）、緑（接地線＝定着）、赤（3線目＝誤り）、灰（外装） */
:root {
  --black: #262521;
  --white: #f5f6f2;
  --sheath: #d3d6cf;
  --sheath-dark: #9fa49b;
  --green: #2c7a4a;
  --green-soft: #e1efe5;
  --red: #b8352b;
  --red-soft: #f6e2df;
  --ink: #262521;
  --muted: #5d6058;
  --radius: 10px;
  font-family: "BIZ UDPGothic", "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif;
  color: var(--ink);
  background: var(--white);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
body { margin: 0; line-height: 1.7; font-size: 16px; }
button { font: inherit; color: inherit; }
a { color: var(--ink); }
:focus-visible { outline: 3px solid var(--green); outline-offset: 2px; }

.bar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 12px;
  padding: 8px max(14px, env(safe-area-inset-left)) 8px max(14px, env(safe-area-inset-right));
  background: var(--black); color: var(--white);
  border-bottom: 4px solid var(--sheath);
}
.bar .home { background: none; border: 0; color: var(--white); font-weight: 700; font-size: 17px; padding: 4px 0; cursor: pointer; }
#countdown { margin-left: auto; font-size: 14px; }
#sync { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: #3a3934; }
#sync.ok { color: #bfe3cb; }
#sync.ng { color: #f2b7b0; }

main { max-width: 860px; margin: 0 auto; padding: 16px 14px 80px; }
h2 { font-size: 22px; margin: 8px 0 4px; }
h3 { font-size: 18px; margin: 24px 0 8px; }
h4 { font-size: 16px; margin: 18px 0 6px; }
.sub { color: var(--muted); font-size: 14px; margin: 4px 0 12px; }
.foot { text-align: center; margin-top: 24px; font-size: 14px; }

/* ホーム：予測点を電線のメーターで */
.hero { padding: 8px 0 16px; }
.score { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 8px; }
.score .num { font-size: 64px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.score .unit { font-size: 20px; }
.score .cap { flex-basis: 100%; color: var(--muted); font-size: 14px; }
.score.pass .num { color: var(--green); }
.meter { position: relative; height: 14px; margin: 14px 0 6px; background: var(--sheath); border-radius: 7px; }
.meter i { position: absolute; inset: 0 auto 0 0; background: var(--black); border-radius: 7px; }
.score.pass + .meter i { background: var(--green); }
.meter b { position: absolute; top: -5px; bottom: -5px; width: 3px; background: var(--red); }

button { cursor: pointer; }
.primary, .grid button, .slots button, .sets button, main > button, .mocknav button, .tools button {
  display: block; width: 100%; text-align: left;
  padding: 12px 14px; margin: 8px 0;
  border: 2px solid var(--black); border-radius: var(--radius);
  background: #fff;
}
.primary { background: var(--black); color: var(--white); font-weight: 700; }
.primary.big { padding: 16px; font-size: 18px; }
.primary small { display: block; font-weight: 400; font-size: 13px; opacity: .8; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.grid button { min-height: 64px; }
.slots, .sets, .chips, .points { list-style: none; padding: 0; margin: 0; }
.slots .nm, .sets .nm { display: block; font-weight: 700; }
.slots .st, .sets .st { display: block; font-size: 13px; color: var(--muted); }
.slots .bar { display: block; height: 6px; margin-top: 6px; background: var(--sheath); border-radius: 3px; position: static; border: 0; padding: 0; }
.slots .bar i { display: block; height: 100%; background: var(--green); border-radius: 3px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips button { padding: 6px 12px; border: 1px solid var(--sheath-dark); border-radius: 99px; background: #fff; }
.chips small { margin-left: 6px; color: var(--muted); }
.points li { padding: 10px 0; border-bottom: 1px solid var(--sheath); }

/* 出題 */
.qhead { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.qimg { background: #fff; border: 1px solid var(--sheath); border-radius: var(--radius); padding: 6px; }
.qimg img { display: block; width: 100%; height: auto; }
.qimg.split { display: grid; grid-template-columns: 1fr; gap: 6px; }
.qimg.split img + img { border-top: 1px dashed var(--sheath); padding-top: 6px; }
@media (min-width: 760px) {
  .qimg.split { grid-template-columns: auto auto; justify-content: start; }
  .qimg.split img { width: auto; max-width: 100%; max-height: 70vh; }
  .qimg.split img + img { border-top: 0; padding-top: 0; }
}
.tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 8px 0; }
.tools button { width: auto; margin: 0; padding: 8px 12px; font-size: 14px; }
.hint { font-size: 13px; color: var(--muted); }
.answers { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 12px 0; position: sticky; bottom: 8px; }
.ans {
  height: 60px; font-size: 24px; font-weight: 700;
  border: 2px solid var(--black); border-radius: var(--radius); background: #fff;
  box-shadow: 0 2px 0 var(--black);
}
.ans.picked { background: var(--black); color: var(--white); }
.ans.right { background: var(--green); border-color: var(--green); color: #fff; box-shadow: none; }
.ans.wrong { background: var(--red); border-color: var(--red); color: #fff; box-shadow: none; }
.ans:disabled { cursor: default; }
.confirm { display: grid; grid-template-columns: auto 1fr 1fr; gap: 8px; align-items: center; margin: 4px 0 12px; }
.confirm button { height: 52px; border-radius: var(--radius); border: 2px solid var(--black); font-weight: 700; }
.confirm .sure { background: var(--black); color: var(--white); }
.confirm .unsure { background: #fff; }

#fb { scroll-margin-top: 72px; }

/* 配線図の問題：図面を同じ画面に。スマホは問題の下に固定の高さで、PC は左に並べて追従 */
main.wide { max-width: 1500px; }
.dwg { margin: 8px 0; background: #fff; border: 1px solid var(--sheath-dark); border-radius: var(--radius); overflow: hidden; }
.dwgbar { display: flex; gap: 6px; align-items: center; padding: 6px 8px; font-size: 13px; border-bottom: 1px solid var(--sheath); background: var(--white); }
.dwgbar span { flex: 1; color: var(--muted); }
.dwgbar button { min-width: 40px; height: 34px; padding: 0 10px; border: 2px solid var(--black); border-radius: 8px; background: #fff; font-weight: 700; }
.dwgview { height: 46vh; overflow: auto; -webkit-overflow-scrolling: touch; }
.dwginner { position: relative; }
.dwginner img { display: block; width: 100%; height: auto; }
.ring { position: absolute; width: 46px; height: 46px; margin: -23px 0 0 -23px; border: 4px solid var(--red); border-radius: 50%; pointer-events: none; box-shadow: 0 0 0 3px rgba(255, 255, 255, .8); }
@media (min-width: 1000px) {
  .qlayout.wiring { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); grid-template-areas: "dwg top" "dwg bottom"; gap: 0 18px; align-items: start; }
  .qlayout.wiring .dwg { grid-area: dwg; position: sticky; top: 64px; margin: 0; }
  .qlayout.wiring .dwgview { height: calc(100vh - 120px); }
  .qlayout.wiring .qtop { grid-area: top; }
  .qlayout.wiring .qbottom { grid-area: bottom; }
  .qlayout.wiring .qimg.split { grid-template-columns: 1fr; }
  .qlayout.wiring .qimg.split img { width: 100%; max-height: none; }
}
.verdict { font-size: 22px; font-weight: 700; padding: 10px 14px; border-radius: var(--radius); margin: 12px 0; }
.verdict small { display: block; font-size: 13px; font-weight: 400; }
.verdict.ok { background: var(--green-soft); color: var(--green); border-left: 8px solid var(--green); }
.verdict.ng { background: var(--red-soft); color: var(--red); border-left: 8px solid var(--red); }
.point { border: 2px solid var(--green); border-radius: var(--radius); padding: 10px 14px; background: #fff; font-weight: 700; }
.point span { display: block; font-size: 12px; color: var(--green); font-weight: 700; }
.expl { margin: 12px 0; }
.choices { list-style: none; padding: 0; margin: 12px 0; }
.choices li { display: grid; grid-template-columns: 28px 1fr; padding: 8px 0; border-bottom: 1px solid var(--sheath); font-size: 15px; }
.choices li.right b { color: var(--green); }
.choices li.wrong b { color: var(--red); }
.law, .warn { font-size: 13px; padding: 8px 12px; border-radius: 8px; background: #fbf3dc; }
.src { font-size: 12px; color: var(--muted); }
.mocknav { display: flex; gap: 8px; }

/* 拡大表示 */
#overlay { position: fixed; inset: 0; z-index: 20; background: rgba(38, 37, 33, .96); display: flex; flex-direction: column; }
#overlay[hidden] { display: none; }
.zbar { display: flex; gap: 8px; padding: 8px; justify-content: flex-end; }
.zbar button { padding: 8px 14px; border-radius: 8px; border: 0; background: var(--white); font-weight: 700; }
.zwrap { flex: 1; overflow: auto; -webkit-overflow-scrolling: touch; }
.zwrap img { display: block; background: #fff; max-width: none; }

.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th, .tbl td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--sheath); }
.tbl td:not(:first-child), .tbl th:not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; }
.form label { display: block; margin: 12px 0; }
.form input[type=date], .form input[type=number] { display: block; font: inherit; padding: 8px; border: 2px solid var(--black); border-radius: 8px; margin-top: 4px; }
.form .chk input { margin-right: 8px; }
.note img { max-width: 100%; height: auto; }
.figscroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 8px 0; }
.figscroll svg { display: block; width: 100%; height: auto; }
.note table { display: block; overflow-x: auto; }
.note table { border-collapse: collapse; width: 100%; font-size: 14px; }
.note th, .note td { border: 1px solid var(--sheath-dark); padding: 4px 6px; }
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }

/* 講義 */
.lbar { height: 6px; background: var(--sheath); border-radius: 3px; margin: 4px 0 10px; }
.lbar i { display: block; height: 100%; background: var(--green); border-radius: 3px; }
.lhead { font-size: 13px; color: var(--muted); margin: 0 0 6px; }
.goal { background: var(--green-soft); border-left: 6px solid var(--green); padding: 8px 12px; border-radius: 8px; font-weight: 700; }
.slide h2 { font-size: 21px; margin: 6px 0 10px; }
.slide p, .check p { margin: 8px 0; }
.lnav { display: grid; grid-template-columns: 1fr 2fr; gap: 10px; margin-top: 16px; position: sticky; bottom: 0; padding: 8px 0 12px; background: var(--white); border-top: 1px solid var(--sheath); }
.lnav button:not(.primary) { background: #fff; }
.lnav button { margin: 0; text-align: center; }
.cq { font-size: 17px; }
.cchoices { display: grid; gap: 8px; margin: 12px 0; }
.cc { display: grid; grid-template-columns: 30px 1fr; gap: 6px; align-items: start; text-align: left; padding: 12px; border: 2px solid var(--black); border-radius: var(--radius); background: #fff; font-size: 16px; }
.cc b { font-size: 18px; }
.cc.right { border-color: var(--green); background: var(--green-soft); }
.cc.wrong { border-color: var(--red); background: var(--red-soft); }
.cc:disabled { cursor: default; color: var(--ink); }
.lessons .done { border-color: var(--sheath-dark); }
.lessons .done .nm::after { content: "　済"; color: var(--green); }

.slide .lead { margin: -4px 0 12px; padding: 0 0 10px; color: var(--muted); border-bottom: 1px solid var(--sheath); }
/* 講義の写真と説明の表 */
.note table.items { display: table; width: 100%; border-collapse: collapse; }
.note table.items td { vertical-align: top; padding: 8px 6px; }
.note table.items td:first-child { width: 42%; max-width: 240px; }
@media (min-width: 760px) { .note table.items td:first-child { width: 240px; } }
.note table.items img { width: 100%; height: auto; max-height: 260px; object-fit: contain; display: block; background: #fff; }
.note table.items b.nm { display: block; font-size: 16px; }

/* AI に質問：PC は右の列、スマホは下から出る */
#asktoggle { margin-left: auto; padding: 4px 12px; border-radius: 99px; border: 2px solid var(--white); background: none; color: var(--white); font-weight: 700; font-size: 14px; }
#asktoggle + #countdown { margin-left: 0; }
body.askopen #asktoggle { background: var(--white); color: var(--black); }
#ask { display: none; position: fixed; z-index: 15; background: #fff; flex-direction: column; border-left: 4px solid var(--sheath); }
body.askopen #ask { display: flex; }
.askhead { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--sheath); }
.askhead span { flex: 1; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.askhead button { border: 0; background: none; font-size: 22px; line-height: 1; padding: 0 4px; }
#askbody { flex: 1; overflow-y: auto; padding: 12px; font-size: 15px; }
.msg { margin: 0 0 10px; padding: 8px 12px; border-radius: 10px; line-height: 1.65; }
.msg.user { background: var(--black); color: var(--white); margin-left: 18%; }
.msg.assistant { background: var(--white); border: 1px solid var(--sheath); }
.msg.typing:empty::after { content: "考えています…"; color: var(--muted); }
#askchips { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 12px 8px; }
#askchips button { font-size: 13px; padding: 5px 10px; border: 1px solid var(--sheath-dark); border-radius: 99px; background: #fff; text-align: left; }
#askform { display: grid; grid-template-columns: 1fr auto; gap: 8px; padding: 8px 12px 12px; border-top: 1px solid var(--sheath); }
#askform textarea { font: inherit; font-size: 16px; padding: 8px; border: 2px solid var(--black); border-radius: 8px; resize: none; }
#askform button { margin: 0; width: auto; padding: 0 16px; }
@media (min-width: 1100px) {
  #ask { top: 56px; right: 0; bottom: 0; width: 380px; }
  body.askopen main { margin-right: 400px; }
  body.askopen main:not(.wide) { margin-left: max(14px, calc((100vw - 400px - 860px) / 2)); }
}
@media (max-width: 1099px) {
  #ask { left: 0; right: 0; bottom: 0; height: 72vh; border-left: 0; border-top: 4px solid var(--sheath); border-radius: 14px 14px 0 0; box-shadow: 0 -6px 24px rgba(38, 37, 33, .25); }
}
.cq small { display: block; margin-top: 4px; font-size: 14px; color: var(--muted); }
.bar > * { white-space: nowrap; }
@media (max-width: 520px) {
  .bar { gap: 8px; }
  .bar .home { font-size: 15px; }
  #asktoggle { font-size: 13px; padding: 3px 10px; }
  #countdown { font-size: 12px; }
  #sync { font-size: 11px; padding: 2px 6px; }
}

/* ログイン */
.authbox { border: 2px solid var(--green); background: #fff; border-radius: var(--radius); padding: 12px 14px; margin: 10px 0; }
.authbox .primary { margin-top: 8px; }
.linkbox { width: 100%; font: inherit; font-size: 13px; padding: 8px; border: 1px solid var(--sheath-dark); border-radius: 8px; margin: 6px 0; }
button.mini { padding: 2px 10px; border: 1px solid var(--sheath-dark); border-radius: 6px; background: #fff; font-size: 13px; }
