:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface-1: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --danger: #d03b3b;
  --good: #006300;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #4a3aa7;
  --series-8: #e34948;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface-1: #1a1a19;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --accent-ink: #86b6ef;
    --danger: #e66767;
    --good: #0ca30c;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Yu Gothic UI", sans-serif;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}
.wrap { max-width: 720px; margin: 0 auto; padding: 20px 14px 60px; }
.wrap.wide { max-width: 960px; }

a { color: var(--accent-ink); }
h1 { font-size: 1.35rem; margin: 0 0 4px; }
h2 { font-size: 1.1rem; }
.desc { color: var(--text-secondary); white-space: pre-wrap; margin: 0 0 18px; }
.muted { color: var(--muted); font-size: 0.85rem; }

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 14px;
}
.card h3 { margin: 0 0 10px; font-size: 1rem; }

.flash {
  background: var(--surface-1);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 14px;
  font-size: 0.92rem;
}

/* ---- フォーム部品 ---- */
label.qlabel { display: block; font-weight: 600; margin-bottom: 8px; }
.req { color: var(--danger); font-size: 0.8rem; margin-left: 6px; }
input[type="text"], input[type="password"], textarea, select {
  width: 100%;
  font-size: 1rem;
  font-family: inherit;
  padding: 10px;
  border: 1px solid var(--baseline);
  border-radius: 8px;
  background: var(--page);
  color: var(--text-primary);
}
textarea { min-height: 90px; resize: vertical; }
.choice { display: block; padding: 8px 6px; border-radius: 6px; cursor: pointer; }
.choice:hover { background: var(--grid); }
.choice input { margin-right: 10px; transform: scale(1.2); }
.error { color: var(--danger); font-size: 0.85rem; margin-top: 6px; }

button, .btn {
  display: inline-block;
  font-size: 0.95rem;
  font-family: inherit;
  padding: 10px 18px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
  cursor: pointer;
  text-decoration: none;
}
button.primary, .btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
button.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
button.small, .btn.small { padding: 4px 10px; font-size: 0.82rem; }
.submit-row { margin-top: 20px; }
.submit-row button { width: 100%; padding: 14px; font-size: 1.05rem; }

/* ---- 管理画面 ---- */
.topbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-bottom: 18px;
}
.topbar .spacer { flex: 1; }
.badge {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  font-size: 0.78rem; border: 1px solid var(--border);
}
.badge.open { color: var(--good); border-color: var(--good); font-weight: 600; }
.badge.closed { color: var(--muted); }
.badge.tpl { color: var(--series-4); border-color: var(--series-4); font-weight: 600; }
table.list { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
table.list th, table.list td {
  text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--grid);
  vertical-align: middle;
}
table.list th { color: var(--muted); font-weight: 500; font-size: 0.8rem; }
.urlbox {
  display: flex; gap: 8px; align-items: center;
  background: var(--page); border: 1px dashed var(--baseline);
  border-radius: 8px; padding: 8px 10px; font-size: 0.88rem;
  word-break: break-all;
}
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
form.inline { display: inline; }

/* ---- 結果グラフ(横棒・単一系列) ---- */
.dist { margin: 0; }
.dist .row { display: grid; grid-template-columns: minmax(90px, 32%) 1fr; gap: 8px; align-items: center; padding: 3px 0; }
.dist .lbl { font-size: 0.88rem; color: var(--text-secondary); overflow-wrap: anywhere; }
.dist .barcell { display: flex; align-items: center; gap: 8px; min-height: 22px; }
.dist .bar {
  height: 18px; border-radius: 0 4px 4px 0;
  background: var(--series-1); min-width: 2px;
  border-left: 2px solid var(--baseline);
}
.dist .val { font-size: 0.85rem; color: var(--text-primary); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ---- 過去回比較(グループ横棒) ---- */
.legend { display: flex; gap: 14px; flex-wrap: wrap; margin: 10px 0 16px; font-size: 0.85rem; }
.legend .key { display: flex; align-items: center; gap: 6px; color: var(--text-secondary); }
.legend .sw { width: 12px; height: 12px; border-radius: 3px; }
.cmp-group { margin-bottom: 16px; }
.cmp-group .gtitle { font-size: 0.92rem; font-weight: 600; margin-bottom: 4px; }
.cmp-group .row { display: grid; grid-template-columns: minmax(90px, 30%) 1fr; gap: 8px; align-items: center; padding: 1px 0; }
.cmp-group .lbl { font-size: 0.8rem; color: var(--muted); overflow-wrap: anywhere; }
.cmp-group .barcell { display: flex; align-items: center; gap: 8px; min-height: 18px; }
.cmp-group .bar { height: 12px; border-radius: 0 4px 4px 0; min-width: 2px; border-left: 2px solid var(--baseline); }
.cmp-group .val { font-size: 0.78rem; color: var(--text-secondary); white-space: nowrap; font-variant-numeric: tabular-nums; }
.s1 { background: var(--series-1); } .s2 { background: var(--series-2); }
.s3 { background: var(--series-3); } .s4 { background: var(--series-4); }
.s5 { background: var(--series-5); } .s6 { background: var(--series-6); }
.s7 { background: var(--series-7); } .s8 { background: var(--series-8); }

/* ---- 記述式一覧 ---- */
ul.freetext { list-style: none; padding: 0; margin: 0; }
ul.freetext li {
  border-bottom: 1px solid var(--grid);
  padding: 8px 2px; font-size: 0.92rem; white-space: pre-wrap;
}
ul.freetext li:last-child { border-bottom: none; }

details.editq summary { cursor: pointer; font-weight: 600; }
.qmeta { color: var(--muted); font-size: 0.8rem; margin-left: 8px; font-weight: 400; }
.formgrid { display: grid; gap: 10px; margin-top: 10px; }
.check-inline { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; }
.check-inline input { transform: scale(1.15); }
