:root {
  color-scheme: dark;
  --bg: #07090d;
  --panel: rgba(14, 17, 23, 0.86);
  --panel-solid: #10141b;
  --panel-soft: rgba(255, 255, 255, 0.08);
  --stroke: rgba(255, 255, 255, 0.18);
  --stroke-strong: rgba(255, 255, 255, 0.34);
  --text: #f7f8fb;
  --muted: rgba(247, 248, 251, 0.66);
  --accent: #3de6c2;
  --danger: #ff6b6b;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

button,
textarea {
  font: inherit;
}

button {
  color: inherit;
}

.app {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: var(--bg);
  isolation: isolate;
}

.stage,
.image-canvas,
.mark-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.stage {
  overflow: hidden;
  touch-action: none;
}

.image-canvas {
  z-index: 0;
  background: #05070a;
}

.mark-canvas {
  z-index: 1;
  pointer-events: auto;
}

.home-surface {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-items: center;
  padding: 28px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), transparent 34%),
    radial-gradient(circle at center, rgba(61, 230, 194, 0.18), transparent 28%),
    #07090d;
}

.app:not(.is-home) .home-surface {
  display: none;
}

.drop-core {
  width: min(72vw, 340px);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 10px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 36%, rgba(255, 255, 255, 0.16), transparent 42%),
    rgba(255, 255, 255, 0.055);
  box-shadow: 0 28px 100px rgba(0, 0, 0, 0.46);
  cursor: pointer;
  transform: translateZ(0);
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.drop-core:active {
  transform: scale(0.985) translateZ(0);
}

.app.is-dragging .drop-core {
  border-color: var(--accent);
  background:
    radial-gradient(circle at 50% 36%, rgba(61, 230, 194, 0.28), transparent 42%),
    rgba(255, 255, 255, 0.08);
}

.drop-title {
  font-size: clamp(28px, 7vw, 48px);
  font-weight: 740;
  letter-spacing: 0;
}

.drop-subtitle {
  color: var(--muted);
  font-size: 14px;
}

.file-input {
  position: fixed;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.chrome-button,
.tool-button {
  position: absolute;
  z-index: 12;
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border: 1px solid var(--stroke);
  border-radius: 50%;
  background: rgba(8, 10, 14, 0.54);
  backdrop-filter: blur(18px) saturate(160%);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.26);
  cursor: pointer;
  transform: translateZ(0);
  transition: opacity 160ms ease, transform 160ms ease, border-color 160ms ease;
}

.chrome-button:active,
.tool-button:active {
  transform: scale(0.96) translateZ(0);
}

.top-left {
  left: calc(16px + var(--safe-left));
  top: calc(16px + var(--safe-top));
}

.top-right {
  right: calc(16px + var(--safe-right));
  top: calc(16px + var(--safe-top));
}

.bottom-left {
  left: calc(16px + var(--safe-left));
  bottom: calc(16px + var(--safe-bottom));
}

.bottom-right {
  right: calc(16px + var(--safe-right));
  bottom: calc(16px + var(--safe-bottom));
}

.tool-button {
  left: 50%;
  top: calc(14px + var(--safe-top));
  transform: translateX(-50%) translateZ(0);
}

.tool-button:active {
  transform: translateX(-50%) scale(0.96) translateZ(0);
}

.triangle {
  width: 0;
  height: 0;
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  border-top: 14px solid #fff;
}

.icon,
.tool-glyph {
  position: relative;
  display: inline-block;
}

.icon-menu,
.icon-list {
  width: 22px;
  height: 16px;
  border-top: 2px solid #fff;
  border-bottom: 2px solid #fff;
}

.icon-menu::before,
.icon-list::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 5px;
  border-top: 2px solid #fff;
}

.icon-list::after {
  content: "";
  position: absolute;
  left: 2px;
  top: -6px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 7px 0 #fff, 0 14px 0 #fff;
}

.icon-back {
  width: 24px;
  height: 24px;
}

.icon-back::before {
  content: "";
  position: absolute;
  width: 15px;
  height: 15px;
  left: 4px;
  top: 4px;
  border-left: 2px solid #fff;
  border-bottom: 2px solid #fff;
  transform: rotate(45deg);
}

.icon-back::after {
  content: "";
  position: absolute;
  width: 21px;
  height: 2px;
  left: 5px;
  top: 11px;
  background: #fff;
}

.icon-fullscreen {
  width: 24px;
  height: 24px;
}

.icon-fullscreen::before,
.icon-fullscreen::after {
  content: "";
  position: absolute;
  inset: 1px;
  border: 2px solid #fff;
}

.icon-fullscreen::before {
  clip-path: polygon(0 0, 42% 0, 42% 18%, 18% 18%, 18% 42%, 0 42%);
}

.icon-fullscreen::after {
  clip-path: polygon(58% 0, 100% 0, 100% 42%, 82% 42%, 82% 18%, 58% 18%, 58% 0, 100% 58%, 100% 100%, 58% 100%, 58% 82%, 82% 82%, 82% 58%);
}

.icon-compare {
  width: 24px;
  height: 24px;
  border: 2px solid #fff;
  border-radius: 50%;
}

.icon-compare::before {
  content: "";
  position: absolute;
  inset: -2px 10px -2px auto;
  border-left: 2px solid #fff;
}

.tool-menu {
  position: absolute;
  z-index: 11;
  left: 50%;
  top: calc(74px + var(--safe-top));
  display: grid;
  gap: 8px;
  width: min(320px, calc(100vw - 32px));
  padding: 10px;
  border: 1px solid var(--stroke);
  border-radius: 18px;
  background: rgba(13, 16, 21, 0.9);
  backdrop-filter: blur(24px) saturate(160%);
  -webkit-backdrop-filter: blur(24px) saturate(160%);
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.36);
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) translateY(-8px) translateZ(0);
  transition: opacity 160ms ease, transform 160ms ease;
}

.tool-menu.is-open {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0) translateZ(0);
}

.tool-item {
  height: 52px;
  display: grid;
  grid-template-columns: 42px 1fr;
  align-items: center;
  gap: 10px;
  border: 1px solid transparent;
  border-radius: 14px;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.tool-item.is-active,
.tool-item:active {
  border-color: rgba(61, 230, 194, 0.42);
  background: rgba(61, 230, 194, 0.12);
}

.number-glyph {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border: 2px solid #fff;
  border-radius: 50%;
  font-weight: 800;
}

.arrow-glyph {
  width: 32px;
  height: 16px;
  border-bottom: 2px solid #fff;
  border-radius: 0 0 30px 30px;
  transform: rotate(-18deg);
}

.arrow-glyph::after {
  content: "";
  position: absolute;
  right: -2px;
  bottom: -5px;
  width: 9px;
  height: 9px;
  border-right: 2px solid #fff;
  border-bottom: 2px solid #fff;
  transform: rotate(-35deg);
}

.dot-glyph {
  width: 16px;
  height: 16px;
  margin-left: 7px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 7px rgba(255, 255, 255, 0.16);
}

.project-only {
  opacity: 1;
}

.app.is-home .project-only,
.app.is-home .tool-button,
.app.is-home .tool-menu {
  opacity: 0;
  pointer-events: none;
}

.drawer {
  position: absolute;
  z-index: 20;
  top: 0;
  bottom: 0;
  width: min(380px, 88vw);
  padding: calc(18px + var(--safe-top)) 14px calc(18px + var(--safe-bottom));
  background: rgba(10, 13, 18, 0.94);
  border-color: var(--stroke);
  backdrop-filter: blur(24px) saturate(150%);
  -webkit-backdrop-filter: blur(24px) saturate(150%);
  box-shadow: 0 0 80px rgba(0, 0, 0, 0.42);
  transform: translateX(-105%);
  transition: transform 200ms ease;
}

.drawer-right {
  right: 0;
  transform: translateX(105%);
  border-left: 1px solid var(--stroke);
}

.drawer-left {
  left: 0;
  border-right: 1px solid var(--stroke);
}

.drawer.is-open {
  transform: translateX(0);
}

.drawer-header,
.editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.drawer-header strong,
.editor-header strong,
.export-sheet strong {
  font-size: 16px;
  letter-spacing: 0;
}

.drawer-list {
  display: grid;
  gap: 10px;
  margin-top: 18px;
  max-height: calc(100dvh - 96px);
  overflow: auto;
  padding-bottom: 20px;
}

.drawer-empty {
  min-height: 140px;
  display: grid;
  place-items: center;
  color: var(--muted);
  border: 1px dashed var(--stroke);
  border-radius: 14px;
}

.list-card {
  display: grid;
  gap: 7px;
  padding: 12px;
  border: 1px solid var(--stroke);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.055);
}

.list-card button {
  cursor: pointer;
}

.list-main {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: start;
}

.list-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 720;
}

.list-meta {
  color: var(--muted);
  font-size: 12px;
}

.list-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.plain-button,
.secondary-button,
.primary-button,
.sheet-button {
  min-height: 38px;
  border: 1px solid var(--stroke);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  padding: 0 13px;
  cursor: pointer;
}

.plain-button {
  min-height: 34px;
  color: var(--muted);
  background: transparent;
}

.primary-button {
  border-color: rgba(61, 230, 194, 0.62);
  background: rgba(61, 230, 194, 0.18);
  color: #eafffa;
}

.secondary-button {
  color: #ffdada;
  border-color: rgba(255, 107, 107, 0.42);
  background: rgba(255, 107, 107, 0.1);
}

.editor-panel,
.export-sheet {
  position: absolute;
  z-index: 24;
  left: max(12px, var(--safe-left));
  right: max(12px, var(--safe-right));
  bottom: calc(12px + var(--safe-bottom));
  display: grid;
  gap: 12px;
  padding: 10px 12px 12px;
  border: 1px solid var(--stroke);
  border-radius: 20px;
  background: rgba(12, 15, 21, 0.92);
  backdrop-filter: blur(24px) saturate(160%);
  -webkit-backdrop-filter: blur(24px) saturate(160%);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.42);
  transform: translateY(calc(100% + 28px));
  transition: transform 200ms ease;
}

.editor-panel {
  gap: 8px;
  padding: 8px 10px 10px;
}

.editor-panel.is-open,
.export-sheet.is-open {
  transform: translateY(0);
}

.editor-handle {
  justify-self: center;
  width: 42px;
  height: 4px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.26);
  cursor: pointer;
}

.editor-strip {
  display: grid;
  grid-template-columns: 1fr 44px;
  gap: 8px;
  align-items: center;
}

.editor-expanded {
  display: none;
  gap: 12px;
}

.editor-panel.is-expanded .editor-expanded {
  display: grid;
}

textarea {
  width: 100%;
  min-height: 92px;
  resize: vertical;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 14px;
  padding: 12px;
  outline: none;
  color: var(--text);
  background: rgba(255, 255, 255, 0.07);
  line-height: 1.5;
}

textarea:focus {
  border-color: rgba(61, 230, 194, 0.62);
}

.segmented-control {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--stroke);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.055);
}

.segment-button {
  min-height: 38px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.segment-button.is-active {
  background: rgba(255, 255, 255, 0.13);
  color: var(--text);
}

.segment-icon {
  position: relative;
  display: inline-block;
  width: 26px;
  height: 22px;
}

.segment-label-icon {
  border: 2px solid currentColor;
  border-radius: 7px;
}

.segment-label-icon::before {
  content: "";
  position: absolute;
  left: 5px;
  right: 5px;
  top: 6px;
  border-top: 2px solid currentColor;
  box-shadow: 0 6px 0 currentColor;
}

.segment-marker-icon::before,
.segment-marker-icon::after {
  content: "";
  position: absolute;
  border-radius: 50%;
}

.segment-marker-icon::before {
  left: 4px;
  top: 2px;
  width: 18px;
  height: 18px;
  border: 2px solid currentColor;
}

.segment-marker-icon::after {
  left: 11px;
  top: 9px;
  width: 8px;
  height: 8px;
  background: currentColor;
}

.confirm-button {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(61, 230, 194, 0.5);
  border-radius: 14px;
  background: rgba(61, 230, 194, 0.16);
  color: #eafffa;
  cursor: pointer;
}

.check-icon {
  width: 18px;
  height: 10px;
  border-left: 3px solid currentColor;
  border-bottom: 3px solid currentColor;
  transform: rotate(-45deg) translateY(-2px);
}

.frame-toggle {
  min-height: 34px;
  display: inline-grid;
  grid-template-columns: 20px auto;
  gap: 8px;
  align-items: center;
  padding: 0 10px;
  border: 1px solid var(--stroke);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
}

.frame-toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.frame-toggle:has(input:checked) {
  border-color: rgba(61, 230, 194, 0.48);
  background: rgba(61, 230, 194, 0.12);
  color: var(--text);
}

.frame-icon {
  width: 20px;
  height: 14px;
  border: 2px solid currentColor;
  border-radius: 5px;
}

.rgba-panel {
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: 8px;
  align-items: center;
}

.color-picker {
  width: 52px;
  height: 34px;
  border: 1px solid var(--stroke);
  border-radius: 10px;
  background: transparent;
  padding: 0;
}

.rgba-row {
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: 6px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
}

.rgba-row input {
  width: 100%;
  accent-color: var(--accent);
}

.export-sheet {
  z-index: 30;
}

.sheet-button {
  width: 100%;
  min-height: 48px;
  text-align: left;
}

.arrow-done {
  position: absolute;
  z-index: 13;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  min-width: 112px;
  height: 48px;
  border: 1px solid rgba(61, 230, 194, 0.52);
  border-radius: 999px;
  background: rgba(61, 230, 194, 0.18);
  color: #eafffa;
  box-shadow: 0 16px 46px rgba(0, 0, 0, 0.34);
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) translateY(12px) translateZ(0);
  transition: opacity 160ms ease, transform 160ms ease;
}

.arrow-done.is-visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0) translateZ(0);
}

.hold-progress {
  position: absolute;
  z-index: 32;
  left: 50%;
  top: 50%;
  width: 82px;
  height: 82px;
  margin-left: -41px;
  margin-top: -41px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.48);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  opacity: 0;
  pointer-events: none;
  transform: scale(0.92);
  transition: opacity 120ms ease, transform 120ms ease;
}

.hold-progress.is-visible {
  opacity: 1;
  transform: scale(1);
}

.hold-progress svg {
  width: 72px;
  height: 72px;
  transform: rotate(-90deg);
}

.hold-progress circle {
  fill: none;
  stroke-width: 5;
  stroke: rgba(255, 255, 255, 0.18);
}

#holdProgressRing {
  stroke: #fff;
  stroke-dasharray: 188.5;
  stroke-dashoffset: 188.5;
  transition: stroke-dashoffset 80ms linear;
}

.toast {
  position: absolute;
  z-index: 40;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  max-width: min(460px, calc(100vw - 32px));
  padding: 11px 14px;
  border: 1px solid var(--stroke);
  border-radius: 999px;
  background: rgba(13, 16, 21, 0.92);
  color: var(--text);
  box-shadow: 0 16px 46px rgba(0, 0, 0, 0.34);
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) translateY(10px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.app.is-presentation .chrome-button,
.app.is-presentation .tool-button,
.app.is-presentation .tool-menu,
.app.is-presentation .drawer,
.app.is-presentation .editor-panel,
.app.is-presentation .arrow-done {
  opacity: 0;
  pointer-events: none;
}

.app.is-comparing .chrome-button,
.app.is-comparing .tool-button,
.app.is-comparing .tool-menu,
.app.is-comparing .drawer,
.app.is-comparing .editor-panel,
.app.is-comparing .arrow-done,
.app.is-comparing .export-sheet {
  opacity: 0;
  pointer-events: none;
}

@media (min-width: 720px) {
  .editor-panel,
  .export-sheet {
    left: 50%;
    right: auto;
    width: min(620px, calc(100vw - 32px));
    transform: translateX(-50%) translateY(calc(100% + 28px));
  }

  .editor-panel.is-open,
  .export-sheet.is-open {
    transform: translateX(-50%) translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
