:root {
  --bg: #16151b;
  --bg-2: #1c1a23;
  --surface: #24212d;
  --surface-2: #2e2a39;
  --border: #3b3648;
  --text: #ece9f4;
  --muted: #a39db4;
  --accent: #8b5cf6;
  --accent-2: #a78bfa;
  --accent-3: #6d28d9;
  --accent-soft: rgba(139, 92, 246, .16);
  --danger: #f87171;
  --ok: #4ade80;
  --radius: 14px;
  --gap: 6px;
  --tile: 160px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: radial-gradient(1200px 600px at 10% -10%, #2a2140 0%, transparent 60%), var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}
[hidden] { display: none !important; }
a { color: var(--accent-2); }
svg { width: 20px; height: 20px; flex: none; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 13px; margin: 4px 0 10px; }
.error { color: var(--danger); min-height: 1.2em; margin: 8px 0 0; font-size: 14px; }

/* ------------------------------------------------ buttons & fields */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font: inherit; font-weight: 600;
  cursor: pointer; text-decoration: none; transition: background .15s, transform .1s, border-color .15s;
  -webkit-tap-highlight-color: transparent; white-space: nowrap;
}
.btn:hover { background: #393347; }
.btn:active { transform: scale(.97); }
.btn.primary { background: linear-gradient(135deg, var(--accent) 0%, var(--accent-3) 100%); border-color: transparent; color: #fff; box-shadow: 0 4px 18px rgba(124, 58, 237, .35); }
.btn.primary:hover { filter: brightness(1.1); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.small { padding: 7px 12px; font-size: 14px; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .5; pointer-events: none; }
.icon-btn {
  display: inline-grid; place-items: center; width: 42px; height: 42px; border-radius: 50%;
  border: 0; background: transparent; color: var(--text); cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.icon-btn:hover { background: rgba(255, 255, 255, .08); }
.icon-btn svg { width: 22px; height: 22px; }

input, select {
  width: 100%; font: inherit; color: var(--text); background: var(--bg-2);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; outline: none;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
select {
  appearance: none; padding-right: 34px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='none' stroke='%23a78bfa' stroke-width='2.5' d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 16px;
}
label { display: block; }

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

/* ------------------------------------------------ gate */
.gate { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login { width: 100%; max-width: 380px; text-align: center; box-shadow: 0 20px 60px rgba(0, 0, 0, .45); }
.login h1 { margin: 12px 0 4px; font-size: 26px; }
.login label { text-align: left; font-size: 13px; color: var(--muted); margin: 14px 0; }
.login label input { margin-top: 6px; font-size: 16px; }
.login .btn { margin-top: 6px; padding: 12px; font-size: 16px; }
.logo { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 9px; color: #fff; background: linear-gradient(135deg, var(--accent-2), var(--accent-3)); }
.logo svg { width: 20px; height: 20px; }
.logo.big { width: 64px; height: 64px; border-radius: 18px; box-shadow: 0 8px 30px rgba(124, 58, 237, .45); }
.logo.big svg { width: 36px; height: 36px; }

/* ------------------------------------------------ top bar */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px;
  padding: 10px max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  padding-top: max(10px, env(safe-area-inset-top));
  background: rgba(22, 21, 27, .82); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; }
.tabs { display: flex; gap: 4px; margin: 0 auto; background: var(--bg-2); padding: 4px; border-radius: 12px; border: 1px solid var(--border); }
.tab { display: flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 9px; color: var(--muted); text-decoration: none; font-weight: 600; }
.tab.active { background: var(--accent-soft); color: var(--accent-2); }
.user-btn { display: flex; align-items: center; gap: 8px; background: none; border: 0; color: var(--text); font: inherit; cursor: pointer; padding: 4px; border-radius: 20px; }
.user-btn:hover { background: var(--surface-2); }
.avatar { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; background: linear-gradient(135deg, #c4b5fd, var(--accent-3)); color: #fff; }
.user-name { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-right: 8px; }

.view { padding: 14px max(16px, env(safe-area-inset-left)) calc(110px + var(--safe-b)); max-width: 1600px; margin: 0 auto; }

/* ------------------------------------------------ gallery controls */
.controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.field { flex: 1 1 170px; max-width: 260px; }
.field span { display: block; font-size: 12px; color: var(--muted); margin: 0 0 4px 2px; text-transform: uppercase; letter-spacing: .05em; }
.control-buttons { display: flex; gap: 8px; margin-left: auto; }
.summary { margin: 14px 0 0; color: var(--muted); font-size: 14px; }

/* ------------------------------------------------ grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--tile), 1fr)); gap: var(--gap); }
.tile {
  position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; cursor: pointer;
  background: var(--surface); -webkit-touch-callout: none; user-select: none; -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent; content-visibility: auto; contain-intrinsic-size: var(--tile);
}
.tile img, .tile .ph { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transition: transform .18s ease, border-radius .18s; -webkit-user-drag: none; }
.tile .ph { display: grid; place-items: center; color: var(--muted); font-weight: 700; font-size: 13px; letter-spacing: .05em; background: linear-gradient(135deg, var(--surface), var(--surface-2)); }
.tile .ph.spin::after {
  content: ""; width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--accent); animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.tile:hover img { transform: scale(1.03); }
.tile::after { content: ""; position: absolute; inset: 0; pointer-events: none; background: linear-gradient(180deg, rgba(0,0,0,.35) 0%, transparent 28%, transparent 70%, rgba(0,0,0,.55) 100%); opacity: .9; }
.tile .badge, .tile .who { position: absolute; z-index: 1; font-size: 12px; font-weight: 600; color: #fff; text-shadow: 0 1px 3px rgba(0,0,0,.6); pointer-events: none; }
.tile .b360 {
  position: absolute; z-index: 1; top: 7px; right: 7px; padding: 2px 7px; border-radius: 9px; pointer-events: none;
  font-size: 11px; font-weight: 800; letter-spacing: .03em; color: #fff;
  background: linear-gradient(135deg, var(--accent-2), var(--accent-3)); box-shadow: 0 1px 6px rgba(0,0,0,.45);
}
.tile .badge { right: 7px; bottom: 6px; display: flex; align-items: center; gap: 3px; }
.tile .badge svg { width: 14px; height: 14px; }
.tile .who { left: 8px; bottom: 6px; max-width: 60%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.check {
  position: absolute; z-index: 2; top: 0; left: 0; width: 46px; height: 46px; padding: 0;
  border: 0; background: transparent; cursor: pointer; touch-action: none; -webkit-tap-highlight-color: transparent;
}
.check::before {
  content: ""; position: absolute; top: 8px; left: 8px; width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.9); background: rgba(20, 16, 30, .25); box-shadow: 0 1px 4px rgba(0,0,0,.4);
  transition: background .12s, border-color .12s, transform .12s;
}
.check svg { position: absolute; top: 13px; left: 13px; width: 16px; height: 16px; color: #fff; opacity: 0; transition: opacity .12s; }
.check:hover::before { border-color: #fff; background: rgba(139, 92, 246, .35); }
.tile.selected .check::before { background: var(--accent); border-color: #fff; transform: scale(1.08); }
.tile.selected .check svg { opacity: 1; }
.tile.selected img, .tile.selected .ph { transform: scale(.86); border-radius: 8px; }
.tile:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }
.tile.selected { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent); }
.tile.selected:hover img { transform: scale(.86); }
.selecting .tile:not(.selected) .check::before { border-color: #fff; }

.new-pill {
  position: fixed; z-index: 25; left: 50%; transform: translateX(-50%); top: calc(70px + env(safe-area-inset-top));
  padding: 8px 16px; border: 0; border-radius: 20px; font: inherit; font-weight: 600; color: #fff; cursor: pointer;
  background: linear-gradient(135deg, var(--accent), var(--accent-3)); box-shadow: 0 6px 20px rgba(0,0,0,.45);
  animation: rise .2s ease-out;
}
.empty { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty svg { width: 64px; height: 64px; color: var(--accent-2); opacity: .7; }

/* ------------------------------------------------ selection bar */
.selbar {
  position: fixed; z-index: 30; left: 50%; transform: translateX(-50%);
  bottom: calc(14px + var(--safe-b)); width: min(560px, calc(100% - 20px));
  display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 6px;
  background: rgba(46, 42, 57, .94); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border: 1px solid #4b4460; border-radius: 16px; box-shadow: 0 12px 40px rgba(0,0,0,.5);
  animation: rise .18s ease-out;
}
@keyframes rise { from { transform: translate(-50%, 20px); opacity: 0; } }
.sel-info { flex: 1; display: flex; flex-direction: column; line-height: 1.2; min-width: 0; white-space: nowrap; }
.sel-info .muted { font-size: 13px; }

/* ------------------------------------------------ upload */
.upload-card { max-width: 760px; margin: 10px auto 16px; }
.upload-card h2 { margin: 0 0 4px; }
#uploadPanel { max-width: 760px; margin: 0 auto; }
.dropzone {
  position: relative; margin-top: 16px; display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding: 36px 16px; border: 2px dashed #4b4460; border-radius: var(--radius); background: var(--bg-2);
  cursor: pointer; text-align: center; transition: border-color .15s, background .15s;
}
.dropzone > svg { width: 44px; height: 44px; color: var(--accent-2); }
.dropzone input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.dropzone.over, .dropzone:hover { border-color: var(--accent); background: var(--accent-soft); }
.dropzone .btn { padding: 13px 22px; font-size: 16px; }
body:not(.mobile) .mobile-only { display: none; }
.link-btn { display: inline; color: var(--accent-2); font-weight: 600; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.link-btn input { display: none; }
.upload-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.upload-actions { display: flex; gap: 8px; }
.progress { height: 8px; background: var(--bg-2); border-radius: 6px; overflow: hidden; margin: 12px 0; }
.progress > div { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent-2), var(--accent)); transition: width .25s; }
.queue { list-style: none; margin: 0; padding: 0; max-height: 60vh; overflow: auto; }
.queue li { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 10px 2px; border-top: 1px solid var(--border); font-size: 14px; }
.queue .q-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.queue .q-status { color: var(--muted); text-align: right; white-space: nowrap; }
.queue .q-bar { grid-column: 1 / -1; height: 4px; background: var(--bg-2); border-radius: 3px; overflow: hidden; }
.queue .q-bar > div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.queue li.done .q-status { color: var(--ok); }
.queue li.done .q-bar > div { background: var(--ok); }
.queue li.error .q-status { color: var(--danger); }
.queue li.error .q-bar > div { background: var(--danger); }
.queue .q-retry { background: none; border: 0; color: var(--accent-2); font: inherit; font-weight: 600; cursor: pointer; padding: 0 0 0 8px; }

/* ------------------------------------------------ viewer */
.viewer { position: fixed; inset: 0; z-index: 50; background: #0c0a12; overflow: hidden; }
.viewer-stage {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.viewer-stage .media { display: block; flex: none; max-width: none; max-height: none; object-fit: contain; -webkit-user-drag: none; }
.viewer-stage video.media { background: #000; touch-action: manipulation; }
.viewer-top {
  position: absolute; z-index: 3; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 4px;
  padding: max(6px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) 28px max(8px, env(safe-area-inset-left));
  background: linear-gradient(rgba(12, 10, 18, .88), rgba(12, 10, 18, .55) 60%, rgba(12, 10, 18, 0));
  transition: opacity .25s;
}
.viewer.chrome-off .viewer-top, .viewer.chrome-off .v-nav { opacity: 0; pointer-events: none; }
.v-info { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; text-shadow: 0 1px 3px rgba(0,0,0,.6); }
.v-info b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.v-info span { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.v-check { border: 2px solid rgba(255,255,255,.6); width: 36px; height: 36px; margin: 0 4px; }
.v-check svg { opacity: 0; width: 18px; height: 18px; }
.v-check.on { background: var(--accent); border-color: #fff; }
.v-check.on svg { opacity: 1; }
.v-msg { max-width: 420px; padding: 24px; text-align: center; color: var(--text); touch-action: auto; }
.v-msg img { width: 160px; height: 160px; object-fit: cover; border-radius: 14px; opacity: .8; }
.v-msg p { margin: 16px 0; }
.v-nav {
  position: absolute; top: 50%; transform: translateY(-50%); width: 48px; height: 64px; border: 0; border-radius: 12px;
  background: rgba(46, 42, 57, .6); color: #fff; cursor: pointer; display: grid; place-items: center; z-index: 2; transition: opacity .25s;
}
.v-nav:hover { background: rgba(139, 92, 246, .55); }
.v-nav:disabled { opacity: 0; pointer-events: none; }
.v-nav.prev { left: 10px; } .v-nav.next { right: 10px; }
.v-nav svg { width: 26px; height: 26px; }

.pano { position: absolute; inset: 0; touch-action: none; cursor: grab; }
.pano:active { cursor: grabbing; }
.pano canvas { display: block; width: 100%; height: 100%; }
.pano video { display: none; }
.pano-hint {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); pointer-events: none;
  padding: 8px 14px; border-radius: 20px; background: rgba(20, 18, 28, .7); font-weight: 600; font-size: 14px;
  animation: fadeout 1s 3s forwards;
}
@keyframes fadeout { to { opacity: 0; } }
.pano-bar {
  position: absolute; z-index: 3; left: 50%; transform: translateX(-50%); bottom: max(14px, var(--safe-b));
  width: min(640px, calc(100% - 20px)); display: flex; align-items: center; gap: 6px; padding: 4px 8px;
  background: rgba(20, 18, 28, .78); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,.08); border-radius: 14px; transition: opacity .25s;
}
.pano-photo .pano-bar { width: auto; padding: 4px; }
.viewer.chrome-off .pano-bar { opacity: 0; pointer-events: none; }
.pano-bar input[type=range] { flex: 1; min-width: 40px; padding: 0; border: 0; background: none; box-shadow: none; accent-color: var(--accent); height: 28px; }
.pano-time { font-size: 13px; font-variant-numeric: tabular-nums; color: var(--muted); min-width: 34px; text-align: center; }

/* ------------------------------------------------ admin */
body:not(.is-admin) .admin-only { display: none !important; }
.btn.danger { background: rgba(248, 113, 113, .12); border-color: rgba(248, 113, 113, .45); color: #fca5a5; }
.btn.danger:hover { background: rgba(248, 113, 113, .25); }
.icon-btn.danger { color: #fca5a5; }
.icon-btn.danger:hover { background: rgba(248, 113, 113, .18); }
.is-admin .avatar { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent-2); }
.admin-card { max-width: 760px; margin: 10px auto 16px; }
.admin-card h2 { margin: 0 0 4px; }
.admin-users { margin-top: 12px; }
.admin-user { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--border); }
.admin-user .avatar { flex: none; }
.au-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.au-info .muted { font-size: 13px; }
.admin-box { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--border); }
.small-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.admin-row { display: flex; gap: 8px; align-items: center; }
.admin-row input { margin-top: 6px; flex: 1; }
.admin-row .btn { margin-top: 6px; }
.admin-badge { flex: 1; display: flex; align-items: center; gap: 6px; color: var(--accent-2); font-weight: 600; }

/* ------------------------------------------------ dialog */
.dialog { color: var(--text); width: min(420px, calc(100% - 32px)); box-shadow: 0 20px 60px rgba(0,0,0,.6); }
.dialog::backdrop { background: rgba(0, 0, 0, .6); backdrop-filter: blur(3px); }
.dialog h3 { margin: 0 0 4px; }
.dialog input { margin-top: 12px; font-size: 16px; }
.dialog-buttons { display: flex; gap: 8px; margin-top: 12px; }
.spacer { flex: 1; }

/* ------------------------------------------------ small screens */
@media (max-width: 720px) {
  :root { --tile: 104px; --gap: 3px; }
  .brand span:last-child, .user-name { display: none; }
  .tabs { margin: 0 auto; }
  .tab { padding: 7px 12px; }
  .view { padding-left: 10px; padding-right: 10px; }
  .field { flex: 1 1 calc(50% - 10px); max-width: none; }
  .control-buttons { margin-left: 0; flex: 1 1 calc(50% - 10px); }
  .control-buttons .btn { width: 100%; }
  .tile { border-radius: 4px; }
  .tile .who { display: none; }
  .v-nav { display: none; }
  .tab[data-view=admin] span { display: none; }
  .admin-user .btn span { display: none; }
  .dropzone .drop-text { display: none; }
}
@media (max-width: 380px) { :root { --tile: 96px; } }
@media (hover: none) { .tile:hover img { transform: none; } }
