html[dir="rtl"] .odd,
html[dir="rtl"] .when,
html[dir="rtl"] .stamp { direction: ltr; unicode-bidi: isolate; }
html[dir="rtl"] .team span,
html[dir="rtl"] .league span:first-child { unicode-bidi: plaintext; }
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
  font-size: 12px;
  color: #222;
  background: #ececec;
}
button, input, select { font: inherit; }
button { cursor: pointer; }

.chrome { position: sticky; top: 0; z-index: 5; }
.topbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 18px;
  min-height: 46px;
  padding: 0 14px;
  background: #1c1c1c;
  color: #f3f3f3;
}
.brand {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 1px;
  color: #f0c14a;
}
.sports {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  flex: 1;
  min-width: 280px;
}
.sports button {
  border: 0;
  background: transparent;
  color: #ddd;
  padding: 6px 8px;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.sports button.on {
  color: #f0c14a;
  border-bottom-color: #f0c14a;
}
.top-tools { display: flex; align-items: center; gap: 12px; color: #bbb; }
.fmt select {
  margin-left: 4px;
  background: #2a2a2a;
  color: #fff;
  border: 1px solid #444;
  padding: 3px 6px;
}
.stamp { min-width: 140px; text-align: right; }

.subbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 14px;
  background: #fff;
  border-bottom: 1px solid #ddd;
}
.buckets, .phase { display: flex; gap: 6px; }
.buckets button, .phase button {
  border: 1px solid #d0d0d0;
  background: #fafafa;
  padding: 4px 14px;
  color: #333;
}
.buckets button.on, .phase button.on {
  background: #3e6b4a;
  border-color: #3e6b4a;
  color: #fff;
}
.sub-tools { display: flex; align-items: center; gap: 10px; }
#q {
  width: 180px;
  padding: 4px 8px;
  border: 1px solid #ccc;
}

.layout {
  display: grid;
  grid-template-columns: 1fr 280px;
  height: calc(100vh - 90px);
}
.board { overflow: auto; }
.cols, .match {
  display: grid;
  grid-template-columns: 72px minmax(160px, 1.4fr) 28px 64px 64px 64px 28px 72px 72px 36px 72px 72px;
  align-items: center;
}
.cols {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #e4e4e4;
  border-bottom: 1px solid #ccc;
  color: #555;
  height: 28px;
  padding: 0 8px;
}
.cols span { text-align: center; }
.c-time, .c-team, .c-ml, .c-sp, .c-ou { text-align: left; }

.league {
  position: sticky;
  top: 28px;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  background: #3e6b4a;
  color: #fff;
  padding: 5px 10px;
  font-weight: 700;
}
.league button {
  border: 0;
  background: transparent;
  color: inherit;
  padding: 0;
  font-weight: 700;
}
.match {
  min-height: 52px;
  padding: 4px 8px;
  background: #fff;
  border-bottom: 1px solid #eee;
  align-items: start;
}
.line-stack {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}
.stack-spread { grid-column: 8 / span 2; }
.stack-ou { grid-column: 11 / span 2; }
.line-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-width: 0;
}
.line-row .odd { min-height: 36px; }
.match:nth-child(even) { background: #f7f7f7; }
.match.live { box-shadow: inset 3px 0 0 #e23d3d; }
.when { color: #666; line-height: 1.35; }
.when b { display: block; color: #e23d3d; font-weight: 700; }
.when .score { display: block; color: #222; font-weight: 700; }
.teams { display: flex; flex-direction: column; gap: 3px; }
.team { display: flex; align-items: center; gap: 6px; min-height: 18px; }
.team img { width: 16px; height: 16px; object-fit: contain; }
.group-label { color: #888; text-align: center; }
.gl-sp, .gl-ou { padding-top: 10px; }

.odd {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: 0 3px;
  min-height: 40px;
  border: 1px solid #e1e1e1;
  background: #fff;
  color: #c4161c;
  line-height: 1.15;
}
.odd small { color: #888; font-size: 11px; }
.odd:hover:not(:disabled) { border-color: #3e6b4a; }
.odd.on { background: #ffe58a; border-color: #e2c15a; }
.odd:disabled { color: #bbb; background: transparent; border-color: transparent; cursor: default; }
.odd.up { background: #d9f5df; }
.odd.down { background: #fde0e0; }

.empty, .err {
  padding: 28px 16px;
  color: #777;
}

.slip {
  border-left: 1px solid #ddd;
  background: #fff;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.slip-h {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 0;
  background: #1c1c1c;
  color: #f0c14a;
  font-weight: 700;
  text-align: left;
}
.slip-h em { margin-left: 6px; font-style: normal; color: #aaa; font-weight: 400; }
.slip-body { flex: 1; overflow: auto; padding: 8px 12px; color: #777; }
.slip-item {
  border: 1px solid #eee;
  padding: 8px;
  margin-bottom: 8px;
  color: #333;
}
.slip-item b { display: block; color: #c4161c; }
.slip-item .limit { color: #888; }
.slip-depth {
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px dashed #e5e5e5;
}
.slip-depth-h { color: #888; margin-bottom: 4px; }
.slip-depth-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  width: 100%;
  margin: 2px 0;
  padding: 5px 6px;
  border: 1px solid #eee;
  background: #fff;
  color: #555;
  text-align: left;
}
.slip-depth-row b { display: inline; color: #c4161c; }
.slip-depth-row.on {
  background: #ffe58a;
  border-color: #e2c15a;
}
.slip-item.closed { opacity: 0.7; }
.slip-item.closed b { color: #888; }
.slip-item [data-remove] {
  float: right;
  border: 0;
  background: transparent;
  color: #999;
}
.stake { display: block; padding: 8px 12px; color: #555; }
.stake input { width: 100%; margin-top: 4px; padding: 6px; border: 1px solid #ccc; }
.slip-sum { padding: 0 12px 8px; color: #333; }
.submit {
  margin: 0 12px 12px;
  height: 36px;
  border: 0;
  background: #bfbfbf;
  color: #fff;
}

.slip-mask { display: none; }
.slip-title { flex: 1; min-width: 0; }
.slip-count {
  min-width: 18px;
  height: 18px;
  padding: 0 6px;
  border-radius: 9px;
  background: #c4161c;
  color: #fff;
  font-size: 11px;
  line-height: 18px;
  text-align: center;
}
.slip-toggle { display: none; }

@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  .slip { border-left: 0; border-top: 1px solid #ddd; }
  .board { overflow: auto; }
  .cols, .match {
    grid-template-columns: 64px minmax(120px, 1.3fr) 22px 56px 56px 56px 22px 64px 64px 28px 64px 64px;
  }
}

@media (max-width: 860px) {
  html, body { height: auto; min-height: 100%; }
  body { padding-bottom: calc(56px + env(safe-area-inset-bottom, 0px)); }
  body.slip-open { overflow: hidden; }

  .topbar {
    padding: 8px 12px;
    padding-left: max(12px, env(safe-area-inset-left, 0px));
    padding-right: max(12px, env(safe-area-inset-right, 0px));
    gap: 8px 10px;
  }
  .brand { order: 1; }
  .top-tools { order: 2; margin-left: auto; gap: 8px; }
  .sports {
    order: 3;
    flex: 1 1 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    min-width: 0;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .sports::-webkit-scrollbar { display: none; }
  .sports button { padding: 8px 10px; }
  .stamp { display: none; }
  .fmt select { max-width: 112px; }

  .subbar {
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 10px;
  }
  .buckets, .phase { flex-wrap: wrap; }
  .buckets button, .phase button { padding: 6px 10px; }
  .sub-tools {
    flex: 1 1 100%;
    width: 100%;
  }
  #q, .fmt select, .stake input { font-size: 16px; }
  #q { width: 100%; flex: 1; min-width: 0; }

  .layout {
    display: block;
    height: auto;
    min-height: calc(100dvh - 140px);
  }
  .board { overflow: visible; }
  .cols { display: none; }
  .league {
    position: static;
    padding: 7px 10px;
    font-size: 13px;
  }

  .match {
    display: grid;
    grid-template-columns: 52px minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas:
      "when teams teams teams"
      "gml  omlh  omld  omla"
      "gsp  ssp   ssp   ."
      "gou  sou   sou   .";
    gap: 5px 6px;
    min-height: 0;
    padding: 10px;
  }
  .match > .when { grid-area: when; align-self: start; }
  .match > .teams { grid-area: teams; min-width: 0; }
  .match > .gl-ml { grid-area: gml; }
  .match > .odd-ml-home { grid-area: omlh; }
  .match > .odd-ml-draw { grid-area: omld; }
  .match > .odd-ml-away { grid-area: omla; }
  .match > .gl-sp { grid-area: gsp; }
  .match > .stack-spread { grid-area: ssp; grid-column: auto; }
  .match > .gl-ou { grid-area: gou; }
  .match > .stack-ou { grid-area: sou; grid-column: auto; }

  .team span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .group-label {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    line-height: 1.2;
  }
  .odd {
    margin: 0;
    min-height: 44px;
  }
  .match:has(.odd-ml-home:disabled):has(.odd-ml-draw:disabled):has(.odd-ml-away:disabled) .gl-ml,
  .match:has(.odd-ml-home:disabled):has(.odd-ml-draw:disabled):has(.odd-ml-away:disabled) .odd-ml-home,
  .match:has(.odd-ml-home:disabled):has(.odd-ml-draw:disabled):has(.odd-ml-away:disabled) .odd-ml-draw,
  .match:has(.odd-ml-home:disabled):has(.odd-ml-draw:disabled):has(.odd-ml-away:disabled) .odd-ml-away,
  .match:not(:has(.stack-spread .odd:not(:disabled))) .gl-sp,
  .match:not(:has(.stack-spread .odd:not(:disabled))) .stack-spread,
  .match:not(:has(.stack-ou .odd:not(:disabled))) .gl-ou,
  .match:not(:has(.stack-ou .odd:not(:disabled))) .stack-ou {
    display: none;
  }
  .sub-tools { flex-wrap: wrap; }
  .phase { flex: 0 0 auto; }
  #q { flex: 1 1 100%; }

  .slip-mask {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 29;
    background: rgba(0, 0, 0, 0.4);
  }
  .slip-mask[hidden] { display: none; }

  .slip {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    max-height: calc(48px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid #ddd;
    box-shadow: 0 -6px 20px rgba(0, 0, 0, 0.14);
    transition: max-height 0.22s ease;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .slip.open { max-height: min(78dvh, 640px); }
  .slip:not(.open) .slip-body,
  .slip:not(.open) .stake,
  .slip:not(.open) .slip-sum,
  .slip:not(.open) .submit { display: none; }
  .slip-toggle {
    display: block;
    width: 12px;
    height: 12px;
    border-left: 2px solid #f0c14a;
    border-top: 2px solid #f0c14a;
    transform: rotate(45deg);
    flex: 0 0 12px;
  }
  .slip.open .slip-toggle { transform: rotate(-135deg); margin-top: 4px; }
}

@media (max-width: 400px) {
  .match {
    grid-template-columns: 44px minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr);
    padding: 8px;
    gap: 4px;
  }
  .odd { min-height: 40px; font-size: 12px; }
  .fmt span { display: none; }
}
