:root {
  --cream: #F5EFE3;
  --blue: #1C2E75;
  --red: #D0452B;
  --grey: #8A8578;
  --ink: #22201C;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--cream);
  color: var(--ink);
  font-family: 'Inter', system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button, .secondary, a { font: inherit; }

[hidden] { display: none !important; }

/* Start ------------------------------------------------------------------ */

#start {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px 20px calc(24px + env(safe-area-inset-bottom));
  text-align: center;
}

.wordmark {
  margin: 0;
  font-size: 56px;
  font-weight: 500;
  letter-spacing: -0.01em;
}
.wordmark .paper { font-family: 'Fraunces', Georgia, serif; color: var(--blue); }
.wordmark .txt { font-family: 'JetBrains Mono', ui-monospace, monospace; color: var(--red); font-size: 0.82em; }

.tagline { margin: 0 0 16px; max-width: 22em; font-size: 17px; line-height: 1.4; }

.primary {
  min-height: 52px;
  padding: 0 28px;
  border: 0;
  border-radius: 26px;
  background: var(--blue);
  color: var(--cream);
  font-size: 17px;
  font-weight: 500;
}
.primary:disabled { opacity: 0.6; }

.quiet { margin: 0; color: var(--grey); font-size: 13px; }

#fallback {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
  font-size: 15px;
}
#fallback p { margin: 0; }

.secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  min-width: 220px;
  padding: 0 20px;
  border: 1.5px solid var(--blue);
  border-radius: 22px;
  color: var(--blue);
  background: transparent;
  text-decoration: none;
  font-size: 15px;
  font-weight: 500;
}
.file { position: relative; overflow: hidden; }
.file input { position: absolute; inset: 0; opacity: 0; }

.link {
  min-height: 44px;
  border: 0;
  background: none;
  color: var(--grey);
  font-size: 13px;
  text-decoration: underline;
  word-break: break-all;
}

/* Live ------------------------------------------------------------------- */

#live {
  position: fixed;
  inset: 0;
  background: #000;
  overflow: hidden;
}

#live video, #live canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.pill {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  min-height: 44px;
  padding: 0 20px;
  border: 0;
  border-radius: 22px;
  background: var(--blue);
  color: var(--cream);
  font-size: 15px;
  font-weight: 500;
}
.pill.off { background: rgba(245, 239, 227, 0.92); color: var(--blue); }

.shutter {
  position: absolute;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 4px solid var(--cream);
  background: var(--blue);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.25);
}

#lifting {
  position: fixed;
  z-index: 10;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  color: var(--cream);
  font-size: 20px;
  font-weight: 500;
}

/* Result ----------------------------------------------------------------- */

#result {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: calc(16px + env(safe-area-inset-top)) 0 calc(24px + env(safe-area-inset-bottom));
}
#resultImg { display: block; width: 100%; height: auto; background: var(--cream); box-shadow: 0 1px 6px rgba(0, 0, 0, 0.12); }
.faint { margin: 0 16px; color: var(--red); font-size: 15px; font-weight: 500; }
.segmented { display: inline-flex; border: 1.5px solid var(--blue); border-radius: 22px; overflow: hidden; }
.segmented button {
  min-height: 40px; min-width: 96px; padding: 0 16px; border: 0;
  background: transparent; color: var(--blue); font-size: 15px; font-weight: 500;
}
.segmented button.on { background: var(--blue); color: var(--cream); }
.actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; padding: 4px 16px 0; }
.actions .primary, .actions .secondary { display: inline-flex; align-items: center; justify-content: center; min-width: 96px; text-decoration: none; }
.actions .secondary { min-width: 96px; }
#result .quiet { margin: 0 16px; text-align: center; }
#resultDebug { margin: 0 16px; font-size: 11px; white-space: pre-wrap; color: var(--grey); }

/* Debug panel: for tuning, not for looking at. */
#debug {
  position: absolute;
  left: 8px;
  top: calc(64px + env(safe-area-inset-top));
  width: min(340px, calc(100% - 16px));
  max-height: 60dvh;
  overflow: auto;
  padding: 8px;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font: 12px/1.3 ui-monospace, monospace;
  border-radius: 6px;
}
#debug pre { margin: 0 0 6px; white-space: pre-wrap; }
#debug summary { min-height: 32px; line-height: 32px; cursor: pointer; }
#debug label { display: block; margin: 4px 0; }
#debug input[type=range] { width: 100%; }
#debug button { margin-top: 6px; min-height: 32px; }

/* tune.html: a desktop tool, plain on purpose. */
body.tune { display: flex; min-height: 100vh; background: #fff; font-size: 13px; }
.tune aside { flex: 0 0 300px; padding: 12px; border-right: 1px solid #ddd; background: var(--cream); }
.tune aside h1 { margin: 0 0 12px; font-size: 16px; }
.tune aside label { display: block; margin: 6px 0; }
.tune aside input[type=range], .tune aside select { width: 100%; }
.tune aside button { margin: 8px 0; min-height: 32px; width: 100%; }
.tune aside pre { white-space: pre-wrap; font-size: 12px; }
.tune main { flex: 1; padding: 12px; overflow: auto; }
.tune #panels, .tune #grid { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-start; }
.tune #grid { margin-top: 24px; }
.tune figure { margin: 0; }
.tune figcaption { font-size: 12px; color: #555; margin-top: 4px; max-width: 300px; }
.tune canvas { display: block; background: #eee; max-width: 100%; }
