:root {
  --bg: #f4f6f3;
  --card: #ffffff;
  --text: #17201b;
  --muted: #5f6c65;
  --line: #e1e7e2;
  --accent: #0f7a4a;
  --accent-ink: #ffffff;
  --accent-soft: #e3f3ea;
  --o: #1a9455;
  --o-bg: #dff3e7;
  --x: #d0433b;
  --x-bg: #fbe4e2;
  --q: #b88400;
  --q-bg: #fbf0cf;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 4px 14px rgba(0, 0, 0, .05);
  --comp-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1412; --card: #18201c; --text: #e8ede9; --muted: #9aa8a0; --line: #29332e; --accent: #34c07c; --accent-ink: #04140b;
    --accent-soft: #15301f; --o: #46cc82; --o-bg: #133120; --x: #f07a72; --x-bg: #3a1a18; --q: #e7bd45; --q-bg: #382d0f; --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1412; --card: #18201c; --text: #e8ede9; --muted: #9aa8a0; --line: #29332e; --accent: #34c07c; --accent-ink: #04140b;
  --accent-soft: #15301f; --o: #46cc82; --o-bg: #133120; --x: #f07a72; --x-bg: #3a1a18; --q: #e7bd45; --q-bg: #382d0f; --shadow: none;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  font-size: 16px; line-height: 1.5; -webkit-text-size-adjust: 100%;
}
.hidden { display: none !important; }
a { color: var(--accent); }
button { font: inherit; color: inherit; }

/* header */
.top { max-width: 640px; margin: 0 auto; padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 4px; }
.title-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
h1 { font-size: 18px; margin: 0; letter-spacing: .01em; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); background: var(--card);
  font-weight: 700; color: var(--muted); cursor: pointer; flex: 0 0 auto;
}
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--line); border-radius: 12px; padding: 3px; margin-top: 10px; }
.seg-btn { border: 0; background: transparent; padding: 8px; border-radius: 9px; font-weight: 700; font-size: 15px; color: var(--muted); cursor: pointer; }
.seg-btn.on { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.settings { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.opt { display: flex; align-items: center; gap: 10px; }
.opt > span { flex: 0 0 44px; font-size: 12px; color: var(--muted); }
.chips-sel { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.chips-sel::-webkit-scrollbar { display: none; }
.chips-sel button {
  border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 5px 12px; font-size: 14px; white-space: nowrap; cursor: pointer;
}
.chips-sel button.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }

/* status */
.status {
  position: sticky; top: 0; z-index: 20; max-width: 640px; margin: 8px auto 0; padding: 8px 16px 10px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap;
  background: color-mix(in srgb, var(--bg) 90%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.st-label { font-size: 12px; color: var(--muted); }
.st-remain b { font-size: 26px; line-height: 1; color: var(--accent); font-variant-numeric: tabular-nums; }
.st-remain span { font-size: 13px; color: var(--muted); }
.st-right { display: flex; gap: 8px; }
.st-bar { flex: 1 0 100%; height: 4px; background: var(--line); border-radius: 4px; overflow: hidden; }
.st-bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .3s; }

/* buttons */
.btn {
  border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 10px 14px; cursor: pointer; font-weight: 700; min-height: 44px;
}
.btn.sm { font-size: 14px; padding: 6px 12px; min-height: 40px; line-height: 1.15; }
.btn.sm small { display: block; font-size: 10px; font-weight: 500; color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary small { color: inherit; opacity: .8; }
.btn.wide { width: 100%; font-size: 16px; padding: 13px; }
.btn:disabled { opacity: .4; cursor: default; }
.link { border: 0; background: none; color: var(--muted); text-decoration: underline; padding: 8px; cursor: pointer; font-size: 14px; }

main { max-width: 640px; margin: 0 auto; padding: 0 16px calc(var(--comp-h) + var(--safe-b) + 24px); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 12px; margin: 10px 0; box-shadow: var(--shadow); }
.center { text-align: center; color: var(--muted); }

/* topic */
.topic { border-color: var(--accent); background: var(--accent-soft); }
.topic .k { font-size: 12px; color: var(--muted); }
.topic .t { font-size: 17px; font-weight: 800; margin-top: 2px; }

/* board */
.board { padding: 0; overflow: hidden; }
.slots { display: grid; gap: 1px; background: var(--line); border-bottom: 1px solid var(--line); }
.slot { background: var(--card); padding: 10px 6px 8px; text-align: center; }
.slot .lbl { font-size: 11px; color: var(--muted); }
.slot .num { font-size: 24px; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.slot .num small { font-size: 12px; font-weight: 500; color: var(--muted); margin-left: 1px; }
.slot .sub { font-size: 10px; color: var(--muted); }
.slot.one .num { color: var(--accent); }
.rows { display: flex; flex-direction: column; }
.row { display: grid; align-items: center; gap: 6px; padding: 9px 12px; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row .qt { font-size: 14px; line-height: 1.35; }
.row .qt small { color: var(--muted); font-variant-numeric: tabular-nums; margin-right: 4px; }
.row .marks { display: grid; gap: 6px; }
.row.new { animation: flash 1.2s ease-out; }
@keyframes flash { from { background: var(--accent-soft); } to { background: transparent; } }
.empty { padding: 22px 16px; text-align: center; color: var(--muted); font-size: 14px; }
.m { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; font-weight: 900; font-size: 15px; justify-self: center; }
.legend .m, dialog .m { width: 20px; height: 20px; font-size: 12px; border-radius: 6px; margin: 0 3px 0 8px; vertical-align: -4px; }
.m.o { color: var(--o); background: var(--o-bg); }
.m.x { color: var(--x); background: var(--x-bg); }
.m.q { color: var(--q); background: var(--q-bg); }
.legend { font-size: 11px; color: var(--muted); padding: 8px 8px 10px; border-top: 1px solid var(--line); text-align: center; }

/* quick */
.quick-wrap { margin: 4px -16px 0; }
.quick-title { font-size: 12px; color: var(--muted); padding: 0 16px 6px; }
.quick { display: flex; gap: 8px; overflow-x: auto; padding: 0 16px 4px; scrollbar-width: none; scroll-snap-type: x proximity; }
.quick::-webkit-scrollbar { display: none; }
.qchip {
  flex: 0 0 auto; border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 8px 14px; font-size: 14px;
  white-space: nowrap; cursor: pointer; min-height: 40px; scroll-snap-align: start;
}
.qchip:disabled { opacity: .35; text-decoration: line-through; }

/* composer */
.composer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: color-mix(in srgb, var(--card) 94%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-top: 1px solid var(--line);
  padding: 8px 12px calc(8px + var(--safe-b)); transition: transform .15s;
}
.comp-row { max-width: 640px; margin: 0 auto; display: flex; gap: 8px; align-items: center; }
.comp-row input {
  flex: 1; min-width: 0; font: inherit; font-size: 16px; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 999px; padding: 11px 16px; height: 46px;
}
.comp-row input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.comp-row .list { width: 46px; height: 46px; font-size: 18px; }
.send {
  flex: 0 0 auto; height: 46px; padding: 0 16px; border-radius: 999px; border: 0; background: var(--accent); color: var(--accent-ink); font-weight: 800; cursor: pointer;
}
.send:disabled { opacity: .4; }
.sugg {
  list-style: none; margin: 0 auto 8px; padding: 0; max-width: 640px; display: flex; flex-direction: column; gap: 6px; max-height: 46vh; overflow-y: auto;
}
.sugg li button {
  width: 100%; text-align: left; border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 11px 14px; cursor: pointer;
  display: flex; justify-content: space-between; gap: 10px; align-items: center; min-height: 46px; font-size: 15px;
}
.sugg li button.best:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); font-weight: 700; }
.sugg li button .g { font-size: 11px; color: var(--muted); white-space: nowrap; }
.sugg li button:disabled { opacity: .45; }
.sugg li.note { font-size: 13px; color: var(--muted); padding: 4px 6px; }

/* sheets */
dialog.sheet {
  border: 0; padding: 8px 16px calc(16px + var(--safe-b)); background: var(--card); color: var(--text);
  width: 100%; max-width: 640px; margin: auto auto 0; border-radius: 20px 20px 0 0; max-height: 88vh; overflow-y: auto;
}
dialog.sheet.tall { height: 88vh; }
dialog.sheet[open] { animation: up .22s ease-out; }
@keyframes up { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }
dialog::backdrop { background: rgba(0, 0, 0, .45); }
.grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 10px; }
dialog h2 { margin: 0 0 6px; font-size: 19px; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.sheet-foot { display: flex; justify-content: space-between; margin-top: 6px; }
dialog ol { padding-left: 20px; margin: 6px 0 10px; }
dialog li { margin: 6px 0; font-size: 15px; }
.small { font-size: 13px; color: var(--muted); margin: 4px 0 10px; }
.msg { font-size: 13px; min-height: 1.2em; margin: 6px 0; }
.msg.err { color: var(--x); }
input[type=text] {
  font: inherit; font-size: 16px; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 11px 12px; width: 100%;
}
input[type=text]:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* answer */
.ans-row { position: relative; display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.ans-row .no { flex: 0 0 44px; font-size: 13px; color: var(--muted); font-weight: 700; }
.ans-row input.ok { border-color: var(--accent); background: var(--o-bg); }
.ans-row input.ng { border-color: var(--x); }
.dd {
  position: absolute; left: 54px; right: 0; top: 100%; z-index: 5; background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  margin: 4px 0 0; padding: 4px; list-style: none; box-shadow: 0 10px 28px rgba(0, 0, 0, .18); max-height: 260px; overflow: auto;
}
.dd li { padding: 11px 12px; border-radius: 9px; cursor: pointer; font-size: 16px; }
.dd li small { color: var(--muted); margin-left: 6px; font-size: 12px; }
.dd li.act, .dd li:active { background: var(--o-bg); }

/* list */
.groups { margin-top: 10px; }
.grp { margin-bottom: 14px; }
.grp h3 { font-size: 13px; color: var(--muted); margin: 0 0 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--bg); border-radius: 999px; padding: 7px 12px; font-size: 14px; cursor: pointer; }
.chip:disabled { opacity: .35; text-decoration: line-through; }
.more { border: 0; background: none; color: var(--accent); font-size: 13px; padding: 6px; cursor: pointer; }

/* result */
.res-head { text-align: center; padding: 6px 0 4px; }
.res-head .big { font-size: 34px; }
.res-head h2 { font-size: 22px; margin: 2px 0; }
.res-topic { background: var(--accent-soft); border-radius: 12px; padding: 10px 12px; margin: 10px 0; }
.res-topic .k { font-size: 12px; color: var(--muted); }
.res-topic .t { font-weight: 800; font-size: 16px; }
.res-list { list-style: none; padding: 0; margin: 8px 0; }
.res-list li { display: flex; align-items: center; gap: 10px; padding: 10px 4px; border-bottom: 1px solid var(--line); }
.res-list .mk { font-weight: 900; width: 22px; text-align: center; }
.res-list .ok { color: var(--o); }
.res-list .ng { color: var(--x); }
.res-list a { font-weight: 700; font-size: 17px; text-decoration: none; }
.res-list small { color: var(--muted); }
.share { white-space: pre; font-size: 13px; background: var(--bg); border-radius: 12px; padding: 10px 12px; overflow-x: auto; line-height: 1.35; margin-top: 10px; }
.share-btns { display: grid; grid-template-columns: 2fr 1fr; gap: 8px; margin-top: 10px; }

footer { font-size: 11px; color: var(--muted); padding: 16px 0 8px; }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--comp-h) + var(--safe-b) + 20px); transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 9px 16px; border-radius: 999px; font-size: 14px; z-index: 60; box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
}
@media (min-width: 700px) {
  dialog.sheet { margin: auto; border-radius: 20px; }
}

.set-toggle {
  width: 100%; margin-top: 10px; display: flex; justify-content: space-between; align-items: center; gap: 8px; border: 1px solid var(--line);
  background: var(--card); border-radius: 12px; padding: 9px 12px; font-size: 13px; color: var(--muted); cursor: pointer; text-align: left;
}
.set-toggle b { color: var(--accent); white-space: nowrap; font-size: 13px; }
.set-toggle.open b { opacity: .7; }
