:root {
  color-scheme: dark;
  --bg: #11140f;
  --panel: #1a1f18;
  --ink: #f3f6ee;
  --muted: #b7c0aa;
  --accent: #c6e36a;
  --danger: #ff6b57;
  --line: rgba(255, 255, 255, 0.12);
  --tap: 52px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  height: 100%;
  height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  overflow: hidden;
}

#app {
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding:
    env(safe-area-inset-top)
    env(safe-area-inset-right)
    env(safe-area-inset-bottom)
    env(safe-area-inset-left);
}

.start-screen,
.score-screen {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.start-screen {
  justify-content: center;
  gap: 14px;
  padding: 24px 20px 40px;
}

.score-screen {
  background: #000;
}

.brand {
  font-weight: 750;
  letter-spacing: 0.02em;
  margin-bottom: 8px;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  padding: 6px 14px 4px;
  background: var(--bg);
}

.score-hud {
  font-weight: 700;
  font-size: 1.05rem;
}

.save-state {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.85rem;
}

.lede {
  margin: 0 0 12px;
  font-size: 1.35rem;
  line-height: 1.3;
  font-weight: 650;
}

.big-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 64px;
  border-radius: 18px;
  font-size: 1.2rem;
  font-weight: 750;
  cursor: pointer;
}

.big-btn input {
  display: none;
}

.big-btn.primary,
.toolbar button,
.text-btn {
  border: 0;
}

.big-btn.primary {
  background: var(--accent);
  color: #1a220c;
}

.big-btn.ghost {
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
}

.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  background: #000;
  touch-action: none;
  overflow: hidden;
}

#canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.loupe {
  position: absolute;
  width: 160px;
  height: 160px;
  border-radius: 50%;
  overflow: hidden;
  border: 3px solid #fff;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  pointer-events: none;
  transform: translate(-50%, -100%);
}

.loupe canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.status,
.fail-card {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 16px;
  background: rgba(17, 20, 15, 0.92);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
}

.fail-card {
  top: 50%;
  bottom: auto;
  transform: translateY(-50%);
}

.fail-title {
  margin: 0 0 8px;
  font-size: 1.6rem;
  font-weight: 800;
}

.fail-copy {
  margin: 0 0 16px;
  color: var(--muted);
  line-height: 1.4;
}

.text-btn {
  width: 100%;
  min-height: var(--tap);
  margin-top: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 1rem;
}

.toolbar {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  padding: 10px 12px 12px;
  background: var(--bg);
}

.toolbar button {
  min-height: var(--tap);
  border-radius: 14px;
  background: var(--panel);
  color: var(--ink);
  font-size: 1.05rem;
  font-weight: 700;
}

.toolbar button:disabled {
  opacity: 0.4;
}

.toolbar #manualDoneBtn {
  grid-column: 1 / -1;
  background: var(--accent);
  color: #1a220c;
}

.toolbar.manual-open {
  grid-template-columns: 1fr 1fr;
}

.toolbar.manual-open #undoBtn,
.toolbar.manual-open #saveImageBtn {
  display: none;
}
