:root {
  color-scheme: dark;
  --bg: #0d1117;
  --panel: #151b23;
  --card: #1b2330;
  --border: #344054;
  --text: #f8fafc;
  --muted: #9aa4b2;
  --accent: #7c6cff;
  --red: #e53935;
  --yellow: #f6c700;
  --green: #2eaf59;
  --blue: #2878d0;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
canvas {
  -webkit-tap-highlight-color: transparent;
}

.app {
  width: min(760px, 100%);
  margin: 0 auto;
  padding: 18px;
}

.title {
  margin: 0 0 14px;
  font-size: 28px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}

.stat,
.card {
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 14px;
}

.stat { padding: 11px 13px; }

.stat-label,
.muted,
#msg,
.help {
  color: var(--muted);
}

.stat-label,
.muted,
#msg {
  font-size: 14px;
}

.stat-value {
  margin-top: 3px;
  font-size: 23px;
  font-weight: 800;
}

.card {
  padding: 13px;
  margin-bottom: 10px;
}

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

.badge {
  display: inline-flex;
  min-width: 30px;
  height: 30px;
  padding: 0 10px;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  font-weight: 800;
}

.state-badge { background: var(--accent); }

.meter {
  height: 11px;
  overflow: hidden;
  border-radius: 999px;
  background: #283141;
  margin-top: 9px;
}

.meter-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

#msg { margin: 9px 0 0; }

.canvas-wrap {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--panel);
  margin-bottom: 10px;
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  cursor: crosshair;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-user-drag: none;
}

canvas.charging { cursor: grabbing; }

.power-area {
  flex: 1;
  min-width: 220px;
}

.power-label {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.button {
  border: 1px solid var(--border);
  border-radius: 11px;
  background: transparent;
  color: var(--text);
  padding: 10px 16px;
  cursor: pointer;
  font-weight: 700;
}

.button:hover {
  background: rgba(255, 255, 255, 0.06);
}

.queue,
.pairs {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
  margin-top: 13px;
}

.queue-label { margin-left: 7px; }

.next-balls {
  display: flex;
  gap: 6px;
}

.special-ball-badge {
  cursor: help;
  outline-offset: 3px;
  transition: transform 120ms ease, filter 120ms ease;
}

.special-ball-badge:hover,
.special-ball-badge:focus-visible {
  transform: translateY(-2px);
  filter: brightness(1.15);
}

.special-ball-info {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  margin-top: 11px;
  padding: 11px 12px;
  border: 1px solid rgba(124, 108, 255, 0.65);
  border-radius: 12px;
  background: rgba(124, 108, 255, 0.1);
}

.special-ball-info[hidden] {
  display: none;
}

.special-info-icon {
  flex: 0 0 auto;
  font-size: 25px;
  line-height: 1;
}

.special-info-text {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.special-info-text strong { font-size: 14px; }

.special-info-text span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.pair-red { background: var(--red); }

.pair-yellow {
  background: var(--yellow);
  color: #181818;
}

.pair-green { background: var(--green); }
.pair-blue { background: var(--blue); }

.help {
  margin: 13px 0 0;
  font-size: 14px;
  line-height: 1.55;
}

.section-title {
  margin: 0 0 3px;
  font-size: 19px;
}

.ranking-list {
  list-style: none;
  margin: 13px 0 0;
  padding: 0;
}

.ranking-item {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px 3px;
  border-bottom: 1px solid var(--border);
}

.ranking-item:last-child { border-bottom: 0; }

.ranking-rank,
.ranking-score {
  font-weight: 800;
}

.ranking-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ranking-extra,
.ranking-empty {
  color: var(--muted);
  font-size: 13px;
}

.ranking-result {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
  white-space: nowrap;
}

.ranking-combo {
  color: var(--yellow);
  font-size: 12px;
  font-weight: 700;
}

.modal[hidden] { display: none; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 18px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
}

.modal-dialog {
  position: relative;
  width: min(400px, 100%);
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--card);
}

.modal-dialog h2 { margin: 0; }

.modal-score {
  margin: 10px 0 18px;
  color: var(--muted);
}

.input-label {
  display: block;
  margin-bottom: 7px;
  font-weight: 700;
}

.text-input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--panel);
  color: var(--text);
  padding: 11px 12px;
  font: inherit;
}

.text-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.modal-message {
  min-height: 20px;
  margin: 9px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.modal-message.error { color: #ff7777; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.primary-button {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.button:disabled {
  cursor: wait;
  opacity: 0.55;
}

html,
body,
.app,
.canvas-wrap,
canvas,
button {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

html,
body { overscroll-behavior: none; }

canvas,
button { -webkit-user-drag: none; }

input,
textarea,
.text-input {
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
}

@media (max-width: 560px) {
  .app { padding: 10px; }

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

  .title { font-size: 23px; }

  .special-ball-info {
    align-items: center;
  }
}
