:root {
  --ut-bg: #0a1d4d;
  --ut-bg-deep: #030b24;
  --ut-card: #1e293b;
  --ut-accent: #f7d106;
  --ut-text: #f8fafc;
  --ut-muted: #94a3b8;
  --ut-border: #334155;
  --ut-danger: #ef4444;
  --ut-success: #10b981;
  --ut-radius: 12px;
  --ut-space-1: 6px;
  --ut-space-2: 10px;
  --ut-space-3: 14px;
  --ut-space-4: 18px;
  --ut-shadow-sm: 0 8px 18px rgba(2, 6, 23, 0.28);
  --ut-shadow-md: 0 14px 28px rgba(2, 6, 23, 0.34);
  --ut-shadow-lg: 0 18px 36px rgba(2, 6, 23, 0.42);
  --ut-surface-hero: rgba(13, 28, 66, 0.92);
  --ut-surface-soft: rgba(30, 41, 59, 0.68);
  --ut-safe-bottom: calc(env(safe-area-inset-bottom, 0px) + 10px);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: #0b1f63;
}

body {
  padding: calc(env(safe-area-inset-top, 0px) + 24px) 12px 12px;
  background: radial-gradient(circle at top, var(--ut-bg), var(--ut-bg-deep));
  color: var(--ut-text);
  font-family: 'Inter', system-ui, sans-serif;
  min-height: 100dvh;
  line-height: 1.5;
}

@media (display-mode: standalone) {
  body {
    min-height: 100vh;
    padding-top: calc(env(safe-area-inset-top, 0px) + 24px);
  }
}

.container {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.app-footer {
  max-width: 900px;
  margin: 10px auto 12px;
  padding: 0 12px;
  text-align: center;
}

.app-footer p {
  margin: 0;
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: rgba(203, 213, 225, 0.88);
}

/* Generic App Header */
.app-header {
  max-width: 900px;
  margin: 0 auto 16px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.72), rgba(15, 23, 42, 0.52));
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 14px 28px rgba(2, 6, 23, 0.28);
  backdrop-filter: blur(8px);
}

.app-header__icon {
  width: 68px;
  height: 68px;
  flex: 0 0 68px;
  display: block;
  overflow: hidden;
  border-radius: 16px;
  background: radial-gradient(circle at top left, rgba(247, 209, 6, 0.24), rgba(247, 209, 6, 0.07));
  border: 1px solid rgba(247, 209, 6, 0.28);
  color: #f7d106;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08), 0 6px 16px rgba(2, 6, 23, 0.22);
}

.app-header__logo {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.app-header__text {
  min-width: 0;
}

.app-header__eyebrow {
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(248, 250, 252, 0.72);
  margin-bottom: 3px;
}

.app-header__title {
  margin: 0;
  font-size: clamp(1.45rem, 2.8vw, 2rem);
  line-height: 1;
  font-weight: 800;
  color: #ffffff;
}

.app-header__subtitle {
  margin: 6px 0 0;
  font-size: 0.88rem;
  color: #cbd5e1;
  line-height: 1.4;
}

/* Compact guide */
.guide-wrap {
  position: relative;
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  justify-content: flex-start;
  z-index: 20;
}

.guide-popover {
  position: relative;
  display: inline-block;
}

.guide-popover summary {
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 9px 14px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.78);
  border: 1px solid rgba(148, 163, 184, 0.22);
  color: #dbeafe;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: 0 10px 22px rgba(2, 6, 23, 0.18);
  user-select: none;
}

.guide-popover summary::-webkit-details-marker {
  display: none;
}

.guide-popover summary::before {
  content: "i";
  width: 1.08rem;
  height: 1.08rem;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(247, 209, 6, 0.72);
  color: var(--ut-accent);
  font-size: 0.74rem;
  font-weight: 700;
  line-height: 1;
  text-transform: lowercase;
}

.guide-popover[open] summary {
  border-color: rgba(247, 209, 6, 0.45);
  color: #ffffff;
}

.guide-panel {
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  width: min(340px, calc(100vw - 28px));
  padding: 14px;
  border-radius: 16px;
  background: rgba(15, 23, 42, 0.96);
  border: 1px solid rgba(148, 163, 184, 0.22);
  box-shadow: 0 24px 48px rgba(2, 6, 23, 0.34);
  backdrop-filter: blur(8px);
}

.guide-step + .guide-step {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.guide-step strong {
  display: block;
  margin-bottom: 3px;
  font-size: 0.8rem;
  color: #ffffff;
}

.guide-step p {
  margin: 0;
  font-size: 0.76rem;
  line-height: 1.45;
  color: #cbd5e1;
}

/* Card */
.card {
  background: rgba(30, 41, 59, 0.7);
  border-radius: var(--ut-radius);
  padding: 16px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(6px);
  min-width: 0;
  overflow-x: hidden;
}

.card h2 {
  font-weight: 700;
  font-size: 0.82rem;
  color: var(--ut-text);
  margin: 0 0 12px 0;
  text-transform: uppercase;
  border-bottom: 1px solid var(--ut-border);
  padding-bottom: 8px;
}

.photo-card-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.photo-card-topline h2 {
  margin-bottom: 0;
  border-bottom: none;
  padding-bottom: 0;
}

.photo-status-chips {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  color: #dbeafe;
  background: rgba(15, 23, 42, 0.64);
  border: 1px solid rgba(148, 163, 184, 0.25);
  transition: 0.25s ease;
}

.status-chip-btn {
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  font-family: inherit;
}

.status-chip-btn:hover {
  border-color: rgba(96, 165, 250, 0.45);
  color: #eff6ff;
}

.status-chip.is-ok {
  color: #dcfce7;
  border-color: rgba(74, 222, 128, 0.4);
  background: rgba(20, 83, 45, 0.54);
}

.status-chip.is-perspective {
  color: #fef9c3;
  border-color: rgba(250, 204, 21, 0.45);
  background: rgba(113, 63, 18, 0.45);
}

.next-step-banner {
  margin-top: 6px;
  margin-bottom: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(247, 209, 6, 0.35);
  background: linear-gradient(135deg, rgba(247, 209, 6, 0.12), rgba(15, 23, 42, 0.55));
  color: #fef3c7;
  display: flex;
  align-items: center;
  gap: 10px;
}

.next-step-label {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.62rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  border: 1px solid rgba(247, 209, 6, 0.5);
  background: rgba(247, 209, 6, 0.16);
}

.next-step-text {
  font-size: 0.82rem;
  font-weight: 700;
}

body[data-mobile-next-action="photo"] #nextStepBanner { border-color: rgba(59, 130, 246, 0.38); color: #bfdbfe; }
body[data-mobile-next-action="shape"] #nextStepBanner { border-color: rgba(247, 209, 6, 0.35); color: #fef3c7; }
body[data-mobile-next-action="scale"] #nextStepBanner { border-color: rgba(56, 189, 248, 0.35); color: #bae6fd; }
body[data-mobile-next-action="export"] #nextStepBanner { border-color: rgba(16, 185, 129, 0.35); color: #d1fae5; }

/* Buttons */
button {
  border: none;
  cursor: pointer;
  font-family: inherit;
}

.btn {
  padding: 12px 14px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 0.75rem;
  text-transform: uppercase;
  transition: 0.2s;
  font-family: inherit;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: var(--ut-accent);
  color: #111;
}

.btn-secondary {
  background: #334155;
  color: #fff;
}

.btn-danger-outline {
  background: transparent;
  color: var(--ut-danger);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.btn-success {
  background: var(--ut-success);
  color: #fff;
}

.btn-archive {
  background: #6366f1;
  color: #fff;
}

/* Photo Section Layout */
.photo-controls {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  margin-bottom: 12px;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  padding-bottom: 4px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.photo-controls::-webkit-scrollbar {
  display: none;
}

.photo-controls .btn {
  flex: 0 0 auto;
  white-space: nowrap;
  padding: 10px 16px;
  font-size: 0.78rem;
  min-height: 44px;
}

.photo-controls .tool-btn {
  position: relative;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.photo-controls .tool-btn.tool-active {
  background: linear-gradient(135deg, #ffe45c 0%, #f7d106 100%);
  color: #111827;
  border-color: rgba(247, 209, 6, 0.85);
  box-shadow: 0 12px 28px rgba(247, 209, 6, 0.22);
  transform: translateY(-1px);
}

.photo-controls .tool-btn.tool-active::after {
  content: "ACTIVE";
  position: absolute;
  top: 5px;
  right: 8px;
  font-size: 0.52rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  opacity: 0.65;
}

/* Shape Selector */
#tapShapeSelector {
  display: none;
  gap: 8px;
  margin-bottom: 12px;
  justify-content: space-between;
}

.shape-btn {
  flex: 1;
  text-align: center;
  padding: 10px 4px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--ut-muted);
  border: 1px solid var(--ut-border);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  transition: all 0.2s ease;
  user-select: none;
}

input[name="tapToolShape"]:checked + .shape-btn {
  background: var(--ut-accent);
  color: #111;
  border-color: var(--ut-accent);
  box-shadow: 0 4px 12px rgba(247, 209, 6, 0.3);
  transform: translateY(-1px);
}

/* Imagine area */
.preview-controls {
  margin-bottom: 12px;
  padding: 14px;
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(16, 185, 129, 0.08), rgba(30, 41, 59, 0.5));
  border: 1px solid rgba(16, 185, 129, 0.24);
}

.preview-guidance-title {
  font-size: 0.82rem;
  font-weight: 800;
  color: #d1fae5;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.preview-guidance p {
  margin: 6px 0 0;
  color: #dbe7f5;
  font-size: 0.82rem;
}

.imagine-prompt-label {
  display: block;
  margin: 14px 0 6px;
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #a7f3d0;
}

.imagine-prompt-input {
  width: 100%;
  min-height: 120px;
  resize: vertical;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.24);
  background: rgba(15, 23, 42, 0.72);
  color: #fff;
  padding: 12px 14px;
  font: inherit;
  line-height: 1.45;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.02);
}

.imagine-prompt-input:focus {
  outline: none;
  border-color: rgba(247, 209, 6, 0.7);
  box-shadow: 0 0 0 3px rgba(247, 209, 6, 0.12);
}

.preview-preset-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.preview-context-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.preset-chip {
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.04);
  color: var(--ut-text);
  font-size: 0.78rem;
  font-weight: 700;
}

.preset-chip[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
}

.preset-chip.is-active {
  background: rgba(16, 185, 129, 0.16);
  border-color: rgba(16, 185, 129, 0.75);
  color: #d1fae5;
  box-shadow: 0 8px 18px rgba(16, 185, 129, 0.15);
}

.preview-context-modal-actions {
  margin-top: 10px;
}

.preview-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.preview-status {
  min-height: 1.2em;
  margin-top: 12px;
  font-size: 0.8rem;
  color: #bfdbfe;
}

.preview-status.is-error {
  color: #fecaca;
}

.preview-status.is-success {
  color: #d1fae5;
}

.preview-diagnostics {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid rgba(148, 163, 184, 0.22);
  font-size: 0.75rem;
  color: #dbeafe;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.preview-diagnostics.is-error {
  border-color: rgba(248, 113, 113, 0.35);
  color: #fecaca;
}

.preview-diagnostics.is-success {
  border-color: rgba(74, 222, 128, 0.28);
  color: #dcfce7;
}

.film-preview-panel {
  margin-top: 12px;
  padding: 12px;
  border-radius: 14px;
  background: rgba(7, 14, 34, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.film-preview-stage {
  position: relative;
  overflow: hidden;
  border-radius: 12px;
  background: #020617;
  min-height: 180px;
}

.preview-result-badge {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 2;
  padding: 7px 10px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.88);
  border: 1px solid rgba(148, 163, 184, 0.35);
  color: #e2e8f0;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  box-shadow: 0 10px 24px rgba(2, 6, 23, 0.35);
}

.preview-result-badge.is-ai {
  background: rgba(20, 83, 45, 0.9);
  border-color: rgba(74, 222, 128, 0.45);
  color: #dcfce7;
}

.preview-result-badge.is-fallback {
  background: rgba(127, 29, 29, 0.9);
  border-color: rgba(248, 113, 113, 0.45);
  color: #fee2e2;
}

.film-preview-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 180px;
  padding: 20px;
  color: var(--ut-muted);
  font-size: 0.82rem;
  text-align: center;
}

.film-preview-image {
  display: none;
}

.film-preview-panel.has-result .film-preview-empty {
  display: none;
}

.film-preview-panel.has-result .film-preview-image {
  display: block;
}

.film-preview-image {
  width: 100%;
  height: auto;
  object-fit: contain;
  max-height: 70vh;
}

/* Selection bar */
#selectionBar {
  display: none;
  flex-direction: column;
  gap: 10px;
  background: rgba(247, 209, 6, 0.08);
  border: 1px solid rgba(247, 209, 6, 0.3);
  border-radius: 10px;
  padding: 12px;
  margin-top: 12px;
  margin-bottom: 4px;
}

#selectionHint {
  font-size: 0.85rem;
  color: var(--ut-accent);
  font-weight: 700;
  text-align: center;
}

.sel-btns {
  display: flex;
  gap: 8px;
  justify-content: center;
  width: 100%;
  flex-wrap: wrap;
}

.sel-btns button {
  padding: 10px 20px;
  font-size: 0.8rem;
  border-radius: 999px;
  font-weight: 700;
  font-family: inherit;
  transition: transform 0.2s, box-shadow 0.2s;
}

.sel-btns button:hover {
  transform: translateY(-1px);
}

.sel-btns .btn-confirm {
  background: var(--ut-success);
  color: #fff;
}

.sel-btns .btn-cancel {
  background: var(--ut-card);
  color: var(--ut-muted);
  border: 1px solid var(--ut-border);
}

.sel-btns .btn-addwin {
  background: var(--ut-accent);
  color: #111;
  box-shadow: 0 2px 8px rgba(247, 209, 6, 0.3);
}

#undoBtn {
  background: var(--ut-danger);
  color: white;
  border: none;
  padding: 10px 20px;
  font-size: 0.8rem;
  border-radius: 999px;
  font-weight: 700;
  cursor: pointer;
  display: none;
  transition: 0.2s;
  box-shadow: 0 2px 8px rgba(239, 68, 68, 0.4);
}

#undoBtn:hover {
  transform: translateY(-1px);
}

#undoBtn.visible {
  display: inline-block !important;
}

/* Thumbnails */
#thumbSection {
  display: none;
  position: relative;
  width: 100%;
  padding-top: 8px;
}

#thumbCount {
  font-size: 0.72rem;
  color: var(--ut-muted);
  text-align: left;
  margin-bottom: 6px;
  min-height: 1em;
  font-weight: 600;
}

#thumbBarWrapper {
  position: relative;
  width: 100%;
}

#thumbBar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: rgba(247, 209, 6, 0.4) transparent;
}

#thumbBar::-webkit-scrollbar {
  height: 4px;
}

#thumbBar::-webkit-scrollbar-thumb {
  background: rgba(247, 209, 6, 0.4);
  border-radius: 4px;
}

.thumb-wrap {
  position: relative;
  flex-shrink: 0;
  width: 68px;
  height: 68px;
}

.thumb {
  width: 68px;
  height: 68px;
  object-fit: cover;
  border-radius: 10px;
  border: 2px solid rgba(255, 255, 255, 0.15);
  cursor: pointer;
  display: block;
  transition: border-color 0.2s;
}

.thumb.active {
  border-color: var(--ut-accent);
}

.thumb-delete {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--ut-danger);
  color: white;
  font-size: 11px;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
  cursor: pointer;
  border: 1.5px solid var(--ut-bg-deep);
  opacity: 0;
  transform: scale(0.7);
  transition: opacity 0.18s, transform 0.18s;
  min-width: unset;
  padding: 0;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
  z-index: 5;
}

.thumb-wrap:hover .thumb-delete {
  opacity: 1;
  transform: scale(1);
}

/* Hidden compatibility data store */
#annotationDataStore {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

/* Mobile controls */
.mobile-action-bar,
.mobile-tools-sheet,
.mobile-tools-sheet-backdrop {
  display: none;
}

.mobile-tools-sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.5);
  z-index: 96;
}

.mobile-tools-sheet {
  position: fixed;
  left: 10px;
  right: 10px;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 82px);
  z-index: 97;
  border-radius: 16px;
  background: rgba(15, 23, 42, 0.96);
  border: 1px solid rgba(148, 163, 184, 0.25);
  box-shadow: var(--ut-shadow-lg);
  transform: translateY(14px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.24s ease, opacity 0.24s ease;
}

.mobile-tools-sheet.is-open {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}

.mobile-tools-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px 10px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.2);
}

.mobile-tools-head strong {
  font-size: 0.82rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.mobile-sheet-close {
  min-height: 34px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(51, 65, 85, 0.95);
  color: #f8fafc;
  font-size: 0.72rem;
  font-weight: 700;
}

.mobile-tools-grid {
  padding: 12px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.mobile-sheet-tool {
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  background: rgba(30, 41, 59, 0.9);
  color: #e2e8f0;
  font-size: 0.76rem;
  font-weight: 700;
}

.mobile-sheet-tool-danger {
  color: #fecaca;
  border-color: rgba(248, 113, 113, 0.35);
}

.mobile-action-bar {
  position: fixed;
  left: 8px;
  right: 8px;
  bottom: var(--ut-safe-bottom);
  z-index: 98;
  border-radius: 16px;
  padding: 8px;
  background: rgba(2, 6, 23, 0.93);
  border: 1px solid rgba(148, 163, 184, 0.24);
  box-shadow: var(--ut-shadow-lg);
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  transform: translateY(6px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.24s ease, opacity 0.24s ease;
}

.mobile-action-btn {
  min-height: 56px;
  border-radius: 14px;
  padding: 8px 4px 7px;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid rgba(51, 65, 85, 0.95);
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: transform 0.15s ease, box-shadow 0.2s ease, border-color 0.2s ease, color 0.2s ease, background 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.mobile-action-btn:active {
  transform: scale(0.97);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}

.mobile-action-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  color: currentColor;
}

.mobile-action-icon svg {
  width: 20px;
  height: 20px;
  display: block;
}

.mobile-action-label {
  display: block;
  font-size: 0.64rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  line-height: 1;
}

.mobile-action-btn.is-active {
  color: #111827;
  border-color: rgba(247, 209, 6, 0.9);
  background: linear-gradient(135deg, #fde68a, #f7d106);
  box-shadow: 0 8px 20px rgba(247, 209, 6, 0.26);
}

.mobile-action-btn.is-recommended {
  border-color: rgba(125, 211, 252, 0.8);
  box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.45) inset;
}

.mobile-action-more {
  opacity: 0.9;
}

/* Preview Container */
#previewContainer {
  position: relative;
  width: calc(100% - 30px);
  margin: 0 15px;
  border-radius: var(--ut-radius);
  overflow: hidden;
  background: #000;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

#imageWrapper {
  position: relative;
  transform-origin: 0 0;
  will-change: transform;
  touch-action: none;
}

#previewImg {
  width: 100%;
  display: block;
  pointer-events: none;
}

#drawCanvas,
#selectCanvas {
  position: absolute;
  inset: 0;
}

#drawCanvas {
  touch-action: none;
  background: transparent;
}

#selectCanvas {
  touch-action: none;
  display: none;
  pointer-events: none;
  background: transparent;
}

/* Empty state */
#emptyState {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  min-height: 200px;
  border: 2px dashed rgba(247, 209, 6, 0.35);
  border-radius: var(--ut-radius);
  background: rgba(28, 39, 72, 0.35);
  cursor: pointer;
  padding: 28px 16px;
  text-align: center;
  user-select: none;
  transition: border-color 0.25s;
}

#emptyState:hover {
  border-color: rgba(247, 209, 6, 0.75);
}

.empty-icon {
  width: 48px;
  height: 48px;
  opacity: 0.55;
}

.empty-title {
  font-size: 1rem;
  font-weight: 700;
  margin: 0;
}

.empty-sub {
  font-size: 0.82rem;
  color: var(--ut-muted);
  margin: 0;
  max-width: 240px;
  line-height: 1.5;
}

.empty-cta {
  background: var(--ut-accent);
  color: #111;
  font-weight: 700;
  padding: 8px 20px;
  border-radius: 999px;
  font-size: 0.88rem;
  pointer-events: none;
}

/* Form toggles and modals */
.toggle-label {
  background: var(--ut-bg-deep);
  border: 1px solid var(--ut-border);
  padding: 7px 11px;
  border-radius: 20px;
  font-size: 0.72rem;
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  font-weight: 600;
}

.toggle-label input {
  accent-color: var(--ut-accent);
}

.modal {
  display: none;
  position: fixed;
  z-index: 9000;
  inset: 0;
  background: rgba(2, 8, 23, 0.72);
  backdrop-filter: blur(6px);
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-box {
  width: min(92vw, 420px);
  background: rgba(15, 23, 42, 0.98);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  padding: 18px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}

.modal-box h3 {
  margin: 0 0 8px 0;
  color: var(--ut-text);
}

.modal-box p {
  margin: 0 0 12px 0;
  color: var(--ut-muted);
  font-size: 0.86rem;
  line-height: 1.5;
}

.modal-box label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--ut-accent);
}

.modal-box input,
.modal-box select {
  width: 100%;
  background: var(--ut-bg-deep);
  color: white;
  padding: 12px;
  border: 1px solid var(--ut-border);
  border-radius: 8px;
  font-size: 16px;
  outline: none;
  font-family: inherit;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.modal-box input:focus,
.modal-box select:focus {
  border-color: var(--ut-accent);
  box-shadow: 0 0 0 3px rgba(247, 209, 6, 0.14);
}

.modal-buttons {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.modal-buttons .btn-save,
.modal-buttons .btn-cancel {
  padding: 10px 16px;
  border-radius: 8px;
  font-weight: 800;
  font-size: 0.8rem;
}

.modal-buttons .btn-save {
  background: var(--ut-accent);
  color: #111;
}

.modal-buttons .btn-cancel {
  background: #334155;
  color: #fff;
}

.toast-container {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 2100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  min-width: 220px;
  max-width: min(88vw, 360px);
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(3, 11, 36, 0.95);
  color: #fff;
  font-size: 0.82rem;
  font-weight: 700;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
}

.toast.is-success {
  border-color: rgba(16, 185, 129, 0.5);
}

.toast.is-error {
  border-color: rgba(239, 68, 68, 0.55);
}

@media (max-width: 720px) {
  body {
    padding: calc(env(safe-area-inset-top, 0px) + 24px) 10px calc(118px + env(safe-area-inset-bottom, 0px));
  }

  .app-footer {
    margin: 10px auto calc(84px + env(safe-area-inset-bottom, 0px));
    padding: 0 8px;
  }

  .container,
  .app-header {
    max-width: 100%;
  }

  .app-header {
    padding: 12px 14px;
    gap: 12px;
    border-radius: 16px;
  }

  .app-header__icon {
    width: 58px;
    height: 58px;
    flex-basis: 58px;
    border-radius: 14px;
  }

  .app-header__logo {
    border-radius: 13px;
  }

  .app-header__eyebrow {
    font-size: 0.62rem;
  }

  .app-header__subtitle {
    font-size: 0.8rem;
  }

  .guide-panel {
    width: min(320px, calc(100vw - 24px));
  }

  .card {
    padding: 14px;
    border-radius: 14px;
  }

  #photoCard {
    background: var(--ut-surface-hero);
    border: 1px solid rgba(247, 209, 6, 0.16);
    box-shadow: var(--ut-shadow-md);
  }

  .photo-card-topline {
    align-items: flex-start;
  }

  .photo-card-topline h2 {
    font-size: 0.78rem;
  }

  .photo-status-chips {
    justify-content: flex-start;
  }

  .status-chip {
    min-height: 24px;
    font-size: 0.64rem;
  }

  .next-step-banner {
    min-height: 44px;
    margin-bottom: 10px;
  }

  .photo-measure-tools {
    display: none;
  }

  #tapShapeSelector {
    margin-bottom: 10px;
  }

  #previewContainer {
    width: 100%;
    margin: 0;
    border-radius: 14px;
  }

  #emptyState {
    min-height: clamp(256px, 42vh, 416px);
  }

  .imagine-prompt-input {
    min-height: 110px;
  }

  #thumbSection {
    position: static;
    left: auto;
    right: auto;
    bottom: auto;
    z-index: auto;
    border-radius: 14px;
    border: 1px solid rgba(148, 163, 184, 0.24);
    background: rgba(2, 6, 23, 0.92);
    backdrop-filter: blur(7px);
    box-shadow: var(--ut-shadow-sm);
    padding: 8px 10px 6px;
    margin-top: 10px;
  }

  #thumbCount {
    margin-bottom: 4px;
    font-size: 0.66rem;
  }

  #thumbBar {
    gap: 9px;
    scroll-snap-type: x mandatory;
    padding-bottom: 2px;
  }

  .thumb-wrap {
    width: 72px;
    height: 72px;
    scroll-snap-align: start;
  }

  .thumb {
    width: 72px;
    height: 72px;
    border-radius: 12px;
    transition: transform 0.2s ease, border-color 0.2s ease;
  }

  .thumb.active {
    transform: translateY(-2px) scale(1.04);
  }

  .mobile-action-bar,
  .mobile-tools-sheet,
  .mobile-tools-sheet-backdrop {
    display: block;
  }

  .mobile-action-bar {
    display: grid;
  }

  body[data-mobile-tools-open="true"] .mobile-tools-sheet-backdrop {
    opacity: 1;
  }

  body[data-mobile-tools-open="true"] .mobile-tools-sheet {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
  }

  body[data-mobile-tools-open="false"] .mobile-tools-sheet {
    transform: translateY(14px);
    opacity: 0;
    pointer-events: none;
  }

  body[data-mobile-tools-open="false"] .mobile-tools-sheet-backdrop {
    opacity: 0;
    pointer-events: none;
  }

  body[data-mobile-nav-ready="true"] .mobile-action-bar {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
  }

  #selectionBar {
    margin-bottom: 12px;
  }
}

@media (max-width: 520px) {
  .mobile-action-btn {
    min-height: 54px;
    border-radius: 13px;
    padding: 7px 3px 6px;
    gap: 3px;
  }

  .mobile-action-icon {
    width: 18px;
    height: 18px;
  }

  .mobile-action-icon svg {
    width: 18px;
    height: 18px;
  }

  .mobile-action-label {
    font-size: 0.6rem;
  }

  .modal-box input,
  .modal-box select {
    font-size: 16px;
  }
}

textarea {
  width: 100%;
  min-height: 110px;
  resize: vertical;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(15, 23, 42, 0.45);
  color: #fff;
  padding: 12px 14px;
  font: inherit;
}

