:root {
  --sky-top: #8ec5fc;
  --sky-bottom: #e0f2fe;
  --turf: #2f9e44;
  --turf-dark: #2b8a3e;
  --lane-line: rgba(255, 255, 255, 0.55);
  --wood: #b08968;
  --wood-dark: #8a5a44;
  --ink: #1f2937;
  --card: #ffffff;
  --accent: #f59e0b;
  --accent-dark: #d97706;
  --win: #facc15;
  --danger: #ef4444;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: linear-gradient(160deg, #f1f5f9 0%, #e2e8f0 100%);
  min-height: 100vh;
  padding: 18px;
}

.app {
  max-width: 1180px;
  margin: 0 auto;
  background: var(--card);
  border-radius: 20px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

/* 顶栏 */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 26px;
  background: linear-gradient(135deg, #1e3a8a, #2563eb);
  color: #fff;
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo { font-size: 40px; line-height: 1; }
.brand-text h1 { font-size: 24px; letter-spacing: 1px; }
.brand-text p { font-size: 12px; opacity: 0.82; margin-top: 2px; }
.wallet {
  display: flex; align-items: baseline; gap: 6px;
  background: rgba(255, 255, 255, 0.15);
  padding: 10px 18px; border-radius: 999px;
  backdrop-filter: blur(4px);
}
.wallet-label { font-size: 13px; opacity: 0.85; }
.wallet-amount { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }
.wallet-unit { font-size: 18px; }

/* 布局 */
.layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 0;
}
.track-wrap { padding: 20px; }

.track-header {
  display: flex; align-items: center; justify-content: center;
  gap: 16px; min-height: 34px; margin-bottom: 10px;
}
.countdown { font-size: 30px; font-weight: 900; color: var(--accent-dark); min-width: 40px; }
.race-status { font-size: 14px; color: #475569; font-weight: 600; }

/* 赛道 */
.track {
  position: relative;
  border-radius: 14px;
  padding: 8px 0 8px 0;
  background:
    repeating-linear-gradient(90deg, var(--turf) 0 38px, var(--turf-dark) 38px 76px);
  border: 6px solid var(--wood);
  box-shadow: inset 0 0 0 3px var(--wood-dark);
  overflow: hidden;
}
/* 终点线（红白格） */
.track::after {
  content: "";
  position: absolute;
  top: 0; bottom: 0;
  right: 46px;
  width: 14px;
  background: repeating-linear-gradient(
    0deg, #ef4444 0 14px, #ffffff 14px 28px);
  box-shadow: 0 0 0 2px rgba(0,0,0,0.15);
  z-index: 3;
}

.lane {
  position: relative;
  height: 58px;
  border-bottom: 2px dashed var(--lane-line);
  display: flex;
  align-items: center;
}
.lane:last-child { border-bottom: none; }

.lane-name {
  position: absolute;
  left: 8px;
  z-index: 4;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.6);
  background: rgba(0,0,0,0.25);
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.lane-rank {
  position: absolute;
  right: 8px;
  z-index: 4;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  background: rgba(0,0,0,0.35);
  width: 22px; height: 22px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
}

.horse {
  position: absolute;
  left: 8px;
  font-size: 34px;
  z-index: 5;
  transition: none;
  will-change: left;
  transform: translateX(0);
}
.horse.run { animation: bob 0.32s linear infinite; }
@keyframes bob {
  0%   { transform: translateY(0) rotate(-3deg); }
  50%  { transform: translateY(-4px) rotate(3deg); }
  100% { transform: translateY(0) rotate(-3deg); }
}
.horse.win { filter: drop-shadow(0 0 8px var(--win)); }

/* 下注面板 */
.panel {
  background: #f8fafc;
  border-left: 1px solid #e2e8f0;
  padding: 20px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.panel h2 { font-size: 18px; color: #0f172a; }
.bet-target { font-size: 14px; color: #475569; }
.bet-target strong { color: #2563eb; }

.horse-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.horse-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px;
  background: #fff;
  border: 2px solid transparent;
  border-radius: 12px;
  cursor: pointer;
  transition: border-color .15s, transform .1s;
  box-shadow: 0 2px 6px rgba(0,0,0,0.05);
}
.horse-item:hover { transform: translateY(-1px); }
.horse-item.selected { border-color: var(--accent); background: #fffbeb; }
.horse-item .h-emoji { font-size: 24px; }
.horse-item .h-name { font-weight: 700; flex: 1; }
.horse-item .h-odds { font-weight: 800; color: var(--accent-dark); }
.horse-item .h-odds small { font-weight: 500; color: #94a3b8; }

.bet-amount { display: flex; flex-direction: column; gap: 8px; }
.bet-amount label { font-size: 13px; color: #475569; }
.bet-amount input {
  font-size: 18px; font-weight: 700;
  padding: 10px 12px;
  border: 2px solid #cbd5e1;
  border-radius: 10px;
  width: 100%;
}
.bet-amount input:focus { outline: none; border-color: #2563eb; }
.quick-bets { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.quick-bets button {
  padding: 7px 0; border: none; border-radius: 8px;
  background: #e2e8f0; color: #334155; font-weight: 600; cursor: pointer;
  font-size: 13px;
}
.quick-bets button:hover { background: #cbd5e1; }

.btn-start, .btn-reset {
  padding: 14px; border: none; border-radius: 12px;
  font-size: 16px; font-weight: 800; cursor: pointer;
  color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  box-shadow: 0 6px 16px rgba(217,119,6,0.35);
  transition: transform .1s, filter .1s;
}
.btn-start:hover, .btn-reset:hover { filter: brightness(1.05); transform: translateY(-1px); }
.btn-start:disabled { background: #cbd5e1; box-shadow: none; cursor: not-allowed; }
.btn-reset { background: linear-gradient(135deg, #2563eb, #1d4ed8); box-shadow: 0 6px 16px rgba(37,99,235,0.35); }
.hidden { display: none !important; }

.history { margin-top: auto; }
.history h3 { font-size: 15px; margin-bottom: 8px; color: #0f172a; }
#history-list { list-style: none; display: flex; flex-direction: column; gap: 6px; max-height: 180px; overflow-y: auto; }
#history-list li {
  font-size: 13px; padding: 7px 10px; border-radius: 8px; background: #fff;
  display: flex; justify-content: space-between; gap: 8px;
}
.history-empty { color: #94a3b8; justify-content: center !important; }
.hist-win { color: #16a34a; font-weight: 700; }
.hist-lose { color: var(--danger); font-weight: 700; }

.foot {
  padding: 14px 26px;
  background: #f1f5f9;
  border-top: 1px solid #e2e8f0;
}
.foot p { font-size: 12px; color: #64748b; text-align: center; }

@media (max-width: 880px) {
  .layout { grid-template-columns: 1fr; }
  .panel { border-left: none; border-top: 1px solid #e2e8f0; }
}
