* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-touch-callout: none;
}

:root {
  /* --- Surfaces (apple.com grays) --- */
  --bg: #f5f5f7;
  --card-bg: #ffffff;
  --fill-subtle: rgba(116,116,128,0.08);
  --track: rgba(118,118,128,0.12);

  /* --- Text --- */
  --text: #1d1d1f;
  --text-secondary: #6e6e73;
  --text-tertiary: #86868b;
  --border: #d2d2d7;
  --separator: #d2d2d7;

  /* --- Accents: Apple accessible system colors --- */
  --primary: #1c7c43;
  --primary-dark: #146033;
  --primary-light: #edf6f0;
  --danger: #d70015;
  --danger-light: #fdeceb;
  --gold: #b58a2b;
  --silver: #8a8a8e;
  --bronze: #9c6f52;

  /* --- Flat by default (iOS inset grouped lists) --- */
  --shadow: none;

  /* --- Radius scale --- */
  --r-xs: 6px;
  --r-sm: 8px;
  --r-md: 12px;
  --radius: 18px;
  /* 他に使っていいのは iOS 固有値だけ: 7/9px(segmented) 14px(dialog) 50% 100px */

  /* --- Type scale: Apple の text styles に合わせる --- */
  --t-title: 28px;   /* Title 1  */
  --t-title2: 22px;  /* Title 2  */
  --t-section: 20px; /* Title 3  */
  --t-lead: 17px;    /* Body     */
  --t-body: 15px;    /* Subhead  */
  --t-sub: 13px;     /* Footnote */
  --t-cap: 12px;     /* Caption1 */
  --t-cap2: 11px;    /* Caption2 */

  /* --- 数値専用（本文スケールとは別系統） --- */
  --t-num: 19px;
  --t-num-lg: 34px;

  --focus-ring: rgba(28,124,67,0.18);

  /* --- 麻雀牌は物理物なので両テーマ共通の伝統色 --- */
  --tile-man: #b02a24;
  --tile-pin: #0b6bcb;
  --tile-sou: #1c7c43;
  --tile-honor: #6b4f3f;
  --tile-honor-bg: #fdf6e6;

  /* --- Opaque + interaction surfaces --- */
  --surface-alt: #fafafa;
  --fill-press: rgba(118,118,128,0.2);
  --segment-thumb: #ffffff;
  --tabbar-bg: rgba(250,250,252,0.82);
  --tabbar-border: rgba(0,0,0,0.12);
  --dialog-bg: rgba(248,248,248,0.94);
  --dialog-sep: rgba(60,60,67,0.22);
  --scrim: rgba(0,0,0,0.4);
  --focus: #0071e3;

  /* --- Chart (read by canvas via getComputedStyle) --- */
  --chart-grid: #e8e8ed;
  --chart-label: #86868b;
  --chart-zero: #aeaeb2;
  --chart-dot-ring: #ffffff;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --tab-height: 52px;
  --p1: #248a3d;
  --p2: #0071e3;
  --p3: #c93400;
  --p4: #8944ab;
}

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

:root {
  color-scheme: light dark;
}

/* ========== Dark mode (iOS system dark palette) ========== */
/* OS がダークのとき。ただし手動でライトを選んでいたら適用しない。*/
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000;
    --card-bg: #1c1c1e;
    --surface-alt: #2c2c2e;
    --fill-subtle: rgba(118,118,128,0.18);
    --fill-press: rgba(118,118,128,0.32);
    --track: rgba(118,118,128,0.24);
    --segment-thumb: #636366;
    --tabbar-bg: rgba(22,22,24,0.82);
    --tabbar-border: rgba(255,255,255,0.14);
    --dialog-bg: rgba(44,44,46,0.94);
    --dialog-sep: rgba(84,84,88,0.7);
    --scrim: rgba(0,0,0,0.55);
    --focus: #0a84ff;
    --focus-ring: rgba(48,209,88,0.28);

    --text: #f5f5f7;
    --text-secondary: #aeaeb2;
    --text-tertiary: #8e8e93;
    --border: #38383a;
    --separator: #38383a;

    --primary: #30d158;
    --primary-dark: #248a3d;
    --primary-light: rgba(48,209,88,0.16);
    --danger: #ff453a;
    --danger-light: rgba(255,69,58,0.16);
    --gold: #d4a24c;
    --silver: #aeaeb2;
    --bronze: #c08457;

    --p1: #30d158;
    --p2: #0a84ff;
    --p3: #ff9f0a;
    --p4: #bf5af2;

    --chart-grid: #2c2c2e;
    --chart-label: #8e8e93;
    --chart-zero: #48484a;
    --chart-dot-ring: #1c1c1e;
  }
}

/* 手動でダークを選んだときは OS 設定を上書きする。*/
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #000000;
  --card-bg: #1c1c1e;
  --surface-alt: #2c2c2e;
  --fill-subtle: rgba(118,118,128,0.18);
  --fill-press: rgba(118,118,128,0.32);
  --track: rgba(118,118,128,0.24);
  --segment-thumb: #636366;
  --tabbar-bg: rgba(22,22,24,0.82);
  --tabbar-border: rgba(255,255,255,0.14);
  --dialog-bg: rgba(44,44,46,0.94);
  --dialog-sep: rgba(84,84,88,0.7);
  --scrim: rgba(0,0,0,0.55);
  --focus: #0a84ff;
  --focus-ring: rgba(48,209,88,0.28);

  --text: #f5f5f7;
  --text-secondary: #aeaeb2;
  --text-tertiary: #8e8e93;
  --border: #38383a;
  --separator: #38383a;

  --primary: #30d158;
  --primary-dark: #248a3d;
  --primary-light: rgba(48,209,88,0.16);
  --danger: #ff453a;
  --danger-light: rgba(255,69,58,0.16);
  --gold: #d4a24c;
  --silver: #aeaeb2;
  --bronze: #c08457;

  --p1: #30d158;
  --p2: #0a84ff;
  --p3: #ff9f0a;
  --p4: #bf5af2;

  --chart-grid: #2c2c2e;
  --chart-label: #8e8e93;
  --chart-zero: #48484a;
  --chart-dot-ring: #1c1c1e;
}

:root[data-theme="light"] {
  color-scheme: light;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Hiragino Sans', 'Noto Sans JP', sans-serif;
  letter-spacing: -0.011em;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: -webkit-fill-available;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  /* 上の safe-area は #app-bar 自身が持つ（sticky で固定されたときもノッチ分を確保するため） */
  padding-bottom: calc(var(--tab-height) + var(--safe-bottom));
}

/* ========== App Bar (設定への常表示ゲート) ========== */
#app-bar {
  position: sticky;
  top: 0;
  z-index: 900;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  height: calc(40px + var(--safe-top));
  padding: var(--safe-top) calc(12px + var(--safe-right)) 0 12px;
  background: var(--tabbar-bg);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--tabbar-border);
}

#settings-gear {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

#settings-gear:active {
  background: var(--fill-press);
  color: var(--text);
}

#settings-gear[aria-current="true"] {
  color: var(--primary);
  background: var(--primary-light);
}

/* ========== Tab Bar (Bottom) ========== */
#tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--tab-height) + var(--safe-bottom));
  background: var(--tabbar-bg);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  display: flex;
  justify-content: space-around;
  align-items: flex-start;
  border-top: 0.5px solid var(--tabbar-border);
  padding-bottom: var(--safe-bottom);
  z-index: 1000;
}

.tab-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 0;
  min-width: 0;
  flex: 1;
  border: none;
  background: none;
  color: var(--text-tertiary);
  font-size: var(--t-cap2);
  font-weight: 500;
  letter-spacing: -0.005em;
  cursor: pointer;
  min-height: 44px;
  transition: color 0.2s;
}

.tab-btn.active {
  color: var(--primary);
  font-weight: 600;
}

.tab-btn svg {
  flex-shrink: 0;
}

/* ========== App Container ========== */
#app {
  max-width: 500px;
  margin: 0 auto;
  padding: 0 16px 24px;
  padding-left: calc(16px + var(--safe-left));
  padding-right: calc(16px + var(--safe-right));
}

/* ========== Page Header ========== */
.page-header {
  padding: 10px 0 18px;
  text-align: left;
}

.page-header h2 {
  font-size: var(--t-title);
  font-weight: 700;
  letter-spacing: -0.024em;
  line-height: 1.12;
  color: var(--text);
}

/* ========== Cards ========== */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

/* ========== Section Title ========== */
.section-title {
  font-size: var(--t-section);
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
  margin: 0 0 12px;
}

/* ========== Empty State ========== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}

.empty-state p:first-child {
  font-size: var(--t-body);
  margin-bottom: 8px;
}

/* ========== Buttons ========== */
.btn {
  display: block;
  width: 100%;
  padding: 15px;
  border: none;
  border-radius: var(--r-md);
  font-family: inherit;
  font-size: var(--t-lead);
  font-weight: 600;
  letter-spacing: -0.012em;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.12s ease-out;
  min-height: 48px;
  text-align: center;
}

.btn:active {
  transform: scale(0.98);
  opacity: 0.9;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-secondary {
  background: var(--primary-light);
  color: var(--primary);
}

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

.btn-small {
  padding: 10px 16px;
  font-size: var(--t-body);
  min-height: 40px;
  width: auto;
  display: inline-block;
}

/* ========== Segment Control ========== */
.segment-control {
  display: flex;
  gap: 2px;
  padding: 2px;
  background: var(--track);
  border-radius: 9px;
  border: none;
  margin-bottom: 20px;
}

.segment-btn {
  flex: 1;
  padding: 0 8px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: var(--t-sub);
  font-weight: 500;
  letter-spacing: -0.008em;
  cursor: pointer;
  transition: background 0.2s, box-shadow 0.2s;
  min-height: 34px;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}

.segment-btn.active {
  background: var(--segment-thumb);
  font-weight: 600;
  box-shadow: 0 3px 8px rgba(0,0,0,0.12), 0 3px 1px rgba(0,0,0,0.04);
}

/* ========== Mode Select (3/4 player) — .segment-control と同一形 ========== */
.mode-select {
  display: flex;
  gap: 2px;
  padding: 2px;
  background: var(--track);
  border-radius: 9px;
  border: none;
  margin-bottom: 16px;
}

.mode-btn {
  flex: 1;
  padding: 0 8px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: var(--t-sub);
  font-weight: 500;
  letter-spacing: -0.008em;
  cursor: pointer;
  transition: background 0.2s, box-shadow 0.2s;
  min-height: 34px;
  -webkit-tap-highlight-color: transparent;
}

.mode-btn.active {
  background: var(--segment-thumb);
  font-weight: 600;
  box-shadow: 0 3px 8px rgba(0,0,0,0.12), 0 3px 1px rgba(0,0,0,0.04);
}

.mode-btn:active { opacity: 0.55; }

/* ========== Chip Select (Member) ========== */
.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.chip-item {
  padding: 9px 16px;
  border-radius: 100px;
  border: none;
  background: var(--fill-subtle);
  color: var(--text);
  font-family: inherit;
  font-size: var(--t-body);
  font-weight: 500;
  letter-spacing: -0.011em;
  cursor: pointer;
  transition: background 0.2s;
  min-height: 40px;
  display: flex;
  align-items: center;
}

.chip-item.selected {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
}

.chip-item.deleted {
  display: none;
}

.chip-add {
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--text-secondary);
}

/* ========== Input Styles ========== */
.form-group {
  margin-bottom: 12px;
}

.form-label {
  font-size: var(--t-sub);
  font-weight: 600;
  margin-bottom: 6px;
  display: block;
}

.input-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.input-row label {
  font-size: var(--t-sub);
  font-weight: 600;
  min-width: 90px;
  flex-shrink: 0;
}

.input-row input, .input-row select {
  flex: 1;
  padding: 12px 14px;
  border: none;
  border-radius: var(--r-sm);
  font-family: inherit;
  /* 16px 未満にすると iOS Safari がフォーカス時に拡大する */
  font-size: var(--t-lead);
  color: var(--text);
  outline: none;
  transition: box-shadow 0.2s;
  -webkit-appearance: none;
  appearance: none;
  min-height: 44px;
  background: var(--fill-subtle);
}

.input-row input:focus {
  box-shadow: 0 0 0 3.5px var(--focus-ring);
}

.input-text {
  width: 100%;
  padding: 12px 14px;
  border: none;
  border-radius: var(--r-sm);
  font-family: inherit;
  font-size: var(--t-lead);
  color: var(--text);
  background: var(--fill-subtle);
  outline: none;
  transition: box-shadow 0.2s;
  -webkit-appearance: none;
  appearance: none;
  min-height: 44px;
}

.input-text:focus {
  box-shadow: 0 0 0 3.5px var(--focus-ring);
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.75 6 6.25l5-4.5' fill='none' stroke='%2386868b' stroke-width='1.7' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px !important;
}

.input-options {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
}

.input-options label {
  font-size: var(--t-sub);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.input-options select {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  font-size: var(--t-lead);
  background: var(--card-bg);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  min-height: 44px;
}

.error-msg {
  color: var(--danger);
  font-size: var(--t-sub);
  margin-top: 8px;
  text-align: center;
  min-height: 20px;
}

/* ========== Summary Cards ========== */
/* ========== Standings (inset grouped list) ========== */
.standings {
  background: var(--card-bg);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 8px;
}

.standings-row {
  position: relative;
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 13px 16px;
}

.standings-row + .standings-row::before {
  content: '';
  position: absolute;
  top: 0;
  left: 52px;
  right: 0;
  height: 1px;
  background: var(--separator);
  transform: scaleY(0.5);
  transform-origin: top;
}

.standings-rank {
  font-size: var(--t-body);
  font-weight: 500;
  color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.standings-row:first-child .standings-rank {
  color: var(--text);
  font-weight: 600;
}

.standings-main { min-width: 0; }

.standings-name {
  display: flex;
  align-items: center;
  font-size: var(--t-body);
  font-weight: 600;
  letter-spacing: -0.011em;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-dot {
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 8px;
}

.standings-meta {
  font-size: var(--t-cap);
  font-weight: 400;
  color: var(--text-tertiary);
  letter-spacing: 0;
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.standings-score {
  font-size: var(--t-num);
  font-weight: 600;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.standings-score.positive { color: var(--primary); }
.standings-score.negative { color: var(--danger); }

.chip-badge {
  color: var(--p3);
  font-weight: 600;
  font-size: var(--t-cap2);
}

/* ========== Table ========== */
.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 16px;
  border-radius: var(--radius);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--t-sub);
  background: var(--card-bg);
  border-radius: var(--radius);
  overflow: hidden;
  font-variant-numeric: tabular-nums;
}

th, td {
  padding: 11px 8px;
  text-align: center;
  border-bottom: 0.5px solid var(--separator);
  white-space: nowrap;
}

th {
  background: var(--card-bg);
  color: var(--text-tertiary);
  font-weight: 500;
  font-size: var(--t-cap);
  letter-spacing: 0.01em;
  border-bottom: 1px solid var(--separator);
}

td.positive { color: var(--primary); font-weight: 600; }
td.negative { color: var(--danger); font-weight: 600; }

tr:last-child td { border-bottom: none; }
tr.total-row {
  background: var(--fill-subtle);
  font-weight: 700;
}

/* ========== Home: Recent Group Card ========== */
.recent-group-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 8px;
  cursor: pointer;
  transition: background 0.2s;
  min-height: 44px;
}

.recent-group-card:active {
  background: var(--primary-light);
}

.recent-group-names {
  font-size: var(--t-body);
  font-weight: 600;
}

.recent-group-meta {
  font-size: var(--t-cap2);
  color: var(--text-secondary);
}

.recent-game-card {
  padding: 10px 12px;
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 8px;
}

.recent-game-date {
  font-size: var(--t-cap2);
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.recent-game-players {
  font-size: var(--t-sub);
}

.recent-game-winner {
  color: var(--primary);
  font-weight: 600;
}

/* ========== Score Graph ========== */
.graph-card {
  position: relative;
  padding: 18px 12px 14px;
  margin-bottom: 8px;
}

.graph-canvas {
  width: 100%;
  height: 220px;
  display: block;
  touch-action: none;
}

.graph-tooltip {
  position: absolute;
  background: rgba(29,29,31,0.86);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  color: #fff;
  padding: 7px 11px;
  border-radius: var(--r-sm);
  font-size: var(--t-cap);
  font-weight: 500;
  letter-spacing: -0.008em;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  z-index: 10;
  white-space: nowrap;
  transform: translate(-50%, -100%);
  margin-top: -8px;
  display: none;
}

.graph-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin-top: 16px;
}

.graph-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--t-cap);
  font-weight: 500;
  letter-spacing: -0.008em;
  color: var(--text-secondary);
  background: var(--fill-subtle);
  padding: 5px 11px;
  border-radius: 100px;
}

.graph-legend-color {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

/* ========== Session (Collapsible) ========== */
.session-header-row td {
  padding: 0;
  border-bottom: none;
}

.session-header {
  background: var(--fill-subtle);
  padding: 11px 14px;
  margin: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  min-height: 44px;
  user-select: none;
  -webkit-user-select: none;
}

.session-title {
  font-size: var(--t-sub);
  font-weight: 600;
  letter-spacing: -0.008em;
  color: var(--text);
}

.session-toggle {
  font-size: var(--t-cap);
  color: var(--text-secondary);
  transition: transform 0.2s;
}

.session-toggle.collapsed {
  transform: rotate(-90deg);
}

.session-subtotal-row {
  background: rgba(116,116,128,0.05);
  font-weight: 600;
  font-size: var(--t-cap);
}

/* ========== Settlement ========== */
.settlement-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.settlement-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  background: var(--fill-subtle);
  border-radius: var(--r-md);
}

.settlement-name {
  font-size: var(--t-body);
  font-weight: 600;
  letter-spacing: -0.011em;
}

.settlement-points {
  font-size: var(--t-num);
  font-weight: 600;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.settlement-points.positive { color: var(--primary); }
.settlement-points.negative { color: var(--danger); }

.settlement-none {
  text-align: center;
  color: var(--text-secondary);
  font-size: var(--t-sub);
  padding: 8px 0;
}

/* ========== Points Table ========== */
.points-table td {
  font-size: var(--t-cap);
  padding: 8px 4px;
}

.points-table th:first-child,
.points-table td:first-child {
  background: var(--surface-alt);
  font-weight: 600;
  position: sticky;
  left: 0;
  z-index: 1;
}

/* .segment-control と同一形 */
.toggle-row {
  display: flex;
  gap: 2px;
  padding: 2px;
  background: var(--track);
  border-radius: 9px;
  border: none;
  margin-bottom: 16px;
}

.toggle-btn {
  flex: 1;
  padding: 0 8px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: var(--t-sub);
  font-weight: 500;
  letter-spacing: -0.008em;
  cursor: pointer;
  transition: background 0.2s, box-shadow 0.2s;
  min-height: 34px;
  -webkit-tap-highlight-color: transparent;
}

.toggle-btn.active {
  background: var(--segment-thumb);
  font-weight: 600;
  box-shadow: 0 3px 8px rgba(0,0,0,0.12), 0 3px 1px rgba(0,0,0,0.04);
}

.toggle-btn:active { opacity: 0.55; }

.mangan-list {
  font-size: var(--t-sub);
}

.mangan-list h4 {
  margin-bottom: 10px;
  color: var(--primary);
}

.mangan-item {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  gap: 8px;
}

.mangan-item:last-child { border-bottom: none; }

.mangan-item .label {
  font-weight: 600;
  white-space: nowrap;
}

.mangan-item .values {
  color: var(--text-secondary);
  font-size: var(--t-cap);
  text-align: right;
}

/* ========== Points Calculator ========== */
.calc-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.calc-section {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow);
}

.calc-section-title {
  font-size: var(--t-sub);
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 8px;
}

.calc-hand-area {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  min-height: 48px;
  padding: 6px;
  background: var(--bg);
  border-radius: var(--r-sm);
}

.calc-hint {
  color: var(--text-secondary);
  font-size: var(--t-cap);
  padding: 8px;
  text-align: center;
  width: 100%;
}

.calc-tile {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  min-height: 42px;
  padding: 2px 4px;
  font-size: var(--t-sub);
  font-weight: 600;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: var(--r-xs);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.calc-tile.tile-man { color: var(--text); border-color: var(--tile-man); }
.calc-tile.tile-pin { color: var(--tile-pin); border-color: var(--tile-pin); }
.calc-tile.tile-sou { color: var(--tile-sou); border-color: var(--tile-sou); }
.calc-tile.tile-honor { color: var(--tile-honor); border-color: var(--tile-honor); background: var(--tile-honor-bg); }
.calc-tile.tile-red { color: #fff; background: var(--tile-man); border-color: var(--tile-man); }
.calc-tile.winning {
  background: var(--gold);
  color: #fff;
  border-color: var(--gold);
}

.calc-winning-tile {
  margin-top: 8px;
  font-size: var(--t-sub);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.calc-winning-display {
  font-weight: 600;
  color: var(--primary);
}

.calc-mini-btn {
  font-size: var(--t-cap);
  padding: 6px 10px;
  background: var(--primary-light);
  color: var(--primary);
  border: 1px solid var(--primary);
  border-radius: var(--r-xs);
  cursor: pointer;
  min-height: 32px;
}

.calc-mini-btn-danger {
  background: var(--danger-light);
  color: var(--danger);
  border-color: var(--danger);
}

.calc-melds {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.calc-meld {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  padding: 6px;
  background: var(--bg);
  border-radius: var(--r-xs);
  cursor: pointer;
}

.calc-meld-pending {
  background: var(--fill-subtle);
  border: 1px dashed var(--gold);
}

.calc-meld-type {
  font-size: var(--t-cap2);
  color: var(--text-secondary);
  margin-right: 4px;
}

.calc-meld-tile {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  min-height: 32px;
  padding: 2px;
  font-size: var(--t-cap);
  font-weight: 600;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: var(--r-xs);
}

.calc-meld-tile.tile-man { color: var(--text); border-color: var(--tile-man); }
.calc-meld-tile.tile-pin { color: var(--tile-pin); border-color: var(--tile-pin); }
.calc-meld-tile.tile-sou { color: var(--tile-sou); border-color: var(--tile-sou); }
.calc-meld-tile.tile-honor { color: var(--tile-honor); border-color: var(--tile-honor); background: var(--tile-honor-bg); }
.calc-meld-tile.tile-red { color: #fff; background: var(--tile-man); border-color: var(--tile-man); }

.calc-meld-add-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.calc-situation-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}

.calc-situation-label {
  font-size: var(--t-cap);
  color: var(--text-secondary);
  min-width: 44px;
}

.calc-toggle-btn {
  padding: 6px 12px;
  font-size: var(--t-sub);
  font-weight: 600;
  background: var(--primary-light);
  color: var(--primary);
  border: none;
  border-radius: var(--r-xs);
  cursor: pointer;
  min-height: 34px;
  -webkit-tap-highlight-color: transparent;
}

.calc-toggle-btn.active {
  background: var(--primary);
  color: white;
}

.calc-flag-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.calc-flag-btn {
  padding: 8px;
  font-size: var(--t-sub);
  font-weight: 600;
  background: var(--fill-subtle);
  color: var(--text);
  border: none;
  border-radius: var(--r-xs);
  cursor: pointer;
  min-height: 38px;
}

.calc-flag-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.calc-dora-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  min-height: 36px;
  padding: 4px;
  background: var(--bg);
  border-radius: var(--r-xs);
}

.calc-input-target {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.calc-target-btn {
  flex: 1;
  min-width: 60px;
  padding: 6px;
  font-size: var(--t-cap);
  font-weight: 600;
  background: var(--fill-subtle);
  color: var(--text);
  border: none;
  border-radius: var(--r-xs);
  cursor: pointer;
  min-height: 36px;
}

.calc-target-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.calc-tile-pad {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.calc-tile-pad-row {
  display: flex;
  gap: 3px;
  justify-content: flex-start;
  flex-wrap: wrap;
}

.calc-tile-pad-row .calc-tile {
  flex: 1 1 0;
  min-width: 30px;
  max-width: 44px;
}

.calc-action-row {
  display: flex;
  gap: 8px;
}

.calc-action-row .btn {
  flex: 1;
}

.calc-result-box {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow);
}

.calc-error {
  background: var(--danger-light);
  color: var(--danger);
  padding: 12px;
  border-radius: var(--r-sm);
  font-weight: 600;
  text-align: center;
}

.calc-result-header {
  text-align: center;
  padding: 12px;
  background: var(--primary-light);
  border-radius: var(--r-sm);
  margin-bottom: 12px;
}

.calc-result-points {
  font-size: var(--t-title);
  font-weight: 700;
  color: var(--primary);
}

.calc-result-sub {
  font-size: var(--t-sub);
  color: var(--text-secondary);
  margin-top: 4px;
}

.calc-result-section {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.calc-result-section-title {
  font-size: var(--t-sub);
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 6px;
}

.calc-yaku-list,
.calc-fu-breakdown {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.calc-yaku-item,
.calc-fu-item {
  display: flex;
  justify-content: space-between;
  font-size: var(--t-sub);
  padding: 2px 0;
}

.calc-yaku-total,
.calc-fu-total {
  border-top: 1px dashed var(--border);
  padding-top: 4px;
  font-weight: 600;
  color: var(--primary);
}

.calc-decomp {
  font-size: var(--t-cap);
  line-height: 1.6;
  color: var(--text);
}

@media (max-width: 380px) {
  .calc-tile {
    min-width: 28px;
    min-height: 38px;
    font-size: var(--t-cap);
  }
  .calc-flag-btn {
    font-size: var(--t-cap);
    padding: 6px;
  }
  .calc-result-points {
    font-size: var(--t-title2);
  }
}

.result-box {
  margin-top: 16px;
  padding: 16px;
  background: var(--primary-light);
  border-radius: var(--r-md);
  text-align: center;
  font-size: var(--t-lead);
  font-weight: 600;
  color: var(--primary);
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ========== Statistics ========== */
.stats-overview {
  text-align: center;
  margin-bottom: 16px;
}

.stats-total-games {
  font-size: var(--t-section);
  font-weight: 700;
  color: var(--primary);
}

.stats-player-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.stats-player-name {
  font-size: var(--t-lead);
  font-weight: 600;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--border);
}

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

.stats-item {
  display: flex;
  flex-direction: column;
  padding: 6px 0;
}

.stats-label {
  font-size: var(--t-cap2);
  color: var(--text-secondary);
  margin-bottom: 2px;
}

.stats-value {
  font-size: var(--t-num);
  font-weight: 600;
}

.stats-value.positive { color: var(--primary); }
.stats-value.negative { color: var(--danger); }

/* ========== Settings ========== */
.settings-section {
  margin-bottom: 20px;
}

.settings-section h3 {
  font-size: var(--t-body);
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 8px;
}

.user-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 0;
  border-bottom: 0.5px solid var(--separator);
  min-height: 44px;
}

.user-list-item:last-of-type {
  border-bottom: none;
}

.user-list-item:last-child {
  border-bottom: none;
}

.user-name {
  font-size: var(--t-body);
  font-weight: 600;
}

.user-actions {
  display: flex;
  gap: 8px;
}

.user-actions button {
  background: none;
  border: none;
  cursor: pointer;
  font-size: var(--t-sub);
  padding: 4px 8px;
  border-radius: var(--r-xs);
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-edit, .btn-delete {
  border: none;
  background: none;
  cursor: pointer;
  font-size: var(--t-sub);
  font-weight: 600;
  padding: 10px 14px;
  min-height: 44px;
  min-width: 44px;
  border-radius: var(--r-sm);
}
.btn-edit { color: var(--primary); background: var(--primary-light); }
.btn-delete { color: var(--danger); background: #ffebee; }

/* Data management */
.data-section-title {
  font-size: var(--t-body);
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 6px;
}

.data-description {
  font-size: var(--t-sub);
  color: var(--text-secondary);
  margin-bottom: 12px;
}

/* ========== Edit/Delete buttons in history ========== */
.history-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.btn-edit-game {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: var(--t-sub);
  padding: 4px 6px;
  border-radius: var(--r-xs);
  min-width: 36px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-edit-game:active { opacity: 0.5; }

.btn-delete-game {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: var(--t-lead);
  padding: 4px 10px;
  border-radius: var(--r-xs);
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ========== Dropdown select ========== */
.dropdown-select {
  width: 100%;
  padding: 12px 42px 12px 16px;
  border: none;
  border-radius: var(--r-md);
  font-family: inherit;
  font-size: var(--t-body);
  font-weight: 500;
  letter-spacing: -0.011em;
  color: var(--text);
  background-color: var(--card-bg);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.75 6 6.25l5-4.5' fill='none' stroke='%2386868b' stroke-width='1.7' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 16px center;
  background-size: 12px 8px;
  -webkit-appearance: none;
  appearance: none;
  outline: none;
  min-height: 48px;
  margin-bottom: 10px;
  text-overflow: ellipsis;
}

/* ========== Ranking Table ========== */
.ranking-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--t-sub);
  background: var(--card-bg);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.ranking-table th {
  background: var(--primary);
  color: white;
  font-weight: 600;
  font-size: var(--t-cap);
  padding: 10px 8px;
}

.ranking-table td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
}

.ranking-table tr:last-child td {
  border-bottom: none;
}

/* ========== Responsive ========== */
@media (max-width: 380px) {
  .page-header h2 {
    font-size: var(--t-title2);
  }

  .standings-row {
    gap: 10px;
    padding: 12px 14px;
  }

  .standings-score {
    font-size: var(--t-lead);
  }

  .input-row label {
    min-width: 70px;
    font-size: var(--t-sub);
  }

  .mangan-item {
    flex-direction: column;
    gap: 2px;
  }

  .mangan-item .values {
    text-align: left;
  }
}

/* ========== Modal ========== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--scrim);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-content {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}

.modal-title {
  font-size: var(--t-lead);
  font-weight: 600;
  margin-bottom: 16px;
}

.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.modal-actions .btn {
  flex: 1;
}

/* ========== Dialog (iOS-style alert; replaces native confirm/alert) ========== */
.dialog-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--scrim);
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  opacity: 0;
  transition: opacity 0.18s ease-out;
}

.dialog-overlay.open { opacity: 1; }
.dialog-overlay.closing { opacity: 0; }

.dialog {
  width: 100%;
  max-width: 272px;
  background: var(--dialog-bg);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  border-radius: 14px;
  overflow: hidden;
  text-align: center;
  transform: scale(1.08);
  transition: transform 0.18s ease-out;
}

.dialog-overlay.open .dialog { transform: scale(1); }

.dialog-head {
  padding: 19px 16px 15px;
}

.dialog-title {
  font-size: var(--t-lead);
  font-weight: 600;
  letter-spacing: -0.012em;
  line-height: 1.3;
  color: var(--text);
}

.dialog-body {
  font-size: var(--t-sub);
  font-weight: 400;
  line-height: 1.45;
  color: var(--text);
  margin-top: 5px;
}

.dialog-actions {
  display: flex;
  border-top: 0.5px solid var(--dialog-sep);
}

.dialog-btn {
  flex: 1;
  min-height: 44px;
  padding: 11px 8px;
  border: none;
  background: transparent;
  color: var(--primary);
  font-family: inherit;
  font-size: var(--t-lead);
  font-weight: 400;
  letter-spacing: -0.012em;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.dialog-actions.single .dialog-btn { width: 100%; }
.dialog-btn + .dialog-btn { border-left: 0.5px solid var(--dialog-sep); }
.dialog-btn.primary { font-weight: 600; }
.dialog-btn.destructive { color: var(--danger); }
.dialog-btn:active { background: var(--fill-press); }

.settings-note {
  font-size: var(--t-cap);
  color: var(--text-tertiary);
  line-height: 1.45;
  margin: -10px 0 0 2px;
}

/* ========== Press feedback ========== */
.segment-btn:active { opacity: 0.55; }
.tab-btn:active { opacity: 0.45; }
.live-riichi-btn:active { opacity: 0.55; }
.chip-item:active { opacity: 0.55; }
.dropdown-select:active { background-color: var(--fill-press); }
.btn-delete-game:active { opacity: 0.5; }

/* ========== Keyboard focus ring ========== */
button:focus-visible,
select:focus-visible,
input:focus-visible,
a:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}

h3 {
  font-size: var(--t-section);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  margin: 30px 0 12px;
}

/* AI Comment Card */
/* Yakuman Badge */
.yakuman-badge {
  display: inline-block;
  background: var(--gold);
  color: #fff;
  font-size: var(--t-cap2);
  font-weight: 600;
  padding: 1px 6px;
  border-radius: var(--r-sm);
  margin-top: 2px;
}

.ai-comment-card {
  background: var(--card-bg);
  border: 1px solid var(--separator);
}

.ai-comment-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--separator);
}

.ai-comment-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.ai-comment-item:first-of-type {
  padding-top: 0;
}

.ai-comment-icon {
  font-size: var(--t-section);
  flex-shrink: 0;
  width: 28px;
  text-align: center;
}

.ai-comment-body {
  flex: 1;
  min-width: 0;
}

.ai-comment-title {
  font-weight: 600;
  font-size: var(--t-body);
  color: var(--text);
  margin-bottom: 2px;
}

.ai-comment-text {
  font-size: var(--t-cap);
  color: var(--text-secondary);
  line-height: 1.4;
}

/* ========== 対局モード（点棒リアルタイム管理） ========== */
.start-mode-note {
  font-size: var(--t-cap2);
  color: var(--text-secondary);
  text-align: center;
  margin: 4px 0 12px;
  line-height: 1.4;
}

.chip-item:disabled {
  opacity: 0.3;
  pointer-events: none;
}

/* 復帰カード */
.live-resume-card {
  background: var(--primary);
  color: white;
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  cursor: pointer;
}

.live-resume-label {
  font-size: var(--t-cap2);
  font-weight: 600;
  letter-spacing: 0.1em;
  opacity: 0.85;
}

.live-resume-names {
  font-size: var(--t-body);
  font-weight: 600;
  margin-top: 2px;
}

.live-resume-status {
  font-size: var(--t-cap);
  opacity: 0.9;
  margin-top: 2px;
}

.live-resume-scores {
  font-size: var(--t-cap);
  font-variant-numeric: tabular-nums;
  opacity: 0.85;
  margin-top: 4px;
}

/* 席順 */
.seat-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.seat-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--bg);
  border-radius: var(--r-sm);
}

.seat-wind {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  font-size: var(--t-sub);
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
}

.seat-name {
  flex: 1;
  font-size: var(--t-body);
  font-weight: 600;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.seat-actions {
  display: flex;
  gap: 4px;
}

.btn-seat {
  width: 36px;
  min-height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--card-bg);
  color: var(--text);
  font-size: var(--t-cap);
  cursor: pointer;
}

.btn-seat:disabled {
  opacity: 0.3;
}

.switch-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  font-size: var(--t-sub);
  min-height: 44px;
  cursor: pointer;
}

.switch-row input[type="checkbox"] {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  accent-color: var(--primary);
}

.live-setup-note {
  font-size: var(--t-cap2);
  color: var(--text-secondary);
  line-height: 1.5;
  margin-top: 8px;
}

/* 対局中ヘッダー */
.live-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px 0 10px;
}

.live-round {
  font-size: var(--t-title2);
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.02em;
}

.live-meta {
  display: flex;
  gap: 10px;
  margin-top: 4px;
  font-size: var(--t-cap2);
  color: var(--text-secondary);
}

.live-sticks {
  color: var(--danger);
  font-weight: 600;
}

.live-warn {
  background: var(--danger-light);
  color: var(--danger);
  font-size: var(--t-cap);
  font-weight: 600;
  text-align: center;
  padding: 8px;
  border-radius: var(--r-sm);
  margin-bottom: 8px;
}

/* 卓レイアウト */
.live-table {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.live-table.count-4 {
  grid-template-columns: 1fr 1fr;
}

.live-table.count-3 {
  grid-template-columns: 1fr 1fr;
}

.live-table.count-3 .live-player:first-child {
  grid-column: 1 / -1;
}

.live-player {
  background: var(--card-bg);
  border-radius: var(--radius);
  /* 親のときだけ .dealer が border-color で色を入れる */
  border: 1px solid transparent;
  padding: 12px 14px 10px;
  box-shadow: var(--shadow);
  position: relative;
}

.live-player.dealer {
  border-color: var(--pc);
}

.live-player.busted {
  background: var(--danger-light);
}

.live-player-top {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.live-wind {
  font-size: var(--t-cap2);
  font-weight: 600;
  color: white;
  background: var(--pc);
  border-radius: var(--r-xs);
  padding: 1px 5px;
  flex-shrink: 0;
}

.live-name {
  font-size: var(--t-sub);
  font-weight: 600;
  color: var(--pc);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.live-badge-dealer {
  font-size: var(--t-cap2);
  font-weight: 600;
  color: var(--gold);
  border: 1px solid var(--gold);
  border-radius: var(--r-xs);
  padding: 0 3px;
  flex-shrink: 0;
}

.live-score {
  font-size: var(--t-num-lg);
  font-weight: 700;
  letter-spacing: -0.025em;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  line-height: 1.1;
  margin: 3px 0 1px;
}

.live-player.busted .live-score {
  color: var(--danger);
}

.live-player-bottom {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: var(--t-cap2);
}

.live-rank {
  color: var(--text-secondary);
  font-weight: 600;
}

.live-diff {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.live-riichi-btn {
  width: 100%;
  margin-top: 6px;
  min-height: 34px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--card-bg);
  color: var(--text-secondary);
  font-size: var(--t-cap);
  font-weight: 600;
  cursor: pointer;
}

.live-riichi-btn.on {
  background: var(--danger);
  border-color: var(--danger);
  color: white;
}

.live-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.live-act {
  flex: 1;
  margin: 0;
}

.live-act:disabled {
  opacity: 0.4;
  pointer-events: none;
}

/* 局ログ */
.hand-log {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.hand-log-item {
  background: var(--card-bg);
  border-radius: var(--r-md);
  padding: 8px 10px;
}

.hand-log-head {
  display: flex;
  gap: 8px;
  align-items: baseline;
}

.hand-log-no {
  font-size: var(--t-cap2);
  font-weight: 600;
  color: var(--primary);
  flex-shrink: 0;
}

.hand-log-desc {
  font-size: var(--t-cap);
  color: var(--text);
  line-height: 1.4;
}

.hand-log-deltas {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.hand-log-delta {
  font-size: var(--t-cap2);
  font-variant-numeric: tabular-nums;
}

.hand-log-delta.zero,
.live-preview-deltas .zero {
  color: var(--text-secondary);
}

.hand-log-scores {
  font-size: var(--t-cap2);
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  margin-top: 3px;
}

/* 和了入力モーダル */
.live-modal-content {
  max-width: 380px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.fu-list .chip-item {
  padding: 8px 12px;
  min-width: 46px;
  justify-content: center;
}

.live-preview {
  background: var(--primary-light);
  border-radius: var(--r-md);
  padding: 10px;
  margin-top: 12px;
  font-size: var(--t-cap);
  color: var(--text);
}

.live-preview-head {
  font-weight: 600;
  line-height: 1.5;
}

.live-preview-deltas {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
  font-size: var(--t-cap);
  font-variant-numeric: tabular-nums;
}

.live-end-reason {
  font-size: var(--t-lead);
  font-weight: 600;
  color: var(--primary);
  text-align: center;
  margin-bottom: 12px;
}

.btn-hand-log {
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text-secondary);
  border-radius: var(--r-xs);
  font-size: var(--t-cap2);
  padding: 2px 5px;
  margin-top: 2px;
  cursor: pointer;
}

/* ========== 対局共有 (Share export/import) ========== */
.share-modal-content {
  max-width: 480px;
  width: 92%;
}

.share-select-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.share-game-list {
  max-height: 44vh;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 8px;
}

.share-session-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: var(--t-sub);
  color: var(--text-secondary);
  margin: 8px 0 4px;
}

.share-game-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.share-game-item:last-child { border-bottom: none; }

.share-game-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.share-game-time {
  font-size: var(--t-sub);
  color: var(--text-secondary);
}

.share-game-names {
  font-size: var(--t-body);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.share-selected-count {
  font-size: var(--t-sub);
  color: var(--text-secondary);
  margin: 8px 0;
}

.share-textarea {
  width: 100%;
  min-height: 180px;
  font-family: monospace;
  font-size: 12px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--bg);
  color: var(--text);
  resize: vertical;
}

.share-player-map {
  max-height: 40vh;
  overflow-y: auto;
  margin-bottom: 8px;
}

.share-player-row {
  margin-bottom: 12px;
}

.share-player-name {
  font-size: var(--t-body);
  font-weight: 600;
  margin-bottom: 4px;
}

.share-player-select {
  width: 100%;
}

/* ========== 点数計算機: 牌の視認性改善 ========== */
.calc-tile {
  flex-direction: column;
  gap: 0;
  line-height: 1.05;
  min-height: 46px;
}

.tile-num {
  font-size: 17px;
  font-weight: 700;
}

.tile-mark {
  font-size: 10px;
  opacity: 0.85;
  font-weight: 600;
}

.tile-honor-char {
  font-size: 15px;
  font-weight: 700;
}

/* 萬子は色が地の色と同じで判別しづらいため背景を薄く敷く */
.calc-tile.tile-man { background: var(--tile-man-bg, #fdf4f4); }
.calc-tile.tile-pin { background: var(--tile-pin-bg, #f2f7fd); }
.calc-tile.tile-sou { background: var(--tile-sou-bg, #f2faf4); }

.calc-tile.tile-red .tile-num,
.calc-tile.tile-red .tile-mark { color: #fff; }

.calc-tile.winning .tile-num,
.calc-tile.winning .tile-mark,
.calc-tile.winning .tile-honor-char { color: #fff; }

/* パッドの種類ラベル */
.calc-pad-group { margin-bottom: 8px; }

.calc-pad-label {
  font-size: 11px;
  color: var(--text-secondary);
  margin-bottom: 3px;
  font-weight: 600;
}

/* ========== 設定画面のサイト情報リンク ========== */
.settings-links {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 20px 0 8px;
  padding: 4px 0;
}

.settings-links a {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: var(--t-body);
  padding: 11px 4px;
  border-bottom: 1px solid var(--separator);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.settings-links a::after {
  content: '\203A';
  color: var(--text-tertiary);
  font-size: var(--t-lead);
}

.settings-links a:last-child { border-bottom: none; }

/* ========== バックアップ促し ========== */
.backup-reminder {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--primary-light);
  border-radius: var(--r-sm);
  padding: 13px 14px;
  margin-bottom: 16px;
}

.backup-reminder-text {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  flex: 1;
}

.backup-reminder-text strong {
  font-size: var(--t-body);
  font-weight: 600;
}

.backup-reminder-text span {
  font-size: var(--t-sub);
  color: var(--text-secondary);
  line-height: 1.55;
}

.backup-reminder .btn { flex-shrink: 0; }

@media (max-width: 420px) {
  .backup-reminder { flex-direction: column; align-items: stretch; }
  .backup-reminder .btn { width: 100%; }
}

/* ========== ホーム画面に追加する案内 ========== */
.a2hs-hint {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(var(--tab-height) + var(--safe-bottom) + 10px);
  z-index: 950;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 13px 12px 13px 14px;
  background: var(--dialog-bg);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: 0 6px 24px rgba(0,0,0,0.16);
  animation: a2hs-in 0.28s ease-out;
}

@keyframes a2hs-in {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.a2hs-hint-body {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  flex: 1;
  min-width: 0;
}

.a2hs-hint-body img { flex-shrink: 0; border-radius: 50%; }

.a2hs-hint-text {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.a2hs-hint-text strong {
  font-size: var(--t-body);
  font-weight: 600;
}

.a2hs-hint-text span {
  font-size: var(--t-sub);
  color: var(--text-secondary);
  line-height: 1.55;
}

.a2hs-hint-close {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--text-tertiary);
  font-size: 22px;
  line-height: 1;
  padding: 2px 6px;
  cursor: pointer;
  min-width: 32px;
  min-height: 32px;
}

/* 手順の行だけ少し際立たせ、アイコンを文中に置く */
.a2hs-howto {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 2px;
  margin-top: 5px;
  font-weight: 600;
  color: var(--text) !important;
}

.a2hs-icon {
  width: 1.15em;
  height: 1.15em;
  vertical-align: -0.22em;
  margin: 0 2px;
  color: var(--primary);
  flex-shrink: 0;
}

/* ヒートマップは1セルに2行入るため、他のグラフより高さが要る */
.heatmap-canvas { height: 252px; }
