:root {
  --bg: #101317;
  --panel: #f7f4ef;
  --panel-2: #ffffff;
  --ink: #16181d;
  --muted: #6f747c;
  --line: #d8d3ca;
  --green: #2f8f68;
  --blue: #1f6feb;
  --red: #c44536;
  --gold: #c28a24;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.32);
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  background: var(--bg);
  overflow: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.sync-settings { max-width: 880px; }
.sync-settings small { line-height: 1.5; color: var(--muted); }
.sync-fields { display: grid; gap: 16px; min-width: 0; margin: 0; padding: 0; border: 0; }
.sync-unlock, .sync-key-row, .sync-actions { display: flex; align-items: end; gap: 10px; flex-wrap: wrap; }
.sync-unlock .field, .sync-key-row input { flex: 1 1 220px; min-width: 0; }
.sync-key-row input { min-height: 42px; padding: 8px; }
.sync-settings progress { width: 100%; height: 14px; accent-color: var(--green); }
#syncQueueStatus { line-height: 1.6; overflow-wrap: anywhere; }

.print-frame {
  position: fixed;
  left: -10000px;
  top: 0;
  width: 1px;
  height: 1px;
  border: 0;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.stage {
  position: relative;
  width: 100vw;
  height: 100dvh;
  min-height: 100vh;
  overflow: hidden;
  background: #0b0d10;
  color: #fff;
  touch-action: manipulation;
  cursor: default;
}

.stage.is-idle {
  cursor: pointer;
}

.camera-video,
.frame-preview-canvas,
.idle-image,
.overlay-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.camera-video {
  object-fit: cover;
  background: #0b0d10;
}

.frame-preview-canvas {
  z-index: 3;
  object-fit: contain;
  background: #0b0d10;
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease;
}

.stage.show-overlay.has-frame-preview .frame-preview-canvas {
  opacity: 1;
}

.stage.show-overlay.has-frame-preview .camera-video {
  opacity: 0;
}

.idle-image {
  object-fit: cover;
  z-index: 2;
  opacity: 0;
  transition: opacity 180ms ease;
}

.stage.is-idle .idle-image.has-image {
  opacity: 1;
}

.overlay-image {
  object-fit: contain;
  pointer-events: none;
  z-index: 4;
  opacity: 0;
  transition: opacity 120ms ease;
}

.stage.show-overlay .overlay-image {
  opacity: 1;
}

.top-strip {
  position: absolute;
  z-index: 25;
  top: max(14px, env(safe-area-inset-top));
  left: max(14px, env(safe-area-inset-left));
  right: max(14px, env(safe-area-inset-right));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  pointer-events: none;
}

.status-text {
  max-width: min(620px, calc(100vw - 96px));
  min-height: 38px;
  display: flex;
  align-items: center;
  padding: 8px 12px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 6px;
  background: rgba(10, 13, 17, 0.72);
  color: rgba(255, 255, 255, 0.9);
  font-size: clamp(13px, 1.4vw, 16px);
  overflow-wrap: anywhere;
  backdrop-filter: blur(10px);
}

.top-strip .icon-button {
  pointer-events: auto;
}

.stage.live-mode .status-text,
.stage.live-mode #openAdminButton {
  display: none;
}

.icon-button {
  width: 40px;
  height: 40px;
  border: 1px solid rgba(22, 24, 29, 0.16);
  border-radius: 6px;
  display: inline-grid;
  place-items: center;
  background: #fff;
  color: var(--ink);
  font-size: 22px;
  line-height: 1;
}

.icon-button.ghost {
  border-color: rgba(255, 255, 255, 0.2);
  background: rgba(10, 13, 17, 0.65);
  color: #fff;
  backdrop-filter: blur(10px);
}

.countdown {
  position: absolute;
  z-index: 30;
  inset: 0;
  display: grid;
  place-items: center;
  color: white;
  font-weight: 900;
  font-size: min(32vw, 260px);
  line-height: 1;
  text-shadow: 0 12px 42px rgba(0, 0, 0, 0.75);
}

.flash {
  position: absolute;
  inset: 0;
  z-index: 34;
  pointer-events: none;
  background: #fff;
  opacity: 0;
}

.flash.fire {
  animation: flash 360ms ease;
}

@keyframes flash {
  0% {
    opacity: 0;
  }
  18% {
    opacity: 0.88;
  }
  100% {
    opacity: 0;
  }
}

.admin-hotspot {
  position: absolute;
  z-index: 23;
  top: max(0px, env(safe-area-inset-top));
  right: max(0px, env(safe-area-inset-right));
  width: 25px;
  height: 25px;
  cursor: default;
}

.result-screen {
  position: absolute;
  z-index: 40;
  inset: 0;
  display: block;
  background: #0b0d10;
}

.stage .result-screen.hidden {
  display: none !important;
}

.result-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #0b0d10;
}

.result-image.is-updating {
  opacity: 0.65;
}

.result-actions {
  position: absolute;
  z-index: 43;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(8px, env(safe-area-inset-bottom));
  width: min(440px, calc(100vw - 36px));
  max-width: min(440px, calc(100vw - 36px));
  max-height: calc(100dvh - 16px - env(safe-area-inset-bottom));
  display: grid;
  gap: 5px;
  padding: 5px;
  border: 1px solid rgba(22, 24, 29, 0.12);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  box-shadow: var(--shadow);
  overflow: auto;
  transition: transform 260ms ease, right 260ms ease;
}

.result-set-panel,
.result-button-panel {
  border-radius: 6px;
  background: #eee;
}

.result-set-panel {
  position: relative;
  min-height: 72px;
  padding: 8px 44px 8px 8px;
}

.result-button-panel {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 8px;
}

.mail-panel {
  display: grid;
  gap: 6px;
  padding: 8px;
  border-radius: 6px;
  background: #eee;
}

.mail-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.mail-form input {
  width: 100%;
  min-height: 44px;
  border: 1px solid rgba(22, 24, 29, 0.18);
  border-radius: 6px;
  padding: 9px 11px;
  background: #fff;
  color: var(--ink);
}

.mail-state {
  min-height: 18px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.smtp-test-log {
  min-height: 150px;
  max-height: 260px;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: auto;
  background: #11151b;
  color: #dfe7f3;
  font: 12px/1.45 ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  white-space: pre-wrap;
}

.result-meta {
  min-width: 118px;
  display: grid;
  gap: 2px;
  color: rgba(255, 255, 255, 0.82);
  font-size: 13px;
}

.result-meta strong {
  font-size: 22px;
  color: #fff;
  letter-spacing: 0;
}

.variant-switch {
  display: flex;
  align-items: stretch;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.variant-switch button {
  width: 78px;
  min-height: 68px;
  display: grid;
  grid-template-rows: 42px auto;
  gap: 4px;
  border: 1px solid transparent;
  border-radius: 5px;
  padding: 5px;
  background: transparent;
  color: var(--ink);
  font-weight: 800;
}

.variant-switch button.active {
  border-color: #174ea6;
  background: var(--blue);
  color: #fff;
}

.variant-switch button.is-uploaded::after {
  content: "";
  position: absolute;
  top: 5px;
  right: 5px;
  width: 6px;
  height: 6px;
  display: block;
  border-radius: 50%;
  background: #48c78e;
}

.variant-button {
  position: relative;
}

.variant-thumb {
  position: relative;
  width: 100%;
  height: 42px;
  display: block;
  overflow: hidden;
  border-radius: 4px;
  background:
    linear-gradient(45deg, rgba(255, 255, 255, 0.22) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(255, 255, 255, 0.22) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(255, 255, 255, 0.22) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(255, 255, 255, 0.22) 75%);
  background-size: 12px 12px;
  background-position: 0 0, 0 6px, 6px -6px, -6px 0;
  background-color: rgba(10, 13, 17, 0.9);
}

.variant-thumb img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.variant-frame {
  object-fit: contain;
  z-index: 2;
}

.variant-label {
  min-width: 0;
  color: inherit;
  font-size: 11px;
  line-height: 1.05;
  overflow-wrap: anywhere;
  text-align: center;
}

.action-button {
  min-height: 44px;
  border: 1px solid rgba(22, 24, 29, 0.16);
  border-radius: 6px;
  padding: 10px 14px;
  background: #fff;
  color: var(--ink);
  font-weight: 700;
}

.action-button.primary {
  border-color: #174ea6;
  background: var(--blue);
  color: #fff;
}

.action-button.quiet {
  background: transparent;
  color: var(--ink);
  border-color: rgba(22, 24, 29, 0.22);
}

.action-button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.qr-panel {
  position: static;
  width: 100%;
  min-height: 0;
  padding: 5px;
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  box-shadow: none;
}

.qr-panel canvas {
  width: auto;
  max-width: min(100%, 360px);
  height: auto;
  display: block;
  margin: 0 auto;
  background: #fff;
  image-rendering: pixelated;
}

.qr-link-text {
  margin-top: 12px;
  font-size: 13px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.result-countdown {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f7f8fa;
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.panel-close-button {
  width: 30px;
  height: 30px;
  border: 1px solid rgba(22, 24, 29, 0.14);
  border-radius: 999px;
  display: inline-grid;
  place-items: center;
  background: #fff;
  color: var(--ink);
  font-size: 20px;
  line-height: 1;
  font-weight: 800;
}

.result-set-panel .panel-close-button {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
}

.upload-spinner {
  width: 118px;
  height: 118px;
  position: relative;
  margin: 18px auto 10px;
}

.upload-spinner span {
  position: absolute;
  inset: 12px;
  border: 5px solid transparent;
  border-top-color: var(--blue);
  border-right-color: var(--blue);
  border-radius: 50%;
  animation: upload-spin 900ms linear infinite;
}

.upload-spinner span + span {
  inset: 28px;
  border-top-color: var(--green);
  border-right-color: var(--green);
  animation-direction: reverse;
  animation-duration: 700ms;
}

@keyframes upload-spin {
  to {
    transform: rotate(360deg);
  }
}

.stage.result-panels-collapsed .result-actions {
  right: 0 !important;
  transform: translateX(calc(100% - 15px));
  cursor: pointer;
}

.version-badge {
  position: fixed;
  left: max(10px, env(safe-area-inset-left));
  bottom: max(8px, env(safe-area-inset-bottom));
  z-index: 130;
  pointer-events: none;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0;
  opacity: 0.5;
  padding: 6px 8px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: max(18px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  background: rgba(0, 0, 0, 0.62);
}

.modal-shell {
  width: min(1120px, 100%);
  max-height: min(860px, 100%);
  display: grid;
  grid-template-rows: auto auto 1fr;
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.modal-header {
  min-height: 74px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.modal-header h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.1;
}

.modal-header p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.tabs {
  display: flex;
  gap: 1px;
  border-bottom: 1px solid var(--line);
  background: var(--line);
  overflow-x: auto;
}

.tab-button {
  min-width: 120px;
  min-height: 46px;
  border: 0;
  background: #ede8df;
  color: var(--ink);
  font-weight: 700;
}

.tab-button.active {
  background: var(--panel);
  color: #0b4f7a;
}

.modal-body {
  min-height: 0;
  overflow: auto;
  padding: 20px;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.panel-grid {
  display: grid;
  grid-template-columns: minmax(280px, 390px) 1fr;
  gap: 20px;
  align-items: start;
}

.settings-stack,
.settings-grid,
.asset-list {
  display: grid;
  gap: 14px;
}

.settings-grid {
  grid-template-columns: repeat(2, minmax(240px, 1fr));
}

.field {
  display: grid;
  gap: 7px;
  color: var(--ink);
  font-weight: 700;
}

.field span,
.switch-row span {
  font-size: 14px;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid #bfc4ca;
  border-radius: 6px;
  padding: 8px 10px;
  background: #fff;
  color: var(--ink);
}

.field textarea {
  min-height: 104px;
  resize: vertical;
}

.field input[type="range"] {
  padding: 0;
}

.field input:disabled {
  background: #eceff3;
  color: var(--muted);
}

.field.wide {
  grid-column: 1 / -1;
}

.field.compact input {
  min-width: 0;
}

.switch-row {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  font-weight: 700;
}

.switch-row input {
  width: 22px;
  height: 22px;
  accent-color: var(--green);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.segmented button {
  min-height: 42px;
  border: 1px solid #bfc4ca;
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-weight: 700;
}

.learn-row,
.stepper-row,
.size-row,
.storage-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.wide-row {
  grid-column: 1 / -1;
}

.learn-row span,
.storage-row span {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.stepper-row strong {
  min-width: 84px;
  text-align: center;
}

.size-row {
  align-items: start;
}

.size-row .field {
  flex: 1 1 160px;
}

.profile-hint {
  margin-top: -6px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.camera-preview-frame,
.layout-preview {
  width: 100%;
  aspect-ratio: 3 / 2;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #121820;
}

.camera-preview-frame video {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.layout-preview {
  display: block;
}

.asset-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 136px minmax(220px, 1.2fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
}

.asset-group-title {
  margin-top: 4px;
  padding: 2px 2px 0;
  color: #3b3f47;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0;
}

.asset-row.is-dragover {
  border-color: var(--blue);
  background: #eef5ff;
}

.asset-row div {
  display: grid;
  gap: 4px;
}

.asset-help {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.35;
}

.asset-file-control {
  display: grid;
  gap: 6px;
  align-content: center;
}

.asset-row span {
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.asset-row input[type="file"] {
  min-width: 0;
  color: var(--ink);
}

.effect-row {
  grid-template-columns: minmax(180px, 1fr) minmax(220px, 1.2fr);
}

.effect-row select {
  min-height: 42px;
  border: 1px solid #bfc4ca;
  border-radius: 6px;
  padding: 8px 10px;
  background: #fff;
  color: var(--ink);
}

.asset-preview {
  width: 136px;
  height: 84px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  background:
    linear-gradient(45deg, #e7e4de 25%, transparent 25%),
    linear-gradient(-45deg, #e7e4de 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e7e4de 75%),
    linear-gradient(-45deg, transparent 75%, #e7e4de 75%);
  background-size: 18px 18px;
  background-position: 0 0, 0 9px, 9px -9px, -9px 0;
  background-color: #f8f8f8;
}

.asset-preview img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: none;
}

.asset-preview.has-asset img {
  display: block;
}

.audio-preview {
  background: #f8f8f8;
}

.audio-preview audio {
  width: 128px;
  height: 38px;
  display: none;
}

.audio-preview.has-asset audio {
  display: block;
}

.storage-row {
  justify-content: space-between;
  margin-top: 18px;
}

.sample-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.quick-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.file-photo-strip {
  min-height: 92px;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow-x: auto;
}

.file-photo-strip > span {
  color: var(--muted);
}

.file-photo-thumb {
  flex: 0 0 auto;
  width: 104px;
  height: 68px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0;
  overflow: hidden;
  background: #101317;
}

.file-photo-thumb img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.gallery-toolbar {
  margin: 0 0 14px;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 14px;
}

.gallery-card {
  display: grid;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.gallery-card img {
  width: 100%;
  aspect-ratio: 3 / 2;
  object-fit: cover;
  border-radius: 6px;
  background: #101317;
  cursor: pointer;
}

.gallery-card img.is-empty {
  background:
    linear-gradient(135deg, rgba(0, 0, 0, 0.04) 25%, transparent 25%) 0 0 / 18px 18px,
    #eef0f2;
  cursor: default;
}

.gallery-card strong {
  font-size: 14px;
}

.gallery-card span {
  color: var(--muted);
  font-size: 12px;
}

.gallery-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.gallery-actions .icon-button {
  width: 44px;
  height: 44px;
}

.pin-modal {
  z-index: 120;
}

.pin-shell {
  width: min(360px, calc(100vw - 32px));
  display: grid;
  gap: 16px;
  padding: 18px;
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow);
}

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

.pin-header h2 {
  margin: 0;
  font-size: 22px;
}

.pin-display {
  min-height: 52px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-size: 30px;
  font-weight: 800;
  letter-spacing: 0;
}

.pin-display.error {
  border-color: var(--red);
  color: var(--red);
}

.pin-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.pin-grid button {
  min-height: 58px;
  border: 1px solid #bfc4ca;
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-size: 24px;
  font-weight: 800;
}

@media (max-width: 820px) {
  .result-actions {
    top: auto;
    right: max(10px, env(safe-area-inset-right));
    bottom: max(10px, env(safe-area-inset-bottom));
    left: max(10px, env(safe-area-inset-left));
    width: auto;
    max-width: none;
    max-height: calc(100dvh - 20px - env(safe-area-inset-bottom));
    align-items: stretch;
    justify-content: stretch;
    padding: 5px;
  }

  .result-actions .action-button {
    flex: 0 1 auto;
  }

  .result-meta {
    min-width: 0;
  }

  .qr-panel {
    width: 100%;
    padding: 5px;
  }

  .panel-grid,
  .settings-grid {
    grid-template-columns: 1fr;
  }

  .asset-row {
    grid-template-columns: 1fr auto;
  }

  .effect-row {
    grid-template-columns: 1fr;
  }

  .asset-row input[type="file"] {
    grid-column: 1 / -1;
  }

  .asset-preview {
    grid-column: 1 / -1;
    width: 100%;
    height: 120px;
  }

  .tabs {
    scrollbar-width: none;
  }
}

@media (max-width: 520px) {
  .modal {
    padding: 0;
  }

  .modal-shell {
    width: 100%;
    height: 100%;
    max-height: none;
    border-radius: 0;
  }

  .modal-header {
    padding: 14px;
  }

  .modal-body {
    padding: 14px;
  }

  .result-actions {
    gap: 5px;
  }

  .action-button {
    padding-inline: 10px;
  }
}
