:root {
  --bg: #111318;
  --surface: #1b1e26;
  --surface-2: #262a35;
  --text: #f2f3f5;
  --muted: #9aa0ac;
  --accent: #4f8cff;
  --accent-hover: #3d78e6;
  --danger: #e5484d;
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
}

.hidden { display: none !important; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--surface-2);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}

.topbar h1 {
  font-size: 1.1rem;
  margin: 0;
}

.user-box {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
}

.avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
}

main {
  max-width: 520px;
  margin: 0 auto;
  padding: 20px 16px 110px;
}

.screen { width: 100%; }

.capture-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 60%, transparent);
  z-index: 50;
}

.capture-bar .btn-large {
  max-width: 520px;
  margin: 0 auto;
  display: block;
}

/* En PC no hace falta el botón de sacar foto: se usa desde el celular */
@media (min-width: 768px) {
  .capture-bar { display: none; }
  main { padding-bottom: 40px; }
}

.login-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 28px 20px;
  text-align: center;
  margin-top: 15vh;
}

.login-card p {
  color: var(--muted);
  margin-bottom: 24px;
  line-height: 1.5;
}

.btn-primary {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 10px;
  padding: 12px 20px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-large {
  padding: 20px;
  font-size: 1.1rem;
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--surface-2);
  border-radius: 10px;
  padding: 10px 16px;
  cursor: pointer;
  font-size: 0.9rem;
}
.btn-ghost:hover { color: var(--text); border-color: var(--accent); }

.section-title {
  font-size: 1rem;
  color: var(--muted);
  margin: 0 0 12px;
}

.gallery {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.gallery-item {
  position: relative;
  aspect-ratio: 3/4;
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
}

.gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  cursor: pointer;
}

.gallery-item a.dl {
  position: absolute;
  bottom: 4px;
  right: 4px;
  background: rgba(0,0,0,0.6);
  color: white;
  border-radius: 6px;
  padding: 4px 6px;
  font-size: 0.75rem;
  text-decoration: none;
}

.gallery-item .downloaded-badge {
  position: absolute;
  top: 4px;
  left: 4px;
  background: #2ecc71;
  color: white;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: bold;
  box-shadow: 0 1px 4px rgba(0,0,0,0.5);
}

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

.editor-wrap, .preview-wrap {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 10px;
  display: flex;
  justify-content: center;
  margin-bottom: 12px;
  position: relative;
}

.magnifier {
  position: fixed;
  width: 130px;
  height: 130px;
  border-radius: 50%;
  border: 3px solid var(--accent);
  box-shadow: 0 6px 16px rgba(0,0,0,0.5);
  pointer-events: none;
  z-index: 150;
  background: #000;
}

#editorCanvas, #previewCanvas {
  max-width: 100%;
  max-height: 65vh;
  touch-action: none;
  border-radius: 6px;
}

.editor-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}
.editor-actions .btn-ghost, .editor-actions .btn-primary {
  flex: 1;
}

.field-label {
  display: block;
  color: var(--muted);
  font-size: 0.85rem;
  margin: 16px 0 6px;
}

.text-input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--surface-2);
  color: var(--text);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 1rem;
}
.text-input:focus {
  outline: none;
  border-color: var(--accent);
}

.select-input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--surface-2);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.95rem;
  margin-bottom: 12px;
}
.select-input:focus {
  outline: none;
  border-color: var(--accent);
}

.filter-toggle {
  display: flex;
  gap: 20px;
  justify-content: center;
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: 10px;
}

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 300;
  padding: 20px;
}

.lightbox-imgwrap {
  width: 100%;
  height: 78vh;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
}

.lightbox img {
  max-width: 100%;
  max-height: 78vh;
  border-radius: 8px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.6);
  cursor: grab;
  user-select: none;
  -webkit-user-drag: none;
  will-change: transform;
}
.lightbox img:active { cursor: grabbing; }

.lightbox-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: var(--surface-2);
  color: var(--text);
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 1.1rem;
  cursor: pointer;
}

.lightbox-dl {
  width: auto;
  padding: 12px 24px;
  text-decoration: none;
  text-align: center;
}

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-2);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 0.9rem;
  z-index: 100;
  max-width: 90vw;
}
.toast.error { background: var(--danger); }

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  z-index: 200;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--surface-2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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