/* 麻雀スコア記録アプリ — スマホ縦持ち前提のスタイル */

:root {
  --green: #1f6b4a;
  --green-dark: #175139;
  --green-light: #e8f3ee;
  --bg: #f2f4f6;
  --card: #ffffff;
  --text: #1c2124;
  --muted: #6b7580;
  --line: #dfe4e8;
  --plus: #14794a;
  --minus: #c0392b;
  --warn-bg: #fff6e0;
  --warn-line: #e6b34a;
  --err-bg: #fdecea;
  --err-line: #d9534f;
  --radius: 12px;
  --tabbar-h: 58px;
}

/* 画面の出し分けは JS の hidden 属性で行っている。
 * ブラウザ既定の `[hidden]{display:none}` は詳細度0なので、
 * `.login-screen{display:flex}` のようなクラス指定に負けて効かない。
 * 実際これでログイン成功後もログイン画面が被さったままになり、
 * 「ログインできない」ように見えていた。hidden は常に最優先で消す。 */
[hidden] { display: none !important; }

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", "Yu Gothic", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3 { margin: 0; font-weight: 700; }

/* ---------------------------------------------------------------- ログイン */
.login-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, var(--green) 0%, var(--green-dark) 100%);
  padding: 20px;
  z-index: 50;
}
.login-box {
  width: 100%; max-width: 340px;
  background: var(--card);
  border-radius: 16px;
  padding: 28px 22px;
  text-align: center;
  box-shadow: 0 10px 40px rgba(0,0,0,.25);
}
.login-logo { font-size: 44px; line-height: 1; }
.login-box h1 { font-size: 20px; margin: 8px 0 2px; }
.login-lead { color: var(--muted); font-size: 13px; margin: 0 0 18px; }
.login-box input {
  width: 100%; padding: 12px; font-size: 16px;
  border: 1px solid var(--line); border-radius: 8px; margin-bottom: 12px;
}
/* 打った文字を確認できるようにする（IMEで全角になっていた等の切り分け用） */
.pass-field { position: relative; }
.pass-field input { padding-right: 58px; }
.pass-reveal {
  position: absolute; top: 0; right: 0; height: 45px;
  padding: 0 12px; border: 0; background: none;
  color: var(--muted); font-size: 13px; cursor: pointer;
}

/* ---------------------------------------------------------------- 骨格 */
.appbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  background: var(--green); color: #fff;
  padding: 12px 14px;
  padding-top: calc(12px + env(safe-area-inset-top));
}
.appbar-title { font-weight: 700; font-size: 16px; }

main { padding: 12px 12px calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom)); }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
}
.card-head h2 { font-size: 16px; }
.sub-head { font-size: 14px; margin: 16px 0 8px; color: var(--muted); }

/* ---------------------------------------------------------------- フォーム */
.field { display: flex; flex-direction: column; gap: 3px; flex: 1 1 0; min-width: 0; margin-bottom: 10px; }
.field > span { font-size: 12px; color: var(--muted); }
.field-narrow { flex: 0 0 90px; }
.field-row { display: flex; gap: 8px; }

input[type=text], input[type=password], input[type=number],
input[type=date], input[type=datetime-local], select {
  width: 100%;
  padding: 9px 10px;
  font-size: 16px; /* iOS の自動ズーム防止 */
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-family: inherit;
}
input[type=color] { width: 40px; height: 38px; padding: 2px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
select { appearance: none; background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6'><path d='M0 0l5 6 5-6z' fill='%236b7580'/></svg>"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 26px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; margin: 8px 0; }
.check input { width: 18px; height: 18px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 11px 16px;
  border: 0; border-radius: 8px;
  font-size: 15px; font-weight: 600; font-family: inherit;
  cursor: pointer; text-decoration: none;
}
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:disabled { background: #b6c2bd; cursor: not-allowed; }
.btn-ghost { background: #fff; color: var(--green); border: 1px solid var(--green); }
.btn-danger { background: #fff; color: var(--minus); border: 1px solid var(--minus); }
.btn-block { display: flex; width: 100%; margin-top: 6px; }
.btn-sm { padding: 7px 12px; font-size: 13px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.linkbtn { background: none; border: 0; color: inherit; opacity: .85; font-size: 13px; cursor: pointer; font-family: inherit; text-decoration: underline; padding: 4px; }
.card .linkbtn { color: var(--green); }

.hint { font-size: 12px; color: var(--muted); margin: 8px 0 0; }
.error-text { color: var(--minus); font-size: 13px; margin: 10px 0 0; }

/* ---------------------------------------------------------------- 入力テーブル */
.rule-summary { font-size: 12px; color: var(--muted); background: var(--green-light); border-radius: 8px; padding: 8px 10px; margin: 2px 0 12px; }

.input-table { width: 100%; border-collapse: collapse; }
.input-table th {
  font-size: 11px; color: var(--muted); font-weight: 600;
  text-align: left; padding: 0 4px 4px;
}
.input-table td { padding: 3px 4px; vertical-align: middle; }
.col-seat { width: 30px; }
.col-score { width: 96px; }
.col-chip { width: 76px; }
.seat-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--green-light); color: var(--green-dark);
  font-size: 13px; font-weight: 700;
}
.input-table input[type=number] { text-align: right; padding: 9px 6px; }
.input-table select { padding: 9px 22px 9px 8px; }

/* ± ボタン。スマホの数字キーパッドには「−」キーが無いので、
 * マイナス点は「数字を打つ → ± で反転」で入れる。
 * 入力欄の左端に重ねて置き、そのぶん左パディングを空けている。 */
.num-cell { position: relative; }
.num-cell input[type=number] { width: 100%; padding-left: 28px; }
.sign-btn {
  position: absolute; left: 1px; top: 1px; bottom: 1px; width: 26px;
  display: flex; align-items: center; justify-content: center;
  padding: 0; border: 0; border-right: 1px solid var(--line);
  border-radius: 7px 0 0 7px;
  background: #f6f8f9; color: var(--muted);
  font-size: 15px; line-height: 1; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.sign-btn:active { background: var(--green-light); color: var(--green-dark); }
.table-hint { font-size: 11px; color: var(--muted); margin: 6px 2px 0; }
.table-hint b { color: var(--text); }

.total-bar {
  display: flex; align-items: baseline; gap: 8px;
  margin-top: 10px; padding: 9px 12px;
  background: #f6f8f9; border-radius: 8px;
  font-size: 14px;
}
.total-label { color: var(--muted); font-size: 12px; }
.total-value { font-weight: 700; font-variant-numeric: tabular-nums; }
.total-diff { margin-left: auto; font-size: 13px; font-weight: 600; }
.total-bar.is-ok { background: var(--green-light); }
.total-bar.is-ok .total-diff { color: var(--plus); }
.total-bar.is-ng { background: var(--err-bg); }
.total-bar.is-ng .total-diff { color: var(--minus); }

.buster-wrap { background: var(--warn-bg); border: 1px solid var(--warn-line); border-radius: 8px; padding: 10px; margin-top: 10px; }
.buster-wrap .field { margin-bottom: 0; }

.msg { border-radius: 8px; padding: 9px 11px; font-size: 13px; margin-top: 10px; }
.msg-error { background: var(--err-bg); border: 1px solid var(--err-line); color: #8a2b26; }
.msg-warn  { background: var(--warn-bg); border: 1px solid var(--warn-line); color: #7a5a10; }

/* ---------------------------------------------------------------- 結果テーブル */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.result-table, .stats-table {
  width: 100%; border-collapse: collapse; font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.result-table th, .stats-table th {
  background: #f6f8f9; color: var(--muted); font-size: 11px; font-weight: 600;
  padding: 6px 7px; white-space: nowrap; text-align: right; border-bottom: 1px solid var(--line);
}
.result-table th:nth-child(-n+2), .stats-table th:first-child { text-align: left; }
.result-table td, .stats-table td {
  padding: 7px; white-space: nowrap; text-align: right;
  border-bottom: 1px solid var(--line);
}
.result-table td:nth-child(-n+2), .stats-table td:first-child { text-align: left; }
.result-table tbody tr:last-child td, .stats-table tbody tr:last-child td { border-bottom: 0; }
.rank-badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 50%;
  font-size: 12px; font-weight: 700; color: #fff; background: var(--muted);
}
.rank-1 { background: #d4a017; }
.rank-2 { background: #8c9199; }
.rank-3 { background: #a97142; }
.rank-4 { background: #5a6470; }
.plus  { color: var(--plus); font-weight: 700; }
.minus { color: var(--minus); font-weight: 700; }
.zero  { color: var(--muted); }
.tobi-mark { display: inline-block; margin-left: 4px; font-size: 10px; color: #fff; background: var(--minus); border-radius: 4px; padding: 1px 4px; vertical-align: middle; }

.settlement { margin-top: 12px; background: var(--green-light); border-radius: 8px; padding: 10px 12px; }
.settlement h4 { margin: 0 0 6px; font-size: 13px; color: var(--green-dark); }
.settlement ul { margin: 0; padding-left: 18px; font-size: 13px; }
.settlement li { margin: 2px 0; }
.settlement .none { font-size: 13px; color: var(--muted); }

/* ---------------------------------------------------------------- 履歴 */
.badge-count { font-size: 12px; color: var(--muted); }
.history-item { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; }
.history-head { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.history-type { background: var(--green-light); color: var(--green-dark); border-radius: 4px; padding: 1px 6px; font-weight: 600; }
.history-actions { margin-left: auto; display: flex; gap: 6px; }
.history-players { display: grid; grid-template-columns: auto 1fr auto auto; gap: 3px 8px; font-size: 13px; font-variant-numeric: tabular-nums; align-items: center; }
.history-players .hp-score { text-align: right; color: var(--muted); }
.history-players .hp-pt { text-align: right; font-weight: 700; }
.history-note { font-size: 12px; color: var(--muted); margin-top: 6px; }
.empty { color: var(--muted); font-size: 14px; text-align: center; padding: 24px 0; }

/* ---------------------------------------------------------------- 設定 */
.player-list, .rule-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.list-item { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; }
.list-item .dot { width: 12px; height: 12px; border-radius: 50%; flex: 0 0 auto; }
.list-item .grow { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item.is-inactive { opacity: .5; }
.list-item .sub { font-size: 11px; color: var(--muted); }
.tag-default { font-size: 10px; background: var(--green); color: #fff; border-radius: 4px; padding: 1px 5px; }
.inline-form { display: flex; gap: 6px; align-items: center; }
.inline-form input[type=text] { flex: 1 1 auto; }
.rule-form { border-top: 1px solid var(--line); padding-top: 12px; }

/* ---------------------------------------------------------------- タブ */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex;
  background: #fff; border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1; border: 0; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  padding: 7px 0 8px; font-size: 11px; color: var(--muted); font-family: inherit;
}
.tab-icon { font-size: 18px; line-height: 1.2; }
.tab.is-active { color: var(--green); font-weight: 700; }

/* ---------------------------------------------------------------- トースト */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: rgba(28,33,36,.94); color: #fff;
  padding: 10px 18px; border-radius: 20px; font-size: 13px;
  z-index: 40; max-width: 90vw; text-align: center;
}

/* ---------------------------------------------------------------- 画面幅が広い場合 */
@media (min-width: 700px) {
  main { max-width: 760px; margin: 0 auto; }
  .login-box { max-width: 380px; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14181b; --card: #1e2428; --text: #e7ecef; --muted: #9aa5ad;
    --line: #333c42; --green-light: #1d3a2f; --warn-bg: #3a3018; --err-bg: #3a2220;
    --plus: #4ec98a; --minus: #ef7a6d;
  }
  input[type=text], input[type=password], input[type=number],
  input[type=date], input[type=datetime-local], select, input[type=color] { background: #262d32; color: var(--text); }
  .result-table th, .stats-table th, .total-bar { background: #262d32; }
  .btn-ghost { background: transparent; }
  .tabbar { background: var(--card); }
  .msg-error { color: #ffb4ad; }
  .msg-warn { color: #ffd98a; }
}

/* ------------------------------------------------ チップ精算 */
/* チップはその日の最後にまとめて数えるので、対局入力とは別カードにしている。
 * 普段は畳んでおいて、必要なときだけ開く。 */
#chipBody .input-table .col-name { width: auto; }
#chipBody .input-table td:last-child { text-align: right; white-space: nowrap; }
.chip-money { font-variant-numeric: tabular-nums; font-size: 13px; }
.chip-money.plus { color: var(--plus); }
.chip-money.minus { color: var(--minus); }
.chip-money.zero { color: var(--muted); }

/* 履歴のチップ精算レコード。順位が無いので着順バッジの代わりに印を出す */
.history-item.is-chips { border-left: 3px solid var(--warn-line); }
.history-item.is-chips .history-type { background: var(--warn-bg); color: #8a6a1a; }
.chip-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 6px;
  background: var(--warn-bg); color: #8a6a1a;
  font-size: 11px; font-weight: 700;
}

/* ------------------------------------------------ ゲーム代 */
/* 場代・飲食代・立替の3つで金額を入れるので、対局入力より1列多い。
 * table-layout:fixed で幅を固定し、5列ぶんスマホの横幅に収まるよう詰める。 */
#feeBody .fee-table { table-layout: fixed; }
#feeBody .fee-table th { font-size: 11px; padding: 4px 2px; }
#feeBody .fee-table td { padding: 3px 2px; }
#feeBody .fee-table .col-name { width: 58px; }
#feeBody .fee-table .col-score { width: 60px; }
#feeBody .fee-table .col-chip { width: 46px; }
#feeBody .fee-table select {
  width: 100%; padding: 9px 14px 9px 4px; background-position: right 3px center; font-size: 13px;
}
.fee-input { width: 100%; text-align: right; padding: 9px 3px; }
.fee-cost {
  text-align: right; white-space: nowrap;
  font-variant-numeric: tabular-nums; font-size: 11px; color: var(--muted);
}
#feeBody .field-row { align-items: flex-end; gap: 8px; }
#feeBody .field-row .btn { white-space: nowrap; margin-bottom: 2px; }

/* ------------------------------------------------ その会の精算（成績画面の上） */
/* 1日ぶん／2日ぶんを選んで「今日いくら払う・もらう」をひと目で見るための枠。
 * 日をまたぐ会があるので「2日間」ボタンを用意している。 */
.session-box { margin: 12px 0 4px; }
.session-meta { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.session-players {
  display: grid; grid-template-columns: 1fr auto auto auto; gap: 4px 10px;
  font-size: 14px; font-variant-numeric: tabular-nums; align-items: center;
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
}
.session-players .sp-pt { text-align: right; color: var(--muted); font-size: 13px; }
.session-players .sp-chip { text-align: right; color: var(--muted); font-size: 13px; }
.session-players .sp-money { text-align: right; }
.session-box .msg { margin-top: 8px; }
.session-box .settlement { margin-top: 10px; }
