*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --color-primary: #1230A8;
  --color-primary-dark: #0B1F6E;
  --color-success: #16A34A;
  --color-bg: #EEF2F6;
  --color-surface: #FFFFFF;
  --color-text: #1A202C;
  --color-text-muted: #64748B;
  --radius: 12px;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.07);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

html, body {
  height: 100%;
  overflow: hidden;
}

html {
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, 'Segoe UI', system-ui, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.35;
}

/* ── App shell ── */
.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  height: 100svh;
  overflow: hidden;
  background: var(--color-bg);
}

/* ── Header ── */
.header {
  flex-shrink: 0;
  background: linear-gradient(160deg, var(--color-primary), var(--color-primary-dark));
  color: #fff;
  padding: 0.5rem 0.75rem;
  padding-top: calc(0.5rem + var(--safe-top));
}

.header__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.45rem;
}

.btn-back {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  text-decoration: none;
  font-size: 0.72rem;
  font-weight: 800;
}

.btn-back:active {
  background: rgba(255, 255, 255, 0.28);
}

.header__info {
  min-width: 0;
  flex: 1;
}

.header__title {
  font-size: 0.9rem;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}

.header__subtitle {
  font-size: 0.65rem;
  opacity: 0.85;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.counter-badge {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: rgba(255,255,255,0.18);
  border-radius: 8px;
  padding: 0.2rem 0.55rem;
  line-height: 1.1;
}

.counter-badge strong {
  font-size: 0.95rem;
  font-weight: 800;
}

.counter-badge span {
  font-size: 0.55rem;
  opacity: 0.85;
}

/* ── Workspace: editor + dock ── */
.workspace {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

/* Editor fills all remaining space */
.editor {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 0.4rem 0.75rem;
  overflow: hidden;
}

.preview-section {
  position: relative;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.format-badge {
  position: absolute;
  top: 0;
  right: 0;
  background: rgba(0,0,0,0.5);
  color: #fff;
  font-size: 0.55rem;
  font-weight: 700;
  padding: 0.15rem 0.4rem;
  border-radius: 0 var(--radius) 0 6px;
  z-index: 3;
  pointer-events: none;
}

/* Canvas: sized by JS, maintains 9:16 */
.canvas-wrapper {
  position: relative;
  background: #111;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow), 0 0 0 1px rgba(0,0,0,0.06);
  touch-action: none;
  user-select: none;
  flex-shrink: 0;
}

.canvas-wrapper--tap {
  cursor: pointer;
  touch-action: manipulation;
}

.canvas-wrapper--tap:active {
  opacity: 0.92;
}

.canvas-wrapper.dragging {
  cursor: grabbing;
}

.canvas-wrapper--round {
  border-radius: 50%;
  background: #040814;
}

#preview-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* Placeholder */
.canvas-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 1;
  transition: opacity 0.25s;
}

.canvas-placeholder.hidden {
  opacity: 0;
}

.placeholder-tap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  background: rgba(0,0,0,0.45);
  border: 2px dashed rgba(255,255,255,0.4);
  border-radius: 12px;
  padding: 1rem 1.25rem;
  text-align: center;
}

.placeholder-icon {
  font-size: 1.8rem;
}

.canvas-placeholder p {
  font-size: 0.72rem;
  color: rgba(255,255,255,0.9);
  font-weight: 600;
}

/* ── Dock (controls at bottom) ── */
.dock {
  flex-shrink: 0;
  padding: 0.4rem 0.75rem;
  padding-bottom: calc(0.5rem + var(--safe-bottom));
  background: var(--color-bg);
  border-top: 1px solid rgba(0,0,0,0.06);
}

.dock--editing .motivation-box {
  display: none;
}

.use-hint {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.4rem 0.55rem;
  margin-bottom: 0.4rem;
  padding: 0.35rem 0.45rem;
  background: var(--color-surface);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.use-hint .app-logos {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.use-hint .app-logos__icon {
  display: inline-flex;
}

.use-hint .app-logos__icon small {
  display: none;
}

.use-hint .app-logo {
  width: 22px;
  height: 22px;
  border-radius: 22%;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
}

.use-hint .app-logos__caption {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--color-text-muted);
  text-align: center;
}

.motivation-box {
  background: var(--color-surface);
  border-radius: 8px;
  padding: 0.4rem 0.6rem;
  margin-bottom: 0.4rem;
  font-size: 0.65rem;
  color: var(--color-text-muted);
  line-height: 1.4;
  border-left: 3px solid var(--color-primary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.adjust-controls {
  background: var(--color-surface);
  border-radius: var(--radius);
  padding: 0.45rem 0.55rem;
  box-shadow: var(--shadow);
}

.control-row {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.control-group--flex {
  flex: 1;
}

.control-group input[type="range"] {
  width: 100%;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: #DDE3EA;
  border-radius: 2px;
  outline: none;
}

.control-group input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 24px;
  height: 24px;
  background: var(--color-primary);
  border-radius: 50%;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

.control-group input[type="range"]::-moz-range-thumb {
  width: 24px;
  height: 24px;
  background: var(--color-primary);
  border-radius: 50%;
  border: none;
}

.btn-icon {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid #DDE3EA;
  background: #fff;
  font-size: 1.1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
  color: var(--color-text);
}

.btn-icon--rotate {
  font-size: 0.95rem;
}

.btn-icon:active {
  background: #F1F5F9;
}

.drag-hint {
  text-align: center;
  font-size: 0.62rem;
  color: var(--color-text-muted);
  margin-top: 0.25rem;
}

.action-buttons {
  display: flex;
  gap: 0.4rem;
}

.btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  padding: 0.7rem 0.5rem;
  border: none;
  border-radius: var(--radius);
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  min-height: 44px;
}

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

.btn--secondary {
  background: #DDE3EA;
  color: var(--color-text);
  flex: 0.7;
}

.btn--success {
  background: var(--color-success);
  color: #fff;
  flex: 1.3;
  box-shadow: 0 3px 10px rgba(22,163,74,0.3);
}

/* Toast */
.toast {
  position: fixed;
  bottom: calc(1rem + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: #1A202C;
  color: #fff;
  padding: 0.6rem 1.1rem;
  border-radius: 50px;
  font-size: 0.82rem;
  font-weight: 500;
  z-index: 999;
  max-width: calc(100vw - 2rem);
  text-align: center;
  transition: transform 0.3s;
  pointer-events: none;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

.hidden {
  display: none !important;
}

/* ── Picker sheet (galeria / câmera) ── */
.picker-sheet {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.picker-sheet__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  animation: fadeIn 0.2s ease;
}

.picker-sheet__panel {
  position: relative;
  width: 100%;
  max-width: 420px;
  background: var(--color-surface);
  border-radius: 16px 16px 0 0;
  padding: 1rem 1rem calc(1rem + var(--safe-bottom));
  animation: slideUp 0.25s ease;
}

.picker-sheet__title {
  text-align: center;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--color-text-muted);
  margin-bottom: 0.75rem;
}

.picker-option {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  width: 100%;
  padding: 0.85rem 1rem;
  border: none;
  background: var(--color-bg);
  border-radius: var(--radius);
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  margin-bottom: 0.5rem;
  transition: background 0.15s;
}

.picker-option:active {
  background: #DDE3EA;
}

.picker-option__icon {
  font-size: 1.6rem;
  flex-shrink: 0;
}

.picker-option__text {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.picker-option__text strong {
  font-size: 0.95rem;
  color: var(--color-text);
}

.picker-option__text small {
  font-size: 0.72rem;
  color: var(--color-text-muted);
}

.picker-cancel {
  width: 100%;
  padding: 0.85rem;
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  margin-top: 0.25rem;
}

.picker-cancel:active {
  color: var(--color-text);
}

.picker-cancel--link {
  display: block;
  text-align: center;
  text-decoration: none;
  margin-top: 0.15rem;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

/* ── Result sheet (compartilhar / salvar / ver) ── */
.result-sheet {
  position: fixed;
  inset: 0;
  z-index: 1100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.result-sheet__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  animation: fadeIn 0.2s ease;
}

.result-sheet__panel {
  position: relative;
  width: 100%;
  max-width: 420px;
  background: var(--color-surface);
  border-radius: 16px 16px 0 0;
  padding: 1rem 1rem calc(1rem + var(--safe-bottom));
  animation: slideUp 0.25s ease;
}

.result-sheet__title {
  text-align: center;
  font-size: 1rem;
  font-weight: 800;
  color: var(--color-text);
  margin-bottom: 0.75rem;
}

.result-preview {
  width: 120px;
  margin: 0 auto 1rem;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  aspect-ratio: 9 / 16;
}

.result-preview--round {
  width: 168px;
  aspect-ratio: 1 / 1;
  border-radius: 50%;
}

.result-preview img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.result-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.result-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  padding: 0.75rem 0.4rem;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--color-text);
  transition: transform 0.12s;
}

.result-btn:active {
  transform: scale(0.95);
}

.result-btn__icon {
  font-size: 1.5rem;
}

.result-btn--share {
  background: #EFF6FF;
  color: #1D4ED8;
}

.result-btn--save {
  background: #F0FDF4;
  color: #15803D;
}

.result-btn--view {
  background: #FDF4FF;
  color: #7E22CE;
}

/* ── View fullscreen ── */
.view-overlay {
  position: fixed;
  inset: 0;
  z-index: 1200;
  background: rgba(0, 0, 0, 0.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  padding-top: calc(1rem + var(--safe-top));
  padding-bottom: calc(1rem + var(--safe-bottom));
}

.view-overlay__close {
  position: absolute;
  top: calc(0.75rem + var(--safe-top));
  right: 0.75rem;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 1.1rem;
  cursor: pointer;
  z-index: 2;
}

.view-overlay img {
  max-width: 100%;
  max-height: calc(100dvh - 5rem);
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
}

.view-overlay__hint {
  margin-top: 0.75rem;
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.6);
}

/* ── Desktop ── */
@media (min-width: 768px) {
  body {
    background: #CBD5E1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
    height: auto;
    min-height: 100dvh;
    padding: 1rem;
  }

  .app {
    width: 390px;
    height: 844px;
    max-height: calc(100dvh - 2rem);
    border-radius: 24px;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  }

  .motivation-box {
    font-size: 0.72rem;
    -webkit-line-clamp: 3;
  }
}
