:root {
  --bg: #f3efe5;
  --panel: #fff;
  --line: #d8d0bc;
  --ink: #182019;
  --muted: #5c655f;
  --accent: #2d8f6d;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

body {
  min-height: 100dvh;
  padding: 12px;
}

.splash-screen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: grid;
  place-items: center;
  background: rgba(9, 22, 30, 0.72);
  backdrop-filter: blur(4px);
}

.splash-screen.hidden {
  display: none;
}

.splash-card {
  width: min(92vw, 420px);
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 14px;
  background: rgba(20, 42, 54, 0.92);
  color: #eef9ff;
  padding: 16px;
}

.splash-card h2 {
  margin: 0 0 8px;
  font-size: 1.1rem;
}

.splash-card p {
  margin: 0 0 10px;
  font-size: 0.92rem;
  color: #d8edf8;
}

.splash-card progress {
  width: 100%;
  height: 10px;
}

.layout {
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  gap: 12px;
}

.game-card,
.debug-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  min-width: 0;
}

.game-header h1 {
  margin: 0;
  font-size: 1.1rem;
}

.game-header p {
  margin: 6px 0 10px;
  color: var(--muted);
  font-size: 0.92rem;
}

.game-nav {
  margin-bottom: 8px;
}

.back-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  color: var(--ink);
  text-decoration: none;
  padding: 8px 12px;
  font-size: 14px;
}

#gameCanvas {
  width: min(100%, 800px);
  height: auto;
  aspect-ratio: 4 / 3;
  border-radius: 10px;
  border: 1px solid #32554f;
  background: #8ad0f8;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.game-topbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 8px;
}

.game-hud {
  display: flex;
  gap: 10px;
  margin-top: 10px;
  align-items: center;
}

button,
select {
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  padding: 8px 10px;
}

.debug-card h2 {
  margin: 2px 0 8px;
  font-size: 1rem;
}

.viewer-stage {
  position: relative;
  aspect-ratio: 16 / 10;
  max-height: 220px;
  background: #0d1610;
  border-radius: 10px;
  border: 1px solid #2e4639;
  overflow: hidden;
}

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

#overlay {
  pointer-events: none;
}

.status-badge {
  position: absolute;
  left: 8px;
  top: 8px;
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 12px;
  color: #fff;
  background: rgba(0, 0, 0, 0.52);
}

.controls {
  margin-top: 8px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.controls label {
  display: grid;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.stats-grid {
  display: grid;
  margin-top: 10px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.stat {
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px;
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.stat strong {
  display: block;
  margin-top: 4px;
}

.calibration-box {
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px;
}

.calibration-box h3 {
  margin: 0 0 8px;
  font-size: 0.9rem;
}

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

.calib-values {
  margin-top: 8px;
  display: flex;
  gap: 16px;
  font-size: 13px;
}

details {
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  overflow: hidden;
}

summary {
  cursor: pointer;
  padding: 8px 10px;
  background: #faf7ef;
  font-size: 13px;
}

.details-actions {
  display: flex;
  justify-content: flex-end;
  padding: 8px 10px 0;
}

.copy-btn {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-size: 12px;
  padding: 4px 8px;
}

pre {
  margin: 0;
  max-height: 220px;
  max-width: 100%;
  overflow-y: auto;
  overflow-x: auto;
  white-space: pre;
  word-break: normal;
  padding: 8px;
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .controls,
  .calibration-controls {
    grid-template-columns: 1fr;
  }
}
