/* 麻雀大会スコア。スマホで卓上から片手で使う前提の見た目 */

:root {
  --bg: #f3f5f2;
  --surface: #ffffff;
  --surface-2: #eef2ee;
  --text: #1c2420;
  --muted: #66716b;
  --line: #d9e0db;
  --accent: #15803d;
  --accent-strong: #14532d;
  --accent-soft: #dcfce7;
  --plus: #1d4ed8;
  --minus: #dc2626;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --band: #ea7a1a;
  --me: #fff7d6;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #0f1412;
    --surface: #18201c;
    --surface-2: #212b26;
    --text: #e8eee9;
    --muted: #9aa69f;
    --line: #2d3832;
    --accent: #22c55e;
    --accent-strong: #16a34a;
    --accent-soft: #14301f;
    --plus: #60a5fa;
    --minus: #f87171;
    --warn: #fbbf24;
    --warn-soft: #3a2e10;
    --band: #f59e0b;
    --me: #2f2a14;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'Noto Sans JP', 'Yu Gothic UI', sans-serif;
  font-size: 16px;
  line-height: 1.6;
}

.page {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 16px 32px;
}
.page.with-nav { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
.page.center { text-align: center; padding-top: 30vh; }

.demo-banner {
  margin: 0 -16px;
  padding: 6px 16px;
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 13px;
  text-align: center;
}

/* ヘッダー */
.app-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 0 10px;
}
.app-header h1 { font-size: 20px; margin: 0; line-height: 1.3; }
.title-block { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.title-block .muted { font-size: 13px; }
.back { color: var(--accent); text-decoration: none; white-space: nowrap; }

/* カード */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin: 12px 0;
  border: 1px solid var(--line);
}
.card.flush { padding: 0; overflow: hidden; }
.card.center { text-align: center; }
.card.current { border-color: var(--accent); }
.card h2 { font-size: 17px; margin: 0 0 10px; }
.card h3 { font-size: 15px; margin: 18px 0 8px; color: var(--muted); }
.big-q { font-size: 22px !important; text-align: center; margin: 8px 0 16px !important; }

.muted { color: var(--muted); }
.center { text-align: center; }
.error-line { color: var(--minus); font-weight: 600; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.center { justify-content: center; }

.plus { color: var(--plus); }
.minus { color: var(--minus); }
.zero { color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ボタン */
.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: 10px;
  min-height: 44px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { background: transparent; color: var(--minus); border-color: var(--minus); }
.btn.big { display: flex; width: 100%; min-height: 54px; font-size: 18px; margin-top: 12px; }
.btn.small { min-height: 34px; padding: 4px 12px; font-size: 14px; }
.btn.link { background: none; border: none; color: var(--accent); padding: 8px; }
.btn.link.danger { color: var(--minus); }
.btn.round { width: 56px; height: 56px; border-radius: 50%; font-size: 26px; padding: 0; }

/* 入力欄 */
.input {
  width: 100%;
  font: inherit;
  font-size: 16px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  margin: 4px 0;
}
.input.num { width: 120px; text-align: right; }
.input.num.small { width: 84px; padding: 6px 8px; }
textarea.input { resize: vertical; }
.field { display: flex; flex-direction: column; margin: 10px 0; }
.field > span { font-size: 14px; color: var(--muted); }
.field.inline { flex-direction: row; align-items: center; justify-content: space-between; gap: 12px; }
.field.inline input[type='checkbox'] { width: 24px; height: 24px; }
.uma-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.uma-row .input.num { width: 100%; }

/* チップ風の選択ボタン */
.chip-grid { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0; }
.chip {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  padding: 8px 14px;
  border-radius: 999px;
  min-height: 44px;
  cursor: pointer;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip small { opacity: 0.75; }

/* 大会作成のステップ表示 */
.stepper { display: flex; list-style: none; padding: 0; margin: 4px 0 0; gap: 4px; }
.stepper li {
  flex: 1;
  text-align: center;
  font-size: 13px;
  padding: 6px 0;
  border-bottom: 3px solid var(--line);
  color: var(--muted);
}
.stepper li.active { border-color: var(--accent); color: var(--text); font-weight: 700; }
.stepper li.done { border-color: var(--accent-soft); }

.count-line { font-size: 22px; font-weight: 700; text-align: center; padding: 6px; border-radius: 10px; }
.count-line.ok { background: var(--accent-soft); color: var(--accent-strong); }
.count-line.warn { background: var(--warn-soft); color: var(--warn); }
.name-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.name-chip {
  border: none;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
}
.name-chip .x { margin-left: 6px; color: var(--muted); }

.sticky-actions {
  position: sticky;
  bottom: 0;
  background: var(--surface);
  padding: 12px 0 4px;
  margin-top: 16px;
}
.admin .sticky-actions { background: var(--bg); bottom: calc(68px + env(safe-area-inset-bottom)); }

.summary { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; }
.summary dt { color: var(--muted); }
.summary dd { margin: 0; font-weight: 600; }

.rule-section-edit { border-top: 1px dashed var(--line); padding-top: 10px; margin-top: 10px; }
.rule-section-edit .row .input { flex: 1; }
.rule-list { margin: 0; padding-left: 1.2em; }
.rule-list li { margin: 4px 0; }

/* 名前選び */
.name-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.name-btn {
  font: inherit;
  font-size: 18px;
  font-weight: 600;
  min-height: 60px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
}

/* ホームの大きなカード */
.hero { text-align: center; border-width: 2px; border-color: var(--accent); }
.hero.done { border-color: var(--band); }
.hero-sub { font-size: 16px; color: var(--muted); font-weight: 600; }
.hero-main { font-size: 28px; font-weight: 800; margin: 4px 0 10px; }
.hero-main.small { font-size: 22px; }
.table-label { font-size: 44px; color: var(--accent); }
.members { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-bottom: 8px; }
.member { background: var(--surface-2); padding: 4px 12px; border-radius: 999px; font-size: 16px; }
.member.me { background: var(--me); font-weight: 700; outline: 2px solid var(--band); }
.status { font-size: 18px; padding: 10px; border-radius: 10px; }
.status.ok { background: var(--accent-soft); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stats .btn.big { grid-column: 1 / -1; margin-top: 4px; }
.stat { display: flex; flex-direction: column; align-items: center; background: var(--surface-2); border-radius: 10px; padding: 8px 4px; }
.stat.wide { grid-column: 1 / -1; flex-direction: row; justify-content: space-between; padding: 10px 14px; }
.stat.inside { background: var(--accent-soft); }
.stat.outside { background: var(--warn-soft); }
.stat-label { font-size: 12px; color: var(--muted); }
.stat-value { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat-value small { font-size: 13px; font-weight: 600; color: var(--muted); }
.stat-value.small { font-size: 17px; }

.my-schedule { width: 100%; border-collapse: collapse; }
.my-schedule td { padding: 8px 4px; border-bottom: 1px solid var(--line); }
.my-schedule tr.current td { background: var(--accent-soft); font-weight: 700; }

/* 素点入力 */
.score-form .hint { font-size: 14px; color: var(--muted); margin: 0 0 8px; }
.picker { margin-bottom: 8px; flex-wrap: nowrap; }
.picker .input { flex: 1; }
.seat-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 58px;
  gap: 8px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.wind {
  font-size: 30px;
  font-weight: 800;
  text-align: center;
  background: var(--surface-2);
  border-radius: 10px;
  line-height: 52px;
}
.seat-select {
  width: 100%;
  font: inherit;
  font-weight: 600;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
}
.seat-main { min-width: 0; }
.score-line { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin-top: 6px; }
.sign {
  width: 40px;
  height: 48px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  font-size: 22px;
  font-weight: 800;
  cursor: pointer;
}
.sign.neg { background: var(--minus); border-color: var(--minus); color: #fff; }
.score-input {
  width: 84px;
  height: 48px;
  font-size: 24px;
  font-weight: 700;
  text-align: right;
  padding: 0 8px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.score-input:focus { border-color: var(--accent); outline: none; }
.suffix { font-size: 22px; font-weight: 700; color: var(--muted); }
.score-echo { flex-basis: 100%; font-size: 13px; color: var(--muted); white-space: nowrap; }
.score-echo.minus { color: var(--minus); }
.seat-result { text-align: right; }
.pt-preview { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.rank-preview { font-size: 13px; color: var(--muted); }
.total-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  justify-content: center;
  font-size: 18px;
  padding: 12px 0 0;
}

.badge {
  display: inline-block;
  font-size: 13px;
  font-weight: 700;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
}
.badge.ok { background: var(--accent-soft); color: var(--accent-strong); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }

.confirm-table, .settle-table { width: 100%; border-collapse: collapse; font-size: 16px; }
.confirm-table td, .settle-table td, .settle-table th { padding: 8px 4px; border-bottom: 1px solid var(--line); }
.settle-table th { font-size: 13px; color: var(--muted); text-align: left; }
.settle-table tr.me td { background: var(--me); font-weight: 700; }
.confirm-table td:nth-child(4) { font-weight: 800; font-size: 18px; }

/* 順位表 */
.segmented { display: flex; background: var(--surface-2); border-radius: 10px; padding: 4px; margin: 12px 0 0; }
.segmented button {
  flex: 1;
  border: none;
  background: none;
  font: inherit;
  font-weight: 600;
  padding: 8px;
  border-radius: 8px;
  color: var(--muted);
  cursor: pointer;
}
.segmented button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.rank-head, .rank-row {
  display: grid;
  grid-template-columns: 44px 1fr 72px 56px;
  gap: 8px;
  align-items: center;
  padding: 10px 14px;
}
.rank-head { font-size: 12px; border-bottom: 1px solid var(--line); }
.rank-row {
  width: 100%;
  border: none;
  border-bottom: 1px solid var(--line);
  background: none;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.rank-row.me { background: var(--me); }
.rank-badge {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  background: var(--surface-2);
}
.rank-badge.r1 { background: #eab308; color: #fff; }
.rank-badge.r2 { background: #94a3b8; color: #fff; }
.rank-badge.r3 { background: #b45309; color: #fff; }
.rank-name { font-weight: 700; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-total { font-weight: 800; font-size: 19px; text-align: right; font-variant-numeric: tabular-nums; }
.rank-diff { text-align: right; font-size: 13px; font-variant-numeric: tabular-nums; }
.rank-detail { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 14px 12px 66px; background: var(--surface-2); }
.chip-mini { font-size: 13px; background: var(--surface); padding: 2px 8px; border-radius: 6px; }
.final-line {
  background: var(--band);
  color: #fff;
  font-weight: 800;
  font-size: 14px;
  text-align: center;
  letter-spacing: 0.2em;
  padding: 3px 0;
}

.table-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.table-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  text-align: left;
}
button.table-card { cursor: pointer; }
.table-card.mine { border: 2px solid var(--band); }
.table-card.done { background: var(--accent-soft); }
.table-card .me { font-weight: 700; color: var(--band); }

/* 精算 */
.stepper-row { display: flex; align-items: center; justify-content: center; gap: 20px; margin: 8px 0; }
.chip-count { font-size: 44px; font-weight: 800; min-width: 100px; font-variant-numeric: tabular-nums; }
.my-amount {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px;
  margin: 10px 0;
  border-radius: 12px;
  background: var(--surface-2);
}
.my-amount strong { font-size: 34px; }
.my-amount.plus strong { color: var(--plus); }
.my-amount.minus strong { color: var(--minus); }
.my-amount small { color: var(--muted); }

/* 共有 */
.qr { width: 220px; height: 220px; margin: 12px auto; background: #fff; border-radius: 12px; padding: 6px; display: flex; align-items: center; justify-content: center; color: #333; }
.qr svg { width: 100%; height: 100%; }
.url-box { word-break: break-all; background: var(--surface-2); padding: 10px; border-radius: 8px; font-family: ui-monospace, Menlo, monospace; font-size: 13px; margin: 8px 0 12px; }

.list-item {
  display: flex;
  flex-direction: column;
  padding: 12px 4px;
  border-bottom: 1px solid var(--line);
  color: var(--text);
  text-decoration: none;
}

/* 下のタブ */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}
.nav-item {
  flex: 1;
  max-width: 160px;
  text-align: center;
  padding: 14px 0 16px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 700;
  font-size: 15px;
  border-top: 3px solid transparent;
}
.nav-item.on { color: var(--accent); border-top-color: var(--accent); }

/* モーダルとトースト */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}
.modal {
  background: var(--surface);
  width: 100%;
  max-width: 640px;
  max-height: 92vh;
  overflow: auto;
  border-radius: 18px 18px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
}
.modal h2 { margin: 0 0 12px; font-size: 18px; }
.modal-actions { display: flex; gap: 8px; margin-top: 16px; }
.modal-actions .btn { flex: 1; min-height: 52px; }

#toasts {
  position: fixed;
  top: 12px;
  left: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  z-index: 100;
  pointer-events: none;
}
.toast {
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 10px;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  transition: opacity 0.3s;
}
.toast.ok { background: var(--accent); color: #fff; }
.toast.error { background: var(--minus); color: #fff; }
.toast.out { opacity: 0; }
.stat-value.top { color: var(--band); line-height: 39px; }
