:root {
  color-scheme: dark;
  --bg: #0e0f12;
  --surface: #181a1f;
  --surface-2: #20232a;
  --border: #2a2d34;
  --text: #e8e9ec;
  --muted: #8b8f98;
  --accent: #7c9cff;
  --accent-text: #0e0f12;
  --danger: #ff7b7b;
  --warn-bg: #3a2a12;
  --warn-text: #ffd28a;
  --ok: #7bd88f;
  --radius: 14px;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

/* Hide content in the app switcher / when the tab is in the background. */
body.obscured .screen,
body.obscured .overlay {
  filter: blur(24px);
}

[hidden] {
  display: none !important;
}

h1,
h2 {
  margin: 0;
}

h2 {
  margin: 28px 0 10px;
  font-size: 1rem;
}

.brand {
  font-size: 1.4rem;
  letter-spacing: 0.04em;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.85rem;
}

.hint {
  font-size: 0.78rem;
  color: var(--muted);
}

.center-text {
  text-align: center;
}

.grow {
  flex: 1;
}

.ellipsis {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

/* ---- screens and cards ------------------------------------------------- */

.screen.center {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  text-align: center;
}

.card {
  width: 100%;
  max-width: 420px;
  display: grid;
  gap: 14px;
  padding: 22px 18px;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.card p {
  margin: 0;
  line-height: 1.45;
}

.stack {
  display: grid;
  gap: 12px;
}

label {
  display: grid;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--muted);
}

label.check {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
}

label.check input {
  width: 22px;
  height: 22px;
}

input:not([type='checkbox']):not([type='file']) {
  width: 100%;
  padding: 12px;
  font: inherit;
  font-size: 1rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
}

input:focus-visible,
button:focus-visible,
.button:focus-within,
a.button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.secret {
  padding: 14px;
  font: 600 1.05rem ui-monospace, 'Cascadia Mono', Consolas, monospace;
  letter-spacing: 0.05em;
  line-height: 1.6;
  word-break: break-all;
  text-align: center;
  background: var(--bg);
  border: 1px dashed var(--border);
  border-radius: 10px;
  user-select: all;
}

.message {
  min-height: 0;
  margin: 0;
  font-size: 0.9rem;
  color: var(--danger);
}

.message:empty {
  display: none;
}

.message.ok {
  color: var(--ok);
}

/* ---- buttons ----------------------------------------------------------- */

button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 18px;
  font: inherit;
  font-size: 1rem;
  font-weight: 600;
  color: var(--accent-text);
  background: var(--accent);
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  text-decoration: none;
  user-select: none;
}

button.small,
.button.small {
  min-height: 38px;
  padding: 0 12px;
  font-size: 0.9rem;
}

button.secondary,
.button.secondary {
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
}

button.danger {
  color: var(--danger);
}

button.link {
  min-height: 40px;
  padding: 0;
  font-weight: 500;
  color: var(--accent);
  background: none;
}

button:disabled {
  opacity: 0.55;
  cursor: progress;
}

/* ---- vault layout ------------------------------------------------------ */

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.topbar nav {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

.content {
  max-width: 820px;
  margin: 0 auto;
  padding: 14px 16px max(32px, env(safe-area-inset-bottom));
}

.banner {
  display: grid;
  gap: 6px;
  margin-bottom: 14px;
  padding: 12px 14px;
  font-size: 0.9rem;
  line-height: 1.4;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.banner.warn {
  color: var(--warn-text);
  background: var(--warn-bg);
  border-color: #6b4a1a;
}

.banner details summary {
  cursor: pointer;
}

.banner ul {
  margin: 6px 0 0;
  padding-left: 18px;
}

.banner .dismiss {
  justify-self: start;
}

.topbar-title {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

/* ---- filter and sort ---------------------------------------------------- */

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

.segments {
  display: inline-flex;
  padding: 3px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.segments button {
  min-height: 36px;
  padding: 0 12px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--muted);
  background: none;
  border-radius: 8px;
}

.segments button.active {
  color: var(--text);
  background: var(--surface-2);
}

.segments .count {
  margin-left: 5px;
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--muted);
}

label.sort {
  display: flex;
  align-items: center;
  gap: 8px;
}

select {
  min-height: 42px;
  padding: 0 10px;
  font: inherit;
  font-size: 0.9rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}

/* ---- gallery grid ------------------------------------------------------- */

.month {
  margin: 18px 0 8px;
  font-size: 0.95rem;
  font-weight: 600;
}

.month:first-child {
  margin-top: 4px;
}

.month .muted {
  margin-left: 6px;
  font-weight: 400;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 3px;
}

@media (min-width: 700px) {
  .grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  }
}

.tile {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 1;
  min-height: 0;
  padding: 0;
  overflow: hidden;
  color: var(--muted);
  background: var(--surface-2);
  border: 0;
  border-radius: 4px;
  -webkit-touch-callout: none;
}

.tile img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition:
    opacity 0.2s,
    transform 0.15s;
}

.tile img.loaded {
  opacity: 1;
}

.tile-kind {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 0.75rem;
  font-weight: 700;
}

.badge {
  position: absolute;
  right: 4px;
  bottom: 4px;
  padding: 1px 6px;
  font-size: 0.72rem;
  font-weight: 600;
  color: #fff;
  background: rgba(0, 0, 0, 0.6);
  border-radius: 6px;
}

.check {
  position: absolute;
  top: 6px;
  left: 6px;
  display: none;
  width: 24px;
  height: 24px;
  font-size: 0.85rem;
  line-height: 20px;
  color: transparent;
  background: rgba(0, 0, 0, 0.35);
  border: 2px solid #fff;
  border-radius: 50%;
}

.selecting .check {
  display: block;
}

.tile.selected .check {
  color: var(--accent-text);
  background: var(--accent);
  border-color: var(--accent);
}

.tile.selected img {
  transform: scale(0.86);
  border-radius: 6px;
}

.select-bar {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px max(10px, env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.select-bar span {
  flex: 1;
}

.selecting .content {
  padding-bottom: 90px;
}

/* ---- viewer ------------------------------------------------------------- */

.viewer {
  position: fixed;
  inset: 0;
  z-index: 20;
  overflow: hidden;
  background: #000;
  user-select: none;
}

.viewer-stage {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.viewer-stage.image {
  touch-action: none;
}

.viewer-stage img,
.viewer-stage video {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  will-change: transform;
}

.viewer-bar {
  position: absolute;
  right: 0;
  left: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  color: #fff;
  transition: opacity 0.2s;
}

.viewer-bar.top {
  top: 0;
  padding-top: max(10px, env(safe-area-inset-top));
  background: linear-gradient(rgba(0, 0, 0, 0.65), transparent);
}

.viewer-bar.bottom {
  bottom: 0;
  padding-bottom: max(14px, env(safe-area-inset-bottom));
  background: rgba(0, 0, 0, 0.75);
}

button.ghost {
  color: #fff;
  background: rgba(255, 255, 255, 0.14);
}

.viewer-nav {
  position: absolute;
  top: 50%;
  z-index: 2;
  width: 44px;
  min-height: 0;
  height: 64px;
  padding: 0;
  font-size: 2rem;
  color: #fff;
  background: rgba(0, 0, 0, 0.35);
  transform: translateY(-50%);
  transition: opacity 0.2s;
}

.viewer-nav.prev {
  left: 8px;
}

.viewer-nav.next {
  right: 8px;
}

@media (hover: none) {
  .viewer-nav {
    display: none;
  }
}

.viewer.bare .viewer-bar,
.viewer.bare .viewer-nav {
  opacity: 0;
  pointer-events: none;
}

.viewer-message {
  position: absolute;
  right: 16px;
  bottom: 30%;
  left: 16px;
  z-index: 1;
  margin: 0;
  color: #fff;
  text-align: center;
  pointer-events: none;
}

ul.uploads,
ul.rows {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

ul.uploads:not(:empty) {
  margin-bottom: 14px;
}

.uploads li,
.rows li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.item-text {
  display: grid;
  min-width: 0;
}

.item-text .muted {
  font-size: 0.8rem;
  font-weight: 400;
}

.uploads li {
  flex-wrap: wrap;
}

.uploads progress {
  flex-basis: 100%;
  width: 100%;
  height: 6px;
  accent-color: var(--accent);
}

.rows li {
  justify-content: space-between;
}

.rows .current {
  color: var(--ok);
  font-size: 0.8rem;
}

/* ---- overlays ---------------------------------------------------------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow-y: auto;
}

.overlay.dark {
  background: #000;
}

.overlay-bar {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(10px);
}

.panel {
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 0 16px max(32px, env(safe-area-inset-bottom));
}

.panel h2:first-child {
  margin-top: 16px;
}

