:root {
  --bg: #0a0a0a;
  --ink: #f2efe8;
  --ink-dim: #8a8680;
  --accent: #ffb800;
  --accent-2: #ff3b3b;
  --mask: rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  color: var(--ink);
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  -webkit-font-smoothing: antialiased;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
  touch-action: manipulation;
}

body { height: 100dvh; }

.stage {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: #000;
  height: 100dvh;
}

/* -------------------------------------------------------- viewport / video */

.viewport {
  position: relative;
  flex: 1;
  overflow: hidden;
  background: #000;
  min-height: 0;
}

video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}

video.mirror { transform: scaleX(-1); }

/* -------------------------------------------------------- overlay SVG */

.overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  mix-blend-mode: difference;
  opacity: 0.95;
}

.overlay line,
.overlay path,
.overlay rect {
  fill: none;
  stroke: rgba(255, 255, 255, 0.88);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.overlay .thin   { stroke: rgba(255, 255, 255, 0.4); stroke-width: 0.6; }
.overlay .dashed { stroke-dasharray: 4 4; }
.overlay .accent { stroke: rgba(255, 184, 0, 0.95); stroke-width: 1.2; }
.overlay .point  { fill: rgba(255, 184, 0, 0.95); stroke: none; }

/* -------------------------------------------------------- teaching labels */

.labels {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
}
.labels .lbl {
  position: absolute;
  transform: translate(-50%, -50%);
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.92);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9), 0 0 2px rgba(0, 0, 0, 0.8);
  white-space: nowrap;
  padding: 3px 6px;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 2px;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  animation: labelFade 0.3s ease;
}
.labels .lbl.accent {
  color: var(--accent);
  border: 1px solid rgba(255, 184, 0, 0.25);
}
.labels .lbl.dim {
  color: rgba(255, 255, 255, 0.6);
  background: rgba(0, 0, 0, 0.25);
  font-weight: 400;
}
.labels .lbl.small {
  font-size: 9px;
  letter-spacing: 0.12em;
  padding: 2px 5px;
}
.labels .lbl.align-left  { transform: translate(0, -50%); }
.labels .lbl.align-right { transform: translate(-100%, -50%); }

@keyframes labelFade {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* -------------------------------------------------------- teaching tip */

.tip {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.82);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
  pointer-events: none;
  max-width: 92%;
  text-align: center;
  z-index: 5;
  padding: 6px 10px;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 2px;
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  opacity: 0;
  transition: opacity 0.2s ease;
}
.tip.show { opacity: 1; }
.tip::before {
  content: '→ ';
  color: var(--accent);
}

/* -------------------------------------------------------- aspect mask */

.ar-mask {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 3;
  display: none;
}
.ar-mask.active { display: block; }
.ar-mask .bar {
  position: absolute;
  background: rgba(0, 0, 0, 0.72);
  transition: all 0.15s ease;
}
.ar-mask .bar-t { top: 0; left: 0; right: 0; }
.ar-mask .bar-b { bottom: 0; left: 0; right: 0; }
.ar-mask .bar-l { top: 0; bottom: 0; left: 0; }
.ar-mask .bar-r { top: 0; bottom: 0; right: 0; }
.ar-mask .frame {
  position: absolute;
  border: 1px solid rgba(255, 255, 255, 0.5);
  pointer-events: none;
}

/* -------------------------------------------------------- level indicator */

.level {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 120px;
  height: 2px;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 4;
  display: none;
  mix-blend-mode: difference;
}
.level.active { display: block; }
.level-bar {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.5);
  transform-origin: center;
  transition: background 0.2s ease, transform 0.08s linear;
}
.level.level-true .level-bar { background: rgba(255, 184, 0, 0.95); }
.level-dot {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 4px;
  height: 4px;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

/* -------------------------------------------------------- HUD */

.hud-top {
  position: absolute;
  top: env(safe-area-inset-top, 0);
  left: 0; right: 0;
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
  z-index: 6;
  pointer-events: none;
}

.hud-right {
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: auto;
}

.hud-chip {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: var(--ink);
  font-family: inherit;
  font-size: 10px;
  letter-spacing: 0.12em;
  padding: 5px 9px;
  border-radius: 2px;
  cursor: pointer;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.hud-chip:active { transform: scale(0.95); }

.brand {
  font-family: 'Fraunces', serif;
  font-style: italic;
  font-weight: 300;
  font-size: 20px;
  letter-spacing: 0;
  text-transform: none;
}
.brand::after { content: '.'; color: var(--accent); }

.hud-mode {
  font-family: inherit;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 500;
  color: var(--accent);
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 184, 0, 0.3);
  padding: 5px 9px;
  border-radius: 2px;
  cursor: pointer;
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.hud-mode .info-mark {
  font-size: 10px;
  opacity: 0.7;
}
.hud-mode:active { transform: scale(0.95); }

/* -------------------------------------------------------- corner marks */

.corners {
  position: absolute;
  inset: 16px;
  pointer-events: none;
  z-index: 4;
  mix-blend-mode: difference;
}
.corner {
  position: absolute;
  width: 18px;
  height: 18px;
  border: 1px solid rgba(255, 255, 255, 0.9);
}
.corner.tl { top: 0;    left: 0;  border-right: none; border-bottom: none; }
.corner.tr { top: 0;    right: 0; border-left:  none; border-bottom: none; }
.corner.bl { bottom: 0; left: 0;  border-right: none; border-top:    none; }
.corner.br { bottom: 0; right: 0; border-left:  none; border-top:    none; }

/* -------------------------------------------------------- controls */

.controls {
  position: relative;
  background: #000;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  padding-bottom: env(safe-area-inset-bottom, 0);
  z-index: 10;
}

.grid-selector {
  display: flex;
  overflow-x: auto;
  padding: 12px 12px 10px;
  scrollbar-width: none;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  -webkit-overflow-scrolling: touch;
}
.grid-selector::-webkit-scrollbar { display: none; }

.grid-btn {
  flex-shrink: 0;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--ink-dim);
  font-family: inherit;
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 8px 12px;
  margin-right: 6px;
  cursor: pointer;
  border-radius: 2px;
  transition: all 0.15s ease;
  white-space: nowrap;
}
.grid-btn:active { transform: scale(0.96); }
.grid-btn.active {
  color: #000;
  background: var(--ink);
  border-color: var(--ink);
}
.grid-btn.active::before {
  content: '● ';
  color: var(--accent);
}

.action-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px 18px;
  gap: 8px;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--ink);
  cursor: pointer;
  padding: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background 0.15s ease;
  width: 48px;
  height: 48px;
  flex-shrink: 0;
}
.icon-btn.small { width: 40px; height: 40px; padding: 8px; }
.icon-btn[hidden] { display: none; }
.icon-btn:active { background: rgba(255, 255, 255, 0.08); }
.icon-btn[aria-pressed="true"] { color: var(--accent); }

.icon-btn svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  stroke-width: 1.5;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.shutter {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--ink);
  border: 3px solid #000;
  box-shadow: 0 0 0 2px var(--ink);
  cursor: pointer;
  transition: transform 0.1s ease;
  flex-shrink: 0;
}
.shutter:active { transform: scale(0.92); }

/* -------------------------------------------------------- intro */

.intro {
  position: absolute;
  inset: 0;
  background: #000;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px;
  text-align: center;
  transition: opacity 0.5s ease;
}
.intro.gone { opacity: 0; pointer-events: none; }

.intro h1 {
  font-family: 'Fraunces', serif;
  font-style: italic;
  font-weight: 300;
  font-size: 64px;
  line-height: 1;
  letter-spacing: -0.02em;
  margin-bottom: 20px;
}
.intro h1::after { content: '.'; color: var(--accent); }

.intro p {
  font-size: 11px;
  line-height: 1.8;
  letter-spacing: 0.1em;
  color: var(--ink-dim);
  text-transform: uppercase;
  max-width: 320px;
  margin-bottom: 40px;
}

.intro button {
  font-family: inherit;
  background: var(--ink);
  color: #000;
  border: none;
  padding: 14px 32px;
  font-size: 11px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  cursor: pointer;
  border-radius: 2px;
  transition: transform 0.15s ease;
}
.intro button:active { transform: scale(0.97); }

.intro .footnote {
  margin-top: 40px;
  font-size: 9px;
  color: var(--ink-dim);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  opacity: 0.6;
}

.error-msg {
  color: var(--accent-2);
  font-size: 10px;
  margin-top: 20px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  max-width: 320px;
  line-height: 1.7;
}

/* -------------------------------------------------------- flash */

.flash {
  position: absolute;
  inset: 0;
  background: white;
  opacity: 0;
  pointer-events: none;
  z-index: 50;
}
.flash.fire { animation: flashFire 0.3s ease-out; }
@keyframes flashFire {
  0% { opacity: 0; }
  20% { opacity: 0.9; }
  100% { opacity: 0; }
}

/* -------------------------------------------------------- toast */

.toast {
  position: absolute;
  left: 50%;
  bottom: 20px;
  transform: translate(-50%, 20px);
  background: rgba(0, 0, 0, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: var(--ink);
  padding: 10px 16px;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  border-radius: 2px;
  z-index: 40;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  text-align: center;
  max-width: 80%;
}
.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* -------------------------------------------------------- review */

.review {
  position: absolute;
  inset: 0;
  background: #000;
  z-index: 80;
  display: none;
  flex-direction: column;
}
.review.show { display: flex; }
.review img {
  flex: 1;
  width: 100%;
  object-fit: contain;
  min-height: 0;
  background: #000;
}
.review-bar {
  display: flex;
  justify-content: space-around;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0));
  background: #000;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}
.review-bar button {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--ink);
  padding: 12px 28px;
  font-family: inherit;
  font-size: 10px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  border-radius: 2px;
  cursor: pointer;
}
.review-bar button.primary {
  background: var(--ink);
  color: #000;
  border-color: var(--ink);
}

/* -------------------------------------------------------- info sheet */

.info-sheet {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 90;
  display: none;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.info-sheet.show { display: flex; }
.info-card {
  background: #0a0a0a;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  width: 100%;
  max-width: 640px;
  padding: 24px 24px calc(24px + env(safe-area-inset-bottom, 0));
  border-radius: 8px 8px 0 0;
}
.info-title {
  font-family: 'Fraunces', serif;
  font-style: italic;
  font-weight: 300;
  font-size: 28px;
  margin-bottom: 14px;
}
.info-example {
  width: 100%;
  aspect-ratio: 1 / 1;
  max-height: 280px;
  margin: 0 auto 8px;
  border-radius: 4px;
  overflow: hidden;
  background: #000;
  border: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
}
.info-example svg {
  width: 100%;
  height: 100%;
  display: block;
}
.info-example .ex-overlay line,
.info-example .ex-overlay path,
.info-example .ex-overlay rect {
  fill: none;
  stroke: rgba(255, 255, 255, 0.85);
  stroke-width: 0.9;
  vector-effect: non-scaling-stroke;
}
.info-example .ex-overlay .thin   { stroke: rgba(255, 255, 255, 0.45); stroke-width: 0.55; }
.info-example .ex-overlay .dashed { stroke-dasharray: 3 3; }
.info-example .ex-overlay .accent { stroke: #ffb800; stroke-width: 1.2; }
.info-example .ex-overlay .point  { fill: #ffb800; stroke: none; }

.info-caption {
  font-size: 10px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--ink-dim);
  margin-bottom: 16px;
  text-align: center;
}
.info-caption strong {
  color: var(--accent);
  font-weight: 500;
}

.info-body {
  font-size: 12px;
  line-height: 1.7;
  color: var(--ink-dim);
  margin-bottom: 20px;
}

.info-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}
.info-actions button {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--ink);
  padding: 10px 22px;
  font-family: inherit;
  font-size: 10px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  border-radius: 2px;
  cursor: pointer;
}
.info-actions .info-use {
  background: var(--ink);
  color: #000;
  border-color: var(--ink);
}
