:root {
  color-scheme: light;
  --bg: #f6f7fb;
  --panel: #fff;
  --ink: #16172a;
  --muted: #565b72;
  --line: #dedfeb;
  --accent: #5147e5;
  --accent-text: #4137cc;
  --soft: #eeecff;
  --danger: #a62542;
  --done-bg: #def4ec;
  --done-ink: #166149;
  font-family: "Hiragino Sans", "Yu Gothic", system-ui, sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121322;
  --panel: #1c1d30;
  --ink: #f5f3ff;
  --muted: #b4b3c9;
  --line: #383a55;
  --accent: #6559ed;
  --accent-text: #bdb6ff;
  --soft: #292550;
  --danger: #ff91a8;
  --done-bg: #193b35;
  --done-ink: #99e6ca;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  min-height: 100svh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) calc(18px + env(safe-area-inset-bottom)) env(safe-area-inset-left);
  user-select: none;
  -webkit-user-select: none;
}
input:not([type="checkbox"]), textarea {
  user-select: text;
  -webkit-user-select: text;
}
button, input, select { font: inherit; }
button, select, input:not([type="checkbox"]) {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--ink);
  background: var(--panel);
}
button { padding: 8px 14px; font-weight: 700; cursor: pointer; touch-action: manipulation; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { cursor: default; }
:focus-visible { outline: 3px solid var(--accent-text); outline-offset: 3px; }
h1, h2, p { margin: 0; }
h1 { font-size: 1.25rem; }
h2 { font-size: 1.1rem; }
.top { border-bottom: 1px solid var(--line); background: var(--panel); }
.top-inner {
  max-width: 820px;
  min-height: 66px;
  padding: 8px 20px;
  margin: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.brand { display: flex; gap: 4px; align-items: center; font-size: 1.23rem; font-weight: 900; letter-spacing: .035em; }
.brand img { margin-right: 5px; }
.brand span { color: var(--accent-text); }
.theme { width: 44px; padding: 0; font-size: 1.35rem; }
main { width: min(100%, 820px); margin: auto; padding: 20px 20px 0; }
.navigation { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; background: var(--panel); padding: 4px; border: 1px solid var(--line); border-radius: 16px; margin-bottom: 16px; }
.navigation button { border: 0; color: var(--muted); }
.navigation [aria-current] { background: var(--soft); color: var(--accent-text); }
#notice:empty { display: none; }
#notice { margin-bottom: 10px; color: var(--accent-text); font-size: .875rem; overflow-wrap: anywhere; }
.panel { border-radius: 20px; border: 1px solid var(--line); background: var(--panel); }
.controls, .section { padding: 16px; }
.controls { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; align-items: end; }
.group-field { display: grid; gap: 5px; color: var(--muted); font-size: .8rem; font-weight: 700; min-width: 0; }
.group-field select { width: 100%; padding: 6px 10px; font-size: 1rem; min-width: 0; }
.progress-block { display: grid; gap: 8px; padding-bottom: 5px; }
.progress-label { display: flex; justify-content: space-between; gap: 8px; font-size: .9rem; color: var(--muted); }
.progress-label strong, .progress-label b { color: var(--ink); }
progress { width: 100%; height: 8px; border: 0; border-radius: 9px; color: var(--accent); background: var(--soft); overflow: hidden; }
progress::-webkit-progress-bar { background: var(--soft); }
progress::-webkit-progress-value { background: var(--accent); border-radius: 9px; }
progress::-moz-progress-bar { background: var(--accent); border-radius: 9px; }
.result {
  min-height: clamp(180px, 31svh, 310px);
  margin: 14px 0;
  padding: 16px;
  border-radius: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: #fff;
  background: radial-gradient(ellipse at 100% 0, #5849d8 0%, transparent 65%), #21204a;
}
.result.has-result { background: radial-gradient(ellipse at 100% 0, #7262f5 0%, transparent 70%), #4335c8; }
.result-label { font-size: .85rem; letter-spacing: .12em; font-weight: 700; }
.number { font-size: clamp(4.25rem, 15svh, 8rem); line-height: 1; font-weight: 900; font-variant-numeric: tabular-nums; }
.placeholder { color: #c5bfff; }
.result-name { margin-top: 3px; font-weight: 700; overflow-wrap: anywhere; max-width: 100%; }
.actions { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.actions button { min-height: 52px; }
.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.primary:hover:not(:disabled), .danger:hover:not(:disabled) { filter: brightness(1.12); }
.secondary { color: var(--accent-text); }
button:disabled:not(.undo) { background: var(--bg); color: var(--muted); border-color: var(--line); opacity: .72; }
.undo { display: block; margin: 5px auto 0; border: 0; background: transparent; color: var(--muted); font-size: .85rem; }
.undo:disabled { opacity: .7; }
.section + .section { margin-top: 14px; }
.section-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; }
.section-head .group-field { min-width: min(170px, 100%); max-width: 100%; }
.empty { text-align: center; padding: 32px 16px; }
.empty button { margin-top: 16px; }
.table-wrap { margin-top: 10px; overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
td, th { text-align: left; padding: 4px 6px; border-bottom: 1px solid var(--line); }
th, td:not(:nth-child(2)) { white-space: nowrap; }
td:nth-child(2) { overflow-wrap: anywhere; }
thead { color: var(--muted); }
tr:last-child td, tbody tr:last-child th { border-bottom: 0; }
td input { display: block; margin: 0; width: 44px; height: 44px; accent-color: var(--accent); cursor: pointer; clip-path: none; }
.status { border-radius: 20px; padding: 3px 7px; font-size: .75rem; font-weight: 700; }
.pending { background: var(--soft); color: var(--accent-text); }
.picked { background: var(--done-bg); color: var(--done-ink); }
.absent { background: var(--bg); color: var(--muted); }
.history, .groups { margin: 10px 0 0; padding: 0; list-style: none; }
.history li, .groups li { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px 12px; padding: 10px 0; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.history li:last-child, .groups li:last-child { border: 0; padding-bottom: 0; }
.history span, .muted, small { color: var(--muted); font-size: .875rem; }
.muted { margin-top: 8px; }
small { display: block; }
.group-actions { display: flex; gap: 5px; flex-wrap: wrap; }
.group-actions button { min-width: 44px; padding-inline: 8px; }
.danger-text { color: var(--danger); }
.danger { background: #a62542; color: #fff; border-color: #a62542; }
dialog { width: min(520px, calc(100% - 32px)); max-height: calc(100% - 2rem - env(safe-area-inset-top) - env(safe-area-inset-bottom)); padding: 20px; border: 1px solid var(--line); border-radius: 20px; color: var(--ink); background: var(--panel); }
dialog::backdrop { background: #101024a8; }
dialog p { margin-top: 12px; overflow-wrap: anywhere; }
dialog form { display: grid; gap: 12px; }
.edit-fields { display: grid; grid-template-columns: minmax(0, 1fr) 84px; gap: 10px; }
dialog label { display: grid; gap: 4px; font-size: .875rem; }
dialog label[hidden] { display: none; }
dialog input { width: 100%; padding: 4px 8px; }
fieldset { min-width: 0; border: 1px solid var(--line); border-radius: 12px; padding: 8px; }
legend { font-size: .85rem; }
.name-fields { display: grid; gap: 8px; max-height: min(36svh, 260px); overflow: auto; padding: 4px; }
.name-fields label { grid-template-columns: 48px minmax(0, 1fr); align-items: center; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
@media (max-width: 480px) {
  main, .top-inner { padding-inline: 12px; }
  main { padding-top: 12px; }
  .top-inner { min-height: 58px; }
  .controls, .section { padding: 12px; }
  .controls { gap: 14px; }
}
