:root {
  color-scheme: light;
  --bg: #f0f2f5;
  --surface: #ffffff;
  --text: #1f2d3d;
  --muted: #6f7b8f;
  --line: #e3e7ed;
  --banker: #d63b4b;
  --player: #1a5fd0;
  --tie: #2f9e4f;
  --analyze: #f2a51a;
  --danger-soft: #fde8ec;
  --blue-soft: #eef4ff;
  --focus: #6d94e6;
  --shadow: 0 1px 3px rgb(16 24 40 / 6%), 0 1px 2px rgb(16 24 40 / 4%);
  --z-sheet-backdrop: 20;
  --z-sheet: 30;
  --z-dialog: 40;
  --z-toast: 50;
  font-family: "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-size: 13px;
}

button,
input,
select {
  color: inherit;
  font: inherit;
}

button,
select,
input[type="checkbox"],
input[type="radio"] {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid rgb(109 148 230 / 35%);
  outline-offset: 2px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.app-shell {
  min-height: 100dvh;
}

.topbar {
  height: 40px;
  margin: 10px 16px 0;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.shoe-trigger {
  display: none;
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  text-align: left;
}

.shoe-name {
  display: block;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.2;
}

.shoe-trigger strong {
  display: flex;
  align-items: center;
  gap: 3px;
  min-width: 0;
  font-size: 15px;
}

.chevron {
  color: var(--muted);
  font-size: 14px;
}

.desktop-status {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #596579;
}

.desktop-status i {
  width: 1px;
  height: 14px;
  background: var(--line);
}

.link-button,
.text-button {
  padding: 3px 7px;
  color: var(--player);
  background: transparent;
  border: 0;
  font-weight: 600;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.new-shoe-button,
.ai-pill,
.icon-button {
  display: none;
}

.main-content {
  max-width: 1880px;
  margin: 0 auto;
  padding: 12px 16px 28px;
}

.panel {
  margin-bottom: 12px;
  padding: 12px 16px;
  background: var(--surface);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.panel-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.panel h1,
.panel h2 {
  margin: 0;
  letter-spacing: 0;
}

.panel h1 {
  font-size: 16px;
}

.analysis-count {
  margin-left: auto;
  padding: 2px 10px;
  color: #b42134;
  background: var(--danger-soft);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}

.auto-control {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
}

.auto-control input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.switch-track {
  width: 30px;
  height: 17px;
  padding: 2px;
  border-radius: 999px;
  background: #ccd2dc;
  transition: background-color 160ms ease-out;
}

.switch-track::after {
  content: "";
  display: block;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgb(0 0 0 / 18%);
  transition: transform 160ms ease-out;
}

.auto-control input:checked + .switch-track {
  background: var(--tie);
}

.auto-control input:checked + .switch-track::after {
  transform: translateX(13px);
}

.auto-control input:focus-visible + .switch-track {
  outline: 3px solid rgb(109 148 230 / 35%);
  outline-offset: 2px;
}

.analysis-content {
  min-height: 104px;
}

.analysis-empty {
  padding: 38px 12px 16px;
  color: #7d889a;
  text-align: center;
  font-size: 14px;
}

.analysis-empty small {
  display: block;
  margin-top: 6px;
  font-size: 11px;
}

.analysis-result {
  display: grid;
  grid-template-columns: 140px minmax(0, 1fr);
  gap: 14px;
  max-width: 720px;
  margin: 16px auto 4px;
}

.analysis-stale {
  grid-column: 1 / -1;
  padding: 5px 9px;
  color: #9a4d06;
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: 8px;
  font-size: 12px;
}

.recommendation-badge {
  min-height: 94px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px;
  color: #fff;
  border-radius: 8px;
  background: #68758a;
}

.recommendation-badge.B {
  background: var(--banker);
}

.recommendation-badge.P {
  background: var(--player);
}

.recommendation-badge.B,
.recommendation-badge.P,
.recommendation-badge.WAIT {
  color: #fff;
}

.recommendation-word {
  font-size: 30px;
  font-weight: 800;
  line-height: 1;
}

.recommendation-confidence {
  margin-top: 6px;
  font-size: 11px;
  opacity: 0.95;
}

.probability-bars {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 7px;
}

.probability-row {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) 50px;
  align-items: center;
  gap: 7px;
  font-size: 12px;
}

.probability-row > b,
.road-stats b {
  font-weight: 700;
}

.B {
  color: var(--banker);
}

.P {
  color: var(--player);
}

.T {
  color: var(--tie);
}

.bar-track {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: #edf0f4;
}

.bar-track i {
  display: block;
  height: 100%;
  border-radius: 999px;
}

.bar-track i.B {
  background: var(--banker);
}

.bar-track i.P {
  background: var(--player);
}

.bar-track i.T {
  background: var(--tie);
}

.analysis-meta {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}

.analysis-error {
  max-width: 720px;
  margin: 18px auto 0;
  padding: 10px 12px;
  color: #9f2030;
  background: #fff1f3;
  border: 1px solid #fecdd3;
  border-radius: 8px;
  line-height: 1.6;
}

.desktop-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 32px;
}

.desktop-toolbar label {
  font-weight: 700;
}

.desktop-toolbar select,
.desktop-toolbar button,
.sheet-controls select,
.sheet-controls button {
  height: 32px;
  padding: 0 12px;
  border: 1px solid #d8dde6;
  border-radius: 4px;
  background: #fff;
}

.desktop-toolbar select {
  min-width: 220px;
}

.keyboard-hint {
  margin-left: auto;
  color: var(--muted);
  font-size: 11px;
}

kbd {
  padding: 1px 4px;
  border: 1px solid #d9dee6;
  border-radius: 4px;
  background: #f7f8fa;
  font-family: inherit;
}

.desktop-entry-buttons {
  display: flex;
  gap: 10px;
  margin: 10px 0 8px;
}

.result-button,
.analyze-button,
.undo-button {
  border: 0;
  color: #fff;
  font-weight: 800;
  transition: filter 140ms ease-out, transform 80ms ease-out;
  box-shadow: 0 2px 5px rgb(0 0 0 / 12%);
}

.result-button:hover,
.analyze-button:hover {
  filter: brightness(1.05);
}

.result-button:active,
.analyze-button:active,
.undo-button:active {
  transform: scale(0.98);
}

.desktop-entry-buttons .result-button {
  width: 84px;
  height: 54px;
  border-radius: 8px;
  font-size: 20px;
}

.result-button.banker {
  background: var(--banker);
}

.result-button.player {
  background: var(--player);
}

.result-button.tie {
  background: var(--tie);
}

.desktop-entry-buttons .analyze-button {
  width: 136px;
  height: 54px;
  margin-left: 12px;
  border-radius: 8px;
  background: var(--analyze);
  font-size: 17px;
}

.roads-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.roads-title-row h2 {
  font-size: 14px;
}

.road-stats {
  color: var(--muted);
  font-size: 12px;
}

#streakText::before {
  content: " · ";
}

#streakText:empty::before {
  content: "";
}

.road-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 8px 0 4px;
  color: #4b5563;
  font-size: 12px;
  font-weight: 700;
}

.ask-group {
  display: inline-flex;
  gap: 12px;
  font-weight: 500;
}

.ask-b {
  color: var(--banker);
}

.ask-p {
  color: var(--player);
}

.ask-symbols {
  display: inline-flex;
  gap: 4px;
  margin-left: 3px;
  vertical-align: -2px;
}

.ask-symbol {
  display: inline-block;
  width: 12px;
  height: 12px;
  color: #c5cbd5;
}

.ask-symbol.ring {
  border: 2px solid currentColor;
  border-radius: 50%;
}

.ask-symbol.dot {
  border-radius: 50%;
  background: currentColor;
}

.ask-symbol.slash {
  position: relative;
}

.ask-symbol.slash::after {
  content: "";
  position: absolute;
  top: 5px;
  left: 0;
  width: 13px;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
  transform: rotate(-45deg);
}

.road-frame,
.derived-panel {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafbfc;
}

.bead-scroller,
.svg-scroller {
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
}

.bead-scroller {
  padding: 6px;
}

.bead-grid {
  width: max-content;
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(6, 30px);
  grid-auto-columns: 30px;
  gap: 6px;
}

.bead-cell {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  border: 1px solid #e3e5ea;
  border-radius: 50%;
  background: #f1f2f5;
  font-size: 12px;
  font-weight: 800;
  user-select: none;
}

.bead-cell.B {
  border-color: var(--banker);
  background: var(--banker);
}

.bead-cell.P {
  border-color: var(--player);
  background: var(--player);
}

.bead-cell.T {
  border-color: var(--tie);
  background: var(--tie);
}

.bead-cell.next {
  border: 2px solid #9db8f0;
  box-shadow: 0 0 0 3px rgb(26 95 208 / 12%);
}

.road-svg {
  display: block;
}

.desktop-road-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.22fr) minmax(340px, 0.78fr);
  gap: 12px;
  align-items: start;
}

.road-left {
  min-width: 0;
}

.derived-desktop {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.derived-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 10px;
  color: #4b5563;
  border-bottom: 1px solid var(--line);
  background: #f7f8fa;
  font-size: 12px;
}

.derived-head span {
  color: var(--muted);
}

.derived-mobile {
  display: none;
}

.disclaimer {
  max-width: none;
  color: #4b5563;
  font-size: 12px;
  line-height: 1.7;
}

.disclaimer h2 {
  margin-bottom: 2px;
  font-size: 13px;
}

.disclaimer p {
  max-width: 72ch;
  margin: 0;
}

.mobile-footer {
  display: none;
}

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: var(--z-sheet-backdrop);
  background: rgb(17 24 39 / 45%);
}

.bottom-sheet {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: var(--z-sheet);
  max-height: 72dvh;
  padding: 8px 14px calc(14px + env(safe-area-inset-bottom));
  overflow-y: auto;
  background: #fff;
  border-radius: 12px 12px 0 0;
  transform: translateY(105%);
  transition: transform 180ms cubic-bezier(0.16, 1, 0.3, 1);
}

.bottom-sheet.open {
  transform: translateY(0);
}

.sheet-handle {
  width: 38px;
  height: 4px;
  margin: 0 auto 8px;
  border-radius: 99px;
  background: #d8dde5;
}

.sheet-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.sheet-title-row h2 {
  margin: 0;
  font-size: 16px;
}

.sheet-title-row p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.close-button {
  width: 32px;
  height: 32px;
  padding: 0;
  color: #677387;
  border: 0;
  border-radius: 50%;
  background: transparent;
  font-size: 22px;
  line-height: 1;
}

.close-button:hover {
  background: #f1f3f6;
}

.sheet-controls {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.sheet-primary {
  width: 100%;
  height: 38px;
  margin: 8px 0;
  color: var(--player);
  border: 1px solid #bcd0f5;
  border-radius: 8px;
  background: var(--blue-soft);
  font-weight: 700;
}

.shoe-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.shoe-list button {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 9px 12px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.shoe-list button.active {
  border-color: #8fb0ed;
  background: var(--blue-soft);
}

.shoe-list small {
  color: var(--muted);
}

.menu-sheet {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.menu-item {
  padding: 12px 14px;
  text-align: left;
  border: 0;
  border-radius: 8px;
  background: #f7f8fa;
  font-size: 14px;
}

.menu-item.danger {
  color: var(--banker);
}

.menu-foot {
  margin: 0;
  padding-top: 4px;
  color: #8f99aa;
  text-align: center;
  font-size: 11px;
}

.app-dialog {
  width: min(640px, calc(100vw - 32px));
  max-height: min(84dvh, 760px);
  padding: 0;
  color: var(--text);
  border: 0;
  border-radius: 8px;
  box-shadow: 0 12px 32px rgb(16 24 40 / 18%);
  overflow: auto;
}

.app-dialog::backdrop {
  background: rgb(17 24 39 / 52%);
}

.app-dialog form {
  padding: 18px 20px;
}

.app-dialog header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.app-dialog h2 {
  margin: 0;
  font-size: 18px;
}

.app-dialog form > label {
  display: grid;
  gap: 6px;
  margin: 12px 0;
  color: #4b5563;
  font-weight: 700;
}

.app-dialog input[type="url"],
.app-dialog input[type="text"],
.app-dialog input[type="password"],
.card-count-grid input {
  width: 100%;
  height: 38px;
  padding: 0 10px;
  color: var(--text);
  border: 1px solid #ccd3dd;
  border-radius: 6px;
  background: #fff;
}

.app-dialog input::placeholder {
  color: #737e90;
}

.app-dialog .remember-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
}

.dialog-note,
.security-note {
  color: #5e6a7d;
  line-height: 1.6;
}

.prompt-info {
  display: grid;
  gap: 4px;
  margin: 10px 0 14px;
  padding: 9px 10px;
  color: #4f5b6e;
  border: 1px solid #dbe4f4;
  border-radius: 6px;
  background: #f5f8fe;
  font-size: 12px;
  line-height: 1.6;
}

.prompt-info strong {
  color: #2e4f91;
}

.security-note {
  padding: 8px 10px;
  color: #82500b;
  border-radius: 6px;
  background: #fff7e8;
  font-size: 12px;
}

.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

.split-actions {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
}

.primary-button,
.secondary-button {
  min-width: 72px;
  height: 36px;
  padding: 0 14px;
  border-radius: 6px;
  font-weight: 700;
}

.primary-button {
  color: #fff;
  border: 1px solid var(--player);
  background: var(--player);
}

.secondary-button {
  color: #3f4a5c;
  border: 1px solid #cfd5df;
  background: #fff;
}

.app-dialog fieldset {
  margin: 14px 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.app-dialog legend {
  padding: 0 5px;
  font-weight: 700;
}

.deck-fieldset {
  display: flex;
  align-items: center;
  gap: 16px;
}

.deck-fieldset label {
  display: flex;
  align-items: center;
  gap: 5px;
}

.deck-fieldset span {
  color: var(--muted);
}

.card-count-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px 12px;
}

.card-count-grid label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
}

.card-count-grid input {
  height: 34px;
}

.baseline {
  color: #4b5563;
}

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  z-index: var(--z-toast);
  max-width: calc(100vw - 32px);
  padding: 9px 14px;
  color: #fff;
  border-radius: 6px;
  background: #263242;
  box-shadow: 0 4px 12px rgb(0 0 0 / 18%);
  transform: translateX(-50%);
}

.toast.error {
  background: #a82536;
}

@media (max-width: 1100px) {
  .keyboard-hint {
    display: none;
  }
}

@media (max-width: 900px) {
  body {
    overflow: hidden;
  }

  .app-shell {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    height: 100dvh;
    overflow: hidden;
  }

  .topbar {
    flex: 0 0 auto;
    height: 52px;
    margin: 0;
    padding: 7px 10px 7px 12px;
    border-bottom: 1px solid var(--line);
    border-radius: 0;
    box-shadow: none;
  }

  .shoe-trigger,
  .new-shoe-button,
  .ai-pill,
  .icon-button {
    display: block;
  }

  .desktop-status {
    display: none;
  }

  .new-shoe-button {
    padding: 6px 11px;
    color: var(--player);
    white-space: nowrap;
    border: 1px solid #bcd0f5;
    border-radius: 999px;
    background: var(--blue-soft);
    font-size: 13px;
    font-weight: 700;
  }

  .ai-pill {
    padding: 5px 9px;
    color: #8a5b00;
    border: 1px solid #f6d78e;
    border-radius: 999px;
    background: #fff8e6;
    font-size: 11px;
  }

  .ai-pill span {
    margin-right: 3px;
    font-weight: 800;
  }

  .icon-button {
    width: 34px;
    height: 34px;
    padding: 0;
    color: #4b5563;
    border: 1px solid var(--line);
    border-radius: 50%;
    background: #fff;
    font-size: 12px;
    font-weight: 800;
  }

  .main-content {
    flex: 1 1 auto;
    min-height: 0;
    padding: 8px 8px 12px;
    overflow: hidden auto;
    overscroll-behavior: contain;
  }

  .panel {
    margin-bottom: 8px;
    padding: 10px 12px;
    border-radius: 12px;
  }

  .panel h1 {
    font-size: 14px;
  }

  .analysis-count {
    margin-left: 0;
    padding: 1px 8px;
  }

  .analysis-content {
    min-height: 56px;
  }

  .analysis-empty {
    padding: 12px 0 5px;
  }

  .analysis-result {
    grid-template-columns: 104px minmax(0, 1fr);
    gap: 10px;
    margin: 8px 0 0;
  }

  .recommendation-badge {
    min-height: 88px;
  }

  .recommendation-word {
    font-size: 32px;
  }

  .desktop-toolbar,
  .desktop-entry-buttons {
    display: none;
  }

  .desktop-road-layout {
    display: block;
  }

  .roads-title-row h2 {
    font-size: 14px;
  }

  .bead-scroller {
    padding: 5px;
  }

  .bead-grid {
    grid-template-rows: repeat(6, 24px);
    grid-auto-columns: 24px;
    gap: 3px;
  }

  .bead-cell {
    width: 24px;
    height: 24px;
    font-size: 10px;
  }

  .big-road-label {
    margin-top: 8px;
  }

  .ask-group {
    gap: 8px;
    font-size: 11px;
  }

  .derived-desktop {
    display: none;
  }

  .derived-mobile {
    display: block;
    margin-top: 8px;
  }

  .derived-mobile-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
    color: var(--muted);
    font-size: 12px;
  }

  .segmented {
    display: inline-flex;
    gap: 2px;
    padding: 2px;
    border-radius: 8px;
    background: #eef1f5;
  }

  .segmented button {
    padding: 3px 10px;
    color: #4b5563;
    border: 0;
    border-radius: 6px;
    background: transparent;
    font-size: 12px;
  }

  .segmented button.active {
    color: var(--text);
    background: #fff;
    box-shadow: 0 1px 2px rgb(0 0 0 / 8%);
    font-weight: 700;
  }

  .disclaimer {
    color: #606b7c;
    font-size: 11px;
    line-height: 1.6;
  }

  .disclaimer h2 {
    display: none;
  }

  .mobile-footer {
    display: flex;
    flex: 0 0 auto;
    flex-direction: column;
    gap: 6px;
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    background: #fff;
  }

  .footer-results,
  .footer-actions {
    display: grid;
    gap: 8px;
  }

  .footer-results {
    grid-template-columns: repeat(3, 1fr);
  }

  .footer-actions {
    grid-template-columns: 1fr 2.2fr;
  }

  .footer-results .result-button {
    height: 54px;
    border-radius: 12px;
    font-size: 22px;
  }

  .footer-actions .undo-button,
  .footer-actions .analyze-button {
    height: 44px;
    border-radius: 10px;
    font-size: 15px;
  }

  .undo-button {
    color: #374151;
    background: #eef1f5;
    box-shadow: none;
  }

  .footer-actions .analyze-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: var(--analyze);
  }

  .analyze-button small {
    font-size: 11px;
    font-weight: 500;
    opacity: 0.92;
  }

  .toast {
    bottom: calc(122px + env(safe-area-inset-bottom));
  }

  .card-count-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .deck-fieldset {
    flex-wrap: wrap;
  }

  .split-actions {
    grid-template-columns: auto 1fr auto auto;
  }
}

@media (max-width: 420px) {
  .new-shoe-button {
    padding-inline: 9px;
  }

  .ai-pill b {
    display: none;
  }

  .analysis-result {
    grid-template-columns: 92px minmax(0, 1fr);
  }

  .probability-row {
    grid-template-columns: 20px minmax(0, 1fr) 46px;
    gap: 5px;
  }

  .ask-group {
    gap: 5px;
  }

  .ask-symbols {
    gap: 2px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
