:root {
  color-scheme: light;
  --ink: #20211f;
  --muted: #686b66;
  --paper: #f5f1e8;
  --panel: #fffdf8;
  --line: #ded9ce;
  --accent: #111111;
  --accent-dark: #000000;
  --secondary: #565c59;
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
}

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

button,
input,
select {
  font: inherit;
}

.app {
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto auto auto;
  overflow: hidden;
}

.camera {
  position: relative;
  min-height: 0;
  background: #111;
  display: grid;
  place-items: center;
  overflow: hidden;
}

video,
canvas {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}

#guideCanvas {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

#photoCanvas,
#resultCanvas {
  display: none;
}

.has-photo #guideCanvas,
.has-result #guideCanvas {
  display: none;
}

.has-photo #video {
  display: none;
}

.has-photo #photoCanvas {
  display: block;
}

.has-result #photoCanvas,
.has-result #video {
  display: none;
}

.has-result #resultCanvas {
  display: block;
}

.loading-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.58);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
}

.status-loading .loading-overlay {
  opacity: 1;
}

.loading-spinner {
  width: clamp(72px, 22vw, 132px);
  height: clamp(72px, 22vw, 132px);
  border: clamp(5px, 1.4vw, 9px) solid rgba(255, 255, 255, 0.28);
  border-top-color: white;
  border-radius: 50%;
  animation: status-spinner 0.82s linear infinite;
}

.status {
  min-height: 48px;
  padding: 10px 18px;
  color: white;
  background: #171715;
  line-height: 1.35;
  display: flex;
  align-items: center;
  gap: 10px;
}

.status::before {
  display: none;
}

.photo-note {
  padding: 9px 18px 10px;
  color: #4d4f4b;
  background: #efebe2;
  border-top: 1px solid #252520;
  font-size: 14px;
  line-height: 1.35;
}

@keyframes status-spinner {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .loading-spinner {
    animation-duration: 1.6s;
  }
}

.controls {
  padding: 14px 18px max(14px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.title {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1;
  letter-spacing: 0;
}

.title span,
.field span {
  color: var(--muted);
}

.title span {
  display: block;
  margin-top: 5px;
  font-size: 12px;
  letter-spacing: 0.08em;
}

.title strong {
  color: var(--accent-dark);
  font-size: 14px;
  white-space: nowrap;
}

.field {
  display: block;
  margin-bottom: 11px;
}

.field span {
  display: block;
  margin-bottom: 6px;
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

select,
input {
  width: 100%;
  min-height: 44px;
  border: 1px solid #d6d1c7;
  border-radius: 8px;
  padding: 9px 11px;
  color: var(--ink);
  background: white;
}

input[type="range"] {
  min-height: 32px;
  border: 0;
  padding: 0;
  background: transparent;
  accent-color: var(--accent);
}

.wrist-field {
  margin-bottom: 12px;
}

.wrist-control {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 64px;
  gap: 12px;
  align-items: center;
}

.wrist-value {
  color: var(--ink);
  font-weight: 800;
  text-align: right;
  white-space: nowrap;
}

.wrist-presets {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  margin-top: 8px;
}

.actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 9px;
  margin-top: 3px;
}

button,
.file-fallback {
  min-height: 46px;
  border: 0;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: white;
  background: var(--accent);
  cursor: pointer;
}

button:hover,
.file-fallback:hover {
  background: var(--accent-dark);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.wrist-preset {
  min-height: 34px;
  border: 1px solid #d6d1c7;
  color: var(--ink);
  background: #f8f6f0;
  font-size: 14px;
  font-weight: 700;
}

.wrist-preset:hover {
  color: white;
  background: var(--accent-dark);
}

.wrist-preset.is-active {
  border-color: var(--accent);
  color: white;
  background: var(--accent);
}

.file-fallback {
  margin-top: 10px;
  background: var(--secondary);
}

.upload-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 9px;
  margin-top: 10px;
}

.upload-actions .file-fallback {
  margin-top: 0;
}

.file-fallback-secondary {
  background: var(--secondary);
}

.file-fallback input {
  display: none;
}

.result-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
  margin-top: 10px;
  min-height: 46px;
}

.download-button {
  width: 100%;
  border: 1px solid #d6d1c7;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--ink);
  background: transparent;
  font-weight: 700;
}

.download-button:hover {
  color: var(--ink);
  background: #f3f0e8;
}

.download-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.share-button {
  background: transparent;
}

@media (min-width: 860px) {
  .app {
    grid-template-columns: minmax(0, 1fr) 390px;
    grid-template-rows: auto auto minmax(0, 1fr);
  }

  .camera {
    grid-column: 1;
    grid-row: 1 / span 3;
    min-height: 100vh;
    min-height: 100dvh;
  }

  .status {
    grid-column: 2;
    grid-row: 1;
    min-height: 64px;
    border-left: 1px solid var(--line);
  }

  .photo-note {
    grid-column: 2;
    grid-row: 2;
    border-left: 1px solid var(--line);
  }

  .controls {
    grid-column: 2;
    grid-row: 3;
    border-top: 0;
    border-left: 1px solid var(--line);
    overflow: auto;
  }
}
