.bball-page {
  margin: 0;
  min-width: 300px;
  min-height: 100dvh;
  overflow: hidden;
}

.bball-page button,
.bball-page input {
  font: inherit;
}

.bball-page button {
  cursor: pointer;
}

.bball-main {
  position: fixed;
  inset: 0;
  isolation: isolate;
}

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

.bball-top {
  position: absolute;
  z-index: 2;
  top: max(12px, env(safe-area-inset-top));
  left: max(14px, env(safe-area-inset-left));
  right: max(14px, env(safe-area-inset-right));
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  pointer-events: none;
}

.bball-brand,
.bball-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  pointer-events: auto;
}

.bball-brand h1 {
  margin: 0 0 0 6px;
  font-size: clamp(1.1rem, 2.5vw, 1.6rem);
  font-weight: 800;
  letter-spacing: -0.025em;
  color: var(--text-main);
  text-shadow: 0 2px 10px var(--page-bg-color);
}

.bball-button {
  min-height: 42px;
  padding: 9px 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  border: 1px solid var(--control-line);
  border-radius: 12px;
  text-decoration: none;
  background: var(--surface-strong);
  color: var(--text-main);
  font-size: 0.88rem;
  font-weight: 650;
  box-shadow: 0 3px 14px rgb(0 0 0 / 12%);
}

.bball-button:hover {
  background: var(--surface-hover);
  color: var(--text-main);
}

.bball-button-accent {
  border-color: var(--accent);
  color: var(--accent);
}

.bball-button-wide {
  width: 100%;
  margin-top: 7px;
}

.bball-scoreboard {
  position: static;
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  margin-right: auto;
  pointer-events: none;
}

.bball-stat {
  min-width: 87px;
  padding: 8px 12px;
  text-align: center;
  border: 1px solid var(--line);
  background: var(--surface-strong);
  border-radius: 13px;
  backdrop-filter: blur(8px);
}

.bball-stat strong {
  display: block;
  font-size: clamp(20px, 2.4vw, 27px);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
  color: var(--accent);
}

.bball-stat span {
  display: block;
  margin-top: 4px;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.bball-hint {
  position: absolute;
  z-index: 2;
  bottom: max(15px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 20px);
  width: max-content;
  margin: 0;
  padding: 9px 15px;
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: 40px;
  text-align: center;
  color: var(--text-main);
  font-size: 0.86rem;
  pointer-events: none;
}

.bball-toast {
  position: absolute;
  z-index: 3;
  left: 50%;
  top: 31%;
  transform: translate(-50%, -50%) scale(0.96);
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.18s,
    transform 0.18s;
  font-size: clamp(20px, 3vw, 32px);
  font-weight: 850;
  text-align: center;
  border-radius: 16px;
  padding: 12px 24px;
  color: var(--accent);
  background: var(--surface-strong);
  box-shadow: var(--panel-shadow);
}

.bball-toast.visible {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.bball-settings[hidden] {
  display: none;
}

.bball-settings {
  z-index: 5;
  position: fixed;
  top: 66px;
  right: max(14px, env(safe-area-inset-right));
  bottom: 14px;
  width: min(355px, calc(100vw - 28px));
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px;
  background: var(--surface-strong);
  color: var(--text-main);
  border: 1px solid var(--control-line);
  border-radius: 18px;
  box-shadow: var(--panel-shadow);
  backdrop-filter: blur(14px);
}

.bball-settings-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.bball-settings-head h2 {
  font-size: 1.3rem;
  margin: 0;
}

.bball-settings-head button {
  font-size: 1.4rem;
  min-width: 42px;
}

.bball-settings > p {
  color: var(--text-muted);
  line-height: 1.4;
  font-size: 0.82rem;
}

.bball-switch {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 13px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.88rem;
  cursor: pointer;
}

.bball-switch input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.switch-ui {
  position: relative;
  width: 48px;
  min-width: 48px;
  height: 27px;
  border: 1px solid var(--control-line);
  border-radius: 30px;
  background: var(--surface-hover);
}

.switch-ui::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 19px;
  height: 19px;
  border-radius: 50%;
  background: var(--text-main);
  transition: transform 0.15s;
}

.bball-switch input:checked + .switch-ui {
  background: var(--accent);
}

.bball-switch input:checked + .switch-ui::after {
  transform: translateX(20px);
  background: var(--page-bg-color);
}

.bball-switch input:focus-visible + .switch-ui {
  outline: 3px solid var(--focus-ring);
  outline-offset: 3px;
}

.bball-control {
  display: block;
  margin-top: 14px;
  font-size: 0.86rem;
}

.bball-control > span {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 15px;
}

.bball-control output {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.bball-control input {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
  margin-top: 8px;
  min-height: 25px;
}

.bball-warning {
  min-height: 18px;
  color: var(--accent-secondary) !important;
}

@media (max-width: 750px) {
  .bball-top {
    flex-wrap: wrap;
  }

  .bball-brand {
    width: 100%;
    justify-content: space-between;
  }

  .bball-brand h1 {
    margin-right: auto;
  }

  .bball-actions {
    gap: 5px;
  }

  .bball-button {
    min-height: 36px;
    padding: 6px 9px;
    font-size: 0.78rem;
    border-radius: 9px;
  }

  .bball-scoreboard {
    top: 116px;
  }

  .bball-stat {
    min-width: 65px;
    padding: 5px 7px;
  }

  .bball-stat strong {
    font-size: 19px;
  }

  .bball-stat span {
    font-size: 0.64rem;
  }

  .bball-hint {
    font-size: 0.74rem;
    bottom: 8px;
    padding: 6px 11px;
  }

  .bball-settings {
    top: 95px;
    max-height: calc(100dvh - 105px);
    bottom: auto;
  }

  .bball-brand {
    order: 1;
  }

  .bball-actions {
    order: 2;
  }

  .bball-scoreboard {
    order: 3;
    width: 100%;
    flex-wrap: wrap;
    margin-right: 0;
  }
}

@media (max-height: 410px) {
  .bball-scoreboard {
    top: 63px;
  }

  .bball-brand h1 {
    display: none;
  }

  .bball-settings {
    top: 55px;
    bottom: 7px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .bball-toast,
  .switch-ui::after {
    transition: none;
  }
}
