:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --text: #1b2430;
  --muted: #5d6b7c;
  --line: #dde3ea;
  --brand: #1f3a5f;
  --accent: #e4572e;
  --accent-ink: #ffffff;
  --ok: #1f8a4c;
  --warn: #b7791f;
  --danger: #c0392b;
  --chip: #e7eef7;
  --best: #fff4d6;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11161d;
    --surface: #1a212b;
    --text: #e6ebf1;
    --muted: #9aa7b6;
    --line: #2c3643;
    --brand: #0e1824;
    --accent: #ff7a50;
    --accent-ink: #1a0e08;
    --ok: #4cc283;
    --warn: #e0a84a;
    --danger: #ff6b5b;
    --chip: #263345;
    --best: #3a3218;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
  line-height: 1.55;
}
[hidden] { display: none !important; }
h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.3; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.1rem; }
h4 { font-size: 1rem; margin-top: 1.2rem; }
.muted { color: var(--muted); }
.small-text { font-size: .85rem; }

/* ---------- app bar ---------- */
.appbar { background: var(--brand); color: #fff; position: sticky; top: 0; z-index: 10; }
.appbar-inner { max-width: 960px; margin: 0 auto; padding: .7rem 16px; display: flex; align-items: center; justify-content: space-between; }
.brand { margin: 0; font-size: 1.1rem; font-weight: 600; }
.brand b { color: #ffb38f; }
.linklike { background: none; border: 0; color: inherit; font: inherit; padding: 0; cursor: pointer; }
.icon-btn { background: rgba(255,255,255,.12); border: 0; color: #fff; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; cursor: pointer; }
.icon-btn:hover { background: rgba(255,255,255,.22); }

.page { max-width: 960px; margin: 0 auto; padding: 16px 16px 120px; }

/* ---------- common ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
input[type=text], input[type=number], input[type=password], input[type=datetime-local] {
  width: 100%; font: inherit; font-size: 1.05rem; padding: .65rem .75rem; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
}
input:focus-visible, button:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 1px; }
.btn { font: inherit; font-weight: 600; border-radius: 10px; padding: .65rem 1.1rem; border: 1px solid transparent; cursor: pointer; background: var(--chip); color: var(--text); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; border-color: var(--line); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.small { padding: .35rem .7rem; font-size: .85rem; }
.btn.block { width: 100%; padding: .85rem; font-size: 1.05rem; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 8px; }
.btn-row.end { justify-content: flex-end; margin-top: 12px; }
.error { color: var(--danger); min-height: 1.2em; margin: 0 0 8px; font-size: .9rem; }
.chip { display: inline-block; background: var(--chip); border-radius: 999px; padding: .15rem .65rem; font-size: .85rem; font-weight: 600; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check { display: flex; gap: 8px; align-items: center; margin: 8px 0 12px; }

/* ---------- join ---------- */
.join-card { max-width: 420px; margin: 24px auto; }

/* ---------- vote ---------- */
.whoami { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; gap: 8px; }
.whoami strong { font-size: 1.1rem; overflow-wrap: anywhere; }
.deadline { border-radius: 10px; padding: .6rem .9rem; margin-bottom: 12px; font-weight: 600; background: var(--chip); }
.deadline.open { background: color-mix(in srgb, var(--ok) 15%, var(--surface)); color: var(--ok); }
.deadline.soon { background: color-mix(in srgb, var(--warn) 18%, var(--surface)); color: var(--warn); }
.deadline.closed { background: color-mix(in srgb, var(--danger) 15%, var(--surface)); color: var(--danger); }
.questions { list-style: none; padding: 0; margin: 0; }
.q-item { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; }
.q-item.empty { border-style: dashed; }
.q-head { display: flex; gap: 10px; align-items: baseline; margin-bottom: 8px; }
.q-no { font-weight: 800; color: var(--accent); flex: none; }
.q-text { overflow-wrap: anywhere; }
.q-input { display: flex; align-items: center; gap: 10px; }
.q-input input[type=range] { flex: 1; min-width: 0; accent-color: var(--accent); height: 32px; }
.q-item.empty input[type=range] { opacity: .35; }
.q-num { display: flex; align-items: center; gap: 4px; flex: none; }
.q-num input { width: 5.2rem; text-align: right; font-size: 1.3rem; font-weight: 700; padding: .4rem .5rem; }
.q-num span { font-weight: 700; }
.step { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font-size: 1.2rem; cursor: pointer; flex: none; }
.q-clear { margin-top: 6px; font-size: .8rem; color: var(--muted); background: none; border: 0; padding: 0; cursor: pointer; text-decoration: underline; }
.savebar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 9;
  background: var(--surface); border-top: 1px solid var(--line);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
}
.savebar .btn { padding: .8rem 1.6rem; font-size: 1.05rem; }
.save-status { font-size: .88rem; color: var(--muted); }
.save-status.dirty { color: var(--warn); font-weight: 600; }
.save-status.saved { color: var(--ok); }

/* ---------- admin ---------- */
.admin-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.admin-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.tabs { display: flex; gap: 4px; overflow-x: auto; margin-bottom: 14px; border-bottom: 1px solid var(--line); }
.tab { font: inherit; font-weight: 600; background: none; border: 0; padding: .6rem .9rem; color: var(--muted); border-bottom: 3px solid transparent; cursor: pointer; white-space: nowrap; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { padding: .5rem .6rem; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { font-size: .8rem; color: var(--muted); font-weight: 600; }
tr.top td { background: var(--best); }
td.points { font-size: 1.15rem; font-weight: 800; }
td.zero { color: var(--ok); font-weight: 700; }
.bonus { color: var(--ok); font-size: .75rem; font-weight: 700; margin-left: 2px; }
.na { color: var(--muted); }
.q-result h3 { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.q-result .answer { margin-left: auto; font-size: .95rem; }
details { margin-top: 10px; }
summary { cursor: pointer; color: var(--muted); font-size: .9rem; }
.indiv { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 0; padding: 0; list-style: none; }
.indiv li { background: var(--chip); border-radius: 8px; padding: .15rem .55rem; font-size: .85rem; }
.indiv b { margin-right: 4px; }
.group-block { margin-bottom: 8px; }
.group-block h4 { margin: 10px 0 6px; }
.member-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: .4rem 0; border-bottom: 1px solid var(--line); }
.member-row .name { overflow-wrap: anywhere; }
.member-row .meta { color: var(--muted); font-size: .8rem; }
.setq-list { padding-left: 1.6rem; margin: 0; }
.setq-list li { margin-bottom: 10px; }
.setq-row { display: grid; grid-template-columns: 1fr 6.5rem; gap: 8px; align-items: center; }
.setq-row label { display: flex; align-items: center; gap: 4px; }
.setq-row input[type=number] { text-align: right; }
.danger-zone { border-color: color-mix(in srgb, var(--danger) 45%, var(--line)); }
.qr-one { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.qr-box { background: #fff; padding: 8px; border-radius: 10px; line-height: 0; }
.qr-box svg, .qr-cell svg { width: 180px; height: 180px; }
.qr-url { flex: 1; min-width: 200px; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.qr-url code { word-break: break-all; font-size: .85rem; }
.qr-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.qr-cell { background: #fff; color: #111; border: 1px solid #ccc; border-radius: 10px; padding: 10px; text-align: center; break-inside: avoid; }
.qr-cell svg { width: 140px; height: 140px; }
.qr-cell p { margin: 4px 0 0; font-weight: 800; font-size: 1.2rem; }

/* ---------- dialog / toast ---------- */
dialog { border: 0; border-radius: var(--radius); padding: 20px; width: min(92vw, 380px); background: var(--surface); color: var(--text); }
dialog::backdrop { background: rgba(0,0,0,.45); }
.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%) translateY(20px);
  background: #1b2430; color: #fff; padding: .6rem 1.1rem; border-radius: 999px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 20; max-width: calc(100vw - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--danger); }

@media (max-width: 480px) {
  .grid2 { grid-template-columns: 1fr; gap: 0; }
  .q-num input { width: 4.4rem; }
  .step { width: 36px; }
}

@media print {
  .appbar, .admin-head, .tabs, .deadline, .tabpanel > .card:not(:last-child), .btn-row, h3 + .btn-row { display: none !important; }
  body { background: #fff; }
  .page { padding: 0; }
  .card { border: 0; padding: 0; }
  .qr-grid { grid-template-columns: repeat(3, 1fr); }
}
