:root {
  color-scheme: dark;
  --bg: #111113;
  --panel: #1c1c20;
  --panel-strong: #27272d;
  --text: #f7f7f2;
  --muted: #b9b8ae;
  --line: rgba(255, 255, 255, 0.13);
  --accent: #ffcf5a;
  --accent-ink: #17130a;
  --danger: #ff817a;
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.38);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.camera-mode {
  overflow: hidden;
}

button,
a,
input {
  font: inherit;
}

.app-shell {
  min-height: 100svh;
  width: 100%;
  margin: 0 auto;
  padding: 0;
  display: flex;
  flex-direction: column;
}

.screen {
  display: none;
  width: 100%;
}

.screen.is-active {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#cameraView.screen.is-active {
  min-height: 100svh;
  gap: 0;
  overflow: hidden;
}

.top-bar,
.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

#cameraView .top-bar {
  position: fixed;
  inset: max(12px, env(safe-area-inset-top)) 12px auto;
  z-index: 10;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(17, 17, 19, 0.62);
  backdrop-filter: blur(14px);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

#cameraView.is-fullscreen-mode .top-bar {
  background: rgba(17, 17, 19, 0.36);
}

#cameraView.is-fullscreen-mode .top-bar h1,
#cameraView.is-fullscreen-mode .top-bar p,
#cameraView.is-fullscreen-mode .message {
  display: none;
}

h1,
h2,
p {
  margin: 0;
}

h1,
h2 {
  font-size: 1.08rem;
  line-height: 1.15;
  letter-spacing: 0;
}

p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.35;
}

.camera-stage {
  position: relative;
  flex: 1 1 auto;
  height: 100svh;
  min-height: 100svh;
  overflow: hidden;
  border: 0;
  border-radius: 0;
  background: #050506;
  box-shadow: none;
  isolation: isolate;
  touch-action: none;
}

#cameraVideo,
#guideOverlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#cameraVideo {
  object-fit: cover;
  background: #050506;
}

#cameraVideo.is-front {
  transform: scaleX(-1);
}

#guideOverlay {
  z-index: 2;
  object-fit: contain;
  object-position: center;
  pointer-events: none;
  opacity: 0.5;
  user-select: none;
  will-change: transform, opacity;
}

.ratio-frame {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 3;
  width: min(100vw, calc(100svh * var(--capture-ratio, 0.5625)));
  height: min(100svh, calc(100vw / var(--capture-ratio, 0.5625)));
  border: 1px solid rgba(255, 207, 90, 0.72);
  box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.16);
  pointer-events: none;
  transform: translate(-50%, -50%);
}

.ratio-frame.is-hidden {
  display: none;
}

.camera-stage.is-guide-active {
  cursor: grab;
}

.camera-stage.is-dragging {
  cursor: grabbing;
}

.focus-ring {
  position: absolute;
  z-index: 4;
  inline-size: 76px;
  block-size: 76px;
  border: 2px solid var(--accent);
  border-radius: 50%;
  pointer-events: none;
  transform: translate(-50%, -50%) scale(0.85);
  opacity: 0;
}

.grid-overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  background-image:
    linear-gradient(to right, transparent calc(33.333% - 0.5px), rgba(255, 255, 255, 0.42) calc(33.333% - 0.5px), rgba(255, 255, 255, 0.42) calc(33.333% + 0.5px), transparent calc(33.333% + 0.5px)),
    linear-gradient(to right, transparent calc(66.666% - 0.5px), rgba(255, 255, 255, 0.42) calc(66.666% - 0.5px), rgba(255, 255, 255, 0.42) calc(66.666% + 0.5px), transparent calc(66.666% + 0.5px)),
    linear-gradient(to bottom, transparent calc(33.333% - 0.5px), rgba(255, 255, 255, 0.42) calc(33.333% - 0.5px), rgba(255, 255, 255, 0.42) calc(33.333% + 0.5px), transparent calc(33.333% + 0.5px)),
    linear-gradient(to bottom, transparent calc(66.666% - 0.5px), rgba(255, 255, 255, 0.42) calc(66.666% - 0.5px), rgba(255, 255, 255, 0.42) calc(66.666% + 0.5px), transparent calc(66.666% + 0.5px));
}

.gesture-layer {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
}

.focus-ring.is-visible {
  animation: focus-pop 680ms ease-out;
}

@keyframes focus-pop {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(1.25);
  }

  22% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.85);
  }
}

.empty-state {
  position: absolute;
  inset: auto 18px 18px;
  z-index: 3;
  display: grid;
  gap: 4px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(17, 17, 19, 0.72);
  backdrop-filter: blur(12px);
}

.empty-state strong {
  font-size: 0.95rem;
}

.empty-state span {
  color: var(--muted);
  font-size: 0.84rem;
}

.message {
  position: fixed;
  inset: auto 12px calc(176px + env(safe-area-inset-bottom));
  z-index: 11;
  min-height: 20px;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(17, 17, 19, 0.58);
  backdrop-filter: blur(12px);
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.3;
}

.message.is-error {
  color: var(--danger);
}

.controls {
  position: fixed;
  inset: auto 10px max(10px, env(safe-area-inset-bottom));
  z-index: 12;
  display: grid;
  gap: 10px;
  width: min(280px, calc(100vw - 20px));
  margin-left: auto;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(28, 28, 32, 0.72);
  backdrop-filter: blur(16px);
}

.tools-panel {
  display: grid;
  gap: 10px;
}

.tools-panel summary,
.settings-panel {
  display: grid;
  gap: 10px;
}

.tools-panel summary,
.settings-panel summary {
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  color: var(--text);
  cursor: pointer;
  font-weight: 800;
  list-style: none;
}

.tools-panel summary::-webkit-details-marker,
.settings-panel summary::-webkit-details-marker {
  display: none;
}

.tools-panel[open] {
  max-height: 54svh;
  overflow: auto;
  padding-right: 2px;
}

.controls:has(.tools-panel[open]) {
  width: min(390px, calc(100vw - 20px));
}

.tools-panel[open] summary {
  margin-bottom: 10px;
}

.tools-panel[open] + .shutter-button {
  inline-size: 76px;
  block-size: 76px;
}

.settings-panel[open] {
  max-height: 46svh;
  overflow: auto;
  padding-right: 2px;
}

.settings-panel[open] summary {
  margin-bottom: 10px;
}

.guide-position-status {
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(17, 17, 19, 0.5);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.file-actions,
.result-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

#guideInput {
  position: fixed;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.button,
.icon-button,
.shutter-button {
  border: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.button {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  color: var(--text);
  text-align: center;
  text-decoration: none;
  font-weight: 700;
  font-size: 0.92rem;
  line-height: 1.1;
}

.button.primary {
  grid-column: 1 / -1;
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
}

.button.ghost {
  color: var(--muted);
  background: transparent;
}

.icon-button {
  flex: 0 0 46px;
  inline-size: 46px;
  block-size: 46px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--panel);
  color: var(--text);
  font-size: 1.3rem;
}

.icon-button.is-active {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
}

.opacity-control,
.camera-zoom-control,
.ratio-control,
.overlay-tools label {
  display: grid;
  gap: 8px;
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 700;
}

.opacity-control input,
.camera-zoom-control input,
.overlay-tools input {
  width: 100%;
  accent-color: var(--accent);
}

.ratio-control select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  color: var(--text);
  padding: 8px 10px;
}

.overlay-tools {
  display: grid;
  gap: 10px;
}

.move-tools {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.move-tools .button {
  min-height: 38px;
}

.overlay-tools .button {
  width: 100%;
}

.shutter-button {
  justify-self: center;
  inline-size: 86px;
  block-size: 86px;
  display: grid;
  place-items: center;
  border: 7px solid var(--text);
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 0 0 1px var(--line), 0 12px 26px rgba(0, 0, 0, 0.35);
  font-weight: 800;
  font-size: 0.86rem;
}

.credit {
  position: fixed;
  inset: auto 12px calc(10px + env(safe-area-inset-bottom)) 12px;
  z-index: 8;
  color: var(--muted);
  text-align: center;
  font-size: 0.78rem;
  line-height: 1.2;
}

#cameraView .credit {
  display: none;
}

.result-screen .credit {
  position: static;
  inset: auto;
}

.credit a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 700;
}

.credit a:focus-visible,
.credit a:hover {
  text-decoration: underline;
}

.privacy-note a {
  color: var(--accent);
  font-weight: 700;
  text-decoration: none;
}

.privacy-note a:focus-visible,
.privacy-note a:hover {
  text-decoration: underline;
}

.privacy-note {
  display: none;
  margin-top: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(28, 28, 32, 0.72);
}

.screen.is-active ~ .privacy-note {
  display: block;
}

.privacy-note h2 {
  margin-bottom: 6px;
  font-size: 0.9rem;
}

.privacy-note p {
  font-size: 0.78rem;
}

.result-screen {
  width: min(100%, 720px);
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 14px max(16px, env(safe-area-inset-bottom));
  min-height: calc(100svh - 30px);
}

.result-image {
  width: 100%;
  flex: 1 1 auto;
  min-height: 320px;
  max-height: 72svh;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #050506;
  box-shadow: var(--shadow);
}

@media (orientation: landscape) and (max-height: 620px) {
  .app-shell {
    width: 100%;
  }

  .result-screen.screen.is-active {
    display: grid;
    grid-template-columns: minmax(360px, 1fr) 300px;
    grid-template-rows: auto 1fr;
    align-items: stretch;
  }

  .top-bar,
  .result-header {
    grid-column: 1 / -1;
  }

  .camera-stage,
  .result-image {
    height: 100svh;
    min-height: 0;
    max-height: none;
  }

  .controls {
    width: min(340px, 36vw);
    inset: auto 12px max(12px, env(safe-area-inset-bottom)) auto;
  }

  .message {
    inset: auto 12px calc(168px + env(safe-area-inset-bottom)) auto;
    width: min(340px, 36vw);
  }

  .controls,
  .result-actions {
    align-self: stretch;
  }
}

@media (min-width: 760px) {
  .app-shell {
    padding-block: 0;
  }

  .camera-stage {
    min-height: 100svh;
  }
}
