:root {
  --blue: #0071b9;
  --blue-dark: #1e3a8a;
  --blue-light: #60a5fa;
  --blue-disabled: #93c5fd;
  --pink: #ec4899;
  --pink-dark: #be185d;
  --pink-light: #f9a8d4;
  --text: #0f172a;
  --ink: #111111;
  --ground: #eff6ff;
  --card: #ffffff;
  --muted: #737373;
  --line: #e5e5e5;
  --vvh: 100dvh;
  --vvtop: 0px;
  --emoji-font: 'Apple Color Emoji', 'Segoe UI Emoji', 'Noto Color Emoji', sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--ground); color: var(--text); }
body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Yu Gothic', '游ゴシック', 'Hiragino Sans', 'ヒラギノ角ゴ Pro', sans-serif;
  font-weight: 500;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
button:active:not(:disabled) { opacity: 0.8; }
button:focus-visible, input:focus-visible, a:focus-visible { outline: 3px solid var(--blue-light); outline-offset: 2px; }
input { font-size: 16px; }
a { color: var(--blue); }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 48px; padding: 0 22px; border-radius: 999px;
  border: 3px solid var(--ink); background: var(--card); color: var(--text);
  font-size: 15px; font-weight: 900; text-decoration: none; white-space: nowrap;
}
.btn.primary {
  min-height: 52px; background: var(--blue); color: #fff; font-size: 16px;
  box-shadow: 4px 4px 0 var(--ink);
}
.btn.primary:disabled { background: var(--blue-disabled); cursor: default; }
.btn.block { width: 100%; }
.linkbtn { background: none; border: 0; padding: 8px 4px; color: var(--muted); font-size: 14px; font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
.pill {
  flex: none; min-height: 34px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--card); font-size: 14px; font-weight: 600;
}
.pill[aria-pressed='true'] { background: var(--blue); border-color: var(--blue); color: #fff; }
.label {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  background: var(--pink); color: #fff; font-size: 11px; font-weight: 900; white-space: nowrap;
}
.label.wait { background: var(--card); color: var(--pink-dark); border: 1.5px solid var(--pink); }
.label.live { background: var(--blue); }
.label.off { background: var(--muted); }

.card {
  background: var(--card); border: 3px solid var(--ink); border-radius: 22px;
  box-shadow: 6px 6px 0 var(--ink); padding: 18px;
}

/* ---------- scrollable pages ---------- */
.page {
  max-width: 520px; margin: 0 auto;
  padding: 16px max(16px, env(safe-area-inset-right)) calc(40px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  display: flex; flex-direction: column; gap: 16px;
}
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 40px; }
.logo { font-size: 20px; font-weight: 900; letter-spacing: 0.02em; text-decoration: none; color: var(--text); }
.logo b { color: var(--blue); }
.back { background: none; border: 0; padding: 8px 0; font-weight: 900; font-size: 15px; color: var(--text); }
h1, h2, h3 { margin: 0; font-weight: 900; line-height: 1.35; }
h1 { font-size: 24px; }
h2 { font-size: 19px; }
h3 { font-size: 16px; }
p { margin: 0; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.center { text-align: center; align-items: center; }

/* ---------- panel (コマ) ---------- */
.panel {
  position: relative; width: 100%; aspect-ratio: 1;
  background: #fff; border: 4px solid var(--ink); border-radius: 4px;
  box-shadow: 6px 6px 0 var(--ink);
  overflow: hidden; container-type: inline-size;
  user-select: none; -webkit-user-select: none;
}
.scene { position: absolute; inset: 0; z-index: 0; transform-origin: 50% 50%; }
.emo {
  position: absolute; left: 0; top: 0; line-height: 1; white-space: nowrap;
  transform: translate(-50%, -50%) rotate(var(--r, 0deg)) scaleX(var(--f, 1));
  font-size: calc(var(--s) * 1cqw); font-family: var(--emoji-font);
}
.covers { position: absolute; inset: 0; z-index: 1; }
.cover {
  position: absolute; background: #fff; padding: 1.1cqw;
  transition: opacity 0.3s;
}
.cover::before {
  content: ''; display: block; width: 100%; height: 100%;
  border: 0.9cqw solid var(--ink);
  background-color: #dbe4ef;
  background-image: radial-gradient(#9aa9bd 0.45cqw, transparent 0.55cqw);
  background-size: 2.4cqw 2.4cqw;
}
.cover.off { opacity: 0; }
.stamp {
  position: absolute; inset: 0; z-index: 3; display: grid; place-items: center; pointer-events: none;
}
.stamp span {
  font-size: 34px; font-weight: 900; padding: 2px 18px; transform: rotate(-8deg);
  border: 4px solid currentColor; border-radius: 8px; background: rgba(255, 255, 255, 0.9);
  animation: stamp 0.35s ease-out;
}
.stamp .ok { color: var(--blue); }
.stamp .ng { color: var(--muted); }
@keyframes stamp { from { transform: rotate(-8deg) scale(1.6); opacity: 0; } }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
.shake { animation: shake 0.3s; }

/* ---------- fixed full-height screens (editor, question) ---------- */
.fixed {
  position: fixed; left: 0; right: 0; top: var(--vvtop); height: var(--vvh);
  display: flex; flex-direction: column; overflow: hidden;
  padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right);
}
.stage {
  flex: 1 1 auto; min-height: 120px; container-type: size;
  display: grid; place-items: center; padding: 8px 16px 14px;
}
.pwrap { position: relative; width: min(100cqw, 100cqh); aspect-ratio: 1; }
.pwrap .panel { width: 100%; height: 100%; }

/* ---------- home ---------- */
.hero { display: flex; flex-direction: column; gap: 16px; }
.hero .panel { max-width: 300px; align-self: center; }
.home-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.home-actions .primary { grid-column: 1 / -1; }
.badge {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--pink); color: #fff;
  font-size: 12px; line-height: 20px; font-weight: 900;
}
details.trial { font-size: 14px; color: var(--muted); }
details.trial summary { cursor: pointer; padding: 6px 0; font-weight: 600; }
details.trial .row { margin-top: 6px; }
.notice { background: var(--card); border: 2px dashed var(--blue-light); border-radius: 16px; padding: 14px; }

/* ---------- play ---------- */
.play .hud { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px 0; font-weight: 900; font-variant-numeric: tabular-nums; }
.play .hud .pts { font-size: 26px; color: var(--blue); line-height: 1; }
.play .hud .quit { background: none; border: 0; padding: 4px 0; font-weight: 900; font-size: 18px; }
.meter { height: 8px; border-radius: 99px; background: var(--line); overflow: hidden; margin: 0 16px; }
.meter i { display: block; height: 100%; width: 100%; background: var(--blue); }
.play .bottom { padding: 8px 16px calc(10px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 8px; }
.cands { display: flex; gap: 8px; overflow-x: auto; min-height: 52px; align-items: center; scrollbar-width: none; }
.cands::-webkit-scrollbar { display: none; }
.cand {
  flex: none; display: flex; align-items: center; gap: 6px; max-width: 220px; height: 52px; padding: 4px 12px 4px 4px;
  border: 2px solid var(--ink); border-radius: 12px; background: var(--card); font-weight: 600; font-size: 14px; text-align: left;
}
.cand img, .cand .noimg { width: 30px; height: 42px; object-fit: cover; border-radius: 3px; flex: none; background: var(--line); }
.cand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cands .hint { color: var(--muted); font-size: 14px; padding-left: 4px; }
.answer-row { display: flex; gap: 8px; align-items: center; }
.field {
  flex: 1; min-width: 0; height: 48px; padding: 0 14px; border-radius: 14px;
  border: 3px solid var(--ink); background: var(--card); font-size: 16px;
}
.msg { min-height: 20px; font-size: 14px; color: var(--muted); font-weight: 600; }
.play .foot { display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--muted); }

.reveal-card { display: flex; gap: 14px; align-items: flex-start; }
.reveal-card .cover-img { width: 96px; height: auto; flex: none; border-radius: 4px; border: 1px solid var(--line); }
.reveal-card .noimg { width: 96px; aspect-ratio: 0.7; flex: none; border-radius: 4px; background: var(--line); display: grid; place-items: center; color: var(--muted); font-size: 12px; }
.reveal-title { font-size: 20px; font-weight: 900; line-height: 1.3; }
.ok-text { color: var(--blue); font-weight: 900; }
.votes { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.vote { min-height: 48px; border-radius: 999px; border: 3px solid var(--ink); background: var(--card); font-weight: 900; font-size: 15px; }
.vote[aria-pressed='true'] { background: var(--pink); color: #fff; }
.vote.kojitsuke[aria-pressed='true'] { background: var(--muted); }
.vote:disabled:not([aria-pressed='true']) { opacity: 0.45; }
.after-actions { display: flex; flex-direction: column; gap: 10px; }
.after-foot { display: flex; justify-content: space-between; align-items: center; }

.score-big { font-size: 56px; font-weight: 900; line-height: 1; color: var(--blue); }
.score-big small { font-size: 18px; color: var(--text); margin-left: 4px; }
pre.share { white-space: pre-wrap; margin: 0; font-family: inherit; font-size: 15px; background: var(--ground); border-radius: 12px; padding: 12px; line-height: 1.45; }

/* ---------- editor ---------- */
.ed-head { flex: none; height: 48px; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0 8px; }
.ed-head .icon { width: 44px; height: 44px; border: 0; background: none; font-size: 22px; font-weight: 900; }
.ed-head .next { min-height: 38px; padding: 0 16px; font-size: 15px; box-shadow: 3px 3px 0 var(--ink); border-width: 2.5px; }
.ed-head .plain { background: none; border: 0; font-weight: 900; font-size: 15px; padding: 8px; }
.ed-title { flex: 1; min-width: 0; text-align: center; font-size: 13px; color: var(--muted); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ed-title b { color: var(--text); }
.ed .panel { box-shadow: 5px 5px 0 var(--ink); touch-action: none; }
.ed .pwrap { touch-action: none; }
.overlay { position: absolute; inset: 4px; pointer-events: none; container-type: inline-size; z-index: 5; }
.selbox {
  position: absolute; left: 0; top: 0;
  width: max(44px, calc(var(--s) * 1.2cqw)); height: max(44px, calc(var(--s) * 1.2cqw));
  transform: translate(-50%, -50%) rotate(var(--r, 0deg));
  border: 2px dashed var(--blue); border-radius: 6px;
}
.handle {
  position: absolute; right: -36px; bottom: -36px; width: 44px; height: 44px;
  display: grid; place-items: center; pointer-events: auto; touch-action: none; cursor: nwse-resize;
}
.handle::before {
  content: '⤡'; width: 28px; height: 28px; border-radius: 50%; background: var(--blue); color: #fff;
  border: 2px solid #fff; box-shadow: 0 0 0 2px var(--blue); display: grid; place-items: center; font-size: 15px; font-weight: 900;
}
.empty-hint {
  position: absolute; inset: 0; z-index: 2; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  pointer-events: none; color: var(--muted); font-weight: 600; text-align: center; padding: 12px;
}
.empty-hint .theme { pointer-events: auto; }
.theme-chip { font-size: 15px; color: var(--text); }
.theme-chip b { color: var(--blue); }

.tray { flex: none; display: flex; flex-direction: column; background: var(--card); border-top: 3px solid var(--ink); padding-bottom: env(safe-area-inset-bottom); }
.toolbar { height: 48px; display: flex; align-items: center; gap: 2px; padding: 0 6px; border-bottom: 1px solid var(--line); }
.tool { min-width: 44px; height: 40px; border: 0; background: none; border-radius: 10px; font-size: 13px; font-weight: 600; padding: 0 6px; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1; }
.tool .ic { font-size: 18px; font-weight: 900; }
.tool:disabled { opacity: 0.3; }
.tool.del { color: var(--pink-dark); }
.toolbar .sep { width: 1px; height: 24px; background: var(--line); margin: 0 2px; flex: none; }
.toolbar .mid { flex: 1; display: flex; justify-content: space-around; align-items: center; min-width: 0; }
.toolbar .info { flex: 1; text-align: center; font-size: 13px; color: var(--muted); font-weight: 600; }
.toolbar .info.warn { color: var(--pink-dark); font-weight: 900; }
.search { height: 52px; display: flex; gap: 8px; align-items: center; padding: 4px 10px; }
.search input { flex: 1; min-width: 0; height: 42px; border-radius: 999px; border: 1px solid var(--line); background: var(--ground); padding: 0 16px; }
.search .done { flex: none; height: 38px; padding: 0 14px; border-radius: 999px; border: 0; background: var(--blue); color: #fff; font-weight: 900; }
.tray-note { font-size: 12px; color: var(--pink-dark); font-weight: 900; padding: 0 16px 2px; min-height: 0; }
.cats { height: 40px; display: flex; gap: 6px; overflow-x: auto; padding: 3px 10px; scrollbar-width: none; }
.cats::-webkit-scrollbar { display: none; }
.cats .pill { min-height: 32px; font-size: 13px; padding: 0 12px; }
.egrid {
  height: 138px; overflow-y: auto; overscroll-behavior: contain;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); grid-auto-rows: 44px;
  padding: 2px 8px 6px; align-content: start;
}
.egrid button { border: 0; background: none; border-radius: 10px; font-size: 28px; line-height: 1; padding: 0; font-family: var(--emoji-font); }
.egrid button:hover { background: var(--ground); }
.egrid .none { grid-column: 1 / -1; font-size: 13px; color: var(--muted); padding: 10px 6px; }

/* keyboard open: panel shrinks above, results become two horizontal rows right above the keyboard */
.ed.typing .ed-head, .ed.typing .cats { display: none; }
.ed.typing .egrid {
  height: 92px; grid-template-columns: none; grid-template-rows: repeat(2, 44px); grid-auto-flow: column; grid-auto-columns: 44px;
  overflow-x: auto; overflow-y: hidden;
}
.ed.typing .stage { padding-top: 10px; }

/* ② 見せ方 */
.frame-hole { position: absolute; z-index: 2; box-shadow: 0 0 0 200cqw rgba(15, 23, 42, 0.55); outline: 3px solid #fff; border: 2px dashed var(--blue); pointer-events: none; }
.frame-tip {
  position: absolute; z-index: 3; transform: translate(-50%, -100%); margin-top: -8px; white-space: nowrap;
  background: var(--blue); color: #fff; font-size: 12px; font-weight: 900; padding: 3px 10px; border-radius: 999px; pointer-events: none;
}
.focus-dot { position: absolute; z-index: 3; width: 12px; height: 12px; border-radius: 50%; background: var(--blue); border: 2px solid #fff; transform: translate(-50%, -50%); pointer-events: none; }
.frame-ctl { flex: none; background: var(--card); border-top: 3px solid var(--ink); padding: 10px 16px calc(12px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 8px; }
.scrub { display: flex; align-items: center; gap: 10px; }
.scrub .playbtn { width: 44px; height: 44px; flex: none; border-radius: 50%; border: 3px solid var(--ink); background: var(--card); font-size: 16px; font-weight: 900; }
.scrub input[type='range'] { flex: 1; accent-color: var(--blue); height: 44px; }
.scrub .pts { width: 56px; text-align: right; font-weight: 900; font-size: 18px; color: var(--blue); font-variant-numeric: tabular-nums; }
.scrub-labels { display: flex; justify-content: space-between; padding: 0 64px 0 54px; margin-top: -10px; font-size: 12px; color: var(--muted); }
.fact { font-size: 14px; font-weight: 600; }
.fact.warn { color: var(--pink-dark); font-weight: 900; }

/* ③ sheet */
.backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.45); z-index: 40; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: calc(100% - var(--vvtop) - var(--vvh)); z-index: 41;
  max-height: calc(var(--vvh) - 24px); max-width: 560px; margin: 0 auto;
  display: flex; flex-direction: column; background: var(--card);
  border: 3px solid var(--ink); border-bottom: 0; border-radius: 22px 22px 0 0;
}
.sheet-body { overflow-y: auto; overscroll-behavior: contain; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 10px; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.sheet-head button { background: none; border: 0; font-size: 22px; width: 44px; height: 44px; font-weight: 900; }
.results { display: flex; flex-direction: column; gap: 6px; }
.result {
  display: flex; gap: 10px; align-items: center; text-align: left; padding: 6px; border-radius: 12px;
  border: 2px solid var(--line); background: var(--card); min-height: 64px;
}
.result[aria-pressed='true'] { border-color: var(--blue); background: var(--ground); box-shadow: 0 0 0 2px var(--blue); }
.result img, .result .noimg { width: 38px; height: 54px; object-fit: cover; border-radius: 3px; flex: none; background: var(--line); }
.result .t { font-weight: 900; font-size: 15px; line-height: 1.3; }
.result .a { font-size: 12px; color: var(--muted); }
.field-label { font-size: 14px; font-weight: 900; }
.warn-text { color: var(--pink-dark); font-weight: 900; font-size: 14px; }

/* menu */
.menu { position: fixed; z-index: 51; top: calc(var(--vvtop) + 52px); left: 8px; background: var(--card); border: 3px solid var(--ink); border-radius: 16px; box-shadow: 4px 4px 0 var(--ink); overflow: hidden; display: flex; flex-direction: column; }
.menu button { border: 0; background: none; text-align: left; padding: 14px 18px; font-weight: 600; font-size: 15px; border-bottom: 1px solid var(--line); }
.menu button:last-child { border-bottom: 0; }
.menu-backdrop { position: fixed; inset: 0; z-index: 50; }

/* ---------- mine ---------- */
.mine-head { display: flex; justify-content: space-between; align-items: center; }
.diff { font-weight: 900; color: var(--pink-dark); }
.mine-item { display: flex; gap: 12px; align-items: center; text-align: left; width: 100%; background: var(--card); border: 3px solid var(--ink); border-radius: 18px; padding: 10px; box-shadow: 4px 4px 0 var(--ink); }
.mine-item .panel { width: 72px; flex: none; border-width: 2px; box-shadow: none; }
.mine-item .info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.mine-item .t { font-weight: 900; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mine-item .stats { font-size: 13px; color: var(--muted); }
.bars { display: flex; flex-direction: column; gap: 6px; }
.bar { display: grid; grid-template-columns: 7.5em 1fr 2.5em; gap: 8px; align-items: center; font-size: 13px; }
.bar .track { height: 12px; background: var(--ground); border-radius: 99px; overflow: hidden; }
.bar .track i { display: block; height: 100%; background: var(--blue); border-radius: 99px; }
.bar.miss .track i { background: var(--muted); }
.bar .n { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.statgrid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.stat { background: var(--ground); border-radius: 14px; padding: 10px 12px; }
.stat b { display: block; font-size: 22px; font-weight: 900; }
.stat span { font-size: 12px; color: var(--muted); }
ol.wrongs { margin: 0; padding-left: 1.4em; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 100;
  background: var(--text); color: #fff; padding: 10px 18px; border-radius: 999px; font-weight: 600; font-size: 14px;
}

/* PC: panel left, tray right */
@media (min-width: 860px) and (min-height: 560px) {
  .ed:not(.typing) .ed-body { flex-direction: row; }
  .ed .ed-body > .tray, .ed .ed-body > .frame-ctl { width: 400px; border-top: 0; border-left: 3px solid var(--ink); justify-content: flex-start; }
  .ed .egrid { height: auto; flex: 1; }
}
.ed-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }

@media (prefers-reduced-motion: reduce) {
  .shake, .stamp span { animation: none; }
  .cover { transition: none; }
}
.sublink { font-size: 13px; font-weight: 600; color: var(--muted); text-decoration: none; padding: 8px 0; }
pre.share { align-self: stretch; text-align: left; }
.sheet .field { flex: none; }
.tool .ic { font-size: 20px; }
.ed-head { padding-right: 14px; }
.bar { grid-template-columns: 9.5em 1fr 2em; }
