/* ========================================
   バドミントン組み合わせアプリ スタイルシート
   モバイルファースト / タッチ操作最適化
   ======================================== */

:root {
  --green-dark:   #1B5E20;
  --green:        #2E7D32;
  --green-light:  #4CAF50;
  --green-pale:   #E8F5E9;
  --green-mid:    #C8E6C9;
  --orange:       #E65100;
  --orange-light: #FF6D00;
  --red:          #C62828;
  --text:         #212121;
  --text-sub:     #616161;
  --bg:           #F1F3F4;
  --card:         #FFFFFF;
  --border:       #E0E0E0;
  --shadow:       0 2px 8px rgba(0, 0, 0, 0.10);
  --radius:       14px;
  --tap:          48px;  /* 最小タップターゲット */

  --male-bg:      #E3F2FD;
  --male-border:  #90CAF9;
  --male-text:    #1565C0;
  --female-bg:    #FCE4EC;
  --female-border:#F48FB1;
  --female-text:  #AD1457;
}

/* ---- Reset ---- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

body {
  font-family:
    -apple-system, BlinkMacSystemFont,
    'Hiragino Kaku Gothic ProN', 'Hiragino Sans',
    'Noto Sans JP', 'Yu Gothic UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: 40px;
  -webkit-font-smoothing: antialiased;
}

/* ---- Header ---- */
/* ヘッダーとタブをまとめて固定する（個別に sticky にすると重なるため） */
.app-top {
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}

.app-header {
  background: var(--green);
  color: white;
  padding: 14px 20px;
}

.app-title {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.3px;
}

/* 更新が届いたかどうかを見て分かるようにする */
.app-version {
  display: block;
  font-size: 11px;
  opacity: 0.85;
  margin-top: 2px;
}

/* ---- Tabs ---- */
.tab-bar {
  display: flex;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  flex: 1;
  min-height: var(--tap);
  border: none;
  border-bottom: 3px solid transparent;
  background: none;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-sub);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  user-select: none;
}

.tab-btn.active {
  color: var(--green);
  border-bottom-color: var(--green);
  background: var(--green-pale);
}

/* ---- Main layout ---- */
.app-main {
  max-width: 480px;
  margin: 0 auto;
  padding: 14px 12px;
}

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

/* ---- 保存失敗の警告 ---- */
.storage-warning {
  background: #FFF3E0;
  border: 2px solid var(--orange);
  border-radius: 10px;
  color: #7A3E00;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.6;
  padding: 12px 14px;
  margin-bottom: 12px;
}

/* ---- Card ---- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 700;
  color: var(--green-dark);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--green-pale);
}

/* ---- Badge ---- */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  background: var(--green-light);
  color: white;
  border-radius: 11px;
  font-size: 12px;
  font-weight: 700;
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  padding: 0 20px;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: opacity 0.12s, transform 0.1s;
  white-space: nowrap;
  user-select: none;
}

.btn:active:not(:disabled) { transform: scale(0.97); opacity: 0.9; }
.btn:disabled { opacity: 0.35; cursor: not-allowed; }

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

.btn-secondary {
  background: #EEEEEE;
  color: var(--text);
}

/* 主ボタン。状態によって「作成」と「確定」を切り替えるため、色でも意味を変える */
.btn-main {
  width: 100%;
  min-height: 56px;
  color: white;
  font-size: 17px;
  border-radius: 12px;
  margin-top: 6px;
}

.btn-main.mode-generate {
  background: var(--orange);
  box-shadow: 0 3px 8px rgba(230, 81, 0, 0.35);
}

.btn-main.mode-confirm {
  background: var(--green);
  box-shadow: 0 3px 8px rgba(46, 125, 50, 0.35);
}

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

.btn-full {
  width: 100%;
  margin-top: 16px;
}

/* ---- Action area（主ボタン＋補助ボタン） ---- */
.action-area {
  display: flex;
  flex-direction: column;
}

/* 引き直す・取り消しは主ボタンより控えめにして、誤って押されないようにする */
.action-row {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

/* 白地に薄いグレーだと輪郭が分かりにくいため、枠線を付けてボタンだと分かるようにする。
   ただし主ボタンより目立たせない */
.action-row .btn {
  flex: 1;
  min-height: var(--tap);
  padding: 0 12px;
  background: white;
  border: 2px solid #8C8C8C;  /* 白地に対して3:1以上のコントラストを確保する */
  color: var(--text);
  font-size: 15px;
}

.action-row .btn:active:not(:disabled) {
  background: #F0F0F0;
}

/* ---- Add member row ---- */
.add-row {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.text-input {
  flex: 1;
  height: var(--tap);
  padding: 0 14px;
  border: 2px solid var(--border);
  border-radius: 10px;
  font-size: 16px;
  font-family: inherit;
  color: var(--text);
  background: white;
  outline: none;
  transition: border-color 0.15s;
}

.text-input:focus {
  border-color: var(--green-light);
}

/* ---- Member list ---- */
.member-list {
  list-style: none;
  display: flex;
  flex-direction: column;
}

.member-item {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 52px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--border);
}

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

/* 性別カラー（名簿・参加者リスト共通） */
.member-item.gender-m { background: var(--male-bg); }
.member-item.gender-f { background: var(--female-bg); }

.member-name {
  flex: 1;
  font-size: 16px;
  font-weight: 500;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty-text {
  color: var(--text-sub);
  font-size: 14px;
  text-align: center;
  padding: 14px 0 4px;
}

/* ---- 本日の参加者チップ（タップで休憩の切り替え） ---- */
/* 試合中に頻繁に触るので、一覧ではなくチップにして縦の場所を取らないようにしている */
.player-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.player-chip {
  min-height: 40px;
  padding: 8px 14px;
  border: 2px solid var(--border);
  border-radius: 20px;
  background: white;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
}

.player-chip:active { transform: scale(0.96); }

.player-chip.gender-m {
  background: var(--male-bg);
  border-color: var(--male-border);
  color: var(--male-text);
}

.player-chip.gender-f {
  background: var(--female-bg);
  border-color: var(--female-border);
  color: var(--female-text);
}

/* 休憩中は打ち消し線で「抽選対象から外れている」ことを示す */
.player-chip.resting {
  background: #F5F5F5;
  border-color: var(--border);
  color: #9E9E9E;
  text-decoration: line-through;
}

.chip-hint {
  font-size: 12px;
  color: var(--text-sub);
  margin-top: 10px;
  line-height: 1.5;
}

/* ---- 性別ボタン・レベルボタン ---- */
/* 形を変えているのは見分けるため。どちらも未設定だと「−」「−」と同じ表示が
   並ぶので、色と文字では区別できない。性別＝角丸の四角、レベル＝丸。 */
.gender-btn {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  background: white;
  color: var(--text-sub);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.level-btn {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border: 2px solid var(--border);
  border-radius: 50%;
  font-size: 14px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  background: white;
  color: var(--text-sub);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.gender-btn-M {
  background: var(--male-bg);
  border-color: var(--male-border);
  color: var(--male-text);
}

.gender-btn-F {
  background: var(--female-bg);
  border-color: var(--female-border);
  color: var(--female-text);
}

/* ---- Toggle switch ---- */
.toggle {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 28px;
  flex-shrink: 0;
  cursor: pointer;
}

.toggle input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: #BDBDBD;
  border-radius: 28px;
  transition: background 0.2s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 22px;
  height: 22px;
  left: 3px;
  top: 3px;
  background: white;
  border-radius: 50%;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
  transition: transform 0.2s;
}

.toggle input:checked + .toggle-slider {
  background: var(--green-light);
}

.toggle input:checked + .toggle-slider::before {
  transform: translateX(22px);
}

/* ---- Delete button ---- */
.delete-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  background: none;
  border: none;
  border-radius: 50%;
  color: #BDBDBD;
  font-size: 16px;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
  line-height: 1;
}

.delete-btn:hover,
.delete-btn:focus-visible {
  color: var(--red);
  background: #FFEBEE;
}

/* ---- Court controls ---- */
.court-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.court-label {
  font-size: 15px;
  font-weight: 500;
}

.court-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.court-btn {
  width: 40px;
  height: 40px;
  background: var(--green-pale);
  border: none;
  border-radius: 10px;
  font-size: 22px;
  line-height: 1;
  color: var(--green);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  transition: background 0.12s;
  user-select: none;
}

.court-btn:active:not(:disabled) {
  background: var(--green-mid);
}

.court-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.court-display {
  min-width: 48px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  background: var(--bg);
  border-radius: 8px;
  border: 2px solid var(--border);
}

.court-unit {
  font-size: 15px;
  color: var(--text-sub);
}

/* ---- コート別タイプ設定 ---- */
#court-type-list {
  margin-bottom: 14px;
}

.court-type-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}

.court-type-row:last-child {
  border-bottom: none;
}

.court-type-label {
  font-size: 14px;
  font-weight: 500;
  min-width: 60px;
}

.court-type-toggle {
  display: flex;
  gap: 4px;
  margin-left: auto;
}

.court-type-btn {
  padding: 6px 14px;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  background: white;
  color: var(--text-sub);
  transition: all 0.15s;
  min-height: 36px;
}

.court-type-btn.active {
  background: var(--green);
  border-color: var(--green);
  color: white;
}

/* ---- 組み合わせ優先 ---- */
.preference-group {
  margin-bottom: 14px;
}

.preference-label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-sub);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.preference-options {
  display: flex;
  gap: 6px;
}

.preference-option {
  flex: 1;
  cursor: pointer;
}

.preference-option input[type="radio"] {
  display: none;
}

.preference-option span {
  display: block;
  width: 100%;
  text-align: center;
  padding: 8px 4px;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-sub);
  background: white;
  transition: all 0.15s;
  user-select: none;
}

.preference-option input[type="radio"]:checked + span {
  background: var(--green);
  border-color: var(--green);
  color: white;
}

/* 2つ目の希望（実力）の行は、上の行と間隔をあけて別の設定だと分かるようにする */
.preference-label-2nd {
  margin-top: 14px;
}

.preference-hint {
  text-align: left;
  margin-top: 8px;
}

/* 設定が効かない状態・レベルの付け忘れを知らせる。
   黙って効かないのが一番よくないので、本文より目立つ色にする。 */
.preference-warn {
  margin-top: 6px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
  color: var(--orange);
}

/* ---- 組み合わせのしくみ（利用者向けの説明） ----
   閉じているときは1行だけ。記録タブを長くしないため既定で閉じている。 */
.guide-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: var(--tap);
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
  color: var(--green-dark);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  list-style: none;
  user-select: none;
}

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

.guide-summary::before {
  content: '\25B6';
  font-size: 10px;
  color: var(--text-sub);
}

.guide[open] .guide-summary::before { content: '\25BC'; }

.guide[open] .guide-summary {
  border-bottom: 1px solid var(--border);
  padding-bottom: 10px;
  margin-bottom: 4px;
}

.guide-h {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  margin-top: 18px;
  margin-bottom: 4px;
}

.guide-lead {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-sub);
  margin-top: 10px;
}

.guide-list {
  margin: 4px 0 0 1.4em;
  padding: 0;
  font-size: 14px;
  line-height: 1.7;
  color: var(--text);
}

.guide-list li { margin-bottom: 3px; }

.guide-note {
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-sub);
  margin-top: 10px;
}

/* ---- Hint ---- */
.hint-text {
  font-size: 13px;
  color: var(--text-sub);
  text-align: center;
  margin-top: 8px;
  min-height: 18px;
  line-height: 1.4;
}

/* ---- Court cards ---- */
.court-card {
  background: var(--green-pale);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 10px;
}

.court-card-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--green-dark);
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.court-type-tag {
  font-size: 10px;
  font-weight: 600;
  background: var(--green-mid);
  color: var(--green-dark);
  padding: 2px 7px;
  border-radius: 4px;
  letter-spacing: 0;
  text-transform: none;
}

.match-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* シングルス用：横並びで均等配置 */
.singles-row .pair-player {
  flex: 1;
}

.pair {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.pair-player {
  background: white;
  border-radius: 8px;
  padding: 9px 10px;
  font-size: 15px;
  font-weight: 600;
  text-align: center;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 対戦表の性別カラー */
.pair-player.gender-m {
  background: var(--male-bg);
  color: var(--male-text);
}

.pair-player.gender-f {
  background: var(--female-bg);
  color: var(--female-text);
}

.vs-badge {
  font-size: 11px;
  font-weight: 700;
  color: var(--green-dark);
  background: white;
  border-radius: 4px;
  padding: 3px 5px;
  flex-shrink: 0;
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

/* ---- Rest sections ---- */
.rest-block {
  margin-top: 12px;
  padding: 12px;
  background: #FAFAFA;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.rest-block-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-sub);
  letter-spacing: 0.5px;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.rest-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  list-style: none;
}

.rest-chip {
  background: white;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 5px 14px;
  font-size: 14px;
  font-weight: 500;
}

/* 待機は薄いオレンジ */
.rest-block.waiting .rest-chip {
  border-color: #FFCC80;
  background: #FFF8E1;
}

/* 希望休憩はグレー */
.rest-block.hoping .rest-chip {
  border-color: #E0E0E0;
  background: #FAFAFA;
}

/* 性別カラー（待機・休憩チップ） */
.rest-chip.gender-m {
  background: var(--male-bg);
  border-color: var(--male-border);
  color: var(--male-text);
}

.rest-chip.gender-f {
  background: var(--female-bg);
  border-color: var(--female-border);
  color: var(--female-text);
}

/* ---- Dialog ---- */
.dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 24px;
  backdrop-filter: blur(2px);
}

.dialog-box {
  background: white;
  border-radius: 18px;
  padding: 24px 20px 20px;
  width: 100%;
  max-width: 300px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25);
}

.dialog-message {
  font-size: 16px;
  text-align: center;
  line-height: 1.5;
  margin-bottom: 20px;
  word-break: break-all;
}

.dialog-actions {
  display: flex;
  gap: 10px;
}

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

/* ---- 記録タブ：試合数一覧 ---- */
.count-list {
  list-style: none;
  display: flex;
  flex-direction: column;
}

.count-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 6px 4px;
  border-bottom: 1px solid var(--border);
}

.count-item:last-child { border-bottom: none; }
.count-item.gender-m { background: var(--male-bg); }
.count-item.gender-f { background: var(--female-bg); }

.count-name {
  flex: 1;
  font-size: 15px;
  font-weight: 500;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 試合数が最少の人が一目で分かるよう色を変える */
.count-value {
  flex-shrink: 0;
  min-width: 52px;
  text-align: right;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.count-item.count-min .count-value { color: var(--orange); }

/* ---- 記録タブ：対戦履歴 ---- */
.history-round {
  background: #FAFAFA;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 8px;
}

.history-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.history-title {
  flex: 1;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-sub);
  letter-spacing: 0.5px;
}

.history-line {
  font-size: 14px;
  line-height: 1.6;
  word-break: break-word;
}

.history-court-tag {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  background: var(--green-mid);
  color: var(--green-dark);
  padding: 1px 6px;
  border-radius: 4px;
  margin-right: 6px;
}

/* ---- 記録タブ：過去の記録 ---- */
.past-list {
  list-style: none;
  display: flex;
  flex-direction: column;
}

.past-item {
  border-bottom: 1px solid var(--border);
}

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

/* 日付をタップすると中身が開く。過去の記録が画面で読めないと見読性を満たさないため */
.past-head {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: var(--tap);
  padding: 8px 4px;
  border: none;
  background: none;
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.past-arrow {
  flex-shrink: 0;
  font-size: 10px;
  color: var(--text-sub);
}

.past-date { flex: 1; font-weight: 500; }
.past-count { flex-shrink: 0; color: var(--text-sub); }

.past-detail { padding: 2px 0 12px; }

.past-summary {
  background: var(--green-pale);
  border-radius: 8px;
  padding: 9px 11px;
  margin-bottom: 8px;
  font-size: 13px;
  line-height: 1.8;
  color: var(--green-dark);
  word-break: break-word;
}

/* ---- 記録タブ：改修履歴（past-list の見た目を流用） ---- */
.changelog-notes {
  list-style: disc;
  padding-left: 20px;
  font-size: 14px;
  line-height: 1.7;
  color: var(--text);
}
