:root {
  color-scheme: light;
  --bg: #f6f7f8;
  --panel: #ffffff;
  --panel-strong: #f1f3f4;
  --text: #111827;
  --muted: #687076;
  --line: #d9dee3;
  --accent: #111827;
  --accent-2: #0f766e;
  --shadow: 0 8px 24px rgba(17, 24, 39, 0.08);
}

* {
  box-sizing: border-box;
}

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

a {
  color: inherit;
  text-decoration: none;
}

.topbar {
  align-items: center;
  background: rgba(255, 255, 255, 0.88);
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 24px;
  height: 68px;
  justify-content: space-between;
  padding: 0 clamp(16px, 4vw, 48px);
  position: sticky;
  top: 0;
  z-index: 3;
}

.brand {
  align-items: center;
  display: inline-flex;
  font-weight: 800;
  gap: 10px;
}

.brand-mark {
  align-items: center;
  background: var(--accent);
  border-radius: 8px;
  color: #ffffff;
  display: inline-flex;
  font-size: 16px;
  height: 36px;
  justify-content: center;
  width: 36px;
}

nav a,
.button-link,
button {
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  display: inline-flex;
  font: inherit;
  font-weight: 750;
  min-height: 42px;
  padding: 10px 14px;
}

nav {
  align-items: center;
  display: flex;
  gap: 8px;
}

button,
.button-link {
  align-items: center;
  background: var(--panel-strong);
  cursor: pointer;
  justify-content: center;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}

button[type="submit"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.icon-button {
  align-items: center;
  border-radius: 999px;
  display: inline-flex;
  font-size: 15px;
  font-weight: 900;
  height: 42px;
  justify-content: center;
  min-height: 42px;
  padding: 0;
  width: 42px;
}

#start-button {
  background: var(--accent);
  border: 1px solid var(--accent);
  box-shadow: none;
  color: #ffffff;
  font-size: 18px;
  font-weight: 900;
  min-height: 58px;
  min-width: 150px;
  padding: 16px 22px;
}

#start-button:hover {
  background: #000000;
}

button:hover,
.button-link:hover,
nav a:hover {
  border-color: #b7c0c9;
  transform: translateY(-1px);
}

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

.app-shell,
.leaderboard-shell {
  margin: 0 auto;
  max-width: 1280px;
  padding: clamp(16px, 3vw, 36px);
}

.score-hero {
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: flex;
  justify-content: space-between;
  margin: 0 auto 16px;
  max-width: 1036px;
  padding: 16px;
}

.primary-actions {
  align-items: stretch;
  display: flex;
  gap: 10px;
}

.score-hero > div {
  display: grid;
  gap: 2px;
}

.kicker {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  text-transform: uppercase;
}

.score-hero strong {
  font-size: clamp(52px, 12vw, 96px);
  line-height: 0.9;
}

.stage {
  align-items: start;
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(320px, 760px) 170px;
  justify-content: center;
}

.camera-wrap {
  aspect-ratio: 16 / 9;
  background: #050707;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  max-height: min(62vh, 520px);
  max-width: 760px;
  overflow: hidden;
  position: relative;
  width: 100%;
}

video,
canvas {
  height: 100%;
  inset: 0;
  object-fit: contain;
  position: absolute;
  transform: scaleX(-1);
  width: 100%;
}

video {
  opacity: 0;
}

.camera-message {
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--line);
  border-radius: 8px;
  left: 16px;
  padding: 8px 10px;
  position: absolute;
  top: 16px;
}

.meter-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 12px;
  grid-template-rows: minmax(84px, auto) 12px;
  padding: 14px;
}

.stat {
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 4px;
  padding: 14px;
}

.stat span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.stat strong {
  font-size: 34px;
  line-height: 1;
}

.timer strong {
  color: var(--accent-2);
}

.progress-track {
  background: #e5e7eb;
  border-radius: 999px;
  overflow: hidden;
}

#time-progress {
  background: var(--accent-2);
  height: 100%;
  transition: width 160ms linear;
  width: 100%;
}

.player-form {
  display: grid;
  gap: 8px;
}

label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.field-row {
  display: flex;
  gap: 10px;
}

input {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  flex: 1;
  font: inherit;
  min-height: 46px;
  min-width: 0;
  padding: 10px 12px;
}

.note {
  color: var(--muted);
  min-height: 20px;
  margin: 0;
}

.note.warn {
  color: var(--accent-2);
}

.secondary-action {
  background: transparent;
  color: var(--muted);
}

.secondary-action:hover {
  color: var(--text);
}

.result-dialog,
.privacy-dialog {
  background: transparent;
  border: 0;
  color: var(--text);
  max-width: min(420px, calc(100vw - 28px));
  padding: 0;
  width: 100%;
}

.result-dialog::backdrop,
.privacy-dialog::backdrop {
  background: rgba(17, 24, 39, 0.45);
}

.result-card,
.privacy-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 12px;
  padding: 16px;
}

.privacy-card {
  gap: 14px;
}

.modal-head {
  align-items: center;
  display: flex;
  justify-content: space-between;
}

.modal-head h2,
.privacy-card h3,
.privacy-card p {
  margin: 0;
}

.modal-head h2 {
  font-size: 28px;
  line-height: 1;
}

.privacy-card section {
  display: grid;
  gap: 5px;
}

.privacy-card h3 {
  font-size: 14px;
}

.privacy-card p {
  color: var(--muted);
  line-height: 1.45;
}

.result-score {
  align-items: end;
  display: flex;
  justify-content: space-between;
}

.result-score span {
  color: var(--muted);
  font-weight: 850;
}

.result-score strong {
  color: var(--accent-2);
  font-size: 72px;
  line-height: 0.9;
}

.leaderboard-head {
  align-items: center;
  display: flex;
  justify-content: space-between;
  margin-bottom: 18px;
}

h1 {
  font-size: clamp(32px, 5vw, 54px);
  line-height: 1;
  margin: 0;
}

.table-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: auto;
  position: relative;
}

table {
  border-collapse: collapse;
  min-width: 620px;
  width: 100%;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 16px;
  text-align: left;
}

th {
  color: var(--muted);
  font-size: 13px;
}

tbody tr:first-child td {
  color: var(--accent-2);
  font-weight: 850;
}

.empty {
  color: var(--muted);
  margin: 0;
  padding: 24px 16px;
}

@media (max-width: 900px) {
  .app-shell {
    max-width: 620px;
  }

  .stage,
  .score-hero {
    grid-template-columns: 1fr;
  }

  .score-hero {
    align-items: stretch;
    display: grid;
  }

  .primary-actions {
    justify-content: end;
  }

  .camera-wrap {
    justify-self: center;
    max-height: 44vh;
    max-width: 520px;
  }

  .meter-panel {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(70px, auto) 10px;
    padding: 10px;
  }

  .progress-track {
    grid-column: 1 / -1;
  }

}

@media (max-width: 560px) {
  .topbar {
    height: auto;
    padding: 10px 12px;
  }

  .brand {
    font-size: 14px;
  }

  .brand-mark {
    height: 32px;
    width: 32px;
  }

  nav a,
  .icon-button,
  .button-link,
  button {
    min-height: 40px;
    padding: 9px 11px;
  }

  .app-shell,
  .leaderboard-shell {
    padding: 10px;
  }

  .stage {
    gap: 10px;
  }

  .score-hero {
    margin-bottom: 10px;
    padding: 12px;
  }

  .primary-actions {
    display: grid;
    gap: 8px;
    grid-template-columns: 1fr;
  }

  #start-button {
    min-height: 54px;
    min-width: 138px;
    padding: 14px 16px;
  }

  .camera-wrap {
    aspect-ratio: 3 / 4;
    max-height: 42vh;
    max-width: min(100%, 340px);
  }

  .field-row {
    flex-direction: column;
    gap: 8px;
  }

  .meter-panel {
    gap: 8px;
    grid-template-columns: 1fr;
    grid-template-rows: 64px 8px;
    padding: 8px;
  }

  .stat {
    gap: 2px;
    padding: 10px;
  }

  .stat span {
    font-size: 12px;
  }

  .stat strong {
    font-size: 25px;
  }

  .primary-actions button,
  .primary-actions .button-link {
    width: 100%;
  }

  .camera-message {
    left: 10px;
    max-width: calc(100% - 20px);
    padding: 7px 9px;
    top: 10px;
  }
}
