:root {
  color-scheme: light;
  --paper: var(--sakasen-paper);
  --white: var(--sakasen-panel);
  --ink: var(--sakasen-ink);
  --muted: var(--sakasen-muted);
  --line: var(--sakasen-line);
  --mint: #e2f5eb;
  --green: #175c3e;
  --rose: #fbe8e5;
  --red: #923c34;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  min-width: 300px;
  font-family: var(--sakasen-font);
  font-size: .9375rem;
  line-height: 1.65;
  color: var(--ink);
  background: var(--paper);
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3, p { margin: 0; }
a { color: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; }
button:focus-visible, a:focus-visible {
  outline: 3px solid #657a20;
  outline-offset: 4px;
}
.icon-defs { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon {
  width: 1.25rem;
  height: 1.25rem;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.topbar { border-bottom: 1px solid var(--line); }
.topbar-inner, .shell {
  width: min(1080px, calc(100% - 64px));
  margin-inline: auto;
}
.topbar-inner {
  min-height: 84px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
}
.small-icon, .guide-icon {
  display: inline-grid;
  place-items: center;
  flex: none;
}
.shell { padding-block: 38px 32px; }
.button {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: .58rem 1rem;
  gap: .45rem;
  border: 1px solid transparent;
  border-radius: 7px;
  font-weight: 600;
  line-height: 1.4;
  color: inherit;
  background: transparent;
  cursor: pointer;
  transition: background .14s ease, transform .14s ease, border-color .14s ease;
  text-align: center;
}
.button:disabled { cursor: default; opacity: .47; }
.button:not(:disabled):active { transform: translateY(1px); }
.button-quiet { color: var(--muted); }
.button-quiet:not(:disabled):hover { background: #eeefe6; color: var(--ink); }
.button-outline { border-color: var(--line); background: var(--white); }
.button-outline:not(:disabled):hover { background: #f1f2e8; border-color: #b3b6a4; }
.button-primary {
  color: var(--white);
  background: var(--ink);
  border-color: var(--ink);
  min-height: 52px;
  padding-inline: 1.3rem;
}
.button-primary:not(:disabled):hover { background: #484c3f; border-color: #484c3f; }
.button-correct { background: var(--mint); color: var(--green); border-color: #a8d8be; }
.button-correct:not(:disabled):hover { background: #cdebdc; }
.button-incorrect { background: var(--rose); color: var(--red); border-color: #ecc0b9; }
.button-incorrect:not(:disabled):hover { background: #f7d6d1; }
.audio-button { min-height: 42px; font-size: .875rem; white-space: nowrap; padding-inline: .55rem; }
.audio-button .icon { width: 1.125rem; height: 1.125rem; }
.audio-button[aria-pressed="true"] { color: var(--ink); }
.setup {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(250px, .8fr);
  gap: clamp(2rem, 7vw, 5rem);
  align-items: center;
  min-height: 410px;
  padding: clamp(1.5rem, 6vw, 4.8rem);
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--white);
}
.context-line { font-size: .875rem; color: var(--muted); font-weight: 500; margin-bottom: .3rem; }
h1 { font-size: clamp(1.9rem, 3.7vw, 2.65rem); line-height: 1.32; letter-spacing: -.035em; font-weight: 600; }
h2 { font-size: 1.075rem; line-height: 1.45; letter-spacing: -.016em; font-weight: 600; }
.setup h1 { font-size: clamp(2rem, 5.5vw, 3.5rem); }
.intro-copy { margin-block: .9rem 1.55rem; max-width: 30rem; color: var(--muted); line-height: 1.85; }
.setup-guide { border-left: 1px solid var(--line); padding-left: clamp(1rem, 4vw, 3.25rem); }
.setup-guide ol { padding: 0; margin: .8rem 0 0; list-style: none; display: grid; gap: .85rem; }
.setup-guide li { display: flex; align-items: center; gap: .7rem; color: var(--muted); font-weight: 500; }
.guide-icon { width: 36px; height: 36px; border-radius: 8px; background: #f1f3d8; color: var(--ink); }
.page-heading {
  display: flex;
  gap: 1rem;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 22px;
}
.connection {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  font-size: .875rem;
  font-weight: 550;
  color: var(--green);
  white-space: nowrap;
  margin-bottom: .3rem;
}
.connection > span:first-child { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.connection[data-offline="true"] { color: var(--red); }
.workspace-grid {
  display: grid;
  gap: 20px;
  grid-template-columns: minmax(0, 1fr) 305px;
  align-items: start;
}
#room[data-phase="ended"] .workspace-grid { grid-template-columns: minmax(0, 1fr); }
.card {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 24px;
}
.stage { padding: clamp(1.1rem, 2.7vw, 1.75rem); }
.stage-top { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: start; gap: 1rem; }
.round-label { color: var(--muted); font-size: .9rem; font-weight: 500; margin-top: .27rem; }
.stage-track {
  list-style: none;
  display: flex;
  gap: .2rem;
  flex-wrap: wrap;
  margin: 0;
  padding: .25rem;
  border-radius: 8px;
  background: var(--paper);
}
.stage-track li {
  padding: .3rem .68rem;
  border-radius: 5px;
  font-size: .875rem;
  line-height: 1.3;
  font-weight: 550;
  color: var(--muted);
  white-space: nowrap;
}
.stage-track li[aria-current="step"] { color: var(--ink); background: var(--sakasen-lime); }
.stage-state {
  --stage-bg: #f3f4ef;
  --stage-icon-bg: #e5e9e1;
  min-height: 143px;
  display: flex;
  align-items: center;
  gap: 1rem;
  border-radius: 9px;
  padding: clamp(1rem, 3vw, 1.5rem);
  background: var(--stage-bg);
  margin-top: 1.35rem;
}
.stage-state[data-phase="open"] { --stage-bg: #f5f5de; --stage-icon-bg: var(--sakasen-lime); }
.stage-state[data-phase="answering"] { --stage-bg: #eaf1ff; --stage-icon-bg: #d2e2ff; }
.stage-state[data-phase="correct"] { --stage-bg: #eaf6ef; --stage-icon-bg: #caebd8; }
.stage-state[data-phase="incorrect"] { --stage-bg: #fcf0ee; --stage-icon-bg: #f6d9d3; }
.stage-icon {
  display: inline-grid;
  width: 52px;
  height: 52px;
  border-radius: 8px;
  place-items: center;
  background: var(--stage-icon-bg);
  flex: none;
}
.stage-icon .icon { width: 27px; height: 27px; stroke-width: 2; }
.stage-information { min-width: 0; }
.stage-state h3 {
  font-size: clamp(1.13rem, 3.3vw, 1.65rem);
  line-height: 1.38;
  letter-spacing: -.02em;
  font-weight: 600;
  overflow-wrap: anywhere;
}
.stage-state p { margin-top: .27rem; color: var(--muted); }
.stage-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .65rem .85rem;
  margin-top: 1.1rem;
  min-height: 52px;
}
.stage-actions:empty { display: none; }
.judge-actions { display: flex; gap: .55rem; flex-wrap: wrap; }
.judge-actions .button { min-width: 104px; min-height: 52px; }
.invite { grid-column: 2; grid-row: span 2; }
.invite-header, .roster-header, .roster-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .7rem;
}
.invite-header { align-items: start; }
.invite-header p { color: var(--muted); font-size: .875rem; margin-top: .35rem; }
.small-icon { width: 35px; height: 35px; border-radius: 7px; color: var(--ink); background: var(--paper); }
.qr-box {
  aspect-ratio: 1;
  margin: .85rem auto .65rem;
  width: min(100%, 216px);
  display: grid;
  place-items: center;
  color: var(--ink);
  background: #fff;
}
.qr-box svg { display: block; width: 100%; height: 100%; shape-rendering: crispEdges; }
.qr-note { font-size: .875rem; color: var(--muted); text-align: center; }
.invite-actions { display: grid; grid-template-columns: 1fr; gap: .18rem; margin-top: 1rem; }
.invite-actions .button { font-size: .9rem; width: 100%; }
.manual-link { display: block; text-align: center; overflow-wrap: anywhere; }
.roster { grid-column: 1; padding-block: 19px; }
.roster-heading { justify-content: flex-start; }
.roster-count { color: var(--muted); border-radius: 100px; background: var(--paper); padding: .06rem .55rem; font-size: .875rem; font-weight: 550; }
.roster-hint { color: var(--muted); font-size: .875rem; }
.roster-empty { margin: .7rem 0 .1rem; color: var(--muted); }
.player-list { display: grid; gap: .15rem; margin: .7rem 0 0; padding: 0; list-style: none; max-height: 320px; overflow: auto; scrollbar-gutter: stable; }
.player-row { display: grid; grid-template-columns: auto minmax(4ch, 1fr) auto auto; align-items: center; gap: .6rem; min-height: 43px; padding: .25rem .38rem; border-radius: 9px; }
.player-row + .player-row { border-top: 1px solid #f0f1ec; }
.player-row[data-winner="true"] { background: #f1f5ff; }
.player-icon { color: var(--muted); display: inline-flex; }
.player-icon .icon { width: 1.1rem; height: 1.1rem; }
.player-name { min-width: 0; overflow-wrap: anywhere; }
.player-mark { color: var(--muted); font-size: .875rem; justify-self: end; }
.player-score { width: 2rem; text-align: right; font-size: 1.1rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.end-control { display: flex; justify-content: flex-end; margin-top: .85rem; }
.end-control .button { font-size: .875rem; }
.error { font-size: .875rem; margin-top: .75rem; color: var(--red); }
.dialog {
  width: min(540px, calc(100% - 30px));
  max-height: calc(100% - 30px);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: clamp(1rem, 4vw, 1.75rem);
  color: var(--ink);
  background: var(--white);
}
.dialog::backdrop { background: rgba(34, 35, 31, .57); }
.dialog-header, .dialog-actions { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.dialog .icon-button { width: 44px; min-height: 44px; padding: 0; }
.qr-dialog .qr-box { width: min(100%, 62vh, 405px); margin-block: .3rem; }
.projector-note { margin: .2rem 0 0; color: var(--muted); text-align: center; }
.end-dialog { width: min(400px, calc(100% - 30px)); }
.end-dialog p { margin: .6rem 0 1.2rem; color: var(--muted); }
.dialog-actions { justify-content: flex-end; }
.noscript { text-align: center; padding-inline: 1rem; }

@media (max-width: 790px) {
  .workspace-grid { grid-template-columns: minmax(0, 1fr) 255px; gap: 14px; }
  .topbar-inner, .shell { width: calc(100% - 34px); }
  .invite { padding: 16px; }
}
@media (max-width: 640px) {
  .topbar-inner { min-height: 72px; }
  .shell { padding-block: 24px; }
  .workspace-grid { grid-template-columns: minmax(0, 1fr); }
  .invite, .roster { grid-column: 1; grid-row: auto; }
  .setup { grid-template-columns: minmax(0, 1fr); gap: 1.5rem; padding: 1.4rem; }
  .setup-guide { border-left: 0; border-top: 1px solid var(--line); padding: 1.2rem 0 0; }
}
@media (max-width: 390px) {
  .stage-track li { padding-inline: .45rem; }
  .stage-state { gap: .65rem; }
  .stage-icon { width: 43px; height: 43px; }
  .stage-icon .icon { width: 22px; height: 22px; }
}

body.demo-frame { font-size: .875rem; }
.demo-frame .topbar-inner, .demo-frame .shell { width: calc(100% - 32px); }
.demo-frame .topbar-inner { min-height: 52px; justify-content: flex-end; }
.demo-frame .shell { padding-block: 14px 10px; }
.demo-frame .page-heading { margin-bottom: 10px; }
.demo-frame .page-heading h1 { font-size: 1.35rem; }
.demo-frame h2 { font-size: .95rem; }
.demo-frame .context-line, .demo-frame .connection, .demo-frame .round-label { font-size: .75rem; margin: 0; }
.demo-frame .workspace-grid { grid-template-columns: minmax(0, 1fr) minmax(142px, 31%); gap: 10px; }
.demo-frame .card { padding: 12px; }
.demo-frame .stage-top { gap: .45rem; }
.demo-frame .stage-track { gap: .1rem; padding: .15rem; }
.demo-frame .stage-track li { font-size: .72rem; padding: .23rem .43rem; }
.demo-frame .stage-state { min-height: 80px; padding: 12px; gap: 10px; margin-top: 10px; }
.demo-frame .stage-state h3 { font-size: clamp(1rem, 2.7vw, 1.25rem); }
.demo-frame .stage-state p { margin-top: .15rem; }
.demo-frame .stage-icon { width: 37px; height: 37px; }
.demo-frame .stage-icon .icon { width: 21px; height: 21px; }
.demo-frame .stage-controls { gap: .3rem .55rem; min-height: 38px; margin-top: 9px; }
.demo-frame .button { min-height: 42px; padding: .35rem .62rem; font-size: .875rem; }
.demo-frame .button .icon { width: 1rem; height: 1rem; }
.demo-frame .judge-actions { gap: .3rem; }
.demo-frame .judge-actions .button { min-width: 78px; }
.demo-frame .invite-header, .demo-frame .roster-heading { gap: .4rem; }
.demo-frame .invite-header p { font-size: .72rem; margin-top: .15rem; }
.demo-frame .small-icon { width: 28px; height: 28px; }
.demo-frame .small-icon .icon { width: 1rem; height: 1rem; }
.demo-frame .invite .qr-box { width: min(100%, 130px); margin: .4rem auto; }
.demo-frame .invite-actions { margin-top: .4rem; }
.demo-frame .roster-count, .demo-frame .roster-hint, .demo-frame .player-mark { font-size: .73rem; }
.demo-frame .roster-empty, .demo-frame .player-list { margin-top: .35rem; }
.demo-frame .player-list { max-height: 92px; }
.demo-frame .player-row { min-height: 32px; gap: .4rem; }
.demo-frame .player-score { width: 1.4rem; font-size: .9rem; }
.demo-frame .end-control { margin-top: .3rem; }
.demo-frame .setup { min-height: 0; padding: 24px; gap: 18px; }
.demo-frame .setup h1 { font-size: clamp(1.6rem, 4vw, 2.4rem); }
.demo-frame .intro-copy { margin-block: .6rem 1rem; }
.demo-frame .setup-guide { padding-left: 18px; }
.demo-frame .setup-guide ol { gap: .45rem; }
.demo-frame .guide-icon { width: 30px; height: 30px; }
.demo-frame .dialog .icon-button { min-height: 44px; padding: 0; }

@media (max-width: 640px) {
  .demo-frame .invite { grid-column: 2; grid-row: span 2; }
  .demo-frame .setup-guide { padding-left: 0; }
}
@media (max-width: 510px) {
  .demo-frame .topbar-inner, .demo-frame .shell { width: calc(100% - 24px); }
  .demo-frame .workspace-grid { grid-template-columns: minmax(0, 1fr) minmax(122px, .9fr); }
  .demo-frame .stage { grid-column: 1 / -1; }
  .demo-frame .invite { grid-column: 2; grid-row: 2; }
  .demo-frame .roster { grid-row: 2; }
}
@media (max-width: 360px) {
  .demo-frame .workspace-grid { grid-template-columns: minmax(0, 1fr); }
  .demo-frame .invite, .demo-frame .roster { grid-column: 1; grid-row: auto; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}
