* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: "Hiragino Kaku Gothic ProN", "Meiryo", sans-serif;
  background: #0f2419;
  color: #f3f6f4;
  line-height: 1.5;
  padding: 16px;
  -webkit-text-size-adjust: 100%;
}

.container {
  max-width: 980px;
  margin: 0 auto;
}

.hidden {
  display: none !important;
}

button,
input {
  touch-action: manipulation;
  font-family: inherit;
}

.card {
  background: #173324;
  border: 1px solid #2b5940;
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}

h1 {
  color: #f5c542;
  font-size: clamp(1.35rem, 4vw, 1.85rem);
  margin-bottom: 8px;
}

h2 {
  font-size: 1.1rem;
  color: #f5c542;
  border-bottom: 1px solid #2b5940;
  padding-bottom: 6px;
  margin-bottom: 14px;
}

h3 {
  font-size: 1rem;
  margin: 14px 0 8px;
  color: #b7e4c7;
}

/* 難易度選択 */
.subtitle {
  color: #b7e4c7;
  margin-bottom: 18px;
  font-size: 0.95rem;
}

.difficulty-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
}

.diff-btn {
  background: #1f4430;
  border: 2px solid #3c7a57;
  border-radius: 8px;
  padding: 16px;
  color: #fff;
  text-align: left;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 48px;
  transition: transform 0.15s, border-color 0.15s;
}

.diff-btn:hover,
.diff-btn:active {
  transform: translateY(-2px);
  border-color: #f5c542;
}

.diff-title {
  font-weight: bold;
  color: #f5c542;
}

.diff-money {
  font-size: 1.35rem;
  font-weight: bold;
}

.diff-desc {
  font-size: 0.85rem;
  color: #cde5d7;
}

/* ステータスバー */
.status-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.badge-race {
  display: inline-block;
  background: #f5c542;
  color: #111;
  font-weight: bold;
  padding: 4px 10px;
  border-radius: 5px;
  margin-right: 8px;
}

.race-cond {
  font-weight: bold;
  font-size: 1rem;
}

.money-box {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.badge-diff {
  background: #2b5940;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 0.82rem;
}

.money-box strong {
  font-size: 1.25rem;
  color: #f5c542;
}

.profit.plus { color: #52b788; }
.profit.minus { color: #ff6b6b; }

/* 出馬表（横スクロール＋1列目固定） */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 6px;
  border: 1px solid #264d38;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.92rem;
  text-align: center;
  white-space: nowrap;
}

th, td {
  padding: 10px 8px;
  border-bottom: 1px solid #264d38;
}

th {
  background: #11261b;
  color: #b7e4c7;
}

/* 1列目（馬番）を左端に固定して横スクロール時に見失わないようにする */
th:first-child,
td:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  background: #173324;
  border-right: 1px solid #2b5940;
}

th:first-child {
  background: #11261b;
  z-index: 3;
}

td:nth-child(2) {
  text-align: left;
  font-weight: bold;
}

.num-badge {
  display: inline-block;
  width: 26px;
  height: 26px;
  line-height: 26px;
  border-radius: 4px;
  font-weight: bold;
  text-align: center;
}

.apt-good { color: #f5c542; font-weight: bold; }
.apt-bad { color: #8c9e94; }

/* マークシート操作 */
.controls-row {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  margin-bottom: 14px;
}

.control-group {
  flex: 1 1 280px;
}

.control-group label {
  display: block;
  font-size: 0.9rem;
  color: #b7e4c7;
  margin-bottom: 8px;
}

.btn-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.select-btn {
  background: #214733;
  color: #fff;
  border: 1px solid #3c7a57;
  padding: 10px 14px;
  min-height: 44px;
  border-radius: 6px;
  font-size: 0.95rem;
  cursor: pointer;
}

.select-btn.active {
  background: #f5c542;
  color: #111;
  font-weight: bold;
  border-color: #f5c542;
}

.multi-check {
  display: flex !important;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  min-height: 40px;
  cursor: pointer;
  color: #f5c542 !important;
  font-weight: bold;
}

.multi-check input[type="checkbox"] {
  width: 20px;
  height: 20px;
}

.picker-area {
  background: #11261b;
  padding: 12px;
  border-radius: 8px;
  margin-bottom: 14px;
}

.picker-row {
  margin-bottom: 14px;
}

.picker-row:last-child {
  margin-bottom: 0;
}

.picker-title {
  font-size: 0.9rem;
  color: #b7e4c7;
  margin-bottom: 8px;
}

.horse-btns {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 8px;
}

.horse-pick-btn {
  min-height: 46px;
  padding: 8px 4px;
  border-radius: 6px;
  border: 2px solid #3c7a57;
  background: #1b3b2a;
  color: #fff;
  font-size: 1.05rem;
  font-weight: bold;
  cursor: pointer;
}

.horse-pick-btn.selected {
  background: #e63946;
  border-color: #ffb703;
  color: #fff;
}

.horse-pick-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.bet-summary {
  background: #1f4430;
  padding: 14px;
  border-radius: 8px;
}

.preview-text {
  font-size: 0.95rem;
  margin-bottom: 10px;
  color: #ffe8a3;
}

.buy-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

/* iOSでの自動ズーム防止のため16px以上に設定 */
input[type="number"] {
  width: 110px;
  min-height: 44px;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid #3c7a57;
  background: #11261b;
  color: #fff;
  font-size: 16px;
}

.total-cost {
  font-weight: bold;
  color: #f5c542;
  font-size: 1rem;
}

.primary-btn {
  background: #2d936c;
  color: #fff;
  border: none;
  padding: 12px 20px;
  min-height: 48px;
  border-radius: 6px;
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
}

.primary-btn:disabled {
  background: #3d5247;
  cursor: not-allowed;
}

.secondary-btn {
  background: #495057;
  color: #fff;
  border: none;
  padding: 12px 20px;
  min-height: 48px;
  border-radius: 6px;
  font-size: 0.95rem;
  cursor: pointer;
}

.purchased-area ul {
  list-style: none;
  max-height: 200px;
  overflow-y: auto;
}

.purchased-area li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  background: #11261b;
  padding: 8px 10px;
  border-radius: 6px;
  margin-bottom: 6px;
  font-size: 0.9rem;
}

.cancel-btn {
  background: #c1121f;
  color: #fff;
  border: none;
  padding: 6px 12px;
  min-height: 36px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.start-race-wrap {
  margin-top: 18px;
  text-align: center;
}

.race-start-btn {
  background: linear-gradient(135deg, #f5c542, #e09f3e);
  color: #111;
  font-size: 1.15rem;
  font-weight: bold;
  border: none;
  padding: 14px 36px;
  min-height: 54px;
  border-radius: 8px;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.4);
}

/* レースレーン */
.commentary {
  background: #11261b;
  border-left: 4px solid #f5c542;
  padding: 10px 14px;
  font-weight: bold;
  margin-bottom: 12px;
  color: #ffe8a3;
  font-size: 0.95rem;
}

.track {
  background: #235937;
  border: 2px solid #fff;
  border-radius: 6px;
  padding: 6px 8px;
  margin-bottom: 16px;
  overflow: hidden;
}

.lane {
  position: relative;
  height: 30px;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.25);
  display: flex;
  align-items: center;
}

.lane:last-child {
  border-bottom: none;
}

.horse-runner {
  position: absolute;
  left: 0%;
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.8rem;
  font-weight: bold;
  white-space: nowrap;
  transition: left 0.08s linear;
}

.ranking-list,
.payout-list {
  margin-left: 20px;
  margin-bottom: 12px;
  font-size: 0.92rem;
}

.ranking-list li,
.payout-list li {
  margin-bottom: 4px;
}

.hit-item {
  color: #f5c542;
  font-weight: bold;
}

.round-summary {
  background: #11261b;
  padding: 12px;
  border-radius: 6px;
  font-weight: bold;
  margin-bottom: 14px;
}

.next-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

/* スマホ・小型画面向け調整（640px以下） */
@media (max-width: 640px) {
  body {
    padding: 8px;
  }

  .card {
    padding: 14px;
    margin-bottom: 12px;
  }

  /* ステータスバーを縦積みにして見やすく */
  .status-bar {
    flex-direction: column;
    align-items: flex-start;
  }

  .money-box {
    width: 100%;
    padding-top: 8px;
    border-top: 1px solid #2b5940;
  }

  /* 出馬表を少しコンパクトに */
  table {
    font-size: 0.85rem;
  }

  th, td {
    padding: 8px 6px;
  }

  /* 馬番ボタンを5列×2段の大きなグリッドに変更 */
  .horse-btns {
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
  }

  .horse-pick-btn {
    min-height: 48px;
    font-size: 1.1rem;
  }

  /* 券種・買い方ボタンを均等に配置 */
  .select-btn {
    flex: 1 1 auto;
    text-align: center;
    padding: 10px 10px;
  }

  /* 購入・発走・次へボタンを横幅いっぱいに広げて押しやすく */
  .buy-row {
    flex-direction: column;
    align-items: stretch;
  }

  .buy-row label {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  #add-ticket-btn,
  .race-start-btn,
  .next-actions button {
    width: 100%;
  }

  /* レース中の馬名が右端ではみ出しにくいよう文字サイズ調整 */
  .horse-runner {
    font-size: 0.72rem;
  }
}