/* 紹介ページと同じ教科書ふうの紙面。文法の巻なので青が主色。答案の赤ペン（○×）を見せ場にする。
   外部のフォントや画像は使わない（オフラインでも同じ見た目になるように、端末の文字を使う） */
:root {
  --paper: #ffffff; --tint: #f6f9fb; --ink: #24303a; --muted: #55636f; --line: #d7dfe5;
  --blue: #1565b0; --blue-dk: #0f4c86; --blue-pale: #e6f1fb;
  --orange: #e8590c; --orange-pale: #fff0e4;
  --green: #00857a; --green-pale: #e3f4f1;
  --red: #cf2a2a; --red-pale: #fdecec;
  --amber: #b57a00; --amber-pale: #fff4d1; --yellow-pale: #fff8d6;
  --gray-pale: #eef1f4; --on: #ffffff;
  --ui: "Hiragino Maru Gothic ProN", "BIZ UDPGothic", "Yu Gothic UI", "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  --en: "Segoe UI", "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
  --tabs-h: 58px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent }
html, body { height: 100%; margin: 0 }
body { background: var(--paper); color: var(--ink); font: 400 16px/1.7 var(--ui); overflow: hidden }
[hidden] { display: none !important }
button { font: inherit; color: inherit; cursor: pointer }
:focus-visible { outline: 3px solid var(--orange); outline-offset: 2px }
h1, h2, h3 { margin: 0; line-height: 1.4 }
p { margin: 0 }

#app { display: flex; flex-direction: column; height: 100%; padding-top: env(safe-area-inset-top, 0px) }
#page { flex: 1; overflow-y: auto; padding: 0 max(16px, env(safe-area-inset-right, 0px)) 28px max(16px, env(safe-area-inset-left, 0px)); -webkit-overflow-scrolling: touch }
#page > * { max-width: 640px; margin-left: auto; margin-right: auto }
#tabs { display: flex; border-top: 2px solid var(--blue); background: var(--paper); padding-bottom: env(safe-area-inset-bottom, 0px) }
#tabs button { flex: 1; min-height: var(--tabs-h); border: 0; background: none; color: var(--muted); font-size: 11.5px; line-height: 1.3; display: grid; place-items: center; align-content: center; gap: 2px }
#tabs button .ic { font: 700 19px/1 var(--en) }
#tabs button.on { color: var(--blue); font-weight: 700; background: var(--blue-pale) }

.head { display: flex; align-items: center; gap: 10px; padding: 14px 0 6px; min-height: 56px }
.head h1 { flex: 1; font-size: 21px }
.small { color: var(--muted); font-size: 13px }
.note { color: var(--muted); font-size: 13.5px; line-height: 1.75 }
.sec { font-size: 16px; color: var(--blue); margin: 22px 0 8px; display: flex; align-items: center; gap: 8px }
.sec::before { content: ""; width: 6px; height: 18px; border-radius: 3px; background: var(--blue) }

.cover { text-align: center; padding: 20px 0 6px; display: grid; gap: 2px; justify-items: center }
.cover img { width: 72px; height: 72px; border-radius: 17px }
.cover .t { font-size: 25px; font-weight: 700; color: var(--blue); line-height: 1.35 }
.cover .s { font-size: 13px; color: var(--muted) }
.stripes { display: grid; grid-template-columns: repeat(3, 1fr); height: 6px; border-radius: 3px; overflow: hidden; width: 120px; margin-top: 8px }
.stripes i:nth-child(1) { background: var(--blue) } .stripes i:nth-child(2) { background: var(--green) } .stripes i:nth-child(3) { background: var(--orange) }

.card { border: 2px solid var(--blue); border-radius: 14px; padding: 16px; margin-top: 12px; display: grid; gap: 8px; background: var(--paper) }
.card.weak { border-color: var(--orange) }
.card.retry { border-color: var(--line) }
.lap { display: inline-block; justify-self: start; background: var(--blue); color: var(--on); font-weight: 700; font-size: 13px; padding: 2px 12px; border-radius: 999px }
.card.weak .lap { background: var(--orange) }
.card.retry .lap { background: var(--muted) }
.card .big { font-size: 26px; font-weight: 700; line-height: 1.35 }
.card .uname { font-size: 19px; font-weight: 700; color: var(--orange); line-height: 1.5 }
.prog { height: 10px; background: var(--blue-pale); border-radius: 999px; overflow: hidden }
.prog i { display: block; height: 100%; background: var(--orange) }

.btn { border: 0; border-radius: 999px; background: var(--orange); color: var(--on); font-weight: 700; font-size: 17px; padding: 13px 24px; box-shadow: 0 3px 0 #b84308; width: 100% }
.btn:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 #b84308 }
.btn:disabled { background: #c8d0d6; box-shadow: none; color: #fff; cursor: default }
.btn.blue { background: var(--blue); box-shadow: 0 3px 0 var(--blue-dk) }
.btn.out { background: var(--paper); color: var(--blue); border: 2px solid var(--blue); box-shadow: none }
.btn.danger { background: var(--paper); color: var(--red); border: 2px solid var(--red); box-shadow: none }
.btn.text { background: none; color: var(--blue); box-shadow: none; padding: 6px 4px; width: auto; font-size: 15px; text-decoration: underline; text-underline-offset: 3px }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(62px, 1fr)); gap: 8px }
.grid button { border: 2px solid var(--line); background: var(--paper); border-radius: 12px; padding: 6px 2px; display: grid; gap: 0; line-height: 1.3 }
.grid button b { font: 700 17px/1.3 var(--en) }
.grid button span { font-size: 12px; color: var(--muted) }
.grid button.d6 { border-color: var(--green); background: var(--green-pale) }
.grid button.d6 span { color: var(--green); font-weight: 700 }
.grid button.d4 { border-color: #9cc6ec; background: var(--blue-pale) }
.grid button.d0 { border-color: #f1b3b3; background: var(--red-pale) }
.grid button.nx { border-color: var(--orange); box-shadow: inset 0 0 0 1px var(--orange) }

.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; text-align: center }
.stats div { background: var(--blue-pale); border-radius: 12px; padding: 10px 4px; min-width: 0 }
.stats b { font-size: 26px; color: var(--blue); line-height: 1.3; display: block }
.stats small { display: block; color: var(--muted); font-size: 12px }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 6px }
.chips button { border: 2px solid var(--blue); background: var(--paper); color: var(--blue); border-radius: 999px; padding: 3px 14px; font-size: 14px; font-weight: 700 }
.chips button.on { background: var(--blue); color: var(--on) }
.grp { font-size: 13px; color: var(--muted); font-weight: 700; margin: 14px 0 2px }
.urow { display: grid; grid-template-columns: 46px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); cursor: pointer; width: 100%; background: none; border-left: 0; border-right: 0; border-top: 0; text-align: left }
.code { display: inline-grid; place-items: center; background: var(--blue); color: var(--on); font: 700 15px/1 var(--en); height: 32px; border-radius: 8px; padding: 0 6px; min-width: 40px }
.code.k { background: var(--green) }
.urow .nm { font-weight: 700; font-size: 15px; line-height: 1.45 }
.urow .sub { font-size: 12.5px; color: var(--muted); line-height: 1.5 }
.st { font-size: 12.5px; font-weight: 700; padding: 2px 10px; border-radius: 999px; white-space: nowrap; background: var(--gray-pale); color: var(--muted) }
.st.review { background: var(--red-pale); color: var(--red) }
.st.check { background: var(--amber-pale); color: var(--amber) }
.st.ok { background: var(--green-pale); color: var(--green) }

.wl { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); cursor: pointer; width: 100%; background: none; border-left: 0; border-right: 0; border-top: 0; text-align: left }
.wl .q { font: 400 15px/1.5 var(--en); overflow: hidden; text-overflow: ellipsis; white-space: nowrap }
.wl .sub { font-size: 12.5px; color: var(--muted) }
.wl .mk { color: var(--red); font-weight: 700; font-size: 13px; white-space: nowrap; grid-row: 1 / span 2; grid-column: 2 }

/* 問題を解く画面 */
#overlay { position: fixed; inset: 0; z-index: 20; background: var(--paper); display: flex; flex-direction: column; padding-top: env(safe-area-inset-top, 0px) }
#overlay .bar { display: flex; align-items: center; gap: 8px; background: var(--blue); color: var(--on); padding: 8px max(12px, env(safe-area-inset-right, 0px)) 8px max(12px, env(safe-area-inset-left, 0px)); min-height: 52px }
#overlay .bar .ttl { flex: 1; font-weight: 700; font-size: 16px; min-width: 0 }
#overlay .bar .ttl small { font-weight: 400; color: #d6e7f7; margin-left: 6px }
#overlay .back { border: 0; background: none; color: var(--on); font-size: 28px; line-height: 1; padding: 0 8px }
#overlay .clock { font: 700 15px/1 var(--en); font-variant-numeric: tabular-nums; background: rgba(255, 255, 255, .16); padding: 6px 10px; border-radius: 999px }
.thin { height: 5px; background: var(--blue-pale) }
.thin i { display: block; height: 100%; background: var(--orange); transition: width .2s }
.stage { flex: 1; overflow-y: auto; padding: 14px max(16px, env(safe-area-inset-right, 0px)) 18px max(16px, env(safe-area-inset-left, 0px)) }
.stage .mid { width: 100%; max-width: 620px; margin: 0 auto; display: grid; gap: 14px }
.qno { font-weight: 700; color: var(--blue); font-size: 14px }
.stem { font: 400 clamp(19px, 5vw, 23px)/1.75 var(--en); overflow-wrap: anywhere }
.blank { display: inline-block; min-width: 4.5em; border-bottom: 2px solid var(--ink); text-align: center; color: var(--orange); font-weight: 700 }
.opts { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none }
.opt { width: 100%; display: grid; grid-template-columns: 30px minmax(0, 1fr) 28px; gap: 8px; align-items: center; text-align: left; background: var(--paper); color: var(--ink); border: 2px solid var(--line); border-radius: 12px; padding: 11px 12px; font: 400 17.5px/1.5 var(--en); min-height: 54px }
.opt:hover:not(:disabled) { border-color: var(--blue) }
.opt:disabled { cursor: default }
.opt .mark { font: 700 16px/1 var(--ui); color: var(--blue); text-align: center }
.opt .pen { font: 900 25px/1 var(--ui); text-align: center }
.opt[data-state="sel"] { border-color: var(--blue); background: var(--blue-pale); box-shadow: inset 0 0 0 1px var(--blue) }
.opt[data-state="right"] { border-color: var(--green); background: var(--green-pale) }
.opt[data-state="right"] .pen { color: var(--green) }
.opt[data-state="wrong"] { border-color: var(--red); background: var(--red-pale) }
.opt[data-state="wrong"] .pen { color: var(--red) }
.opt[data-state="dim"] { opacity: .55 }
.foot { padding: 10px max(16px, env(safe-area-inset-right, 0px)) calc(12px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px)); border-top: 1px solid var(--line) }
.foot .in { max-width: 620px; margin: 0 auto; display: grid; gap: 8px }

/* 解説 */
.diag { border-radius: 12px; padding: 12px 16px; background: var(--yellow-pale); display: grid; gap: 4px }
.diag .h { font-size: 14px; font-weight: 700; color: var(--muted) }
.diag .un { font-size: 19px; font-weight: 700; color: var(--orange); line-height: 1.5 }
.diag .rule { font-size: 14.5px; line-height: 1.75; border-top: 1px dashed #e4d48a; padding-top: 6px; margin-top: 2px }
.ans { border-radius: 12px; padding: 12px 16px; background: var(--tint); display: grid; gap: 6px }
.ans.ok { background: var(--green-pale) }
.ans .h { font-weight: 700; font-size: 15px; color: var(--red) }
.ans.ok .h { color: var(--green) }
.ans .en { font: 400 17px/1.65 var(--en); overflow-wrap: anywhere }
.ans .en u { text-decoration: none; background: linear-gradient(transparent 62%, #ffd9b8 62%); font-weight: 700 }
.ans .tip { font-size: 14.5px; line-height: 1.75 }
.ans .tip b { color: var(--blue) }
.tags { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 13px; color: var(--muted) }
.tag { border: 1.5px solid var(--blue); color: var(--blue); background: var(--paper); border-radius: 999px; padding: 1px 10px; font-size: 13px; font-weight: 700 }
.tag.main { background: var(--blue); color: var(--on) }
.linkbtn { justify-self: start; border: 0; background: none; color: var(--blue); font-weight: 700; font-size: 14.5px; padding: 2px 0; text-decoration: underline; text-underline-offset: 3px }

/* 結果 */
.score { text-align: center; display: grid; gap: 2px; padding: 8px 0 }
.score .pen { font: 900 64px/1.1 var(--ui); color: var(--red) }
.score b { font-size: 34px }
.score b em { font-style: normal; font-size: 54px; color: var(--blue) }
.fixu { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 10px 12px; border: 2px solid var(--orange); border-radius: 12px; background: var(--orange-pale); width: 100%; text-align: left }
.fixu .nm { font-weight: 700; line-height: 1.45 }
.fixu .n { font-size: 13px; color: var(--orange); font-weight: 700; white-space: nowrap }
details.rev { border: 2px solid var(--line); border-radius: 12px; padding: 0 12px }
details.rev[open] { padding-bottom: 12px }
details.rev > summary { list-style: none; cursor: pointer; padding: 10px 0; display: flex; gap: 10px; align-items: center; font-size: 15px }
details.rev > summary::-webkit-details-marker { display: none }
details.rev > summary .pen { font: 900 22px/1 var(--ui); width: 24px; text-align: center }
details.rev > summary .pen.o { color: var(--green) } details.rev > summary .pen.x { color: var(--red) }
details.rev > summary .sp { flex: 1 }
details.rev > summary::after { content: "▾"; color: var(--muted) }
details.rev[open] > summary::after { content: "▴" }
details.rev .body { display: grid; gap: 10px }

/* 下から出るシート */
#sheet { position: fixed; inset: 0; z-index: 30; background: rgba(20, 33, 61, .45); display: flex; align-items: flex-end; justify-content: center }
#sheet .in { background: var(--paper); width: 100%; max-width: 680px; max-height: 88%; overflow-y: auto; border-radius: 18px 18px 0 0; padding: 16px max(16px, env(safe-area-inset-right, 0px)) calc(20px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px)); display: grid; gap: 12px }
.sh-h { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 12px; align-items: center }
.sh-h .code { height: 44px; min-width: 52px; font-size: 18px; border-radius: 10px }
.sh-h h2 { font-size: 19px }
.sh-h .x { border: 0; background: var(--gray-pale); border-radius: 50%; width: 36px; height: 36px; font-size: 20px; line-height: 1 }
.facts { display: grid; gap: 0; margin: 0 }
.facts dt { font-size: 13px; font-weight: 700; color: var(--blue); margin-top: 10px }
.facts dd { margin: 2px 0 0; line-height: 1.8 }
.facts dd.ex { font-family: var(--en); background: var(--tint); border-radius: 10px; padding: 8px 12px }
.mine { background: var(--blue-pale); border-radius: 12px; padding: 10px 14px; display: grid; gap: 2px }
.realc { font-size: 14px; line-height: 1.7 }
.realc b { color: var(--orange) }

.set { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); cursor: pointer }
.set .tx { flex: 1 } .set .sub { font-size: 13px; color: var(--muted) }
.set input { width: 22px; height: 22px; accent-color: var(--blue); flex: none }
textarea { width: 100%; min-height: 96px; font: 13px/1.5 Consolas, monospace; color: var(--ink); border: 2px solid var(--line); border-radius: 10px; padding: 8px 10px; word-break: break-all }
.box { background: var(--tint); border-radius: 12px; padding: 12px 14px; display: grid; gap: 8px }
.empty { text-align: center; color: var(--muted); padding: 18px 0; font-size: 14.5px }

#toast { position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); z-index: 40; background: var(--ink); color: var(--on); padding: 10px 18px; border-radius: 999px; font-size: 14px; max-width: 90%; text-align: center }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important } }
