:root {
  --bg: #0f0f12;
  --panel: #1a1a21;
  --text: #f2f2f5;
  --muted: #8b8b9a;
  --accent: #6c8cff;
  --radius: 14px;
  --safe: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  touch-action: pan-x pan-y;
  overscroll-behavior: none;
}

.app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: var(--panel);
  border-bottom: 1px solid #2a2a34;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  max-width: min(100%, 260px);
}

.btn {
  appearance: none;
  border: 1px solid #3a3a48;
  background: #25252f;
  color: var(--text);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 15px;
  cursor: pointer;
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.btn-file {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.btn-file-text {
  pointer-events: none;
  position: relative;
  z-index: 0;
}

/* iOS Safari / Yandex: прямой тап по input внутри label (не programmatic click) */
.btn-file input[type="file"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  opacity: 0;
  font-size: 16px;
  cursor: pointer;
  z-index: 1;
}

.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px;
  min-height: 0;
}

.hint {
  margin: 0 0 10px;
  font-size: 14px;
  color: var(--muted);
  text-align: center;
  max-width: 340px;
  line-height: 1.4;
}

.hint.hidden {
  display: none;
}

.canvas-box {
  position: relative;
  flex: 1;
  width: 100%;
  max-width: min(100%, 900px);
  min-height: 200px;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  touch-action: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.viewport {
  position: relative;
  display: inline-block;
  max-width: 100%;
  transform-origin: center center;
  will-change: transform;
}

.face-pick-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
}

.face-pick-layer.hidden {
  display: none;
}

.face-pick-marker {
  position: absolute;
  width: 34px;
  height: 34px;
  margin: -17px 0 0 -17px;
  border-radius: 50%;
  border: 2px solid #fff;
  background: rgba(90, 110, 255, 0.88);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
  padding: 0;
}

.face-pick-marker.active {
  background: #e85d4a;
  border-color: #ffe0db;
  transform: scale(1.08);
}

.remove-person-pick {
  margin-top: 10px;
}

.remove-person-pick.hidden {
  display: none;
}

.remove-person-hint {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.35;
}

.remove-person-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.remove-person-chip {
  appearance: none;
  border: 1px solid #3a3a48;
  background: #25252f;
  color: var(--text);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.remove-person-chip.active {
  border-color: #e85d4a;
  background: #3a2528;
  color: #ffd4cc;
}

.canvas-box.pick-person-mode #view {
  cursor: crosshair;
}

#view {
  display: block;
  max-width: 100%;
  max-height: min(52vh, 520px);
  width: auto;
  height: auto;
  touch-action: none;
}

.status {
  margin: 0 0 8px;
  min-height: 1.25em;
  font-size: 13px;
  color: #a8b0ff;
  text-align: center;
  max-width: 420px;
  line-height: 1.35;
}

.dock-level {
  padding-bottom: 14px;
  margin-bottom: 14px;
  border-bottom: 1px solid #2a2a34;
}

.dock-level:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

.dock-select {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid #3a3a48;
  background: #25252f;
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%238b8b9a' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

.comet-prompt-row {
  display: flex;
  gap: 10px;
  align-items: stretch;
  margin-top: 10px;
}

.comet-prompt-row textarea {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #3a3a48;
  background: #15151a;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
}

.btn-apply {
  flex-shrink: 0;
  align-self: stretch;
  padding: 10px 16px;
  border-color: var(--accent);
  background: #2a3150;
  color: #dbe4ff;
  font-weight: 600;
  white-space: nowrap;
}

.dock-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.dock-tab {
  flex: 0 0 auto;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid #3a3a48;
  background: #25252f;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
}

.dock-tab.active {
  border-color: var(--accent);
  background: #2a3150;
  color: #dbe4ff;
}

.dock-tab:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.tool-panel {
  padding: 4px 0 8px;
}

.tool-panel.hidden {
  display: none !important;
}

.panel-hint {
  margin: 0 0 10px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}

.dock-level-rotate .adj-title {
  margin-bottom: 10px;
}

.btn-block {
  width: 100%;
  margin-bottom: 8px;
}

.btn-ghost {
  background: transparent;
  border-color: #4a4a5c;
  color: var(--muted);
  font-size: 14px;
}

.adj-panel {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid #2a2a34;
}

.adj-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 10px;
}

.adj-details {
  margin-top: 6px;
  border: 1px solid #2a2a34;
  border-radius: 10px;
  padding: 0 10px 8px;
  background: #15151a;
}

.adj-details summary {
  cursor: pointer;
  padding: 10px 0;
  font-size: 14px;
  font-weight: 600;
  list-style: none;
}

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

.adj-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 6px 0;
  font-size: 13px;
  color: var(--text);
}

.adj-row span {
  flex: 0 0 92px;
  color: var(--muted);
}

.adj-row input[type="range"] {
  flex: 1;
  min-width: 0;
  accent-color: var(--accent);
}

.btn-row {
  display: flex;
  gap: 10px;
}

.btn-row .btn {
  flex: 1;
}

.btn-small {
  padding: 8px 10px;
  font-size: 12px;
  min-width: 0;
}

.comet-hint {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.45;
  margin: 0 0 10px;
}

.comet-hint code {
  font-size: 11px;
  background: #1a1a22;
  padding: 2px 6px;
  border-radius: 6px;
}

.comet-hint a {
  color: var(--accent);
  text-decoration: underline;
}

.comet-hint strong {
  font-weight: 600;
  color: var(--text);
}

.comet-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.comet-model-row .comet-select {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid #3a3a48;
  background: #15151a;
  color: var(--text);
  font-size: 14px;
}

.comet-prompt-label {
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
}

.comet-prompt-label textarea {
  width: 100%;
  box-sizing: border-box;
  min-height: 72px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #3a3a48;
  background: #15151a;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
}

.dock {
  flex-shrink: 0;
  max-height: min(48vh, 420px);
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  background: var(--panel);
  border-top: 1px solid #2a2a34;
  padding: 12px 16px calc(12px + var(--safe));
}

.safe-bottom {
  padding-bottom: calc(12px + var(--safe));
}

.tools {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  margin-bottom: 12px;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 4px;
  scrollbar-width: thin;
}

.tools::-webkit-scrollbar {
  height: 5px;
}

.tools::-webkit-scrollbar-thumb {
  background: #3a3a55;
  border-radius: 4px;
}

.tool {
  flex: 0 0 auto;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid #3a3a48;
  background: #25252f;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
}

.tool.active {
  border-color: var(--accent);
  background: #2a3150;
  color: #dbe4ff;
}

.sliders {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.slider-label {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  color: var(--muted);
}

.slider-label span {
  min-width: 52px;
}

.slider-label input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
}

.slider-label input[type="color"] {
  width: 48px;
  height: 36px;
  padding: 0;
  border: 1px solid #3a3a48;
  border-radius: 8px;
  background: transparent;
}

.adj-row.adj-toggle {
  justify-content: space-between;
}

.adj-row.adj-toggle input[type="checkbox"] {
  width: 22px;
  height: 22px;
  accent-color: var(--accent);
}

.skin-sliders {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid #2a2a34;
}

.makeup-presets {
  margin: 8px 0;
  gap: 8px;
}

.makeup-presets .btn {
  flex: 1;
}

.hidden {
  display: none !important;
}

.lip-only.hidden {
  display: none !important;
}
