/* GaoFinder: mobile first, โทนมืดแบบกลาสมีแสงไล่สี สลับเป็นโทนสว่างตามเครื่อง */
:root {
  --bg: #0b0b14; --bg2: #12121f; --card: rgba(255,255,255,.06); --card-solid: #16162a;
  --text: #f4f4fb; --muted: #a3a3c2; --border: rgba(255,255,255,.10);
  --accent: #8b7bff; --accent2: #ff6fb1; --accent-text: #fff;
  --grad: linear-gradient(135deg, #7c6cff 0%, #c76bff 50%, #ff6fb1 100%);
  --warn: #ffb86b; --ok: #5ef0b0; --radius: 22px; --shadow: 0 10px 40px rgba(0,0,0,.35);
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root { --bg: #f6f5ff; --bg2: #ffffff; --card: rgba(255,255,255,.75); --card-solid: #fff;
    --text: #16142b; --muted: #635f86; --border: rgba(40,30,120,.12);
    --accent: #6a58f5; --warn: #b45f06; --ok: #0f9f68; --shadow: 0 10px 30px rgba(60,40,160,.10); color-scheme: light; }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100dvh; font-family: "Anuphan", system-ui, "Noto Sans Thai", sans-serif;
  color: var(--text); line-height: 1.55; background: var(--bg);
  padding-bottom: 140px;
}
body::before { content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(60vmax 40vmax at 0% -10%, rgba(124,108,255,.35), transparent 60%),
    radial-gradient(50vmax 35vmax at 110% 0%, rgba(255,111,177,.25), transparent 60%); }
header, main { max-width: 960px; margin: 0 auto; padding: 0 16px; }
h1 { margin: 0; font-size: clamp(2rem, 7vw, 3rem); font-weight: 700; letter-spacing: -.02em; }
h1 span { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
h2 { margin: 0 0 8px; font-size: 1.15rem; font-weight: 600; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
a { color: var(--accent); }

/* ส่วนหัว */
.hero { padding-top: 28px; padding-bottom: 12px; }
.brand { display: flex; align-items: center; gap: 12px; }
.logo { width: 44px; height: 44px; border-radius: 14px; background: var(--grad); box-shadow: 0 6px 24px rgba(199,107,255,.45); position: relative; flex: none; }
.logo::before { content: ""; position: absolute; inset: 10px 13px 13px 10px; border: 3px solid #fff; border-radius: 50%; }
.logo::after { content: ""; position: absolute; width: 10px; height: 3px; background: #fff; border-radius: 2px; right: 7px; bottom: 10px; transform: rotate(45deg); }
.sub { color: var(--muted); margin: 10px 0 0; font-size: 1.02rem; }
.pills { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 0; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; font-size: .85rem;
  background: var(--card); border: 1px solid var(--border); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.pill:empty { display: none; }
#albumName { font-weight: 600; }
#albumName::before { content: "📸"; }
.admin-bar { display: flex; align-items: center; gap: 8px; margin: 12px 0 0; color: var(--muted); font-size: .9rem; }

/* การ์ด */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px;
  margin: 16px 0; box-shadow: var(--shadow); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); }
.step { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--grad); color: #fff; font-size: .9rem; font-weight: 700; flex: none; }
.count { color: var(--muted); font-weight: 500; font-size: .9rem; }
.hint { color: var(--muted); font-size: .9rem; margin: 6px 0; }
.hint:empty { display: none; }
.hint.lock::before { content: "🔒 "; }
.status { font-size: .92rem; margin: 8px 0; }
.warn { color: var(--warn); font-size: .9rem; }

/* ปุ่ม */
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 12px 0; }
button, label.button, a.mini {
  font: inherit; font-weight: 500; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 20px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--card); color: var(--text); cursor: pointer; text-decoration: none;
  transition: transform .12s ease, box-shadow .2s ease, background .2s ease; -webkit-tap-highlight-color: transparent;
}
button:active, label.button:active { transform: scale(.97); }
button:disabled { opacity: .45; cursor: not-allowed; transform: none; }
button.primary, label.button.primary { background: var(--grad); color: #fff; border-color: transparent; box-shadow: 0 8px 24px rgba(199,107,255,.35); }
button.ghost { background: transparent; }
button:focus-visible, label.button:focus-within, a:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.row.big > * { flex: 1 1 200px; min-height: 56px; font-size: 1.02rem; }
#scanBtn, #stopBtn { width: 100%; min-height: 56px; font-size: 1.05rem; }

/* ฟอร์ม */
.field { display: block; margin: 12px 0; font-size: .95rem; }
.field input[type=text], .field input[type=password], #loginForm input, #folderLink {
  width: 100%; padding: 12px 14px; border-radius: 14px; border: 1px solid var(--border);
  background: var(--bg2); color: var(--text); font: inherit; margin-top: 6px;
}
.field input[type=range] { width: 100%; accent-color: var(--accent); }
.check { display: inline-flex; gap: 8px; align-items: center; }
#loginForm input { flex: 1; min-width: 0; margin: 0; }
.tabs { display: flex; gap: 4px; margin-bottom: 8px; }
.tab.active { background: var(--grad); color: #fff; }
progress { width: 100%; height: 8px; border: 0; border-radius: 99px; overflow: hidden; background: var(--border); appearance: none; }
progress::-webkit-progress-bar { background: var(--border); }
progress::-webkit-progress-value { background: var(--grad); border-radius: 99px; }
progress::-moz-progress-bar { background: var(--grad); }
details { margin-top: 10px; }
summary { cursor: pointer; color: var(--accent); }
#tune summary { color: var(--muted); font-size: .9rem; }
code { background: var(--bg2); padding: 1px 6px; border-radius: 6px; }

/* รูปหน้า */
.faces { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 10px; }
.faces figure { margin: 0; text-align: center; font-size: .8rem; color: var(--muted); position: relative; }
.faces img { width: 88px; height: 88px; object-fit: cover; border-radius: 50%; border: 3px solid var(--accent2); }
.faces .remove { position: absolute; top: -4px; right: auto; left: calc(50% + 26px); min-height: 28px; width: 28px; padding: 0; font-size: .8rem; background: var(--card-solid); }
figure.warn { color: var(--warn); font-size: .85rem; max-width: 240px; }
.pick { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; justify-content: center; }
.faces .pick img { width: 52px; height: 52px; border: 3px solid transparent; cursor: pointer; }
.faces .pick img.chosen { border-color: var(--accent2); }

/* ผลลัพธ์ */
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 640px) { .grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; } }
.item { position: relative; border-radius: 18px; overflow: hidden; background: var(--card-solid); border: 2px solid transparent; transition: border-color .15s, transform .15s; }
.item.selected { border-color: var(--accent2); transform: scale(.98); }
.item img { width: 100%; aspect-ratio: 3/4; object-fit: cover; display: block; cursor: zoom-in; }
.item .sel { position: absolute; top: 8px; left: 8px; z-index: 1; width: 34px; height: 34px; min-height: 0; padding: 0; border-radius: 50%;
  border: 2px solid #fff; background: rgba(0,0,0,.30); backdrop-filter: blur(6px); box-shadow: 0 2px 8px rgba(0,0,0,.3); }
.item .sel::after { content: ""; width: 8px; height: 14px; border: solid #fff; border-width: 0 3px 3px 0; transform: translateY(-2px) rotate(45deg); opacity: 0; }
.item.selected .sel { background: var(--grad); border-color: transparent; }
.item.selected .sel::after { opacity: 1; }
.item .meta { padding: 8px 10px 0; font-size: .8rem; display: flex; justify-content: space-between; gap: 6px; }
.item .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.item .score { color: var(--ok); font-weight: 600; white-space: nowrap; }
.item .score.maybe { color: var(--warn); }
.item .actions { display: flex; gap: 6px; padding: 8px 10px 10px; flex-wrap: wrap; }
.item .actions { flex-wrap: nowrap; }
.item .mini { min-height: 36px; padding: 6px 10px; font-size: .82rem; flex: 1 1 auto; }
.item .mini.drive { flex: 0 0 auto; color: var(--muted); }

/* แถบดาวน์โหลดติดล่างจอ */
.dlbar { position: fixed; left: 50%; bottom: max(12px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 20;
  width: min(940px, calc(100% - 24px)); display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px;
  border-radius: 24px; background: var(--card-solid); border: 1px solid var(--border); box-shadow: 0 16px 50px rgba(0,0,0,.45); }
.dlbar .count { flex: 1 1 100%; text-align: center; font-size: .85rem; }
.dlbar button { flex: 1 1 0; min-height: 46px; padding: 8px 10px; font-size: .88rem; }
.dlbar #selectAll { flex: 0 0 auto; }
@media (min-width: 640px) { .dlbar .count { flex: 1 1 auto; text-align: left; padding-left: 8px; } .dlbar button { flex: 0 0 auto; } }

/* หน้าต่าง */
dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--card-solid); color: var(--text); padding: 16px; box-shadow: var(--shadow); max-width: min(96vw, 1100px); }
dialog::backdrop { background: rgba(5,5,15,.65); backdrop-filter: blur(6px); }
#viewer img { max-width: 100%; max-height: 72dvh; display: block; border-radius: 14px; margin: 0 auto; }
#viewer .row { justify-content: center; }
dialog.sheet { width: min(420px, 92vw); text-align: center; padding: 24px; }
dialog.sheet h2 { justify-content: center; }
dialog.sheet .row { justify-content: center; }
.thanks-emoji { font-size: 3rem; line-height: 1; margin-bottom: 8px; }
.social { display: grid; gap: 10px; margin: 16px 0 8px; }
.social a { display: flex; align-items: center; justify-content: center; min-height: 52px; border-radius: 999px; color: #fff; text-decoration: none; font-weight: 600; }
.social .fb { background: #1877f2; }
.social .ig { background: linear-gradient(45deg, #f9a43a, #e1306c 50%, #833ab4); }

/* ผู้ดูแล */
button.google { background: #fff; color: #1f1f1f; border-color: #747775; }
.shared { border-left: 3px solid var(--accent); padding-left: 12px; margin: 10px 0; }
.shared .row input { flex: 1; min-width: 0; margin: 0; }
.albums { display: grid; gap: 4px; }
.album { display: flex; flex-wrap: wrap; gap: 8px; justify-content: space-between; align-items: center; padding: 12px 0; border-top: 1px solid var(--border); }
.album:first-child { border-top: 0; }
#folderInfo { white-space: pre-line; }

[hidden] { display: none !important; }
/* โหมดหน้า: login = ผู้ดูแลยังไม่เข้าสู่ระบบ, admin = เครื่องมือเต็ม, visitor = หน้าค้นหาของอัลบั้ม */
body[data-mode="loading"] main > section,
body[data-mode="loading"] #modelStatus,
body[data-mode="login"] main > section:not(#loginCard),
body[data-mode="login"] #modelStatus,
body:not([data-mode="login"]) #loginCard,
body:not([data-mode="admin"]) .admin-only,
body:not([data-mode="visitor"]) .visitor-only { display: none !important; }
body:not([data-mode="visitor"]) { padding-bottom: 24px; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

#thanks progress { margin-top: 12px; }
#thanks .follow { margin: 12px 0 0; font-weight: 500; }
.spinner { width: 44px; height: 44px; margin: 4px auto 12px; border-radius: 50%; border: 4px solid var(--border); border-top-color: var(--accent2); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
