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

:root {
  --bg: #faf7f2;
  --card: #ffffff;
  --text: #2d2a26;
  --sub: #7a7468;
  --accent: #e07a5f;
  --accent-hover: #c96a4f;
  --border: #e8e2d8;
  --success: #81b29a;
  --error: #e07a5f;
  --radius: 16px;
  --shadow: 0 2px 12px rgba(0,0,0,0.06);
}

html { font-size: 16px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  padding: 24px 20px 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100dvh;
}

header {
  text-align: center;
  padding: 28px 0 24px;
}

header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

header .sub {
  color: var(--sub);
  font-size: 0.95rem;
  margin-top: 6px;
}

/* --- Tab Navigation --- */

#tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 24px;
  background: var(--card);
  border-radius: 12px;
  padding: 4px;
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 300px;
}

.tab {
  flex: 1;
  padding: 10px 16px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--sub);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.tab.active {
  background: var(--accent);
  color: #fff;
}

.tab-content {
  width: 100%;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 24px;
  width: 100%;
  text-align: center;
}

.card label {
  display: block;
  font-size: 0.95rem;
  color: var(--sub);
  margin-bottom: 14px;
}

.card input[type="password"] {
  width: 100%;
  padding: 14px 16px;
  font-size: 1.1rem;
  border: 2px solid var(--border);
  border-radius: 12px;
  text-align: center;
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}

.card input[type="password"]:focus {
  border-color: var(--accent);
}

.card button {
  margin-top: 16px;
  width: 100%;
  padding: 14px;
  font-size: 1.05rem;
  font-weight: 600;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.15s;
  -webkit-appearance: none;
}

.card button:hover { background: var(--accent-hover); }
.card button:active { background: var(--accent-hover); }

.error-msg {
  color: var(--error);
  font-size: 0.9rem;
  margin-top: 12px;
}

#file-input { display: none; }

.pick-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 16px 32px;
  font-size: 1.1rem;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border-radius: 14px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  box-shadow: 0 4px 16px rgba(224,122,95,0.25);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.pick-btn:hover { background: var(--accent-hover); }
.pick-btn:active { transform: scale(0.97); }

#picker { margin: 8px 0 20px; text-align: center; }

/* --- Drop Zone (desktop) --- */

#drop-zone {
  width: 100%;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 36px 20px;
  text-align: center;
  transition: border-color 0.2s, background 0.2s;
  margin-bottom: 20px;
}

#drop-zone.drag-over {
  border-color: var(--accent);
  background: rgba(224,122,95,0.06);
}

.drop-inner svg { color: var(--sub); margin-bottom: 8px; }
.drop-inner p { font-size: 0.95rem; color: var(--sub); }
.drop-inner .sub { font-size: 0.8rem; margin-top: 4px; }

/* --- Queue --- */

#queue { width: 100%; }

#queue-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}

.queue-item {
  position: relative;
  aspect-ratio: 1;
  border-radius: 12px;
  overflow: hidden;
  background: var(--border);
  box-shadow: var(--shadow);
}

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

.queue-item .remove-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.55);
  color: #fff;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  backdrop-filter: blur(4px);
}

.queue-item .progress-overlay {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 4px;
  background: rgba(0,0,0,0.2);
}

.queue-item .progress-overlay .bar {
  height: 100%;
  background: var(--success);
  transition: width 0.2s;
  width: 0;
}

.queue-item.uploading .progress-overlay .bar { width: 50%; }
.queue-item.done .progress-overlay .bar { width: 100%; }
.queue-item.error { outline: 3px solid var(--error); }

.queue-item .status-icon {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.6rem;
  pointer-events: none;
}

.queue-item.done .status-icon::after { content: '✓'; color: #fff; text-shadow: 0 0 6px rgba(0,0,0,0.5); }
.queue-item.error .status-icon::after { content: '!'; color: #fff; text-shadow: 0 0 6px rgba(0,0,0,0.5); }

/* --- Done Message --- */

.done-msg {
  text-align: center;
  color: var(--sub);
  font-size: 0.95rem;
  margin-top: 12px;
}

.done-msg a {
  color: var(--accent);
  font-weight: 600;
  text-decoration: underline;
}

/* --- Actions --- */

.queue-actions {
  width: 100%;
  text-align: center;
}

#upload-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 16px 40px;
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 14px;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s, transform 0.1s;
  box-shadow: 0 4px 16px rgba(224,122,95,0.25);
  -webkit-appearance: none;
}

#upload-btn:hover:not(:disabled) { background: var(--accent-hover); }
#upload-btn:active:not(:disabled) { transform: scale(0.97); }
#upload-btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* --- Upload Status --- */

.upload-status {
  width: 100%;
  margin-top: 16px;
  text-align: center;
}

#status-text {
  font-size: 0.9rem;
  color: var(--sub);
  display: block;
  margin-bottom: 8px;
}

.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

#progress-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.3s;
}

/* --- Gallery --- */

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

.gallery-item {
  aspect-ratio: 1;
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  background: var(--border);
  transition: transform 0.15s;
}

.gallery-item:hover { transform: scale(1.03); }
.gallery-item:active { transform: scale(0.97); }

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

.empty-msg {
  text-align: center;
  color: var(--sub);
  font-size: 1rem;
  padding: 48px 20px;
}

/* --- Lightbox --- */

#lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.92);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  animation: fadeIn 0.2s;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

#lightbox-img {
  max-width: 92vw;
  max-height: 85vh;
  object-fit: contain;
  border-radius: 8px;
}

#lightbox-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.15);
  color: #fff;
  font-size: 1.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  -webkit-tap-highlight-color: transparent;
}

#lightbox-download {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 24px;
  background: rgba(255,255,255,0.2);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  z-index: 10;
  -webkit-tap-highlight-color: transparent;
}

#lightbox-prev,
#lightbox-next {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.1);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  -webkit-tap-highlight-color: transparent;
}

#lightbox-prev { left: 12px; }
#lightbox-next { right: 12px; }

#lightbox-prev:hover,
#lightbox-next:hover,
#lightbox-download:hover {
  background: rgba(255,255,255,0.3);
}

@media (min-width: 481px) {
  #lightbox-prev { left: 24px; }
  #lightbox-next { right: 24px; }
}

/* --- Footer --- */

footer {
  margin-top: auto;
  padding-top: 32px;
  text-align: center;
}

footer p {
  font-size: 0.8rem;
  color: var(--sub);
}

/* --- Utils --- */

.hidden { display: none !important; }

/* --- Responsive --- */

@media (max-width: 380px) {
  #queue-grid, #gallery-grid { grid-template-columns: repeat(2, 1fr); }
  .pick-btn { padding: 14px 24px; font-size: 1rem; }
}

@media (min-width: 481px) {
  #app { padding: 40px 20px 60px; }
  header h1 { font-size: 2rem; }
}
