:root {
  --paper: #fff8e7;
  --ink: #2b2118;
  --coral: #ff6b4a;
  --teal: #2ec4b6;
  --sun: #ffd166;
  --rose: #ef476f;
  --sky: #118ab2;
  --mint: #06d6a0;
  --grape: #7b5ea7;
  --leaf: #4caf50;
  --orange: #fb8500;
  --brown: #8d6e63;
  --black: #1a1a1a;
  --white: #ffffff;
  --shadow: 0 8px 24px rgba(43, 33, 24, 0.12);
  --radius: 1.25rem;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --ad-height: 56px;
  --header-h: 3.5rem;
  font-family: "Nunito", "Trebuchet MS", system-ui, sans-serif;
}

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

html {
  height: 100%;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at 12% 18%, rgba(255, 209, 102, 0.35), transparent 40%),
    radial-gradient(circle at 88% 8%, rgba(46, 196, 182, 0.25), transparent 42%),
    linear-gradient(165deg, #fff3d6 0%, var(--paper) 45%, #ffe8d6 100%);
  background-attachment: fixed;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  overflow-x: hidden;
}

body.has-ads {
  padding-bottom: calc(var(--ad-height) + var(--safe-bottom));
}

button,
input,
a {
  font: inherit;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.65rem 1rem;
  min-height: var(--header-h);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(10px);
  background: rgba(255, 248, 231, 0.92);
  border-bottom: 2px solid rgba(255, 107, 74, 0.15);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: inherit;
  text-decoration: none;
  cursor: default;
  user-select: none;
}

.brand:hover {
  text-decoration: none;
  color: inherit;
}

.brand-mark {
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 0.85rem;
  background: var(--coral);
  display: grid;
  place-items: center;
  color: white;
  font-weight: 800;
  font-size: 1.1rem;
  box-shadow: 0 4px 0 rgba(200, 70, 40, 0.35);
  flex-shrink: 0;
}

.brand h1 {
  margin: 0;
  font-size: 1.25rem;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.brand p {
  margin: 0;
  font-size: 0.7rem;
  opacity: 0.7;
  font-weight: 700;
}

.icon-btn {
  border: 0;
  background: #fff;
  color: var(--ink);
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 999px;
  box-shadow: var(--shadow);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 1.05rem;
  flex-shrink: 0;
}

.icon-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  filter: none;
}

.toolbar-actions .icon-btn-share {
  background: #06d6a0;
  color: #fff;
  box-shadow: 0 3px 0 #049a72;
}

.toolbar-actions .icon-btn-share:not(:disabled) {
  opacity: 1;
}

.toolbar-actions .icon-btn-danger {
  background: #ef476f;
  color: #fff;
  box-shadow: 0 3px 0 #b82f4f;
}

.toolbar-actions .icon-btn-danger:not(:disabled) {
  opacity: 1;
}

.main {
  flex: 1;
  width: min(720px, 100%);
  margin: 0 auto;
  padding: 0.75rem 0.85rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.prompt-card,
.studio-card,
.hint-card {
  background: rgba(255, 255, 255, 0.88);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.85rem;
}

.prompt-card h2,
.studio-card .studio-toolbar span {
  margin: 0 0 0.5rem;
  font-size: 1rem;
  font-weight: 800;
}

.prompt-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.prompt-row {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
}

.prompt-row input {
  flex: 1;
  min-width: 0;
  border: 2px solid rgba(43, 33, 24, 0.12);
  border-radius: 999px;
  padding: 0.8rem 1rem;
  background: #fffef9;
  outline: none;
}

.prompt-row input:focus {
  border-color: var(--teal);
}

.btn {
  border: 0;
  border-radius: 999px;
  padding: 0.8rem 1.05rem;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  flex-shrink: 0;
}

.btn:active {
  transform: translateY(2px);
}

.btn-primary {
  background: var(--coral);
  color: white;
  box-shadow: 0 4px 0 #d94b2f;
}

.btn-primary:disabled {
  opacity: 0.55;
  cursor: wait;
}

.btn-voice {
  width: 100%;
  background: var(--teal);
  color: white;
  box-shadow: 0 4px 0 rgba(20, 140, 130, 0.45);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.85rem 1.05rem;
}

.btn-voice:hover {
  filter: brightness(1.05);
}

.btn-voice[aria-pressed="true"],
.btn-voice.is-listening {
  background: var(--rose);
  box-shadow: 0 4px 0 rgba(180, 40, 70, 0.45);
  animation: voice-pulse 1.1s ease-in-out infinite;
}

.btn-voice:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  animation: none;
}

.btn-voice-icon {
  font-size: 1.15rem;
  line-height: 1;
}

.btn-voice-label {
  font-size: 1rem;
}

@keyframes voice-pulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.6rem;
}

.chip {
  border: 0;
  background: #fff3e0;
  color: var(--ink);
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
}

.chip:hover {
  background: #ffe0b8;
}

.studio-toolbar {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.45rem;
  margin-bottom: 0.65rem;
}

.studio-toolbar #studio-title {
  font-weight: 800;
  font-size: 1.05rem;
}

.toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  justify-content: flex-start;
}

.canvas-wrap {
  position: relative;
  width: 100%;
  max-width: min(100%, 560px);
  margin: 0 auto;
  aspect-ratio: 1;
  max-height: min(68vw, calc(100dvh - 22rem));
  border-radius: 1rem;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(43, 33, 24, 0.04) 1px, transparent 1px),
    linear-gradient(rgba(43, 33, 24, 0.04) 1px, transparent 1px),
    #fffef9;
  background-size: 24px 24px;
  border: 3px solid rgba(43, 33, 24, 0.08);
  touch-action: none;
  user-select: none;
}

.canvas-stage {
  position: absolute;
  inset: 0;
  transform-origin: 0 0;
  will-change: transform;
}

.canvas-stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#lineCanvas {
  z-index: 2;
  pointer-events: none;
}

#paintCanvas {
  z-index: 1;
  cursor: crosshair;
  touch-action: none;
  pointer-events: none;
}

.canvas-empty {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 1.25rem;
  color: rgba(43, 33, 24, 0.55);
  font-weight: 700;
  pointer-events: none;
}

.canvas-empty.hidden {
  display: none;
}

.palette {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(2.35rem, 1fr));
  gap: 0.4rem;
  margin-top: 0.7rem;
}

.swatch {
  aspect-ratio: 1;
  border-radius: 999px;
  border: 3px solid transparent;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.12);
  cursor: pointer;
  position: relative;
}

.swatch[aria-pressed="true"] {
  border-color: var(--ink);
  transform: scale(1.08);
}

.swatch.eraser {
  background:
    linear-gradient(135deg, #fff 46%, #ff6b4a 46%, #ff6b4a 54%, #fff 54%),
    repeating-conic-gradient(#eee 0% 25%, #fff 0% 50%) 0 0 / 10px 10px;
}

.brush-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.7rem;
}

.brush-row label {
  font-size: 0.85rem;
  font-weight: 800;
  white-space: nowrap;
}

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

.status {
  min-height: 1.2rem;
  margin: 0.45rem 0 0;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--sky);
}

.status.error {
  color: var(--rose);
}

.ad-slot {
  border-radius: 0.9rem;
  overflow: hidden;
  background: linear-gradient(90deg, #f5f0e6, #efe8d8);
  border: 1px dashed rgba(43, 33, 24, 0.18);
  min-height: 72px;
  display: grid;
  place-items: center;
  position: relative;
}

.ad-slot::before {
  content: "Anúncio";
  position: absolute;
  top: 0.35rem;
  left: 0.5rem;
  font-size: 0.65rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  opacity: 0.45;
}

.ad-slot .ad-placeholder {
  text-align: center;
  padding: 0.65rem;
  font-size: 0.8rem;
  font-weight: 700;
  opacity: 0.7;
}

.ad-banner-fixed {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  height: calc(var(--ad-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: #1a1a1a;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #f5f5f5;
  font-size: 0.8rem;
  font-weight: 700;
}

.ad-banner-fixed .ad-inner {
  width: min(720px, 100%);
  height: var(--ad-height);
  display: grid;
  place-items: center;
  background: #222;
}

.install-banner {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  background: var(--teal);
  color: white;
  border-radius: var(--radius);
  padding: 0.75rem 0.9rem;
  box-shadow: var(--shadow);
}

.install-banner.show {
  display: flex;
}

.install-banner button {
  border: 0;
  background: white;
  color: var(--ink);
  font-weight: 800;
  border-radius: 999px;
  padding: 0.5rem 0.85rem;
  cursor: pointer;
  flex-shrink: 0;
}

.loading-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  background: rgba(255, 248, 231, 0.82);
  display: none;
  place-items: center;
  flex-direction: column;
  gap: 0.75rem;
  font-weight: 800;
}

.loading-overlay.show {
  display: flex;
}

.spinner {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  border: 4px solid rgba(255, 107, 74, 0.2);
  border-top-color: var(--coral);
  animation: spin 0.8s linear infinite;
}

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

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--ad-height) + var(--safe-bottom) + 1rem);
  transform: translateX(-50%) translateY(120%);
  background: var(--ink);
  color: white;
  padding: 0.7rem 1rem;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.9rem;
  z-index: 50;
  transition: transform 0.25s ease;
  max-width: 90vw;
  text-align: center;
}

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

.confirm-dialog {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
  place-items: center;
  padding: 1.25rem;
  background: rgba(43, 33, 24, 0.45);
  backdrop-filter: blur(2px);
}

.confirm-dialog.show {
  display: grid;
}

.confirm-dialog-card {
  width: min(100%, 22rem);
  background: #fffef9;
  border-radius: 1.25rem;
  padding: 1.25rem 1.15rem 1.1rem;
  box-shadow: 0 18px 40px rgba(43, 33, 24, 0.22);
}

.confirm-dialog-card p {
  margin: 0 0 1rem;
  font-weight: 700;
  font-size: 1rem;
  line-height: 1.4;
  color: var(--ink);
}

.confirm-dialog-actions {
  display: flex;
  gap: 0.65rem;
  justify-content: flex-end;
}

.confirm-dialog-actions .btn {
  min-width: 5.5rem;
}

.hint-card {
  margin: 0;
  font-size: 0.88rem;
  font-weight: 700;
  color: rgba(43, 33, 24, 0.7);
  line-height: 1.45;
}

@media (max-width: 520px) {
  .canvas-wrap {
    max-height: min(78vw, calc(100dvh - 24rem));
  }

  .hint-card {
    font-size: 0.82rem;
  }
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-premium {
  border: 0;
  border-radius: 999px;
  padding: 0.45rem 0.85rem;
  font-weight: 800;
  font-size: 0.82rem;
  color: #fff;
  background: linear-gradient(135deg, var(--grape), var(--coral));
  box-shadow: var(--shadow);
}

.premium-badge {
  font-size: 0.78rem;
  font-weight: 800;
  color: var(--grape);
  background: rgba(123, 94, 167, 0.12);
  border-radius: 999px;
  padding: 0.35rem 0.65rem;
}

.premium-quota {
  margin: 0.35rem 0 0;
  font-size: 0.82rem;
  font-weight: 700;
  color: rgba(43, 33, 24, 0.65);
}

.premium-modal {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(43, 33, 24, 0.45);
}

.premium-modal.show {
  display: flex;
}

.premium-card {
  position: relative;
  width: min(100%, 22rem);
  background: #fff8e7;
  border-radius: 1.25rem;
  padding: 1.25rem 1rem 1rem;
  box-shadow: var(--shadow);
}

.premium-card h2 {
  margin: 0 0 0.75rem;
  font-size: 1.35rem;
}

.premium-list {
  margin: 0 0 1rem;
  padding-left: 1.1rem;
  line-height: 1.5;
}

.premium-note {
  margin: 0 0 1rem;
  font-size: 0.85rem;
  color: rgba(43, 33, 24, 0.7);
}

.premium-close {
  position: absolute;
  top: 0.4rem;
  right: 0.55rem;
  border: 0;
  background: transparent;
  font-size: 1.5rem;
  line-height: 1;
  color: rgba(43, 33, 24, 0.55);
}

.btn-block {
  width: 100%;
  margin-top: 0.5rem;
}

.btn-ghost {
  background: transparent;
  color: var(--ink);
  border: 2px solid rgba(43, 33, 24, 0.12);
}

@media (min-width: 720px) {
  .main {
    padding-top: 1.1rem;
    gap: 0.9rem;
  }

  .canvas-wrap {
    max-height: min(560px, calc(100dvh - 18rem));
  }
}
