:root {
  --bg: #faf6f1;
  --surface: #ffffff;
  --surface-2: #f2ebe3;
  --text: #2b2420;
  --muted: #7a6d64;
  --border: #e4d9ce;
  --accent: #b4532a;
  --accent-hover: #9a4421;
  --accent-text: #ffffff;
  --danger: #b3261e;
  --danger-bg: #fdecea;
  --ok-bg: #e8f3ea;
  --ok-text: #24603a;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 4px 14px rgba(60, 40, 20, .07);
  --radius: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1714;
    --surface: #26201c;
    --surface-2: #2f2823;
    --text: #f1e9e2;
    --muted: #b0a297;
    --border: #3d342e;
    --accent: #e0814f;
    --accent-hover: #ec956a;
    --accent-text: #1b1714;
    --danger: #f2867e;
    --danger-bg: #3a2220;
    --ok-bg: #1f3326;
    --ok-text: #9fd6ae;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 14px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 16px;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); color: var(--text);
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--surface-2); }
.btn:focus-visible, input:focus-visible, select:focus-visible, .tile:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 2px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { color: var(--danger); }
.btn.primary.danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.primary.danger-solid:hover { filter: brightness(.92); }
.btn.danger:hover { background: var(--danger-bg); }
.btn.small { min-height: 34px; padding: 4px 12px; font-size: 14px; }
.btn[disabled] { opacity: .55; cursor: default; }

label.field { display: block; margin-bottom: 14px; }
label.field span { display: block; font-size: 14px; font-weight: 600; margin-bottom: 5px; }
input[type=text], input[type=password], select {
  width: 100%; min-height: 44px; padding: 9px 12px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface);
}
.hint { font-size: 13px; color: var(--muted); margin: -8px 0 14px; }

.error { background: var(--danger-bg); color: var(--danger); padding: 10px 12px; border-radius: 10px; margin: 0 0 14px; font-size: 14px; }
.notice { background: var(--ok-bg); color: var(--ok-text); padding: 10px 12px; border-radius: 10px; margin: 0 0 14px; font-size: 14px; }

/* ---------- login / setup ---------- */
.center-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.card {
  width: 100%; max-width: 400px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 18px;
  box-shadow: var(--shadow); padding: 32px 28px;
}
.brand { font-family: Georgia, "Times New Roman", serif; font-weight: 600; letter-spacing: .2px; }
.card .brand { font-size: 28px; margin: 0 0 4px; text-align: center; }
.card .sub { text-align: center; color: var(--muted); margin: 0 0 24px; }
.card .btn.primary { width: 100%; margin-top: 4px; }
.logo-mark { display: block; margin: 0 auto 12px; width: 52px; height: 52px; }

/* ---------- main layout ---------- */
header.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 24px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
header.top .brand { font-size: 22px; margin: 0; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
header.top .brand a { color: inherit; text-decoration: none; }
.user-menu { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 200px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow); padding: 6px; z-index: 20;
}
.menu button { display: block; width: 100%; text-align: left; padding: 9px 12px; border: 0; background: none; border-radius: 8px; cursor: pointer; }
.menu button:hover { background: var(--surface-2); }
.menu .who { padding: 8px 12px 10px; font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--border); margin-bottom: 4px; }

main { max-width: 1240px; margin: 0 auto; padding: 20px 24px 64px; }

.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin: 4px 0 6px; font-size: 15px; }
.crumbs a { text-decoration: none; padding: 2px 4px; border-radius: 6px; }
.crumbs a:hover { background: var(--surface-2); }
.crumbs .sep { color: var(--muted); }
h1.folder-title { font-family: Georgia, "Times New Roman", serif; font-size: 30px; font-weight: 600; margin: 0 0 16px; overflow-wrap: anywhere; }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; }

.section-label { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin: 18px 0 10px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.tile {
  position: relative; display: block; width: 100%; padding: 0; margin: 0;
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
  background: var(--surface); box-shadow: var(--shadow);
  cursor: pointer; text-align: left; color: inherit; text-decoration: none;
  transition: transform .15s;
}
.tile:hover { transform: translateY(-2px); }
.tile .thumb { aspect-ratio: 1 / 1; background: var(--surface-2); display: grid; place-items: center; overflow: hidden; }
.tile .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .thumb .ph { color: var(--muted); font-size: 13px; padding: 8px; text-align: center; overflow-wrap: anywhere; }
.tile .label { padding: 8px 10px; font-size: 14px; }
.tile .label strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .label small { color: var(--muted); }
.tile.folder .thumb svg { width: 56px; height: 56px; color: var(--accent); opacity: .85; }
.photo-grid .tile { box-shadow: none; }
.photo-grid .tile .label { display: none; }

.empty { text-align: center; padding: 56px 16px; color: var(--muted); border: 2px dashed var(--border); border-radius: 16px; }
.empty strong { display: block; color: var(--text); font-size: 18px; margin-bottom: 4px; }

/* drag & drop */
.drop-overlay {
  position: fixed; inset: 0; z-index: 40; display: grid; place-items: center;
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  border: 4px dashed var(--accent); pointer-events: none;
  font-size: 22px; font-weight: 600; color: var(--text);
}

/* upload progress */
.upload-panel {
  position: fixed; right: 20px; bottom: 20px; z-index: 30; width: min(360px, calc(100vw - 32px));
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow);
  padding: 14px 16px;
}
.upload-panel .bar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin: 8px 0; }
.upload-panel .bar div { height: 100%; background: var(--accent); width: 0; transition: width .2s; }
.upload-panel ul { margin: 6px 0 0; padding-left: 18px; font-size: 13px; color: var(--danger); max-height: 120px; overflow: auto; }

/* ---------- dialogs ---------- */
dialog {
  border: 1px solid var(--border); border-radius: 16px; padding: 24px;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow);
  width: min(440px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(20, 12, 6, .45); }
dialog h2 { margin: 0 0 14px; font-size: 20px; }
dialog p { margin: 0 0 16px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
dialog.wide { width: min(620px, calc(100vw - 32px)); }

.people { list-style: none; padding: 0; margin: 0 0 18px; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.people li { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.people li:first-child { border-top: 0; }
.people .name { flex: 1; min-width: 120px; font-weight: 600; overflow-wrap: anywhere; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); font-weight: 600; }
.add-person { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; align-items: end; }
.add-person label.field { margin: 0; }
@media (max-width: 560px) { .add-person { grid-template-columns: 1fr; } }

/* ---------- photo viewer ---------- */
.viewer {
  position: fixed; inset: 0; z-index: 50; background: #0d0a08; color: #f4ece6;
  display: grid; grid-template-rows: auto 1fr;
}
.viewer .bar-top { display: flex; align-items: center; gap: 8px; padding: 10px 14px; flex-wrap: wrap; }
.viewer .bar-top .title { flex: 1; min-width: 120px; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.viewer .bar-top .count { color: #a99a8f; font-size: 14px; }
.viewer .btn { background: rgba(255, 255, 255, .08); border-color: rgba(255, 255, 255, .16); color: #f4ece6; }
.viewer .btn:hover { background: rgba(255, 255, 255, .16); }
.viewer .btn.primary { background: #e0814f; border-color: #e0814f; color: #1b1714; }
.viewer .btn.danger { color: #f2867e; }
.viewer select { width: auto; min-height: 34px; padding: 4px 10px; background: #26201c; border-color: #3d342e; color: #f4ece6; font-size: 14px; }
.viewer .stage { position: relative; display: grid; place-items: center; min-height: 0; padding: 0 8px 12px; }
.viewer .stage img { max-width: 100%; max-height: 100%; object-fit: contain; user-select: none; }
.viewer .stage .ph { color: #a99a8f; text-align: center; padding: 24px; }
.viewer .nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 52px; height: 52px; border-radius: 50%; border: 0; cursor: pointer;
  background: rgba(255, 255, 255, .12); color: #fff; font-size: 26px; line-height: 1;
}
.viewer .nav:hover { background: rgba(255, 255, 255, .24); }
.viewer .nav.prev { left: 14px; }
.viewer .nav.next { right: 14px; }

@media (max-width: 640px) {
  header.top { padding: 8px 16px; }
  header.top .brand { font-size: 19px; }
  main { padding: 16px 16px 56px; }
  h1.folder-title { font-size: 24px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
  .photo-grid { grid-template-columns: repeat(3, 1fr); gap: 4px; }
  .photo-grid .tile { border-radius: 6px; }
  .viewer .nav { width: 42px; height: 42px; font-size: 22px; }
  .viewer .nav.prev { left: 6px; }
  .viewer .nav.next { right: 6px; }
}
