:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --text: #16202a;
  --muted: #5d6b78;
  --border: #dde3e9;
  --accent: #1f7a8c;
  --accent-hover: #186676;
  --accent-soft: #e3f1f4;
  --danger: #c0392b;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 32, .06), 0 4px 16px rgba(16, 24, 32, .06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1418;
    --surface: #182027;
    --text: #e8eef2;
    --muted: #93a2ae;
    --border: #28333c;
    --accent: #4fb3c6;
    --accent-hover: #6cc3d3;
    --accent-soft: #1b2e35;
    --danger: #e0685b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.hero {
  position: relative;
  padding: 56px 16px 40px;
  text-align: center;
  color: #fff;
  background:
    linear-gradient(180deg, rgba(10, 30, 40, .35), rgba(10, 30, 40, .75)),
    radial-gradient(120% 90% at 20% 10%, #3f8fa3 0%, #1d4e5f 45%, #0d2530 100%);
  overflow: hidden;
}
.hero::after {
  /* mountain silhouette */
  content: "";
  position: absolute; left: 0; right: 0; bottom: -1px; height: 60px;
  background: var(--bg);
  clip-path: polygon(0 100%, 0 70%, 8% 45%, 15% 62%, 24% 30%, 33% 58%, 41% 40%, 50% 66%, 60% 25%, 69% 55%, 78% 38%, 88% 60%, 95% 48%, 100% 58%, 100% 100%);
}
.hero h1 { margin: 0 0 6px; font-size: clamp(28px, 5vw, 42px); letter-spacing: -.02em; }
.hero p { margin: 0; opacity: .85; }
.hero .top-link { position: absolute; top: 14px; right: 16px; color: #fff; opacity: .75; font-size: 14px; }

.container { max-width: 1100px; margin: 0 auto; padding: 24px 16px 64px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.trip-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}
.trip-card { display: block; overflow: hidden; color: inherit; transition: transform .15s; }
.trip-card:hover { transform: translateY(-2px); text-decoration: none; }
.trip-card .cover {
  aspect-ratio: 4 / 3;
  background: linear-gradient(135deg, #2b6a7a, #123642);
  display: grid; place-items: center;
  color: rgba(255, 255, 255, .8);
  font-size: 40px;
}
.trip-card .cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.trip-card .meta { padding: 12px 14px; }
.trip-card .meta strong { display: block; font-size: 16px; }
.trip-card .meta span { color: var(--muted); font-size: 14px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; font-size: 15px;
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: var(--accent); color: #fff;
  cursor: pointer;
  text-decoration: none !important;
  white-space: nowrap;
}
.btn:hover { background: var(--accent-hover); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn.secondary:hover { background: var(--accent-soft); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--border); }
.btn.danger:hover { background: rgba(192, 57, 43, .08); }
.btn.small { padding: 6px 10px; font-size: 13px; }

input[type=text], input[type=password] {
  font: inherit;
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.field { margin-bottom: 14px; }
.checkbox { display: flex; gap: 8px; align-items: center; font-weight: 400; }

.lock-box { max-width: 380px; margin: 24px auto; padding: 28px; text-align: center; }
.lock-box .icon { font-size: 40px; }
.lock-box h2 { margin: 6px 0 4px; }
.lock-box p { color: var(--muted); margin: 0 0 18px; }
.lock-box form { display: flex; flex-direction: column; gap: 10px; }

.error { color: var(--danger); font-size: 14px; min-height: 1.2em; margin: 6px 0 0; }
.muted { color: var(--muted); }
.empty { text-align: center; padding: 48px 16px; color: var(--muted); }

.toolbar {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between;
  margin-bottom: 18px;
}
.toolbar .actions { display: flex; flex-wrap: wrap; gap: 8px; }

.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
  margin-bottom: 20px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.dropzone.over, .dropzone:hover { border-color: var(--accent); background: var(--accent-soft); }
.dropzone strong { color: var(--text); }
.dropzone .row { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; align-items: center; margin-top: 12px; }
.dropzone .row input { max-width: 220px; }

.progress { margin: -8px 0 20px; }
.progress .bar { height: 8px; background: var(--border); border-radius: 99px; overflow: hidden; }
.progress .bar div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.progress p { margin: 6px 0 0; font-size: 14px; color: var(--muted); }

.gallery {
  --tile: 170px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--tile), 1fr));
  gap: 8px;
}
.gallery[data-size="s"] { --tile: 110px; gap: 4px; }
.gallery[data-size="m"] { --tile: 170px; }
.gallery[data-size="l"] { --tile: 300px; gap: 10px; }
@media (max-width: 640px) {
  .gallery[data-size="s"] { --tile: 72px; gap: 3px; }
  .gallery[data-size="m"] { --tile: 105px; gap: 5px; }
  .gallery[data-size="l"] { --tile: 100%; }
}

.toolbar-left { display: flex; align-items: center; gap: 12px; }
.size-switch {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface);
}
.size-switch button {
  font: inherit; font-size: 13px; font-weight: 600;
  padding: 6px 11px;
  border: 0; background: transparent; color: var(--muted);
  cursor: pointer;
}
.size-switch button + button { border-left: 1px solid var(--border); }
.size-switch button.active { background: var(--accent); color: #fff; }
.photo {
  position: relative;
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
  background: var(--border);
  cursor: zoom-in;
  border: 0; padding: 0;
}
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo .noprev {
  width: 100%; height: 100%; display: grid; place-items: center; text-align: center;
  font-size: 12px; color: var(--muted); padding: 8px; word-break: break-all;
}
.photo .by {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 16px 8px 6px;
  font-size: 12px; color: #fff; text-align: left;
  background: linear-gradient(transparent, rgba(0, 0, 0, .6));
  opacity: 0; transition: opacity .15s;
}
.photo:hover .by, .photo:focus .by { opacity: 1; }

/* Select mode (deleting photos) */
.select-bar {
  position: sticky; top: 8px; z-index: 10;
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between;
  padding: 10px 14px; margin-bottom: 14px;
}
.select-bar .actions { display: flex; flex-wrap: wrap; gap: 6px; }
.select-bar[hidden] { display: none; }
.gallery.selecting .photo { cursor: pointer; }
.gallery.selecting .photo.locked { opacity: .35; cursor: not-allowed; }
.gallery.selecting .photo::after {
  content: "";
  position: absolute; top: 8px; right: 8px;
  width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid #fff; background: rgba(0, 0, 0, .25);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .4);
}
.gallery.selecting .photo.locked::after { display: none; }
.gallery.selecting .photo.selected { outline: 3px solid var(--danger); outline-offset: -3px; }
.gallery.selecting .photo.selected img { opacity: .75; }
.gallery.selecting .photo.selected::after {
  content: "✓"; color: #fff; font-size: 14px; font-weight: 700;
  display: grid; place-items: center;
  background: var(--danger); border-color: var(--danger);
}

/* Lightbox */
.lightbox {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(5, 8, 10, .94);
  display: none;
  flex-direction: column;
}
.lightbox.open { display: flex; }
.lightbox .lb-top {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 10px 14px; color: #dfe6ea; font-size: 14px;
}
.lightbox .lb-top .info { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lightbox .lb-top .actions { display: flex; gap: 8px; flex-shrink: 0; }
.lightbox .lb-img { flex: 1; display: grid; place-items: center; min-height: 0; padding: 0 8px 16px; position: relative; }
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; }
.lightbox .nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  background: rgba(255, 255, 255, .12); color: #fff; border: 0;
  width: 44px; height: 44px; border-radius: 50%; font-size: 22px; cursor: pointer;
}
.lightbox .nav:hover { background: rgba(255, 255, 255, .25); }
.lightbox .prev { left: 12px; }
.lightbox .next { right: 12px; }
.lightbox .lb-top, .lightbox .nav { transition: opacity .4s; }
.lightbox.idle .lb-top, .lightbox.idle .nav { opacity: 0; }
.lightbox.idle { cursor: none; }
.lightbox.playing { background: #000; }
.lightbox.playing .lb-img { padding-bottom: 8px; }
.lightbox img { animation: lbfade .5s ease; }
@keyframes lbfade { from { opacity: 0; } to { opacity: 1; } }
.lb-progress { height: 3px; background: rgba(255, 255, 255, .08); visibility: hidden; }
.lightbox.playing .lb-progress { visibility: visible; }
.lb-progress div { height: 100%; width: 0; background: var(--accent); }
.btn[hidden] { display: none; }
.lightbox .btn.secondary { background: rgba(255, 255, 255, .1); color: #fff; border-color: rgba(255, 255, 255, .2); }

/* Admin table */
.admin-list { display: flex; flex-direction: column; gap: 10px; }
.admin-row { padding: 14px 16px; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; }
.admin-row .name strong { font-size: 16px; }
.admin-row .name div { font-size: 13px; color: var(--muted); }
.admin-row .actions { display: flex; flex-wrap: wrap; gap: 6px; }
.section-title { margin: 32px 0 12px; font-size: 18px; }
.create-form { padding: 18px; display: grid; gap: 12px; grid-template-columns: 1fr 1fr auto; align-items: end; }
.create-form .field { margin: 0; }
@media (max-width: 640px) { .create-form { grid-template-columns: 1fr; } }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 60;
}
.toast.show { opacity: 1; }

/* ---------- Phones & touch screens ---------- */
.touch-only { display: none; }
.fab { display: none; }
.lightbox { height: 100dvh; }
.lightbox .lb-top { padding-top: max(10px, env(safe-area-inset-top)); }
.lightbox .lb-img { padding-bottom: max(16px, env(safe-area-inset-bottom)); }

@media (hover: none) and (pointer: coarse) {
  .no-touch { display: none; }
  .touch-only { display: block; }
  .photo .by { opacity: 1; } /* no hover on phones: always show who uploaded */
}

@media (max-width: 640px) {
  .hero { padding: 40px 16px 34px; }
  .hero::after { height: 34px; }
  .hero h1 { font-size: 26px; }
  .hero .top-link { top: max(10px, env(safe-area-inset-top)); }
  .container { padding: 16px 12px calc(88px + env(safe-area-inset-bottom)); }

  .trip-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .trip-card .cover { aspect-ratio: 1; font-size: 30px; }
  .trip-card .meta { padding: 8px 10px; }
  .trip-card .meta strong { font-size: 14px; line-height: 1.3; }
  .trip-card .meta span { font-size: 12px; }

  /* toolbar: count + size on one row, action buttons as an even grid below */
  .toolbar { flex-direction: column; align-items: stretch; gap: 10px; }
  .toolbar-left { justify-content: space-between; }
  .toolbar .actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .toolbar .actions .btn { font-size: 14px; padding: 10px 8px; }
  .size-switch button { padding: 8px 14px; }

  .dropzone { padding: 18px 12px; margin-bottom: 16px; }
  .dropzone .row { flex-direction: column; align-items: stretch; }
  .dropzone .row input { max-width: none; }

  .select-bar { top: max(6px, env(safe-area-inset-top)); padding: 10px; }
  .select-bar .actions { width: 100%; display: grid; grid-template-columns: 1fr 1fr 1fr; }

  .photo .by { font-size: 10px; padding: 12px 5px 3px; }
  .gallery[data-size="s"] .photo .by { display: none; }

  /* full-screen viewer: icon buttons on top, file info below them */
  .lightbox { background: #000; }
  .lightbox .lb-top { flex-wrap: wrap; padding-left: 10px; padding-right: 10px; }
  .lightbox .lb-top .actions { order: 1; width: 100%; justify-content: flex-end; }
  .lightbox .lb-top .info { order: 2; width: 100%; font-size: 12px; opacity: .75; }
  .lightbox .lb-top .btn.small { min-width: 42px; height: 40px; font-size: 16px; }
  .lightbox .lbl { display: none; }
  .lightbox .nav { width: 38px; height: 38px; font-size: 20px; background: rgba(255, 255, 255, .1); }
  .lightbox .prev { left: 6px; }
  .lightbox .next { right: 6px; }
  .lightbox .lb-img { padding-left: 0; padding-right: 0; }

  .fab {
    display: grid; place-items: center;
    position: fixed; z-index: 20;
    right: 16px; bottom: calc(18px + env(safe-area-inset-bottom));
    width: 58px; height: 58px; border-radius: 50%;
    border: 0; background: var(--accent); color: #fff; font-size: 24px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, .3);
    cursor: pointer;
  }
  .fab[hidden] { display: none; }

  .toast { bottom: calc(90px + env(safe-area-inset-bottom)); max-width: calc(100% - 32px); text-align: center; }

  .admin-row .actions { width: 100%; display: grid; grid-template-columns: 1fr 1fr 1fr; }
  .admin-row .actions .btn { padding: 9px 4px; }
}

/* ---------- Trip logos ---------- */
.hero-logo {
  display: block; margin: 0 auto 12px;
  max-width: 120px; max-height: 84px; object-fit: contain;
  filter: drop-shadow(0 2px 8px rgba(0, 0, 0, .35));
}
.hero-logo[hidden] { display: none; }
.lock-logo { max-width: 140px; max-height: 96px; object-fit: contain; }

.trip-card .cover { position: relative; }
.trip-card .cover img.logo-center {
  width: 62%; height: 62%; object-fit: contain;
  filter: drop-shadow(0 2px 8px rgba(0, 0, 0, .3));
}
.trip-card .cover img.logo-badge {
  position: absolute; left: 10px; bottom: 10px;
  width: 52px; height: 52px; object-fit: contain;
  padding: 5px; border-radius: 12px;
  background: rgba(255, 255, 255, .92);
  box-shadow: 0 2px 8px rgba(0, 0, 0, .25);
}
.lock-badge { position: absolute; top: 8px; right: 10px; font-size: 18px; }

.logo-slot {
  flex-shrink: 0;
  width: 56px; height: 56px; padding: 4px;
  border-radius: 12px;
  border: 1px dashed var(--border);
  background: var(--bg);
  color: var(--muted); font: inherit; font-size: 12px; font-weight: 600;
  display: grid; place-items: center;
  cursor: pointer;
}
.logo-slot:hover { border-color: var(--accent); color: var(--accent); }
.logo-slot img { width: 100%; height: 100%; object-fit: contain; }
.admin-row .name { flex: 1; min-width: 160px; }

@media (max-width: 640px) {
  .hero-logo { max-width: 90px; max-height: 60px; margin-bottom: 8px; }
  .trip-card .cover img.logo-badge { width: 40px; height: 40px; left: 8px; bottom: 8px; }
}
