:root {
  color-scheme: dark;
  --bg: #0b0f14;
  --panel: #151a22;
  --panel-2: #1d2430;
  --line: #354052;
  --text: #f7fafc;
  --muted: #a7b0bf;
  --accent: #f59e0b;
  --ok: #22c55e;
  --warn: #ef4444;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select,
.upload-button {
  font: inherit;
}

button,
.upload-button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--text);
  font-weight: 700;
}

button:active,
.upload-button:active {
  transform: translateY(1px);
}

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

.upload-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 132px;
  padding: 0 14px;
}

.upload-button input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  min-height: 100dvh;
}

.camera-stage {
  position: relative;
  min-height: 100dvh;
  overflow: hidden;
  background: #05070a;
}

#camera,
#overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#camera {
  object-fit: fill;
}

#overlay {
  touch-action: none;
}

.permission-panel {
  position: absolute;
  inset: 0;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 18px;
  padding: 24px;
  background: rgba(5, 7, 10, 0.76);
}

.permission-panel.hidden {
  display: none;
}

.brand {
  margin: 0;
  font-size: clamp(28px, 8vw, 64px);
  font-weight: 800;
  letter-spacing: 0;
  text-align: center;
}

.control-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px;
  border-left: 1px solid var(--line);
  background: var(--panel);
}

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

.label {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.score-value {
  display: block;
  min-width: 128px;
  font-size: 92px;
  font-weight: 900;
  line-height: 0.95;
  letter-spacing: 0;
}

.state-stack {
  display: grid;
  gap: 8px;
  justify-items: end;
}

.state-pill,
.ball-pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  max-width: 148px;
  padding: 0 10px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ball-pill.visible {
  border-color: #4ade80;
  color: var(--ok);
}

.button-grid,
.calibration-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.calibration-row {
  grid-template-columns: minmax(0, 1fr) 82px;
}

.calibration-row input,
.calibration-row select {
  min-height: 44px;
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--text);
  padding: 0 10px;
}

.status-line {
  margin: auto 0 0;
  min-height: 42px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

@media (max-width: 820px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) auto;
  }

  .camera-stage {
    min-height: 64dvh;
  }

  .control-panel {
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .score-value {
    font-size: 68px;
  }
}
