:root {
  --bg: #f3efe6;
  --card: #fffdf8;
  --ink: #1f2a3a;
  --sub: #6b7385;
  --line: #e2dccd;
  --accent: #c8432f;     /* 朱肉 */
  --accent-ink: #fffdf8;
  --navy: #2f5d8a;
  --soft: #ece6d8;
  --good: #2f7a4a;
  --bad: #b8432c;
  --cogs: #9aa6b8;
  --sga: #d7bf8a;
  --op: #3f8a5a;
  --loss: #c8432f;
  --shadow: 0 2px 0 #ded6c4;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171c25;
    --card: #212836;
    --ink: #edf0f5;
    --sub: #a3abba;
    --line: #333c4d;
    --accent: #e0644f;
    --accent-ink: #171c25;
    --navy: #7fa8d6;
    --soft: #2b3344;
    --good: #7cc596;
    --bad: #ef8a72;
    --cogs: #6f7d93;
    --sga: #a8915e;
    --op: #5fb07d;
    --loss: #e0644f;
    --shadow: 0 2px 0 #0f131a;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font-family: 'Zen Kaku Gothic New', system-ui, sans-serif;
  font-weight: 500;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
  padding: env(safe-area-inset-top) 0 calc(88px + env(safe-area-inset-bottom));
}
main { max-width: 520px; margin: 0 auto; padding: 0 16px; }
h1, h2, h3 { margin: 0; line-height: 1.3; font-weight: 900; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }
p { margin: 0; }
.sub { color: var(--sub); font-size: 14px; }
.hint { font-size: 13px; color: var(--sub); margin-top: 6px; }
.num { font-variant-numeric: tabular-nums; }
.k { font-size: 12px; color: var(--accent); font-weight: 700; letter-spacing: .08em; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  margin-top: 14px;
  box-shadow: var(--shadow);
}
.stack > * + * { margin-top: 10px; }

.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: 52px; padding: 0 16px;
  border-radius: 12px; border: 2px solid var(--accent);
  background: var(--accent); color: var(--accent-ink);
  font: inherit; font-weight: 700; font-size: 16px;
  cursor: pointer; touch-action: manipulation;
  transition: transform .08s ease;
}
.btn:active { transform: translateY(1px) scale(.99); }
.btn.ghost { background: transparent; color: var(--accent); }
.btn[disabled] { opacity: .45; pointer-events: none; }
.row { display: flex; gap: 10px; align-items: center; }
.row > .btn { flex: 1; }

input[type=text] {
  width: 100%; min-height: 52px; padding: 0 14px;
  border-radius: 12px; border: 2px solid var(--line); background: var(--bg); color: var(--ink);
  font: inherit; font-size: 17px;
}
input[type=text]:focus { outline: none; border-color: var(--accent); }
label.lbl { display: block; font-weight: 700; margin-bottom: 6px; }

/* 看板 */
.hero { text-align: center; padding-top: 18px; }
.hero svg { width: 100%; max-width: 340px; height: auto; display: block; margin: 0 auto; }
.hero h1 { font-size: 28px; letter-spacing: .06em; margin-top: 8px; }
.hero p { color: var(--sub); margin-top: 4px; font-size: 14px; }

details.how summary { cursor: pointer; font-weight: 700; list-style: none; display: flex; justify-content: space-between; }
details.how summary::-webkit-details-marker { display: none; }
details.how summary::after { content: '＋'; color: var(--accent); }
details.how[open] summary::after { content: '－'; }
details.how ol { margin: 10px 0 0; padding-left: 20px; }
details.how li + li { margin-top: 6px; }

/* ロビー */
.code { font-size: 40px; font-weight: 900; letter-spacing: .2em; text-align: center; }
.plist { list-style: none; padding: 0; margin: 0; }
.plist li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px dashed var(--line); }
.plist li:first-child { border-top: 0; }
.dot { width: 14px; height: 14px; border-radius: 4px; flex: none; }
.plist .name { flex: 1; font-weight: 700; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plist .pts { font-weight: 900; }
.tag { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--soft); color: var(--sub); white-space: nowrap; }
.tag.ok { background: color-mix(in srgb, var(--good) 16%, transparent); color: var(--good); }
.tag.hot { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }
.x { border: 0; background: none; color: var(--sub); font: inherit; font-size: 13px; text-decoration: underline; cursor: pointer; padding: 6px; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.opt {
  min-height: 48px; padding: 6px 10px; border-radius: 12px;
  border: 2px solid var(--line); background: var(--bg); color: var(--ink);
  font: inherit; font-weight: 700; font-size: 15px; cursor: pointer; touch-action: manipulation;
}
.opt[aria-pressed=true] { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--card)); }
.opt[disabled] { cursor: default; }

/* 出題中 */
.topbar {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(6px);
  margin: 0 -16px; padding: 10px 16px;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  border-bottom: 1px solid var(--line);
}
.qno { font-weight: 900; font-size: 18px; }
.qno small { font-weight: 500; color: var(--sub); font-size: 13px; margin-left: 6px; }
.myscore { text-align: right; font-size: 12px; color: var(--sub); line-height: 1.2; }
.myscore b { color: var(--ink); font-size: 20px; }
.x2 { display: inline-block; background: var(--accent); color: var(--accent-ink); border-radius: 6px; font-size: 12px; font-weight: 900; padding: 0 6px; margin-left: 6px; vertical-align: 2px; }

.timer { margin-top: 12px; }
.tsegs { display: grid; grid-template-columns: 20fr 15fr 15fr; gap: 4px; }
.tseg { height: 8px; border-radius: 6px; background: var(--soft); overflow: hidden; position: relative; }
.tseg i { position: absolute; inset: 0; background: var(--navy); transform-origin: left; }
.tseg.done i { transform: scaleX(0); }
.tlabels { display: grid; grid-template-columns: 20fr 15fr 15fr; gap: 4px; font-size: 12px; color: var(--sub); margin-top: 3px; }
.tlabels span.on { color: var(--ink); font-weight: 700; }
.tnow { display: flex; justify-content: space-between; align-items: baseline; margin-top: 6px; }
.tnow b { font-size: 18px; }
.tnow .sec { font-size: 13px; color: var(--sub); }

.sheet h3 { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.sheet h3 small { font-weight: 500; font-size: 12px; color: var(--sub); }
.chart { width: 100%; height: auto; display: block; margin-top: 8px; }
.chart text { font-family: inherit; }
.locked { display: flex; gap: 10px; align-items: center; margin-top: 12px; padding: 12px; border-radius: 12px; border: 2px dashed var(--line); color: var(--sub); font-size: 14px; }
.locked svg { width: 22px; height: 22px; flex: none; }
.opened { animation: open .5s ease; }
@keyframes open { from { opacity: 0; transform: translateY(6px); } }

.pl { margin-top: 10px; font-size: 14px; }
.pl .ln { display: flex; justify-content: space-between; padding: 4px 0; border-top: 1px dashed var(--line); }
.pl .ln:first-child { border-top: 0; }
.pl .ln.sum { font-weight: 900; border-top: 1px solid var(--ink); }
.pl .ln small { color: var(--sub); margin-left: 6px; font-size: 12px; }
.minus { color: var(--bad); }

.choices { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.choice {
  display: flex; align-items: center; gap: 12px; text-align: left;
  min-height: 56px; padding: 8px 14px; border-radius: 12px;
  border: 2px solid var(--line); background: var(--card); color: var(--ink);
  font: inherit; font-weight: 700; font-size: 16px; cursor: pointer; touch-action: manipulation;
}
.choice .no { width: 26px; height: 26px; border-radius: 50%; border: 2px solid currentColor; display: grid; place-items: center; font-size: 13px; flex: none; color: var(--navy); }
.choice[aria-pressed=true] { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--card)); }
.choice[aria-pressed=true] .no { color: var(--accent); }
.choice[disabled] { cursor: default; opacity: .55; }
.choice[disabled][aria-pressed=true] { opacity: 1; }
.waitlist { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; padding: 3px 10px; border-radius: 99px; background: var(--soft); }
.chip.done { background: color-mix(in srgb, var(--good) 16%, transparent); }

/* 答え合わせ */
.ans-head { display: flex; align-items: center; gap: 12px; }
.ans-head .mk { width: 54px; height: 54px; flex: none; }
.ans-head b { font-size: 20px; display: block; line-height: 1.3; }
.reasons { margin: 8px 0 0; padding-left: 20px; }
.reasons li + li { margin-top: 6px; }
.note { margin-top: 10px; padding: 10px 12px; border-left: 4px solid var(--navy); background: var(--soft); border-radius: 8px; font-size: 14px; }
.cmp { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 13px; table-layout: fixed; }
.cmp th, .cmp td { padding: 6px 4px; border-top: 1px dashed var(--line); text-align: right; vertical-align: top; }
.cmp th:first-child, .cmp td:first-child { text-align: left; color: var(--sub); font-weight: 500; width: 30%; }
.cmp thead th { border-top: 0; font-size: 12px; line-height: 1.3; }
.cmp .hit { background: color-mix(in srgb, var(--accent) 10%, transparent); font-weight: 700; }
.cmp thead .hit { color: var(--accent); }
.res-mine { margin-top: 10px; font-weight: 700; }
.res-mine.ok { color: var(--good); }
.res-mine.ng { color: var(--bad); }
.nextbar { position: sticky; bottom: calc(10px + env(safe-area-inset-bottom)); margin-top: 14px; padding-right: 68px; z-index: 4; }
.nextbar .btn { box-shadow: 0 6px 16px rgba(0,0,0,.18); }
.sample-note { font-size: 12px; color: var(--sub); margin-top: 14px; text-align: center; }

/* 最後 */
.final li .crown { width: 22px; height: 16px; vertical-align: -2px; }
.final .name { white-space: normal; }
.final .name small { font-weight: 500; font-size: 12px; }
.memo { list-style: none; padding: 0; margin: 8px 0 0; }
.memo li { padding: 10px 0; border-top: 1px dashed var(--line); }
.memo li:first-child { border-top: 0; }
.memo b { display: block; }
.memo .mt { font-size: 12px; color: var(--sub); margin-top: 2px; }
.memo p { font-size: 14px; margin-top: 4px; }

#toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(10px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px;
  opacity: 0; transition: .25s; pointer-events: none; z-index: 90; max-width: calc(100% - 32px);
}
#toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }
.pop { animation: pop .35s ease; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* 演出 */
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 75; overflow: hidden; }
.confetti i { position: absolute; top: -20px; width: 9px; height: 13px; border-radius: 2px; animation: fall linear forwards; }
.confetti i.art { width: 16px; height: 16px; background: none; }
.confetti i.art svg { width: 100%; height: 100%; }
@keyframes fall { to { transform: translate(var(--dx), 105vh) rotate(var(--rot)); } }
.shake { animation: shake .45s ease; }
@keyframes shake { 20% { transform: translateX(-9px) rotate(-1deg); } 40% { transform: translateX(8px) rotate(1deg); } 60% { transform: translateX(-6px); } 80% { transform: translateX(4px); } }

.pings { position: fixed; top: calc(64px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 80; display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; width: calc(100% - 32px); max-width: 420px; }
.pingc { display: flex; align-items: center; gap: 8px; background: var(--card); color: var(--ink); border: 2px solid; border-radius: 99px; padding: 6px 14px; font-size: 14px; box-shadow: 0 6px 18px rgba(0,0,0,.15); animation: pingIn .35s cubic-bezier(.3,1.6,.5,1); }
.pingc.out { opacity: 0; transform: translateY(-8px); transition: .4s; }
@keyframes pingIn { from { transform: translateY(-14px) scale(.8); opacity: 0; } }

.flystamp { position: fixed; bottom: 90px; z-index: 81; pointer-events: none; display: flex; flex-direction: column; align-items: center; animation: fly 2.8s ease-out forwards; }
.flystamp b { background: var(--card); color: var(--ink); border: 3px solid var(--c); border-radius: 14px; padding: 8px 14px; font-size: 18px; font-weight: 900; box-shadow: 0 6px 16px rgba(0,0,0,.18); white-space: nowrap; }
.flystamp small { margin-top: 3px; background: var(--c); color: #fff; border-radius: 99px; padding: 0 8px; font-size: 11px; }
@keyframes fly { 0% { transform: translateY(30px) scale(.4); opacity: 0; } 12% { transform: translateY(0) scale(1.15); opacity: 1; } 20% { transform: scale(1); } 80% { opacity: 1; } 100% { transform: translateY(-46vh) rotate(-6deg); opacity: 0; } }

.stampbar { position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 50; display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
.fab { width: 56px; height: 56px; border-radius: 50%; border: 0; background: var(--navy); color: #fff; box-shadow: 0 6px 16px rgba(0,0,0,.22); cursor: pointer; display: grid; place-items: center; }
.fab svg { width: 28px; height: 28px; }
.tray { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 12px; width: min(300px, calc(100vw - 32px)); box-shadow: 0 10px 30px rgba(0,0,0,.2); }
.tray-h { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.tray-h .snd { border: 2px solid var(--line); background: var(--bg); color: var(--ink); border-radius: 99px; font: inherit; font-size: 12px; padding: 2px 10px; cursor: pointer; }
.tray-g { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }

.reveal { position: fixed; inset: 0; z-index: 70; background: rgba(15, 20, 30, .88); display: grid; place-items: center; padding: 16px; animation: fadeIn .25s; }
.reveal.out { opacity: 0; transition: .25s; }
@keyframes fadeIn { from { opacity: 0; } }
.rv-card { width: 100%; max-width: 420px; background: var(--card); border-radius: 20px; padding: 22px 18px; text-align: center; box-shadow: 0 20px 50px rgba(0,0,0,.35); }
.rv-k { color: var(--sub); font-size: 14px; }
.rv-title { font-size: 28px; letter-spacing: .1em; margin-bottom: 10px; }
.rv-stage { min-height: 260px; display: flex; flex-direction: column; justify-content: center; }
.rv-sub { color: var(--sub); font-size: 14px; margin-top: 12px; }
.rv-me { position: relative; padding: 40px 0 50px; }
.rv-co { font-size: 26px; font-weight: 900; line-height: 1.35; padding: 0 20px; }
.hanko { position: absolute; right: 2px; bottom: -6px; width: 92px; height: 92px; border-radius: 50%; border: 5px solid currentColor; display: grid; place-items: center; font-size: 24px; font-weight: 900; transform: scale(3) rotate(-30deg); opacity: 0; }
.hanko.black { color: var(--good); }
.hanko.red { color: #c8352a; }
.hanko.on { animation: hanko .28s cubic-bezier(.2,1.5,.5,1) forwards; }
@keyframes hanko { to { transform: scale(1) rotate(-14deg); opacity: .9; } }
.rv-rank, .rv-ans { list-style: none; padding: 0; margin: 10px 0 0; display: flex; flex-direction: column; gap: 6px; }
.rv-row { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 12px; background: var(--soft); text-align: left; transform: translateX(40px); opacity: 0; transition: .35s cubic-bezier(.3,1.4,.5,1); }
.rv-row.in { transform: none; opacity: 1; }
.rv-row.me { outline: 3px solid var(--accent); }
.rv-row.gold { background: color-mix(in srgb, #d4a62a 30%, var(--card)); }
.rv-pos { font-weight: 900; width: 20px; }
.rv-dot { width: 12px; height: 12px; border-radius: 4px; flex: none; }
.rv-name { flex: 1; min-width: 0; font-weight: 700; display: flex; align-items: center; gap: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rv-ans .rv-name { flex-direction: column; align-items: flex-start; gap: 0; }
.rv-name small { font-weight: 500; color: var(--sub); font-size: 12px; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.rv-name .crown { width: 24px; height: 18px; margin: 0; flex: none; }
.rv-up { color: var(--good); font-weight: 900; font-size: 13px; animation: bounce .6s ease 2; white-space: nowrap; }
.rv-down { color: var(--bad); font-size: 13px; }
@keyframes bounce { 50% { transform: translateY(-4px); } }
.rv-worth { font-size: 15px; }
.rv-pts { font-size: 18px; min-width: 36px; text-align: right; }
.rv-pts.ok { color: var(--good); }
.rv-pts.ng { color: var(--bad); }
.rv-go { margin-top: 16px; }
.rv-skip { position: fixed; top: calc(14px + env(safe-area-inset-top)); right: 16px; border: 1px solid rgba(255,255,255,.4); background: transparent; color: #fff; border-radius: 99px; padding: 4px 14px; font: inherit; font-size: 13px; cursor: pointer; }

@media (prefers-reduced-motion: reduce) { .pop, .opened, .rv-up { animation: none; } }
