:root {
  --bg: #faf8f5;
  --bg-panel: #ffffff;
  --bg-editor: #1b1e24;
  --accent: #f7a412;
  --accent-2: #19b4e9;
  --accent-green: #4cb04d;
  --text: #23282e;
  --text-inverse: #ffffff;
  --muted: #7a828d;
  --border: rgba(35,40,46,0.10);
  --radius: 20px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

.screen { display: none; height: 100%; width: 100%; }
.screen.active { display: flex; flex-direction: column; }

/* ---------------------------------------------------------- start screen */

.start-wrap {
  position: relative;
  margin: auto;
  text-align: center;
  padding: 24px;
  max-width: 420px;
}

.start-wrap::before,
.start-wrap::after {
  content: "";
  position: absolute;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: radial-gradient(circle at 35% 35%, var(--accent-2), transparent 65%);
  opacity: 0.5;
  z-index: -1;
}

.start-wrap::before { top: -10px; left: 6px; }
.start-wrap::after { bottom: 10px; right: 0; background: radial-gradient(circle at 35% 35%, var(--accent), transparent 65%); }

.brand {
  font-family: 'Baloo 2', -apple-system, BlinkMacSystemFont, sans-serif;
  font-weight: 800;
  font-size: 2.3rem;
  margin: 0 0 4px;
  background: linear-gradient(90deg, var(--accent), var(--accent-green), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hint { color: var(--muted); margin-bottom: 28px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 16px 28px;
  border-radius: 999px;
  border: none;
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}

.btn-primary {
  background: linear-gradient(90deg, var(--accent), #ffc257);
  color: #2c1a00;
  font-weight: 700;
  box-shadow: 0 10px 24px rgba(247,164,18,0.35);
}
.btn-ghost {
  background: var(--bg-panel);
  color: var(--text);
  border: 1px solid var(--border);
  margin-top: 10px;
}
.big-upload { width: 100%; }

.error-text { color: #e0384c; margin-top: 14px; min-height: 1.2em; }

/* ---------------------------------------------------------------- editor */

#screen-editor { position: relative; background: var(--bg-editor); }

.editor-topbar {
  display: flex;
  justify-content: space-between;
  padding: 10px 14px calc(6px + var(--safe-bottom, 0px));
  padding-top: max(10px, env(safe-area-inset-top));
}

.icon-btn {
  background: rgba(255,255,255,0.1);
  border: none;
  color: #ffffff;
  width: 44px; height: 44px;
  border-radius: 50%;
  font-size: 1.2rem;
  cursor: pointer;
}

.canvas-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 4px 8px;
}

#canvas {
  max-width: 100%;
  max-height: 100%;
  touch-action: none;
  border-radius: 10px;
  background: #000;
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
}

.panel {
  padding: 14px 16px;
  background: var(--bg-panel);
  border-top-left-radius: var(--radius);
  border-top-right-radius: var(--radius);
}

#text-input {
  width: 100%;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: #f4f2ee;
  color: var(--text);
  font-size: 1.1rem;
}

#text-input {
  resize: none;
  font-family: inherit;
  line-height: 1.35;
}

.swatch-list {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding: 4px 2px;
}

.swatch {
  flex: 0 0 auto;
  width: 46px; height: 46px;
  border-radius: 50%;
  border: 2px solid var(--border);
  cursor: pointer;
}

.sticker-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  max-height: 34vh;
  overflow-y: auto;
  padding: 4px 2px;
}

.sticker-item {
  background: #f4f2ee;
  border: 1px solid var(--border);
  border-radius: 14px;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  cursor: pointer;
}

.sticker-item img { width: 100%; height: 100%; object-fit: contain; }

.bottom-nav {
  display: flex;
  background: var(--bg-panel);
  padding: 8px 6px calc(8px + var(--safe-bottom));
  border-top: 1px solid var(--border);
}

.nav-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 4px;
  font-size: 0.78rem;
  border-radius: 12px;
  cursor: pointer;
}

.nav-btn.active { color: var(--text); background: #f4f2ee; }
.nav-icon { font-size: 1.15rem; line-height: 1; }
.nav-dot { width: 16px; height: 16px; border-radius: 50%; background: conic-gradient(red, orange, yellow, green, blue, violet, red); }
.nav-btn-cta { color: var(--accent); font-weight: 700; }

/* --------------------------------------------------------------- export */

.export-wrap {
  margin: auto;
  text-align: center;
  padding: 24px;
  max-width: 480px;
}

#export-preview {
  max-width: 100%;
  max-height: 60vh;
  border-radius: 14px;
  box-shadow: 0 10px 30px rgba(35,40,46,0.18);
  margin-bottom: 20px;
}

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

/* ------------------------------------------------------------- loading */

.loading-overlay {
  position: fixed; inset: 0;
  background: rgba(250,248,245,0.85);
  display: none;
  align-items: center; justify-content: center;
  z-index: 50;
}

.loading-overlay:not([hidden]) {
  display: flex;
}

.spinner {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 4px solid rgba(35,40,46,0.15);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

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

/* --------------------------------------------------------- desktop view */

@media (min-width: 860px) {
  .start-wrap { max-width: 480px; }

  #screen-editor {
    display: grid;
    grid-template-columns: 1fr 360px;
    grid-template-rows: auto auto 1fr;
    height: 100%;
  }

  .editor-topbar { grid-column: 1 / 3; grid-row: 1 / 2; }
  .canvas-wrap { grid-column: 1 / 2; grid-row: 2 / 4; }

  .bottom-nav {
    grid-column: 2 / 3;
    grid-row: 2 / 3;
    flex-direction: column;
    justify-content: flex-start;
    gap: 6px;
    border-top: none;
    border-left: 1px solid var(--border);
    padding-top: 16px;
  }

  .nav-btn { flex-direction: row; justify-content: flex-start; gap: 10px; font-size: 0.95rem; padding: 12px 14px; }

  .panel {
    grid-column: 2 / 3;
    grid-row: 3 / 4;
    align-self: start;
    border-left: 1px solid var(--border);
    border-top-left-radius: 0;
    overflow-y: auto;
  }

  .sticker-grid { grid-template-columns: repeat(3, 1fr); max-height: 50vh; }
}
