:root {
  color-scheme: light;
  --bg: #f2f2f3;
  --text: #1d1f20;
  --accent: #5980a6;
  --accent-100: #eef6ff;
  --accent-300: #b5d9fd;
  --accent-600: #597ea3;
  --accent-700: #416180;
  --accent-900: #1d2d3d;
  --neutral-300: #d4d4d7;
  --neutral-600: #7a7a7d;
  --neutral-900: #2b2b2d;
  --paper: #f2f2f3;
  --overlay-panel: rgba(29, 31, 32, 0.84);
  --chip: rgba(29, 31, 32, 0.72);
  --ring-marker: #cfe0ef;
  --radius: 0;
  --tap: 44px;
  --font-ui: "Barlow Condensed", "Arial Narrow", sans-serif;
  --font-body: "Barlow", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  height: 100%;
  height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  overflow: hidden;
}

button,
label,
a {
  border-radius: var(--radius);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

#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 {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 22px;
  gap: 0;
}

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

.feedback-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--tap);
  height: var(--tap);
  margin: -10px 0 -10px -10px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

.feedback-btn.on-dark {
  margin: 0;
  width: 32px;
  height: 32px;
  color: var(--paper);
  background: var(--chip);
}

.feedback-overlay {
  position: fixed;
  inset: 0;
  z-index: 9500;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding:
    env(safe-area-inset-top)
    env(safe-area-inset-right)
    env(safe-area-inset-bottom)
    env(safe-area-inset-left);
  background: rgba(17, 20, 15, 0.45);
}

.feedback-card {
  width: min(100%, 420px);
  margin: 12px;
  padding: 18px 16px 16px;
  background: var(--paper);
  color: var(--text);
  max-height: min(92dvh, 640px);
  overflow: auto;
}

.feedback-title {
  margin: 0 0 6px;
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 28px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.feedback-copy {
  margin: 0 0 16px;
  font-size: 14px;
  line-height: 1.4;
  color: var(--neutral-600);
}

.feedback-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--neutral-600);
}

.feedback-field input,
.feedback-field textarea {
  width: 100%;
  border: 1px solid var(--neutral-300);
  background: #fff;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  letter-spacing: 0;
  text-transform: none;
  font-weight: 400;
  padding: 10px 12px;
}

.feedback-field textarea {
  min-height: 120px;
  resize: vertical;
}

.feedback-close {
  float: right;
  margin: -6px -6px 8px 12px;
  border: 0;
  background: transparent;
  color: var(--neutral-600);
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  min-height: 36px;
  cursor: pointer;
}

.feedback-status {
  margin: 0 0 12px;
  font-size: 14px;
  line-height: 1.35;
}

.feedback-status.is-error {
  color: #8a2f2f;
}

.feedback-hp {
  position: absolute;
  left: -9999px;
  height: 0;
  overflow: hidden;
}

.feedback-card .big-btn {
  margin-top: 4px;
}

.feedback-done {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 28px 8px 18px;
}

.feedback-done-icon {
  display: flex;
  color: var(--accent);
  margin-bottom: 14px;
}

.feedback-done .feedback-copy {
  margin-bottom: 18px;
  max-width: 22em;
}

.feedback-done .big-btn {
  width: 100%;
}

.feedback-card:has(#feedbackDone:not([hidden])) .feedback-close {
  display: none;
}

.start-alpha {
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--neutral-600);
}

.wordmark {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 18px 0 22px;
}

.wordmark-mark {
  position: relative;
  flex: 0 0 26px;
  width: 26px;
  height: 26px;
  border: 1.5px solid var(--accent);
  border-radius: 50%;
}

.wordmark-mark::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 9px;
  height: 9px;
  margin: -4.5px 0 0 -4.5px;
  border-radius: 50%;
  background: var(--accent);
}

.wordmark-title {
  margin: 0;
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 38px;
  line-height: 0.95;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text);
}

.steps {
  list-style: none;
  margin: 0 0 22px;
  padding: 0;
}

.steps li {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid var(--neutral-300);
}

.steps li:first-child {
  border-top: 1px solid var(--neutral-300);
}

.step-num {
  flex: 0 0 22px;
  width: 22px;
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.1em;
  color: var(--accent-700);
}

.step-label {
  font-family: var(--font-body);
  font-size: 19px;
  color: var(--text);
}

.big-btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 64px;
  border-radius: var(--radius);
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 19px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
}

.big-btn input {
  display: none;
}

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

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

.big-btn.primary:hover {
  background: var(--accent-600);
}

.big-btn.primary:active {
  background: var(--accent-700);
}

.big-btn.ghost {
  margin-top: 10px;
  min-height: 52px;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--neutral-300);
  font-size: 16px;
  letter-spacing: 0.06em;
}

.alpha-note {
  margin-top: 18px;
  padding: 14px 15px;
  background: var(--accent-100);
  border: 1px solid var(--accent-300);
}

.alpha-tag {
  display: inline-block;
  margin-bottom: 8px;
  padding: 3px 6px;
  border: 1px solid var(--accent-700);
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent-700);
}

.alpha-note p {
  margin: 0;
  font-family: var(--font-body);
  font-size: 13px;
  line-height: 1.45;
  color: var(--accent-900);
}

.sponsor {
  display: block;
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--neutral-300);
  color: inherit;
  text-decoration: none;
}

.sponsor-kicker {
  display: block;
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--neutral-600);
}

.sponsor-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
}

.sponsor-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.sponsor-brand {
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 19px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent-700);
}

.sponsor-payoff {
  font-family: var(--font-body);
  font-style: italic;
  font-size: 13px;
  color: var(--text);
}

.sponsor-go {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  border: 1px solid var(--neutral-300);
  color: var(--text);
}

.score-screen {
  position: relative;
  background: var(--neutral-900);
  color: var(--paper);
}

.score-screen.is-fail .score-panel,
.score-screen.is-fail .score-chips,
.score-screen.is-fail .score-scrim,
.score-screen.is-fail .save-state {
  display: none;
}

.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  background: var(--neutral-900);
  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: 2px solid #f2f2f3;
  pointer-events: none;
  transform: translate(-50%, -100%);
}

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

.score-ui {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  pointer-events: none;
}

.score-scrim {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 46%;
  background: linear-gradient(to top, rgba(17, 20, 15, 0.55) 0%, rgba(17, 20, 15, 0) 34%);
  pointer-events: none;
}

.score-chips {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px;
  pointer-events: auto;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 9px;
  background: var(--chip);
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--paper);
}

.chip-alpha {
  margin-left: auto;
}

.chip-mark {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: 0 0 8px;
}

.chip-mark-solid {
  border: 1.5px solid var(--ring-marker);
  background: var(--ring-marker);
}

.chip-mark-dash {
  border: 1.5px dashed var(--paper);
  background: transparent;
}

.save-state {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.score-dock {
  position: relative;
  margin-top: auto;
  padding: 0 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: auto;
}

.score-panel {
  position: relative;
  padding: 11px 13px 10px;
  background: var(--overlay-panel);
  border: 1px solid rgba(242, 242, 243, 0.28);
}

.score-panel-main {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
}

.score-point {
  display: block;
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 9px;
  letter-spacing: 0.2em;
  color: rgba(242, 242, 243, 0.72);
}

.score-figures {
  display: flex;
  align-items: baseline;
  gap: 4px;
  font-family: var(--font-ui);
  font-weight: 600;
  color: var(--paper);
  line-height: 0.95;
}

#totalScore {
  font-size: 40px;
}

.score-max {
  font-size: 15px;
  color: rgba(242, 242, 243, 0.72);
}

.score-subline {
  display: block;
  margin-top: 4px;
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(242, 242, 243, 0.82);
}

.hist {
  display: flex;
  align-items: flex-end;
  gap: 5px;
  height: 62px;
  flex: 0 0 auto;
}

.hist-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  width: 16px;
  color: var(--paper);
}

.hist-count {
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 9px;
  line-height: 1;
  margin-bottom: 3px;
}

.hist-bar {
  width: 8px;
  background: var(--ring-marker);
}

.hist-col.is-zero {
  opacity: 0.45;
}

.hist-label {
  margin-top: 4px;
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 8px;
  letter-spacing: 0.04em;
  color: rgba(242, 242, 243, 0.72);
}

.score-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 8px;
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(242, 242, 243, 0.78);
}

.status,
.fail-card {
  position: absolute;
  left: 16px;
  right: 16px;
  top: 56px;
  z-index: 6;
  background: var(--overlay-panel);
  border: 1px solid rgba(242, 242, 243, 0.28);
  padding: 16px;
  color: var(--paper);
  font-family: var(--font-body);
}

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

.fail-title {
  margin: 0 0 8px;
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 28px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.fail-copy {
  margin: 0 0 16px;
  color: rgba(242, 242, 243, 0.78);
  line-height: 1.4;
}

.text-btn {
  width: 100%;
  min-height: var(--tap);
  margin-top: 8px;
  background: transparent;
  color: rgba(242, 242, 243, 0.78);
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 16px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.toolbar {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  pointer-events: auto;
}

.toolbar button {
  position: relative;
  min-height: var(--tap);
  border-radius: var(--radius);
  background: var(--chip);
  color: var(--paper);
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
}

.toolbar #saveImageBtn {
  background: var(--accent);
  color: #fff;
}

.share-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

.share-icon {
  width: 1.05em;
  height: 1.05em;
  flex: 0 0 auto;
}

.toolbar button:disabled {
  opacity: 0.45;
}

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

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

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

.has-marks {
  position: relative;
}

.reg-marks {
  position: absolute;
  inset: -4px;
  pointer-events: none;
}

.reg-marks i {
  position: absolute;
  width: 8px;
  height: 8px;
}

.reg-marks i:nth-child(1) {
  top: 0;
  left: 0;
}

.reg-marks i:nth-child(2) {
  top: 0;
  right: 0;
}

.reg-marks i:nth-child(3) {
  bottom: 0;
  left: 0;
}

.reg-marks i:nth-child(4) {
  bottom: 0;
  right: 0;
}

.reg-marks i::before,
.reg-marks i::after {
  content: "";
  position: absolute;
  background: #1d1f20;
}

.reg-marks i::before {
  left: 50%;
  top: 0;
  width: 1px;
  height: 100%;
  margin-left: -0.5px;
}

.reg-marks i::after {
  top: 50%;
  left: 0;
  height: 1px;
  width: 100%;
  margin-top: -0.5px;
}

.reg-marks.light i::before,
.reg-marks.light i::after {
  background: #f2f2f3;
}

.wait-overlay {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(17, 20, 15, 0.45);
  pointer-events: none;
}

.wait-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 20px 24px;
  background: var(--overlay-panel);
  border: 1px solid rgba(242, 242, 243, 0.28);
  color: var(--paper);
}

.wait-box p {
  margin: 0;
  font-family: var(--font-ui);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.wait-spinner {
  width: 36px;
  height: 36px;
  border: 2px solid rgba(242, 242, 243, 0.22);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: wait-spin 0.8s linear infinite;
}

@keyframes wait-spin {
  to {
    transform: rotate(360deg);
  }
}

.debug-overlay {
  position: fixed;
  top: 4px;
  left: 4px;
  right: auto;
  z-index: 9999;
  margin: 0;
  max-width: min(96vw, 340px);
  padding: 5px 7px;
  background: rgba(0, 0, 0, 0.72);
  color: #d6ff7a;
  font: 10px/1.35 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap;
  pointer-events: none;
}
