@import url('https://fonts.googleapis.com/css2?family=Sora:wght@600;700;800&family=Inter:wght@400;500;600;700&display=swap');

:root {
  --bg-base: #0a0e17;
  --bg-surface: #10151f;
  --bg-elevated: #171e2c;
  --border: #232c40;
  --border-soft: #1a2231;
  --blue: #3b82f6;
  --blue-deep: #1d4ed8;
  --teal: #2dd4bf;
  --text-primary: #eaeffb;
  --text-secondary: #8c96b3;
  --text-muted: #5c6685;
  --danger: #f87171;
  --success: #34d399;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  min-height: 100vh;
}

body {
  background-image:
    radial-gradient(circle at 15% 10%, rgba(59, 130, 246, 0.10), transparent 45%),
    radial-gradient(circle at 85% 90%, rgba(45, 212, 191, 0.08), transparent 45%),
    linear-gradient(rgba(255,255,255,0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.025) 1px, transparent 1px);
  background-size: auto, auto, 34px 34px, 34px 34px;
}

h1, h2, h3 { font-family: 'Sora', sans-serif; margin: 0; letter-spacing: -0.01em; }

a { color: inherit; text-decoration: none; }

.brand-gradient {
  background: linear-gradient(100deg, var(--blue) 0%, var(--teal) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

button {
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  border: none;
}

/* ---------- Layout shell ---------- */
.shell {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 20px 64px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 28px;
}

.topbar .logo-mark {
  height: 34px;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  padding: 6px 14px 6px 6px;
  border-radius: 999px;
}

.user-chip img {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--border);
}

.user-chip span {
  font-size: 13px;
  color: var(--text-secondary);
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.logout-link {
  font-size: 12px;
  color: var(--text-muted);
  margin-left: 4px;
}
.logout-link:hover { color: var(--danger); }

/* ---------- Usage badge ---------- */
.usage-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  margin-bottom: 20px;
  font-size: 13px;
  color: var(--text-secondary);
}

.usage-dots {
  display: flex;
  gap: 5px;
}

.usage-dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
}

.usage-dots span.filled {
  background: linear-gradient(120deg, var(--blue), var(--teal));
}

/* ---------- Hero / heading ---------- */
.page-title { font-size: 26px; font-weight: 700; margin-bottom: 6px; }
.page-subtitle { color: var(--text-secondary); font-size: 14px; margin-bottom: 24px; }

/* ---------- Stage (dropzone / canvas / result) ---------- */
.stage {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  flex: 1;
}

.dropzone {
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-md);
  min-height: 320px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 14px;
  padding: 40px 20px;
  transition: border-color .15s ease, background .15s ease;
  cursor: pointer;
}

.dropzone.dragover {
  border-color: var(--blue);
  background: rgba(59, 130, 246, 0.06);
}

.dropzone-icon {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(59,130,246,0.18), rgba(45,212,191,0.18));
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--teal);
}

.dropzone-title { font-size: 15px; font-weight: 600; }
.dropzone-hint { font-size: 12.5px; color: var(--text-muted); max-width: 280px; }

.dropzone input[type=file] { display: none; }

/* ---------- Editor ---------- */
.editor { display: none; }
.editor.active { display: block; }

.canvas-wrap {
  position: relative;
  width: 100%;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: #000;
  line-height: 0;
}

.canvas-wrap canvas {
  width: 100%;
  height: auto;
  display: block;
  touch-action: none;
}

.canvas-wrap canvas#maskCanvas {
  position: absolute;
  top: 0;
  left: 0;
  cursor: crosshair;
  opacity: 0.55;
}

.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.brush-control {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--text-secondary);
}

.brush-control input[type=range] {
  accent-color: var(--teal);
}

.tool-btn {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-weight: 500;
}
.tool-btn:hover { color: var(--text-primary); border-color: var(--blue); }

.editor-hint {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-top: 10px;
}

.action-row {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.btn-primary {
  flex: 1;
  background: linear-gradient(100deg, var(--blue) 0%, var(--blue-deep) 60%, var(--teal) 130%);
  color: #fff;
  font-weight: 600;
  font-size: 14.5px;
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: filter .15s ease, transform .1s ease;
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:active { transform: scale(0.99); }
.btn-primary:disabled {
  background: var(--bg-elevated);
  color: var(--text-muted);
  cursor: not-allowed;
  filter: none;
}

.btn-secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 14px;
  padding: 14px 18px;
  border-radius: var(--radius-sm);
}
.btn-secondary:hover { color: var(--text-primary); border-color: var(--text-muted); }

/* ---------- Result ---------- */
.result-view { display: none; }
.result-view.active { display: block; }

.result-img-wrap {
  border-radius: var(--radius-md);
  overflow: hidden;
  line-height: 0;
  background: #000;
}
.result-img-wrap img { width: 100%; display: block; }

/* ---------- Spinner / processing overlay ---------- */
.processing-overlay {
  position: absolute;
  inset: 0;
  background: rgba(10, 14, 23, 0.72);
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 14px;
  backdrop-filter: blur(2px);
}
.processing-overlay.active { display: flex; }

.spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.12);
  border-top-color: var(--teal);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.processing-overlay p { font-size: 13px; color: var(--text-secondary); }

/* ---------- Toast / message ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  max-width: 90%;
  text-align: center;
  z-index: 50;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.error { border-color: rgba(248,113,113,0.4); }

/* ---------- Cooldown badge ---------- */
.cooldown-badge {
  font-size: 12.5px;
  color: var(--teal);
  font-variant-numeric: tabular-nums;
}

/* ---------- Login page ---------- */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 32px;
  text-align: center;
}

.login-card .logo-mark {
  height: 40px;
  margin-bottom: 28px;
}

.login-card h1 {
  font-size: 21px;
  margin-bottom: 10px;
}

.login-card p {
  color: var(--text-secondary);
  font-size: 13.5px;
  line-height: 1.6;
  margin-bottom: 28px;
}

.google-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: #fff;
  color: #1f1f1f;
  font-weight: 600;
  font-size: 14.5px;
  padding: 13px 18px;
  border-radius: var(--radius-sm);
  transition: filter .15s ease;
}
.google-btn:hover { filter: brightness(0.96); }

.login-meta {
  margin-top: 22px;
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.6;
}

.error-note {
  margin-top: 16px;
  font-size: 12.5px;
  color: var(--danger);
  background: rgba(248, 113, 113, 0.08);
  border: 1px solid rgba(248, 113, 113, 0.25);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

@media (max-width: 480px) {
  .login-card { padding: 32px 22px; }
  .action-row { flex-direction: column; }
}
