:root {
  --banker: #d92d20;
  --player: #1d4ed8;
  --green: #16a34a;
  --road-cell: 18px;
  --road-dot: 12px;
  --road-height: 112px;
  --road-marker-border: 1.5px;
  --road-latest-border: 1.5px;
  --point-cell: 30px;
  --point-header: 34px;
  --point-input: 30px;
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  padding: 10px;
  color: #1f2937;
  background: #f5f5f5;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

button, textarea { font: inherit; }
button { touch-action: manipulation; }

.container {
  width: 100%;
  max-width: 1500px;
  margin: 0 auto;
}

.road-map {
  padding: 8px;
  border: 1px solid #ddd;
  border-radius: 8px;
  background: #f9f9f9;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .08);
}

.big-road-container {
  min-height: var(--road-height);
  padding: 1px;
  overflow-x: hidden;
  overflow-y: hidden;
  border: 1px solid #ddd;
  border-radius: 6px;
  background: #fff;
  scrollbar-width: thin;
  scrollbar-color: #c5cbd3 transparent;
  overflow-anchor: none;
  overscroll-behavior-inline: contain;
  scroll-behavior: auto;
}

.big-road-container::-webkit-scrollbar { height: 6px; }
.big-road-container::-webkit-scrollbar-thumb { border-radius: 8px; background: #c5cbd3; }

.big-road-grid {
  display: flex;
  width: max-content;
  min-width: 100%;
  border-top: 1px solid #aaa;
  border-left: 1px solid #aaa;
}

.road-column {
  display: flex;
  flex: 0 0 var(--road-cell);
  flex-direction: column;
  width: var(--road-cell);
}

.road-cell {
  position: relative;
  display: grid;
  width: var(--road-cell);
  height: var(--road-cell);
  flex: 0 0 var(--road-cell);
  place-items: center;
  border-right: 1px solid #aaa;
  border-bottom: 1px solid #aaa;
  background: #f9f9f9;
}

.road-column:nth-child(even) .road-cell:nth-child(odd),
.road-column:nth-child(odd) .road-cell:nth-child(even) { background: #f2f2f2; }

.road-marker,
.point-marker {
  display: block;
  border-style: solid;
  border-radius: 50%;
  background: transparent;
}

.road-marker {
  width: var(--road-dot);
  height: var(--road-dot);
  border-width: var(--road-marker-border);
}

.red { border-color: var(--banker) !important; color: var(--banker) !important; }
.blue { border-color: var(--player) !important; color: var(--player) !important; }

.road-cell.latest {
  z-index: 1;
  box-shadow: inset 0 0 0 var(--road-latest-border) rgba(22, 163, 74, .75);
}

.recommend-panel {
  display: flex;
  min-height: 58px;
  align-items: stretch;
  justify-content: space-between;
  gap: 10px;
  margin-top: 12px;
  padding: 6px 8px;
  border: 1px solid #dfe6ee;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 2px 6px rgba(15, 23, 42, .06);
}

.recommend-chip {
  display: flex;
  width: 48%;
  max-width: 48%;
  align-items: center;
  justify-content: center;
  padding: 13px 14px;
  border: 2px solid transparent;
  border-radius: 8px;
  font-size: 24px;
  font-weight: 800;
  line-height: 1;
}

.recommend-chip-neutral { color: #6b7280; background: #f2f4f7; }
.recommend-chip-red { color: #fff; border-color: #b42318; background: var(--banker); }
.recommend-chip-blue { color: #fff; border-color: #1e40af; background: var(--player); }

.recommend-total {
  display: flex;
  min-width: 76px;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  padding: 0 5px;
  border: 0;
  color: #526579;
  background: transparent;
  cursor: pointer;
}

.recommend-total-label { font-size: 12px; font-weight: 700; line-height: 1.1; }
.recommend-total-amount { font-size: 26px; font-weight: 800; line-height: 1; }

.sub-road-block { margin-top: 12px; }

.two-row-road-container {
  min-height: 0;
  padding: 0;
  overflow: visible;
  border: 0;
  background: transparent;
}

.two-row-road-grid {
  display: block;
  width: 100%;
  min-width: 0;
  border: 0;
}

.sequence-section + .sequence-section { margin-top: 10px; }

.sequence-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 34px;
  padding: 6px 9px;
  border: 1px solid #d8dde3;
  border-bottom: 0;
  border-radius: 6px 6px 0 0;
  color: #374151;
  background: #f5f6f8;
  font-size: 15px;
}

.sequence-heading span { color: #7b8490; font-size: 12px; font-weight: 700; }

.sequence-scroll {
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  border: 1px solid #b9bec4;
  border-radius: 0 0 6px 6px;
  background: #fff;
  overflow-anchor: none;
  overscroll-behavior-inline: contain;
  scroll-behavior: auto;
}

.sequence-grid {
  display: flex;
  width: max-content;
  min-width: 100%;
  border-top: 1px solid #aeb4bb;
  border-left: 1px solid #aeb4bb;
}

.sequence-column {
  display: flex;
  width: var(--point-cell);
  flex: 0 0 var(--point-cell);
  flex-direction: column;
}

.sequence-cell {
  position: relative;
  display: grid;
  width: var(--point-cell);
  height: var(--point-cell);
  flex: 0 0 var(--point-cell);
  place-items: center;
  overflow: hidden;
  border-right: 1px solid #b9bec4;
  border-bottom: 1px solid #b9bec4;
  color: #596270;
  background: #fff;
  font-size: 11px;
  font-weight: 700;
}

.sequence-column:nth-child(even) .sequence-cell:nth-child(odd),
.sequence-column:nth-child(odd) .sequence-cell:nth-child(even) { background: #f4f5f7; }

.point-marker {
  width: 19px;
  height: 19px;
  border-width: 2px;
}

.point-marker.wrong {
  position: relative;
  overflow: hidden;
  font-size: 0;
}

.point-marker.wrong::before,
.point-marker.wrong::after {
  position: absolute;
  top: 50%;
  left: 50%;
  width: calc(100% + 4px);
  height: 2px;
  border-radius: 2px;
  background: currentColor;
  content: "";
  transform: translate(-50%, -50%) rotate(45deg);
}

.point-marker.wrong::after { transform: translate(-50%, -50%) rotate(-45deg); }

.point-marker.correct {
  position: relative;
  font-size: 0;
}

.point-marker.correct::after {
  position: absolute;
  top: 50%;
  left: 50%;
  color: #16a34a;
  content: "✔";
  font-size: 17px;
  font-weight: 1000;
  line-height: 1;
  text-shadow: 0 0 1px #fff, 0 0 1px #fff;
  transform: translate(-50%, -54%);
}

.point-marker.correct.reverse-correct::after { color: #dc2626; }

.sequence-cell.has-stake .point-marker { transform: translate(-2px, -2px); }

.stake-amount {
  position: absolute;
  z-index: 3;
  right: 1px;
  bottom: 0;
  max-width: calc(100% - 2px);
  overflow: hidden;
  color: #374151 !important;
  font-size: 8px;
  font-variant-numeric: tabular-nums;
  font-weight: 900;
  line-height: 8px;
  text-align: right;
  text-overflow: clip;
  text-shadow: 0 0 2px #fff, 0 0 2px #fff;
  white-space: nowrap;
}

.sequence-cell.cycle-ended {
  box-shadow: inset 0 0 0 2px #f59e0b;
}

.sequence-cell.cycle-ended::after {
  position: absolute;
  z-index: 2;
  top: 0;
  right: 0;
  min-width: 9px;
  height: 9px;
  padding: 0 1px;
  border-radius: 0 0 0 3px;
  color: #fff;
  background: #f59e0b;
  content: "完";
  font-size: 7px;
  font-weight: 900;
  line-height: 9px;
  text-align: center;
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 10px;
}

.control-panel {
  padding: 10px;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .08);
}

.result-control-panel, .function-row { display: flex; align-items: stretch; }
.result-control-panel { justify-content: center; }
.button-spacer { flex: 0 0 20px; }

.btn {
  flex: 1;
  border: 0;
  border-radius: 6px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}

.btn:active { transform: translateY(1px); filter: brightness(.96); }
.btn:disabled { cursor: not-allowed; opacity: .45; }

.result-btn {
  flex: 0 1 42%;
  min-height: 56px;
  max-width: 520px;
  border-radius: 10px;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .12);
}

.player-btn { background: var(--player); }
.banker-btn { background: var(--banker); }

.function-row { gap: 10px; }

.function-btn {
  min-height: 42px;
  padding: 10px 16px;
  border: 1px solid #d7dce2;
  color: #303741;
  background: #f5f6f8;
}

.strategy-strip {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin-top: 12px;
}

.strategy-chip {
  display: flex;
  min-width: 0;
  min-height: 25px;
  align-items: center;
  justify-content: center;
  border: 1px solid #d9dde3;
  border-radius: 5px;
  color: #6b7280;
  background: #f2f4f7;
  font-size: 12px;
  font-weight: 800;
}

.strategy-chip.reco-red { color: #fff; border-color: #b42318; background: var(--banker); }
.strategy-chip.reco-blue { color: #fff; border-color: #1e40af; background: var(--player); }
.strategy-chip.waiting-x { color: #9a6700; border-color: #f2cc60; background: #fff8c5; }
.strategy-chip.reverse-mode { box-shadow: inset 0 0 0 2px #facc15; }

.stats {
  padding: 10px 4px 18px;
  color: #333;
  font-size: 22px;
  font-weight: 800;
}

.stat-blue { color: var(--player); }
.stat-red { color: var(--banker); }

.modal {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.modal.visible { display: flex; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, .56);
  backdrop-filter: blur(2px);
}

.modal-card {
  position: relative;
  z-index: 1;
  width: min(460px, 100%);
  max-height: 90vh;
  padding: 24px;
  overflow-y: auto;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 22px 60px rgba(0, 0, 0, .26);
}

.small-modal { width: min(420px, 100%); }
.history-modal-card { width: min(560px, 100%); }
.modal-card h2 { margin: 0 0 12px; color: #1f2937; font-size: 20px; }
.modal-card p { margin: 0 0 18px; color: #5b6471; font-size: 14px; line-height: 1.55; }

.modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 34px;
  height: 34px;
  border: 0;
  color: #7b8490;
  background: transparent;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
}

.settings-tip { padding-right: 20px; }

.setting-field { margin-bottom: 13px; }
.setting-field label { display: block; margin-bottom: 6px; font-size: 14px; font-weight: 700; }
.setting-field textarea {
  width: 100%;
  min-height: 56px;
  resize: vertical;
  padding: 9px 10px;
  border: 1px solid #cfd5dc;
  border-radius: 6px;
  color: #222;
  background: #fff;
  outline: none;
  user-select: text;
}
.setting-field textarea:focus { border-color: #667eea; box-shadow: 0 0 0 3px rgba(102, 126, 234, .14); }
.setting-field textarea:disabled { color: #7d8490; background: #f1f3f5; }
.settings-warning { color: #b42318 !important; }

.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.single-action { justify-content: center; }
.modal-btn {
  min-width: 92px;
  padding: 10px 16px;
  border: 0;
  border-radius: 7px;
  font-weight: 700;
  cursor: pointer;
}
.modal-btn.secondary { color: #374151; background: #eceff3; }
.modal-btn.primary { color: #fff; background: #2563eb; }
.modal-btn.danger { color: #fff; background: var(--banker); }

.history-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 4px 0 14px;
}
.summary-item { padding: 10px 8px; border-radius: 7px; background: #f3f4f6; text-align: center; }
.summary-item small { display: block; color: #6b7280; font-size: 11px; }
.summary-item strong { display: block; margin-top: 3px; font-size: 17px; }
.positive { color: #15803d; }
.negative { color: #b42318; }

.history-list { max-height: 48vh; overflow-y: auto; border-top: 1px solid #e5e7eb; }
.history-empty { padding: 26px 4px; color: #8a929d; text-align: center; }
.history-item {
  display: grid;
  grid-template-columns: 42px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px 4px;
  border-bottom: 1px solid #e5e7eb;
  font-size: 13px;
}
.history-number { color: #8a929d; }
.history-result { font-weight: 700; }
.history-profit { font-weight: 800; }

@media (max-width: 768px) {
  :root {
    --road-cell: 13px;
    --road-dot: 9px;
    --road-height: 82px;
    --road-marker-border: 1px;
    --road-latest-border: 1px;
    --point-cell: 27px;
    --point-header: 28px;
    --point-input: 25px;
  }

  body { padding: 5px; }
  .road-map { padding: 6px; }
  .big-road-container { min-height: var(--road-height); }
  .recommend-panel { min-height: 48px; margin-top: 12px; padding: 5px 6px; }
  .recommend-chip { width: 44%; max-width: 44%; margin-left: 5px; padding: 9px 10px; font-size: 20px; }
  .recommend-total { min-width: 64px; }
  .recommend-total-label { font-size: 11px; }
  .recommend-total-amount { font-size: 22px; }
  .sub-road-block { margin-top: 12px; }
  .two-row-road-container { min-height: 0; }
  .point-marker { width: 17px; height: 17px; }
  .point-marker.correct::after { font-size: 15px; }
  .sequence-cell.has-stake .point-marker { transform: translate(-1px, -2px); }
  .stake-amount { font-size: 7px; line-height: 8px; }
  .sequence-cell.cycle-ended::after { min-width: 8px; height: 8px; font-size: 6px; line-height: 8px; }
  .controls { margin-top: 14px; gap: 10px; }
  .control-panel { padding-right: 10px; padding-left: 10px; }
  .result-control-panel { padding: 10px 14px; }
  .function-control-panel { padding-top: 12px; padding-bottom: 12px; }
  .button-spacer { flex-basis: 24px; }
  .result-btn { min-height: 52px; }
  .function-row { gap: 7px; }
  .function-btn { min-height: 40px; padding: 9px 8px; font-size: 14px; }
  .strategy-strip { gap: 4px; margin-top: 9px; }
  .strategy-chip { min-height: 23px; font-size: 11px; }
  .stats { padding: 10px 3px 14px; font-size: 20px; }
  .modal { padding: 12px; }
  .modal-card { padding: 20px 16px; }
}
