/* Lap Remote — viewer styles. Mobile-first, dark, photo-forward. */

:root {
  --bg: #0e0f12;
  --bg-raised: #17191e;
  --bg-hover: #22252c;
  --border: #2a2e37;
  --text: #e8eaee;
  --text-dim: #9aa1ad;
  --accent: #5b9dff;
  --danger: #ff6b6b;

  --cell: 148px;
  --gap: 6px;
  --radius: 10px;
  --topbar-h: auto;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}

/* Several elements below set `display`, which would otherwise beat the UA
   stylesheet's `[hidden] { display: none }` and leave hidden panels on screen. */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

.muted {
  color: var(--text-dim);
}
.small {
  font-size: 13px;
}
.spacer {
  flex: 1;
}
.error {
  color: var(--danger);
  margin: 0;
  font-size: 14px;
}

/* ---------------------------------------------------------------- Login -- */

.login {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(100%, 360px);
  display: grid;
  gap: 16px;
  padding: 28px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 16px;
}

.login-card h1 {
  margin: 0;
  font-size: 22px;
}
.login-card p {
  margin: -8px 0 0;
}

.login-card label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: var(--text-dim);
}

.login-card .checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}
.login-card .checkbox input {
  width: auto;
}

input,
select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 11px;
  min-width: 0;
  outline: none;
}
input:focus,
select:focus {
  border-color: var(--accent);
}

.login-card button[type="submit"] {
  background: var(--accent);
  color: #06111f;
  border: 0;
  border-radius: 8px;
  padding: 11px;
  font-weight: 600;
  cursor: pointer;
}
.login-card button[type="submit"]:disabled {
  opacity: 0.6;
  cursor: progress;
}

/* --------------------------------------------------------------- Topbar -- */

.app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  gap: 8px;
  padding: calc(8px + var(--safe-top)) 12px 8px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.library-name {
  font-size: 16px;
}
.filters select {
  max-width: 42vw;
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.segmented button {
  background: transparent;
  border: 0;
  padding: 8px 12px;
  cursor: pointer;
  color: var(--text-dim);
}
.segmented button.active {
  background: var(--bg-hover);
  color: var(--text);
}

.chip {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
  color: var(--text-dim);
}
.chip[aria-pressed="true"] {
  background: var(--bg-hover);
  color: #ffd479;
  border-color: #4a4128;
}

.icon {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  cursor: pointer;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 17px;
}
.icon:hover {
  background: var(--bg-hover);
  color: var(--text);
}

/* ----------------------------------------------------------------- Grid -- */

main {
  flex: 1;
  padding: 0 8px calc(24px + var(--safe-bottom));
}

/* Days stack; the tiles of each day pack into their own grid. Keeping the
   heading outside the tile grid matters: a full-width heading inside it would
   push every following row's tiles back to column 1. */
.day-group + .day-group {
  margin-top: 18px;
}

.day {
  margin: 0 2px 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-dim);
}

.day-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--cell), 1fr));
  gap: var(--gap);
}

.tile {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-raised);
  cursor: pointer;
  border: 0;
  padding: 0;
  display: block;
  width: 100%;
}

.tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  opacity: 0;
  transition: opacity 0.25s ease;
}
.tile img.loaded {
  opacity: 1;
}

.tile:hover img {
  transform: scale(1.03);
}
.tile img {
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.tile .badge {
  position: absolute;
  bottom: 6px;
  right: 6px;
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.62);
  font-size: 11px;
  line-height: 1.6;
  color: #fff;
  backdrop-filter: blur(4px);
}
.tile .badge.top-left {
  inset: 6px auto auto 6px;
  bottom: auto;
  right: auto;
}
.tile .star {
  color: #ffd479;
}

.sentinel {
  height: 1px;
}
.status {
  text-align: center;
  padding: 20px 0;
  font-size: 13px;
}

/* --------------------------------------------------------------- Viewer -- */

.viewer {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: #08090b;
  display: grid;
  grid-template-rows: 1fr auto;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

.viewer-stage {
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
  min-height: 0;
}
.viewer-stage img,
.viewer-stage video {
  max-width: 100%;
  max-height: 100%;
  display: block;
  object-fit: contain;
}
.viewer-stage .fallback {
  text-align: center;
  color: var(--text-dim);
  padding: 24px;
  display: grid;
  gap: 12px;
  justify-items: center;
}
.viewer-stage .fallback img {
  max-height: 46vh;
  border-radius: var(--radius);
  opacity: 0.6;
}

.viewer-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 76px;
  border: 0;
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  font-size: 32px;
  line-height: 1;
  cursor: pointer;
  border-radius: 12px;
}
.viewer-nav:hover {
  background: rgba(255, 255, 255, 0.14);
}
.viewer-nav.prev {
  left: 10px;
}
.viewer-nav.next {
  right: 10px;
}
.viewer-nav:disabled {
  opacity: 0.25;
  cursor: default;
}

.viewer-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px 12px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.6));
}
.viewer-bar .icon[hidden] {
  display: none;
}

.viewer-info {
  position: absolute;
  top: calc(12px + var(--safe-top));
  right: 12px;
  width: min(84vw, 320px);
  max-height: 70vh;
  overflow: auto;
  padding: 16px;
  background: rgba(23, 25, 30, 0.95);
  border: 1px solid var(--border);
  border-radius: 12px;
  backdrop-filter: blur(12px);
  font-size: 13px;
}
.viewer-info dl {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 14px;
}
.viewer-info dt {
  color: var(--text-dim);
  white-space: nowrap;
}
.viewer-info dd {
  margin: 0;
  word-break: break-all;
}

/* ------------------------------------------------------------ Responsive -- */

@media (max-width: 560px) {
  :root {
    --cell: 31vw;
    --gap: 4px;
  }
  .viewer-nav {
    width: 40px;
    height: 64px;
  }
  .filters select {
    max-width: none;
    flex: 1;
  }
  #filter-query {
    flex: 1 1 100%;
  }
}

@media (min-width: 1100px) {
  :root {
    --cell: 176px;
  }
}

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