:root {
  --bg: #f5f1e8;
  --surface: #fffdf8;
  --surface-2: #efe9dc;
  --ink: #2a2925;
  --muted: #6b665c;
  --line: #e0d8c8;
  --accent: #1e6a4e;
  --accent-ink: #ffffff;
  --accent-soft: #dfeee6;
  --plus: #1e6a4e;
  --minus: #c23b2c;
  --minus-soft: #f8e3df;
  --focus: #2f7dd1;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.06), 0 2px 10px rgb(0 0 0 / 0.04);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141715;
    --surface: #1d211f;
    --surface-2: #272c29;
    --ink: #ecebe6;
    --muted: #a3a097;
    --line: #343b37;
    --accent: #5bbb92;
    --accent-ink: #0c1a13;
    --accent-soft: #1f3a2f;
    --plus: #6fcaa2;
    --minus: #ff8a7a;
    --minus-soft: #3d2420;
    --focus: #7fb4ff;
    --shadow: none;
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family:
    system-ui,
    -apple-system,
    'Hiragino Sans',
    'Hiragino Kaku Gothic ProN',
    'Noto Sans JP',
    'Yu Gothic UI',
    Meiryo,
    sans-serif;
  font-size: 16px;
  line-height: 1.6;
  font-variant-numeric: tabular-nums;
}

a {
  color: var(--accent);
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 13px;
}

/* ---------- 枠 ---------- */

.appbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 52px;
  padding: env(safe-area-inset-top) 16px 0;
  background: var(--accent);
  color: var(--accent-ink);
}

.appbar h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.back {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  margin-left: -10px;
  color: inherit;
  font-size: 32px;
  line-height: 1;
  text-decoration: none;
  border-radius: 50%;
}

.wrap {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px calc(24px + env(safe-area-inset-bottom));
}

.section-title {
  margin: 28px 0 10px;
  font-size: 15px;
  color: var(--muted);
  font-weight: 700;
}

.group > .section-title:first-child {
  margin-top: 0;
}

.empty {
  margin: 28px 0;
  padding: 24px 16px;
  text-align: center;
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}

.empty p {
  margin: 0 0 8px;
}

.empty p:last-child {
  margin-bottom: 0;
}

.foot {
  margin-top: 32px;
  text-align: center;
  font-size: 14px;
}

.hint {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.lead {
  margin: 0 0 14px;
  font-size: 14px;
  color: var(--muted);
}

.lead strong {
  color: var(--ink);
}

kbd {
  padding: 0 5px;
  font-family: inherit;
  font-weight: 700;
  color: var(--ink);
  background: var(--surface-2);
  border-radius: 5px;
}

.error {
  margin: 0;
  padding: 10px 12px;
  color: var(--minus);
  background: var(--minus-soft);
  border-radius: 10px;
  font-size: 14px;
}

/* ---------- ボタン ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 8px 16px;
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
  text-decoration: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
}

.btn.primary {
  color: var(--accent-ink);
  background: var(--accent);
  border-color: var(--accent);
}

.btn.primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn.big {
  min-height: 54px;
  font-size: 17px;
  padding: 10px 22px;
}

.btn.block {
  display: flex;
  width: 100%;
}

.btn.ghost {
  background: transparent;
}

.btn.danger {
  color: var(--minus);
}

.tools {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 24px;
}

.actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.actions .btn.primary {
  flex: 1;
}

.actions.sticky {
  position: sticky;
  bottom: 0;
  margin: 24px -16px 0;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to bottom, transparent, var(--bg) 30%);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(88px + env(safe-area-inset-bottom));
  z-index: 20;
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  transform: translateX(-50%);
  color: var(--bg);
  background: var(--ink);
  border-radius: 12px;
  font-size: 14px;
  box-shadow: var(--shadow);
}

/* ---------- ホーム ---------- */

.cards {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.card {
  display: grid;
  gap: 2px;
  padding: 14px 16px;
  color: inherit;
  text-decoration: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card-head {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--muted);
}

.card-names {
  font-weight: 700;
}

.card-top {
  font-size: 14px;
  color: var(--muted);
}

/* ---------- フォーム ---------- */

.stack {
  display: grid;
  gap: 16px;
}

.group {
  margin: 0;
  padding: 16px;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.group > legend {
  float: left;
  width: 100%;
  margin-bottom: 10px;
  padding: 0;
  font-weight: 700;
}

.group > legend + * {
  clear: both;
}

.text {
  width: 100%;
  min-height: 46px;
  padding: 8px 12px;
  font: inherit;
  font-size: 16px;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.num {
  font-variant-numeric: tabular-nums;
}

.names {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.chip {
  min-height: 38px;
  padding: 4px 14px;
  font: inherit;
  font-size: 15px;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
}

.seg {
  display: flex;
  gap: 6px;
}

.seg.multi {
  flex-wrap: wrap;
}

.seg label {
  flex: 1 0 auto;
}

.seg input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.seg span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 4px 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  font-weight: 700;
  white-space: nowrap;
}

.seg input:checked + span {
  color: var(--accent-ink);
  background: var(--accent);
  border-color: var(--accent);
}

.seg input:focus-visible + span {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.rule summary {
  display: grid;
  gap: 2px;
  cursor: pointer;
  list-style: none;
}

.rule summary::-webkit-details-marker {
  display: none;
}

.summary-title {
  font-weight: 700;
}

.summary-title::after {
  content: ' ▾';
  color: var(--muted);
  font-size: 13px;
}

.rule[open] .summary-title::after {
  content: ' ▴';
}

.summary-sub {
  font-size: 13px;
  color: var(--muted);
}

.rule-body {
  display: grid;
  gap: 16px;
  margin-top: 16px;
}

.field {
  display: grid;
  gap: 6px;
  font-size: 14px;
  font-weight: 700;
}

.field .hint {
  font-weight: 400;
}

.grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.uma-custom {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(64px, 1fr));
  gap: 8px;
}

.uma-custom label {
  display: grid;
  gap: 4px;
  font-weight: 400;
  font-size: 13px;
  color: var(--muted);
}

/* ---------- 成績 ---------- */

.standings {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.standing {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.pos {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  font-weight: 700;
  background: var(--surface-2);
  border-radius: 50%;
}

.pos.first {
  color: var(--accent-ink);
  background: var(--accent);
}

.who {
  display: grid;
  min-width: 0;
}

.who .name {
  font-weight: 700;
  font-size: 17px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.who .meta {
  font-size: 12px;
  color: var(--muted);
}

.total {
  font-size: 22px;
  font-weight: 700;
}

.pt.plus {
  color: var(--plus);
}

.pt.minus {
  color: var(--minus);
}

.rule-line {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin: 12px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.history {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
}

.history th,
.history td {
  padding: 8px 6px;
  text-align: right;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.history thead th {
  font-size: 13px;
  color: var(--muted);
  font-weight: 700;
  max-width: 6em;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history th:first-child {
  width: 2.2em;
  text-align: center;
  color: var(--muted);
}

.history tbody tr {
  cursor: pointer;
}

.history tbody th a {
  display: block;
  color: inherit;
  text-decoration: none;
}

.history td .pt {
  display: block;
  font-weight: 700;
}

.history td .sub {
  display: block;
  font-size: 11px;
  color: var(--muted);
}

.history tfoot th,
.history tfoot td {
  border-bottom: 0;
  font-size: 16px;
}

/* ---------- 点数入力 ---------- */

.score-rows {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.score-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    'name input'
    'result input';
  align-items: center;
  column-gap: 10px;
  padding: 10px 12px 10px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.score-name {
  grid-area: name;
  font-weight: 700;
  font-size: 17px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-result {
  grid-area: result;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 22px;
  font-size: 15px;
  font-weight: 700;
}

.score-input {
  grid-area: input;
  display: flex;
  align-items: center;
  gap: 4px;
}

.score-input input {
  width: 4.2em;
  height: 52px;
  padding: 0 8px;
  font: inherit;
  font-size: 26px;
  font-weight: 700;
  text-align: right;
  color: var(--ink);
  background: var(--bg);
  border: 2px solid var(--line);
  border-radius: 10px;
}

.score-input input:focus {
  border-color: var(--accent);
  outline: none;
}

.score-row.auto input {
  border-style: dashed;
}

.score-row.auto input::placeholder {
  color: var(--accent);
  opacity: 1;
}

.unit {
  font-size: 18px;
  font-weight: 700;
  color: var(--muted);
}

.sign {
  width: 40px;
  height: 40px;
  font: inherit;
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 50%;
  cursor: pointer;
}

.sign[aria-pressed='true'] {
  color: #fff;
  background: var(--minus);
  border-color: var(--minus);
}

.rk {
  display: inline-block;
  min-width: 2.6em;
  padding: 0 6px;
  font-size: 12px;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
  color: var(--muted);
  background: var(--surface-2);
  border-radius: 999px;
}

.rk.top {
  color: var(--accent-ink);
  background: var(--accent);
}

.rk.last {
  color: var(--minus);
  background: var(--minus-soft);
}

.sum {
  margin: 14px 0 0;
  text-align: center;
  font-weight: 700;
}

.sum.error {
  color: var(--minus);
}

.tie {
  margin-top: 14px;
  padding: 12px 14px;
  font-size: 14px;
  background: var(--accent-soft);
  border-radius: var(--radius);
}

.tie p {
  margin: 0 0 8px;
}

.tie-group {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.tie-group + .tie-group {
  margin-top: 8px;
}

@media (min-width: 560px) {
  .names {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* ---------- メンバーが卓の人数より多いとき ---------- */

.member {
  display: flex;
  gap: 4px;
  min-width: 0;
}

.member .text {
  min-width: 0;
}

.icon-btn {
  flex: none;
  width: 40px;
  font: inherit;
  font-size: 20px;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
}

.btn.add {
  margin-top: 10px;
}

.pick {
  margin-bottom: 16px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.pick-title {
  margin: 0 0 8px;
  font-weight: 700;
}

.error-text {
  color: var(--minus);
}

.chip.toggle {
  color: var(--muted);
  background: transparent;
  border-style: dashed;
}

.chip.toggle[aria-pressed='true'] {
  color: var(--accent-ink);
  background: var(--accent);
  border: 1px solid var(--accent);
  font-weight: 700;
}

.standing.idle {
  opacity: 0.6;
}

.history td.off {
  background: var(--surface-2);
  text-align: center;
}

.history th:first-child,
.history td:first-child {
  position: sticky;
  left: 0;
  background: var(--surface);
}
