/* 配色は Android 版（Theme.kt）と同じ。端末のダークモードに合わせて切り替える */
:root {
  color-scheme: light dark;
  --primary: #1b6b45;
  --on-primary: #ffffff;
  --primary-container: #a6f2c3;
  --on-primary-container: #002111;
  --secondary-container: #d0e8d6;
  --on-secondary-container: #0b1f14;
  --background: #f6fbf4;
  --surface: #f6fbf4;
  --on-surface: #171d19;
  --on-surface-variant: #404943;
  --container-high: #e5eae3;
  --container-highest: #dfe4dd;
  --outline: #717971;
  --outline-variant: #c0c9c0;
  --error: #b3261e;
  --positive: #1565c0;
  --hint: rgb(64 73 67 / 0.55);
  --pressed: rgb(23 29 25 / 0.1);
  --disabled-bg: rgb(23 29 25 / 0.12);
  --disabled-fg: rgb(23 29 25 / 0.38);
  --snackbar-bg: #2c322e;
  --snackbar-fg: #edf2eb;
  --snackbar-action: #8bd6a8;

  --label-col: 40px;
  --page-max: 640px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --primary: #8bd6a8;
    --on-primary: #00391f;
    --primary-container: #00522e;
    --on-primary-container: #a6f2c3;
    --secondary-container: #364b3e;
    --on-secondary-container: #d0e8d6;
    --background: #0f1511;
    --surface: #0f1511;
    --on-surface: #dfe4dd;
    --on-surface-variant: #c0c9c0;
    --container-high: #262b27;
    --container-highest: #303632;
    --outline: #8a938b;
    --outline-variant: #404943;
    --error: #f2b8b5;
    --positive: #90caf9;
    --hint: rgb(192 201 192 / 0.55);
    --pressed: rgb(223 228 221 / 0.12);
    --disabled-bg: rgb(223 228 221 / 0.12);
    --disabled-fg: rgb(223 228 221 / 0.38);
    --snackbar-bg: #dfe4dd;
    --snackbar-fg: #2c322e;
    --snackbar-action: #1b6b45;
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--background);
  color: var(--on-surface);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP",
    "Yu Gothic UI", Meiryo, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; -webkit-user-select: none; user-select: none; }
button:disabled { cursor: default; }
p, h1, h2 { margin: 0; }
h1, h2 { font: inherit; }
hr { margin: 0; border: 0; border-top: 1px solid var(--outline-variant); }
.hidden { display: none !important; }

/* ---- 文字 ---- */

.title-large { font-size: 22px; line-height: 28px; }
.title-medium { font-size: 16px; line-height: 24px; font-weight: 500; }
.title-small { font-size: 14px; line-height: 20px; font-weight: 500; }
.body-large { font-size: 16px; line-height: 24px; }
.body-medium { font-size: 14px; line-height: 20px; }
.body-small { font-size: 12px; line-height: 16px; }
.label-large { font-size: 14px; line-height: 20px; font-weight: 500; }
.label-medium { font-size: 12px; line-height: 16px; font-weight: 500; }
.label-small { font-size: 11px; line-height: 16px; font-weight: 500; }
.medium { font-weight: 500; }
.bold { font-weight: 700; }
.grow { flex: 1; min-width: 0; }
.ellipsis { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; min-width: 0; }

.muted { color: var(--on-surface-variant); }
.outline-text { color: var(--outline); }
.pos { color: var(--positive); }
.neg { color: var(--error); }
.zero { color: var(--on-surface-variant); }

.section-title { font-size: 14px; line-height: 20px; font-weight: 500; color: var(--primary); }
.error-text { font-size: 14px; line-height: 20px; color: var(--error); }

/* ---- 画面の枠 ---- */

.screen {
  max-width: var(--page-max);
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  font-variant-numeric: tabular-nums;
}

.top-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  min-height: calc(64px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 4px 0;
  background: var(--surface);
}

.top-bar-title {
  flex: 1;
  min-width: 0;
  padding-left: 12px;
  font-size: 22px;
  line-height: 28px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.top-bar.has-back .top-bar-title { padding-left: 4px; }
.top-bar-actions { display: flex; }

.icon { display: inline-flex; }
.icon svg { width: 24px; height: 24px; fill: currentColor; }

.icon-btn {
  flex: none;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--on-surface-variant);
}

.top-bar.has-back > .icon-btn:first-child { color: var(--on-surface); }
.icon-btn:active { background: var(--pressed); }

.content { padding: 8px 16px calc(112px + env(safe-area-inset-bottom)); }

.empty {
  display: grid;
  place-items: center;
  min-height: 60vh;
  padding: 24px;
  color: var(--on-surface-variant);
  text-align: center;
  white-space: pre-line;
}

.placeholder { padding: 24px; color: var(--on-surface-variant); text-align: center; }

/* ---- カード ---- */

.card {
  display: block;
  width: 100%;
  padding: 16px;
  border: 0;
  border-radius: 12px;
  background: var(--container-highest);
  color: inherit;
  text-align: left;
}

button.card:active,
.adjustment-item:active { background-image: linear-gradient(var(--pressed), var(--pressed)); }

.list { display: flex; flex-direction: column; gap: 12px; }

.session-card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.player-row { display: flex; align-items: center; gap: 8px; padding: 2px 0; }
.player-yen { flex: none; width: 104px; text-align: right; }

.banner {
  display: flex;
  align-items: flex-start;
  gap: 4px;
  margin: 8px 16px 0;
  padding: 12px 4px 12px 16px;
  border-radius: 12px;
  background: var(--secondary-container);
  color: var(--on-secondary-container);
  font-size: 14px;
  line-height: 20px;
}

.banner p { flex: 1; padding-top: 2px; }
.banner .icon-btn { width: 40px; height: 40px; margin-top: -8px; color: inherit; }

/* ---- 対局の表 ---- */

.session { padding: 4px 12px calc(184px + env(safe-area-inset-bottom)); }

.trow {
  display: grid;
  grid-template-columns: var(--label-col) repeat(var(--cols), minmax(0, 1fr));
  column-gap: 3px;
  align-items: center;
}

.tlabel { font-size: 12px; line-height: 16px; font-weight: 500; color: var(--on-surface-variant); }

.fit {
  display: block;
  width: 100%;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-align: center;
}

.cell { display: flex; flex-direction: column; align-items: center; min-width: 0; }
.cell .score { margin-top: 2px; }

.name-cell { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; text-align: center; }

.rule-summary {
  padding: 8px 4px;
  font-size: 12px;
  line-height: 16px;
  color: var(--on-surface-variant);
  white-space: pre-line;
}

.totals { padding: 12px 4px; }
.totals .trow { padding: 2px 0; }
.totals .trow.names { padding-bottom: 6px; }
.totals hr { margin: 4px 8px; }

.names-header { padding: 20px 4px 4px; }

.hanchan-card { margin: 4px 0; padding: 10px 4px; background: var(--container-high); }

.rank {
  display: inline-block;
  max-width: 100%;
  padding: 0 10px;
  overflow: hidden;
  border: 1px solid var(--outline);
  border-radius: 999px;
  color: var(--on-surface-variant);
  font-size: 14px;
  line-height: 20px;
  font-weight: 700;
  white-space: nowrap;
}

.rank.top { border-color: var(--primary); background: var(--primary); color: var(--on-primary); }

.adjustments-title { padding: 24px 4px 4px; }
.adjustments-total { padding: 8px 0; }

.adjustment-item {
  display: block;
  width: 100%;
  padding: 8px 0;
  border: 0;
  border-bottom: 1px solid var(--outline-variant);
  background: transparent;
  text-align: left;
}

.adjustment-memo { padding: 0 0 2px var(--label-col); }

/* ---- 右下のボタン ---- */

.fabs {
  position: fixed;
  z-index: 20;
  right: max(calc(16px + env(safe-area-inset-right)), calc((100vw - var(--page-max)) / 2 + 16px));
  bottom: calc(16px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
}

.fab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 56px;
  padding: 0 20px 0 16px;
  border: 0;
  border-radius: 16px;
  background: var(--primary-container);
  color: var(--on-primary-container);
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.3), 0 4px 8px 3px rgb(0 0 0 / 0.15);
}

.fab.secondary { background: var(--secondary-container); color: var(--on-secondary-container); }
.fab:active { background-image: linear-gradient(var(--pressed), var(--pressed)); }

/* ---- 入力画面 ---- */

.form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px 16px calc(32px + env(safe-area-inset-bottom));
}

.form-group { display: flex; flex-direction: column; gap: 12px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.slot { display: flex; flex-direction: column; gap: 4px; }
.slot:empty { display: none; }
.actions-end { align-items: flex-end; }

.entry-row { display: flex; align-items: center; }
.entry-row .field { flex: 1; min-width: 0; }
.entry-name { flex: none; width: 104px; min-width: 0; padding-right: 8px; }
.entry-sub { min-height: 20px; white-space: nowrap; overflow: hidden; }

.field { display: flex; flex-direction: column; gap: 4px; }
.field-label { padding: 0 4px; font-size: 12px; line-height: 16px; color: var(--on-surface-variant); }
.field:focus-within .field-label { color: var(--primary); }
.field.error .field-label { color: var(--error); }

.field-box {
  display: flex;
  align-items: center;
  min-height: 56px;
  padding: 0 12px 0 16px;
  border: 1px solid var(--outline);
  border-radius: 4px;
  cursor: text;
}

.field-box.has-sign { padding-right: 4px; }
.field:focus-within .field-box { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.field.error .field-box { border-color: var(--error); }
.field.error:focus-within .field-box { box-shadow: inset 0 0 0 1px var(--error); }
.field.disabled { opacity: 0.38; }
.field.disabled .field-box { cursor: default; }

.field-input { position: relative; flex: 1; min-width: 0; }

/* iPhone は 16px 未満の入力欄にフォーカスすると画面が拡大されるので 16px 以上にする */
.field-input input {
  display: block;
  width: 100%;
  margin: 0;
  padding: 15px 0;
  border: 0;
  border-radius: 0;
  outline: 0;
  background: transparent;
  font-size: 16px;
  line-height: 24px;
  -webkit-appearance: none;
  appearance: none;
}

.field-input input::placeholder { color: var(--hint); opacity: 1; }

/* 入力した数字のすぐ後ろに、薄い 00 を重ねて表示する */
.field-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  overflow: hidden;
  font-size: 16px;
  line-height: 24px;
  white-space: pre;
  pointer-events: none;
}

.field-overlay .ghost { visibility: hidden; }
.field-overlay .hint { color: var(--hint); }

.field-suffix { flex: none; padding-left: 4px; color: var(--on-surface-variant); pointer-events: none; }

.sign-btn {
  flex: none;
  width: 44px;
  height: 44px;
  margin-left: 4px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--on-surface-variant);
  font-size: 22px;
  line-height: 1;
}

.sign-btn:active { background: var(--pressed); }

.field-support { padding: 0 4px; font-size: 12px; line-height: 16px; color: var(--on-surface-variant); }
.field-support:empty { display: none; }
.field.error .field-support { color: var(--error); }

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

.btn {
  display: block;
  width: 100%;
  height: 48px;
  margin-top: 8px;
  border: 0;
  border-radius: 24px;
  background: var(--primary);
  color: var(--on-primary);
  font-size: 15px;
  font-weight: 600;
}

.btn:disabled { background: var(--disabled-bg); color: var(--disabled-fg); }

.btn-outlined,
.btn-tonal,
.btn-text {
  max-width: 100%;
  height: 40px;
  padding: 0 20px;
  overflow: hidden;
  border: 0;
  border-radius: 20px;
  background: transparent;
  color: var(--primary);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.btn-outlined { border: 1px solid var(--outline); }
.btn-tonal { width: 100%; height: 44px; background: var(--secondary-container); color: var(--on-secondary-container); }
.btn-tonal:disabled { background: var(--disabled-bg); color: var(--disabled-fg); }
.btn-text { padding: 0 12px; }
.btn-text.danger { color: var(--error); }
.btn-outlined:active, .btn-text:active { background: var(--pressed); }

/* 同点時の順位 */
.ties { gap: 12px; }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--outline);
  border-radius: 8px;
  background: transparent;
  color: var(--on-surface-variant);
  font-size: 14px;
  font-weight: 500;
}

.chip.selected {
  padding-left: 8px;
  border-color: var(--secondary-container);
  background: var(--secondary-container);
  color: var(--on-secondary-container);
}

.chip .icon svg { width: 18px; height: 18px; }

/* ---- ダイアログ ---- */

.dialog {
  width: min(360px, calc(100vw - 48px));
  padding: 0;
  border: 0;
  border-radius: 28px;
  background: var(--container-high);
  color: var(--on-surface);
}

.dialog::backdrop { background: rgb(0 0 0 / 0.4); }
.dialog-body { display: flex; flex-direction: column; gap: 16px; padding: 24px 24px 16px; }
.dialog-title { font-size: 22px; line-height: 28px; }
.dialog-text { font-size: 14px; line-height: 20px; color: var(--on-surface-variant); white-space: pre-line; }
.dialog-menu { display: flex; flex-direction: column; gap: 8px; }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }

.snackbar {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 12px;
  width: max-content;
  max-width: calc(100vw - 32px);
  padding: 12px 8px 12px 16px;
  border-radius: 4px;
  background: var(--snackbar-bg);
  color: var(--snackbar-fg);
  font-size: 14px;
  line-height: 20px;
  transform: translateX(-50%);
  box-shadow: 0 2px 6px rgb(0 0 0 / 0.3);
}

.snackbar button {
  flex: none;
  padding: 6px 8px;
  border: 0;
  background: transparent;
  color: var(--snackbar-action);
  font-weight: 600;
}
