:root {
  --bg: #0f1117;
  --surface: #1a1d29;
  --surface-2: #232735;
  --border: #2e3344;
  --text: #e7e9ee;
  --muted: #9aa0b0;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --danger: #ef4444;
  --ok: #22c55e;
  --radius: 14px;
}

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

body {
  font-family: "Segoe UI", "Sarabun", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---- Topbar ---- */
.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.logo {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
}
.tagline { color: var(--muted); font-size: 0.9rem; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.user-badge { color: var(--muted); font-size: .9rem; }

/* ---- Login ---- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 28px;
  text-align: center;
}
.login-logo { font-size: 2.6rem; }
.login-card h1 { font-size: 1.5rem; margin: 6px 0 4px; }
.login-sub { color: var(--muted); font-size: .9rem; margin-bottom: 22px; }
.field { display: block; text-align: left; margin-bottom: 16px; }
.field span { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 6px; }
.field input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 11px 12px;
  border-radius: 9px;
  font-size: 1rem;
}
.field input:focus { outline: none; border-color: var(--accent); }
.login-btn { width: 100%; padding: 12px; font-size: 1rem; margin-top: 4px; }
.login-btn:disabled { opacity: .6; cursor: not-allowed; }
.login-msg { margin-top: 14px; font-size: .9rem; min-height: 1.2em; }
.login-msg.error { color: var(--danger); }
.login-msg.ok { color: var(--ok); }

/* ---- Container ---- */
.container {
  flex: 1;
  width: 100%;
  max-width: 920px;
  margin: 0 auto;
  padding: 32px 20px 60px;
}

.hero { text-align: center; margin-bottom: 28px; }
.hero h1 { font-size: 1.9rem; margin-bottom: 8px; }
.hero p { color: var(--muted); }

/* ---- Dropzone ---- */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 48px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s, background .2s, transform .1s;
}
.dropzone:hover { border-color: var(--accent); }
.dropzone.dragover {
  border-color: var(--accent);
  background: var(--surface-2);
  transform: scale(1.01);
}
.dz-icon { font-size: 2.4rem; margin-bottom: 10px; }
.dz-title { font-size: 1.1rem; font-weight: 600; }
.dz-sub { color: var(--muted); margin-top: 6px; }
.link-btn {
  background: none;
  border: none;
  color: var(--accent-hover);
  cursor: pointer;
  font: inherit;
  text-decoration: underline;
}

/* ---- Progress ---- */
.progress { margin-top: 18px; }
.progress-bar {
  height: 8px;
  background: var(--surface-2);
  border-radius: 99px;
  overflow: hidden;
}
.progress-bar span {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width .2s;
}
#progressText { color: var(--muted); font-size: .9rem; margin-top: 6px; text-align: center; }

/* ---- Results ---- */
.results { margin-top: 20px; display: flex; flex-direction: column; gap: 12px; }
.result-card {
  display: flex;
  gap: 14px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}
.result-thumb {
  width: 72px; height: 72px;
  object-fit: cover;
  border-radius: 10px;
  background: var(--surface-2);
  flex-shrink: 0;
}
.result-body { flex: 1; min-width: 0; }
.result-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.copy-row { display: flex; gap: 8px; margin-top: 8px; }
.copy-row input {
  flex: 1;
  min-width: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 8px;
  font-size: .85rem;
}
.copy-row button, .btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  white-space: nowrap;
  transition: background .15s;
}
.copy-row button:hover, .btn:hover { background: var(--accent-hover); }

/* ---- Gallery ---- */
.gallery-section { margin-top: 48px; }
.gallery-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.gallery-head h2 { font-size: 1.3rem; }
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
}
.gallery-item {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  aspect-ratio: 1;
}
.gallery-item img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
  transition: transform .2s;
}
.gallery-item:hover img { transform: scale(1.05); }
.gallery-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0,0,0,.75), transparent 60%);
  opacity: 0;
  transition: opacity .2s;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 10px;
  gap: 6px;
}
.gallery-item:hover .gallery-overlay { opacity: 1; }
.overlay-actions { display: flex; gap: 6px; }
.icon-btn {
  flex: 1;
  background: rgba(255,255,255,.12);
  border: none;
  color: #fff;
  padding: 6px;
  border-radius: 6px;
  cursor: pointer;
  font-size: .8rem;
  backdrop-filter: blur(4px);
}
.icon-btn:hover { background: rgba(255,255,255,.25); }
.icon-btn.danger:hover { background: var(--danger); }

.empty { text-align: center; color: var(--muted); padding: 40px 0; }
.hidden { display: none !important; }

/* ---- Footer ---- */
.footer {
  text-align: center;
  padding: 20px;
  color: var(--muted);
  font-size: .85rem;
  border-top: 1px solid var(--border);
}

/* ---- Toast ---- */
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--ok);
  color: #062b12;
  padding: 12px 20px;
  border-radius: 10px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 100;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { background: var(--danger); color: #fff; }

/* ---- View page ---- */
.view-body { align-items: center; }
.viewer {
  max-width: 800px;
  margin: 40px auto;
  padding: 0 20px;
  text-align: center;
  width: 100%;
}
.viewer-img {
  max-width: 100%;
  max-height: 70vh;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.viewer-info { margin-top: 20px; }
.viewer-name { color: var(--muted); margin-bottom: 12px; }
.btn-download {
  display: inline-block;
  margin-top: 12px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 10px 18px;
  border-radius: 8px;
  text-decoration: none;
}
.btn-download:hover { border-color: var(--accent); }
.viewer .copy-row { max-width: 560px; margin: 0 auto; }
