:root {
  --bg: #0b0f14;
  --bg2: #121820;
  --surface: #1a222d;
  --border: #2a3544;
  --text: #e8eef6;
  --muted: #8b9bb0;
  --accent: #5b9fd4;
  --accent-press: #4a8bc0;
  --danger: #e85d5d;
  --danger-press: #c94a4a;
  --radius: 14px;
  --tap: 48px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

body { overscroll-behavior: none; }

#app { min-height: 100%; min-height: 100dvh; }

.screen {
  min-height: 100%;
  min-height: 100dvh;
}

[hidden] { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  border: 0;
}

.muted { color: var(--muted); }
.error { color: var(--danger); font-size: 0.9rem; margin: 0.5rem 0 0; }
.hint { font-size: 0.85rem; margin-top: 1rem; text-align: center; line-height: 1.4; }

/* Auth */
.auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(1.5rem + var(--safe-t)) calc(1.25rem + var(--safe-r)) calc(1.5rem + var(--safe-b)) calc(1.25rem + var(--safe-l));
  background:
    radial-gradient(ellipse at 50% 0%, #1a2a3a 0%, transparent 55%),
    var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 360px;
  text-align: center;
}

.logo {
  font-size: 2.5rem;
  color: var(--accent);
  margin-bottom: 0.5rem;
}

.auth-card h1 {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.auth-card .muted { margin: 0.35rem 0 1.75rem; }

.remember-row, .remember-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-height: 44px;
  margin: 0.15rem 0 0.25rem;
  color: var(--muted);
  font-size: 0.95rem;
  text-align: left;
  user-select: none;
  cursor: pointer;
}

.remember-row, .remember-row input[type="checkbox"] {
  -webkit-appearance: checkbox;
  appearance: auto;
  width: 1.15rem;
  height: 1.15rem;
  min-height: 0;
  margin: 0;
  flex: 0 0 auto;
  accent-color: var(--accent);
}

#auth-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

#auth-form input[type="email"],
#auth-form input[type="password"],
#auth-form input[type="text"] {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  width: 100%;
  box-sizing: border-box;
  min-height: var(--tap);
  margin: 0;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  caret-color: var(--text);
  font: inherit;
  font-size: 16px; /* keeps iOS from zooming / restyling email */
  line-height: 1.25;
  outline: none;
  box-shadow: none;
}

#auth-form input[type="email"]::placeholder,
#auth-form input[type="password"]::placeholder,
#auth-form input[type="text"]::placeholder {
  color: var(--muted);
  opacity: 1;
}

#auth-form input[type="email"]:focus,
#auth-form input[type="password"]:focus,
#auth-form input[type="text"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(91, 159, 212, 0.25);
}

/* Kill browser autofill paint differences between email vs password */
#auth-form input[type="email"]:-webkit-autofill,
#auth-form input[type="password"]:-webkit-autofill,
#auth-form input[type="text"]:-webkit-autofill {
  -webkit-text-fill-color: var(--text);
  caret-color: var(--text);
  box-shadow: 0 0 0 1000px var(--surface) inset;
  transition: background-color 99999s ease-out;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: var(--tap);
  min-width: var(--tap);
  padding: 0.75rem 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  font-weight: 560;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn.primary {
  background: var(--accent);
  border-color: transparent;
  color: #061018;
  width: 100%;
}

.btn.primary:active { background: var(--accent-press); }

.btn.icon {
  padding: 0;
  background: transparent;
  border: none;
  color: var(--text);
}

.btn.danger { color: var(--danger); }
.btn.danger:not(.icon) {
  background: var(--danger);
  border-color: transparent;
  color: #fff;
}

/* Gallery */
.gallery-screen {
  display: flex;
  flex-direction: column;
  padding-bottom: var(--safe-b);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: calc(56px + var(--safe-t));
  padding: var(--safe-t) calc(0.5rem + var(--safe-r)) 0 calc(1rem + var(--safe-l));
  background: rgba(11, 15, 20, 0.92);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
}

.topbar-actions { display: flex; gap: 0.15rem; }

.upload-progress {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}

.upload-bar {
  height: 6px;
  border-radius: 99px;
  background: var(--surface);
  overflow: hidden;
}

#upload-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.2s ease;
}

#upload-status { margin: 0.4rem 0 0; font-size: 0.85rem; }

.gallery {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
  padding: 2px;
  flex: 1;
}

@media (min-width: 600px) {
  .gallery { grid-template-columns: repeat(4, 1fr); }
}
@media (min-width: 900px) {
  .gallery { grid-template-columns: repeat(5, 1fr); max-width: 1100px; margin: 0 auto; width: 100%; }
}

.tile {
  position: relative;
  aspect-ratio: 1;
  background: var(--surface);
  overflow: hidden;
  border: none;
  padding: 0;
  cursor: pointer;
  color: inherit;
}

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

.tile-video-badge {
  position: absolute;
  right: 6px;
  bottom: 6px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
}

.tile-video-badge svg { width: 14px; height: 14px; }

.tile-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}

.empty {
  text-align: center;
  padding: 3rem 1.5rem;
  margin: 0;
}

/* Viewer */
.viewer-screen {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: #000;
  display: flex;
  flex-direction: column;
}

.viewer-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: calc(52px + var(--safe-t));
  padding: var(--safe-t) calc(0.5rem + var(--safe-r)) 0 calc(0.5rem + var(--safe-l));
  background: rgba(0,0,0,0.7);
}

.viewer-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.95rem;
}

.viewer-body {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding-bottom: var(--safe-b);
}

.viewer-body img,
.viewer-body video {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
}

.viewer-body video {
  width: 100%;
  max-height: calc(100dvh - 60px - var(--safe-t) - var(--safe-b));
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 1rem;
  padding-bottom: calc(1rem + var(--safe-b));
}

@media (min-width: 480px) {
  .modal { align-items: center; }
}

.modal-card {
  width: 100%;
  max-width: 360px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.modal-card p { margin: 0 0 1.25rem; }

.modal-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
}

.modal-actions .btn { flex: 1; }
