:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #101821;
  color: #f3f6fa;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  --surface: #18232e;
  --surface-raised: #202e3a;
  --muted: #a4b0bb;
  --accent: #60e0b0;
  --border: #344451;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  overflow: hidden;
  background: #101821;
}

button, input { font: inherit; }
button { color: inherit; }
[hidden] { display: none !important; }

.app-shell { min-height: 100vh; min-height: 100svh; }

.camera-stage {
  background: #0a1016;
  height: 100vh;
  height: 100svh;
  isolation: isolate;
  overflow: hidden;
  position: relative;
}

#camera-stream {
  height: 100%;
  inset: 0;
  object-fit: cover;
  position: absolute;
  width: 100%;
}

.camera-placeholder {
  align-items: center;
  background:
    radial-gradient(ellipse at center, #1d3139 0, #101821 68%);
  color: var(--muted);
  display: flex;
  flex-direction: column;
  inset: 0;
  justify-content: center;
  padding: 28px;
  position: absolute;
  text-align: center;
  z-index: 1;
}

.camera-icon {
  align-items: center;
  border: 1px solid #53616d;
  border-radius: 50%;
  color: var(--accent);
  display: inline-flex;
  font-size: 38px;
  height: 76px;
  justify-content: center;
  margin-bottom: 14px;
  width: 76px;
}

.camera-placeholder p { margin: 0; max-width: 270px; }

.app-header {
  align-items: center;
  display: flex;
  inset: 0 0 auto;
  justify-content: space-between;
  min-height: 68px;
  padding: max(12px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) 12px max(18px, env(safe-area-inset-left));
  position: absolute;
  z-index: 4;
  background: linear-gradient(#071016bf, transparent);
}

.brand {
  align-items: center;
  color: #edf5f5;
  display: inline-flex;
  gap: 10px;
  font-size: 15px;
  text-decoration: none;
}

.brand-mark {
  align-items: center;
  background: var(--accent);
  border-radius: 10px;
  color: #11221e;
  display: inline-flex;
  font-size: 22px;
  font-weight: 800;
  height: 34px;
  justify-content: center;
  width: 34px;
}

.privacy-label {
  color: #e1ece9;
  font-size: 11px;
  text-shadow: 0 1px 5px #000;
}

.framing-reticle {
  inset: 17% 8% 23%;
  pointer-events: none;
  position: absolute;
  z-index: 1;
}

.reticle-corner {
  border-color: #b7ffe5dd;
  border-style: solid;
  height: 28px;
  position: absolute;
  width: 28px;
}

.reticle-top-left { border-width: 2px 0 0 2px; left: 0; top: 0; }
.reticle-top-right { border-width: 2px 2px 0 0; right: 0; top: 0; }
.reticle-bottom-left { border-width: 0 0 2px 2px; bottom: 0; left: 0; }
.reticle-bottom-right { border-width: 0 2px 2px 0; bottom: 0; right: 0; }

.stage-caption {
  color: #fff;
  inset: auto 20px 132px;
  pointer-events: none;
  position: absolute;
  text-align: center;
  text-shadow: 0 2px 12px #000;
  z-index: 2;
}

.eyebrow {
  color: var(--accent);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .14em;
  margin: 0 0 8px;
}

.stage-caption h1 {
  font-size: clamp(29px, 7vw, 46px);
  letter-spacing: -.045em;
  line-height: 1.08;
  margin: 0;
}

.stage-caption > p:last-child {
  color: #e0e8e9;
  font-size: 13px;
  line-height: 1.45;
  margin: 10px auto 0;
  max-width: 400px;
}

.status-error { color: #ff9a9a !important; }

.camera-controls {
  align-items: center;
  background: linear-gradient(transparent, #081017e8 25%);
  bottom: 0;
  display: flex;
  gap: clamp(8px, 3vw, 20px);
  justify-content: center;
  left: 0;
  padding: 32px 16px max(22px, env(safe-area-inset-bottom));
  position: absolute;
  right: 0;
  z-index: 3;
}

.control-button {
  align-items: center;
  background: #14212bcc;
  border: 1px solid #ffffff50;
  border-radius: 999px;
  color: #f6f9fa;
  cursor: pointer;
  display: inline-flex;
  font-size: 12px;
  font-weight: 650;
  gap: 7px;
  justify-content: center;
  min-height: 42px;
  min-width: 76px;
  padding: 0 13px;
  text-decoration: none;
  backdrop-filter: blur(10px);
}

.control-button span:first-child { color: var(--accent); font-size: 17px; }
.control-button:disabled { cursor: not-allowed; opacity: .48; }
.control-button:focus-visible, .shutter-button:focus-visible, .icon-button:focus-visible, .sheet-handle:focus-visible {
  outline: 3px solid #9af4d1;
  outline-offset: 3px;
}

.shutter-button {
  align-items: center;
  background: var(--accent);
  border: 5px solid #ffffffd9;
  border-radius: 50%;
  box-shadow: 0 0 0 2px #0e201a, 0 5px 25px #0008;
  color: #10251e;
  cursor: pointer;
  display: inline-flex;
  font-size: 23px;
  height: 66px;
  justify-content: center;
  min-width: 66px;
  transition: transform .16s ease, opacity .16s ease;
}

.shutter-button:not(:disabled):active { transform: scale(.94); }
.shutter-button:disabled { cursor: not-allowed; opacity: .48; }

.visually-hidden {
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  height: 1px;
  overflow: hidden;
  position: absolute;
  white-space: nowrap;
  width: 1px;
}

.file-button { position: relative; }

.snapshot-preview {
  align-items: center;
  background: #05090de8;
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 76px 5vw 110px;
  position: absolute;
  z-index: 5;
}

.snapshot-preview img {
  max-height: 100%;
  max-width: 100%;
  object-fit: contain;
}

.laser-scan {
  align-items: center;
  background: #07101755;
  display: flex;
  flex-direction: column;
  inset: 0;
  justify-content: center;
  position: absolute;
}

.laser-scan > span {
  animation: laser-sweep 1.7s ease-in-out infinite;
  background: linear-gradient(90deg, transparent, #66f0c2, #c0ffe8, #66f0c2, transparent);
  box-shadow: 0 0 22px 4px #66f0c288;
  height: 3px;
  left: 0;
  position: absolute;
  right: 0;
  top: 20%;
}

.laser-scan p {
  background: #101821db;
  border: 1px solid #ffffff2b;
  border-radius: 999px;
  color: #f3f9f7;
  font-size: 13px;
  margin: 0;
  padding: 11px 16px;
}

@keyframes laser-sweep {
  0% { top: 16%; }
  50% { top: 80%; }
  100% { top: 16%; }
}

.solution-sheet {
  background: #f7fafb;
  border: 1px solid #d5e0e5;
  border-radius: 22px 22px 0 0;
  bottom: 0;
  color: #17212b;
  display: flex;
  flex-direction: column;
  left: max(0px, calc((100vw - 760px) / 2));
  max-height: min(76dvh, 760px);
  overflow: hidden;
  padding: 4px 22px max(16px, env(safe-area-inset-bottom));
  position: fixed;
  right: max(0px, calc((100vw - 760px) / 2));
  z-index: 7;
  box-shadow: 0 -18px 70px #0006;
  transition: max-height .22s ease;
}

.solution-sheet.sheet-expanded { max-height: 94dvh; }

.sheet-handle {
  align-self: center;
  background: transparent;
  border: 0;
  cursor: ns-resize;
  flex: 0 0 24px;
  height: 24px;
  padding: 8px 20px;
}

.sheet-handle span {
  background: #9aa8ae;
  border-radius: 999px;
  display: block;
  height: 4px;
  width: 38px;
}

.sheet-header {
  align-items: flex-start;
  border-bottom: 1px solid #dce5e9;
  display: flex;
  flex: 0 0 auto;
  justify-content: space-between;
  padding: 6px 0 14px;
}

.sheet-header .eyebrow { color: #087c5d; }
.sheet-header h2 { font-size: 20px; letter-spacing: -.025em; margin: 0; }

.icon-button {
  background: #edf2f4;
  border: 1px solid #d4dfe3;
  border-radius: 9px;
  color: #24323a;
  cursor: pointer;
  font-size: 24px;
  height: 36px;
  line-height: 1;
  width: 36px;
}

.sheet-content {
  flex: 1 1 auto;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 16px 2px 22px;
}

.topic-badge {
  background: #dcf5eb;
  border-radius: 999px;
  color: #075d45;
  display: inline-flex;
  font-size: 12px;
  font-weight: 750;
  margin-bottom: 4px;
  padding: 6px 11px;
}

.solution-section { margin: 14px 0 20px; }
.solution-section h3, .final-answer h3 { font-size: 15px; margin: 0 0 8px; }
.solution-section p { line-height: 1.65; margin: 0; }
.solution-section .katex-display { overflow-x: auto; overflow-y: hidden; padding: 5px 0; }

.variable-grid { display: grid; gap: 9px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

.variable-card, .equation-card {
  background: #eef3f5;
  border: 1px solid #dce5e9;
  border-radius: 12px;
  padding: 12px;
}

.math-symbol { color: #08674e; margin-bottom: 6px; }
.variable-card strong { display: block; font-size: 15px; }
.variable-card p { color: #617079; font-size: 12px; margin-top: 4px; }
.target-list { line-height: 1.9; margin: 0; padding-left: 22px; }
.equation-list { display: grid; gap: 9px; }
.equation-card h4 { font-size: 13px; margin: 0 0 8px; }
.math-display { overflow-x: auto; padding: 3px 0; }

.step-list { display: grid; gap: 14px; list-style: none; margin: 0; padding: 0; }
.step-list li { border-left: 3px solid #8ad9bb; padding: 2px 0 4px 14px; }
.step-list h4 { font-size: 14px; margin: 0 0 6px; }
.step-explanation { color: #46545d; line-height: 1.6; margin-bottom: 7px !important; }

.final-answer {
  background: #e3f7ef;
  border: 1px solid #9edfc3;
  border-radius: 14px;
  margin: 20px 0;
  padding: 15px;
}

.final-answer h3 { color: #075d45; }
.final-answer .katex-display { margin: 7px 0; overflow-x: auto; }
.solution-note {
  border-top: 1px solid #dce5e9;
  color: #5f6e76;
  flex: 0 0 auto;
  font-size: 11px;
  line-height: 1.45;
  margin: 0;
  padding: 12px 0 0;
}

.page-footer {
  bottom: 4px;
  color: #c2ccd1;
  font-size: 10px;
  left: 0;
  pointer-events: none;
  position: fixed;
  right: 0;
  text-align: center;
  z-index: 4;
}

@media (max-width: 520px) {
  .app-header {
    min-height: 60px;
    padding-left: max(14px, env(safe-area-inset-left));
    padding-right: max(14px, env(safe-area-inset-right));
  }
  .privacy-label { font-size: 9px; }
  .stage-caption { bottom: 138px; }
  .camera-controls { gap: 8px; padding-left: 9px; padding-right: 9px; }
  .control-button { font-size: 10px; min-width: 58px; padding: 0 9px; }
  .shutter-button { height: 60px; min-width: 60px; }
  .solution-sheet { padding-left: 16px; padding-right: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
  }
}
