:root {
  color-scheme: dark;
  --bg: #050505;
  --panel: #111;
  --panel-2: #191919;
  --text: #f7f7f7;
  --muted: #a3a3a3;
  --line: #2e2e2e;
  --blue: #1f86ff;
  --blue-2: #0f6fe4;
  --paper: #f8f8f5;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

button,
input,
a {
  font: inherit;
}

button,
label,
a {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  overflow: hidden;
  background: var(--bg);
}

.topbar {
  height: calc(76px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 18px 0;
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  align-items: center;
  gap: 10px;
  background: #030303;
  border-bottom: 1px solid #202020;
}

.icon-button {
  width: 46px;
  height: 46px;
  border: 0;
  border-radius: 50%;
  color: #fff;
  background: transparent;
  display: grid;
  place-items: center;
}

.document-title {
  min-width: 0;
  display: grid;
  gap: 3px;
  text-align: center;
}

.document-title input {
  width: 100%;
  border: 0;
  border-bottom: 4px dotted #aaa;
  padding: 0 4px 4px;
  color: #fff;
  background: transparent;
  text-align: center;
  font-size: 19px;
  outline: none;
}

.document-title span {
  color: var(--muted);
  font-size: 13px;
}

.stage {
  position: relative;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: #333;
  overflow: hidden;
}

.empty-state {
  width: min(420px, 100%);
  display: grid;
  justify-items: center;
  gap: 16px;
  text-align: center;
}

.empty-mark {
  width: 82px;
  height: 110px;
  border: 3px solid #fff;
  border-radius: 4px;
  background:
    linear-gradient(#fff 0 0) 18px 26px / 46px 5px no-repeat,
    linear-gradient(#fff 0 0) 18px 44px / 38px 5px no-repeat,
    linear-gradient(#fff 0 0) 18px 62px / 48px 5px no-repeat;
  box-shadow: 0 18px 50px rgb(0 0 0 / 35%);
}

.empty-state h1 {
  margin: 0;
  font-size: 34px;
}

.empty-state p {
  margin: 0;
  color: #d7d7d7;
  line-height: 1.45;
}

.empty-actions {
  width: 100%;
  display: grid;
  gap: 12px;
}

.primary-action,
.secondary-action,
.continue-button,
.pdf-button {
  border: 0;
  border-radius: 999px;
  min-height: 58px;
  display: grid;
  place-items: center;
  font-weight: 700;
  cursor: pointer;
}

.primary-action,
.pdf-button {
  color: #fff;
  background: var(--blue);
}

.secondary-action,
.continue-button {
  color: #fff;
  background: transparent;
  border: 2px solid #777;
}

input[type="file"] {
  display: none;
}

.result-canvas {
  max-width: 100%;
  max-height: 100%;
  background: var(--paper);
  box-shadow: 0 14px 40px rgb(0 0 0 / 42%);
}

.camera-panel {
  position: absolute;
  inset: 0;
  z-index: 4;
  overflow: hidden;
  background: #000;
}

.camera-video,
.camera-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.camera-video {
  object-fit: cover;
}

.camera-overlay {
  pointer-events: none;
}

.camera-hint {
  position: absolute;
  left: 50%;
  top: 44%;
  z-index: 2;
  transform: translate(-50%, -50%);
  max-width: min(82%, 360px);
  padding: 12px 18px;
  border-radius: 999px;
  color: #fff;
  background: rgb(0 0 0 / 58%);
  box-shadow: 0 8px 24px rgb(0 0 0 / 28%);
  font-size: 19px;
  font-weight: 700;
  text-align: center;
}

.camera-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  min-height: 126px;
  padding: 18px 24px calc(20px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: 64px 1fr 64px;
  align-items: center;
  gap: 16px;
  background: linear-gradient(to top, rgb(0 0 0 / 82%), rgb(0 0 0 / 0%));
}

.camera-control {
  width: 56px;
  height: 56px;
  border: 1px solid rgb(255 255 255 / 28%);
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  background: rgb(0 0 0 / 42%);
}

.capture-button {
  width: 78px;
  height: 78px;
  justify-self: center;
  border: 5px solid #fff;
  border-radius: 50%;
  background: #fff;
  box-shadow: inset 0 0 0 7px #000;
}

.crop-panel {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-rows: 1fr auto;
  background: #333;
  padding: 14px;
  gap: 12px;
}

.crop-canvas {
  width: 100%;
  height: 100%;
  min-height: 0;
  object-fit: contain;
  touch-action: none;
}

.crop-controls {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  padding-bottom: 4px;
}

.crop-controls button {
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  color: #111;
  background: #f2f2f2;
  font-weight: 650;
}

.crop-controls button:nth-child(2) {
  color: #fff;
  background: var(--blue);
}

.editbar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: #050505;
  border-top: 1px solid #1d1d1d;
}

.editbar button {
  min-height: 84px;
  border: 0;
  color: #aaa;
  background: transparent;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 7px;
}

.editbar button.active {
  color: #fff;
  background: var(--blue);
}

.editbar span:last-child {
  font-size: 13px;
}

.actionbar {
  padding: 16px 18px calc(16px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  background: #050505;
}

.sheet {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: end center;
  background: rgb(0 0 0 / 45%);
  z-index: 10;
}

.sheet-card {
  width: 100%;
  max-width: 560px;
  padding: 12px 22px calc(22px + env(safe-area-inset-bottom));
  border-radius: 24px 24px 0 0;
  color: #111;
  background: #fff;
}

.sheet-handle {
  width: 74px;
  height: 6px;
  margin: 0 auto 22px;
  border-radius: 999px;
  background: #cfcfcf;
}

.sheet-card h2,
.sheet-card p {
  margin: 0 0 10px;
}

.sheet-card p {
  color: #666;
}

.sheet-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 20px 0;
}

.sheet-actions button,
.sheet-actions a,
.sheet-close {
  min-height: 50px;
  border: 0;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: #111;
  background: #ececec;
  text-decoration: none;
  font-weight: 650;
}

.sheet-actions button:first-child {
  color: #fff;
  background: var(--blue);
}

.sheet-close {
  width: 100%;
}

.icon-home,
.icon-share,
.icon-camera,
.icon-crop,
.icon-rotate,
.icon-spark,
.icon-close {
  width: 25px;
  height: 25px;
  display: block;
  position: relative;
}

.icon-home::before {
  content: "";
  position: absolute;
  inset: 7px 4px 3px;
  background: currentColor;
  clip-path: polygon(50% 0, 100% 42%, 86% 42%, 86% 100%, 14% 100%, 14% 42%, 0 42%);
}

.icon-share::before {
  content: "";
  position: absolute;
  inset: 4px 7px 3px;
  border: 3px solid currentColor;
  border-top: 0;
}

.icon-share::after {
  content: "";
  position: absolute;
  left: 10px;
  top: 2px;
  width: 9px;
  height: 16px;
  border-top: 3px solid currentColor;
  border-left: 3px solid currentColor;
  transform: rotate(45deg);
}

.icon-camera::before {
  content: "";
  position: absolute;
  inset: 7px 2px 4px;
  border: 3px solid currentColor;
  border-radius: 4px;
}

.icon-camera::after {
  content: "";
  position: absolute;
  left: 9px;
  top: 11px;
  width: 7px;
  height: 7px;
  border: 3px solid currentColor;
  border-radius: 50%;
}

.icon-close::before,
.icon-close::after {
  content: "";
  position: absolute;
  left: 3px;
  top: 11px;
  width: 20px;
  height: 3px;
  border-radius: 999px;
  background: currentColor;
}

.icon-close::before {
  transform: rotate(45deg);
}

.icon-close::after {
  transform: rotate(-45deg);
}

.icon-crop::before {
  content: "";
  position: absolute;
  inset: 4px 8px 8px 4px;
  border-left: 3px solid currentColor;
  border-bottom: 3px solid currentColor;
}

.icon-crop::after {
  content: "";
  position: absolute;
  inset: 8px 4px 4px 8px;
  border-top: 3px solid currentColor;
  border-right: 3px solid currentColor;
}

.icon-rotate::before {
  content: "";
  position: absolute;
  inset: 5px;
  border: 3px solid currentColor;
  border-left-color: transparent;
  border-radius: 50%;
}

.icon-rotate::after {
  content: "";
  position: absolute;
  right: 2px;
  top: 3px;
  border: 6px solid transparent;
  border-left-color: currentColor;
}

.icon-spark::before {
  content: "";
  position: absolute;
  inset: 3px;
  background: currentColor;
  clip-path: polygon(50% 0, 61% 35%, 100% 50%, 61% 64%, 50% 100%, 38% 64%, 0 50%, 38% 35%);
}

@media (min-width: 760px) {
  .app-shell {
    max-width: 540px;
    min-height: 920px;
    margin: 24px auto;
    border: 1px solid #252525;
    border-radius: 28px;
    overflow: hidden;
  }
}
