:root {
  --bg: #0d0d0d;
  --card: #161616;
  --line: #2a2a2a;
  --text: #f3f1ec;
  --muted: #9a958c;
  --accent: #e8dcc6;
  --stage: #1c1c1c;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.45 "Segoe UI", "Helvetica Neue", sans-serif;
  min-height: 100vh;
}

a { color: inherit; }
img { display: block; width: 100%; height: 100%; object-fit: cover; }

.top {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.85rem 1.25rem;
  background: rgba(13, 13, 13, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}
.find-box { flex: 1; max-width: 22rem; }
.find-box input {
  width: 100%;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.4rem 0.85rem;
  font: inherit;
}
.find-list { list-style: none; margin: 0; padding: 0; }
.find-list li + li { border-top: 1px solid var(--line); }
.find-list a {
  display: flex;
  gap: 0.9rem;
  align-items: center;
  padding: 0.75rem 0;
  text-decoration: none;
}
.find-list strong { display: block; }
.find-list .meta { margin: 0.15rem 0 0; }
.find-cover {
  width: 56px;
  height: 56px;
  border-radius: 8px;
  overflow: hidden;
  flex: 0 0 56px;
  background: var(--card);
  display: grid;
  place-items: center;
  color: var(--accent);
}

.brand {
  font-weight: 700;
  letter-spacing: 0.18em;
  word-spacing: 0.12em;
  text-transform: uppercase;
  text-decoration: none;
  font-size: 0.92rem;
}

.top-actions { display: flex; gap: 1.1rem; }
.top-actions a { color: var(--muted); text-decoration: none; font-size: 0.92rem; }
.top-actions a:hover { color: var(--text); }
.menu { position: relative; }
.menu summary {
  list-style: none;
  cursor: pointer;
  font-size: 1.2rem;
  line-height: 1;
}
.menu summary::-webkit-details-marker { display: none; }
.menu-list {
  position: absolute;
  right: 0;
  top: calc(100% + 0.45rem);
  z-index: 20;
  min-width: 10.5rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.35rem;
  display: grid;
}
.menu-list a {
  padding: 0.45rem 0.65rem;
  border-radius: 8px;
  text-decoration: none;
}
.menu-list a:hover { background: #222; color: var(--text); }
.tree-head h1 { margin-bottom: 0.4rem; }
.tree-list {
  list-style: none;
  margin: 0;
  padding: 0 0 0 1rem;
  touch-action: pan-y;
}
.tree-page > .tree-list { padding-left: 0; }
.tree-item.closed > .tree-list { display: none; }
.tree-item:not(.closed) > .tree-list:not(:has(.tree-item:not(.tree-drop))) {
  min-height: 1.85rem;
  margin: 0.2rem 0 0.3rem;
  border: 1px dashed #5a564e;
  border-radius: 6px;
}
.tree-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.45rem;
  padding: 0.35rem 0.2rem;
  border-radius: 8px;
}
.tree-row:hover { background: #1b1b1b; }
.tree-row a { text-decoration: none; font-weight: 600; }
.tree-meta { color: var(--muted); font-size: 0.82rem; }
.tree-tools { display: flex; flex-wrap: wrap; gap: 0.15rem 0.45rem; margin-left: auto; }
.tree-name {
  flex: 1;
  min-width: 12rem;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 0.2rem 0.4rem;
  font: inherit;
  font-weight: 600;
}
.tree-drop {
  position: relative;
  height: 0 !important;
  min-height: 0 !important;
  padding: 0 !important;
  overflow: visible;
  background: none;
  border: 0;
  list-style: none;
}
.tree-drop > * { visibility: hidden; height: 0; overflow: hidden; }
.tree-drop::before {
  content: "";
  position: absolute;
  left: 1.1rem;
  right: 0.2rem;
  top: -2px;
  height: 3px;
  background: var(--accent);
  border-radius: 2px;
}
.tree-drop::after {
  content: "▸";
  position: absolute;
  left: 0;
  top: -0.72rem;
  color: var(--accent);
  font-size: 1rem;
  line-height: 1;
}
.tree-dragging { opacity: 0.45; }
.tree-drag,
.tree-twist,
.tree-add,
.tree-import,
.tree-rename,
.tree-copy,
.tree-cut,
.tree-del {
  background: none;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-size: 0.82rem;
}
.tree-drag {
  display: none;
  touch-action: none;
  width: 1.6rem;
  padding: 0;
  font-size: 1.05rem;
  letter-spacing: -0.12em;
  cursor: grab;
}
@media (pointer: coarse) {
  .tree-drag { display: inline-flex; justify-content: center; }
}
.tree-twist { width: 1.4rem; padding: 0; }
.tree-item.closed > .tree-row .tree-twist { transform: rotate(-90deg); }
.tree-add:hover,
.tree-import:hover,
.tree-rename:hover,
.tree-copy:hover,
.tree-cut:hover,
.tree-del:hover { color: var(--text); }
.tree-status { color: var(--accent); }
.tree-import-note { margin: 0 0 0.55rem 2.2rem; font-size: 0.88rem; }
.tree-import-note:empty { display: none; }

.page { max-width: 920px; margin: 0 auto; padding: 1.5rem 1rem 4rem; }
.page.narrow { max-width: 460px; }

h1 { font-size: 1.7rem; font-weight: 600; margin: 0 0 0.25rem; letter-spacing: -0.02em; }
.meta { color: var(--muted); margin: 0 0 1rem; }
.meta a { color: var(--accent); }

.crumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  color: var(--muted);
  font-size: 0.88rem;
  margin-bottom: 1.4rem;
}
.crumbs a { color: var(--muted); }
.crumbs strong { color: var(--text); font-weight: 600; }

.profile {
  display: flex;
  gap: 1.4rem;
  align-items: center;
  margin-bottom: 1.6rem;
}
.avatar {
  width: 92px;
  height: 92px;
  border-radius: 50%;
  overflow: hidden;
  flex: 0 0 92px;
  background: var(--card);
  border: 1px solid var(--line);
}
.avatar.ghost {
  display: grid;
  place-items: center;
  font-size: 2rem;
  color: var(--accent);
}
.actions { display: flex; gap: 0.6rem; flex-wrap: wrap; }

.button {
  display: inline-block;
  background: var(--text);
  color: var(--bg);
  text-decoration: none;
  border: 0;
  border-radius: 999px;
  padding: 0.45rem 0.95rem;
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
}
.button.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
}
.button.danger {
  background: #8a2c2c;
  color: #fff;
}
.button:disabled {
  opacity: 0.4;
  cursor: default;
}
body.edit-mode .tile.photo.selected {
  outline: 3px solid var(--accent);
  outline-offset: -3px;
}
.tile-check,
.viewer-check {
  position: absolute;
  top: 0.4rem;
  right: 0.4rem;
  width: 1.35rem;
  height: 1.35rem;
  border: 2px solid #fff;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.35);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
  z-index: 2;
  cursor: pointer;
}
.tile.photo.selected .tile-check,
.viewer-check.on {
  background: var(--accent);
  border-color: var(--accent);
}
.tile.photo.pinned::before {
  content: "⌖";
  position: absolute;
  top: 0.35rem;
  left: 0.4rem;
  z-index: 2;
  color: #fff;
  font-size: 0.95rem;
  text-shadow: 0 0 4px #000;
}
body.arranging .grid:has(.tile.photo) { touch-action: none; }
body.arranging .tile.photo { cursor: grab; }
.tile-sort-ghost { opacity: 0.4; }
.edit-bar {
  position: sticky;
  bottom: 0;
  z-index: 15;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem;
  margin: 1.25rem -1rem -4rem;
  padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-bottom));
  background: rgba(13, 13, 13, 0.94);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(10px);
}
.edit-count {
  color: var(--muted);
  font-size: 0.88rem;
  margin-right: auto;
}

.chips { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.chip {
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.3rem 0.75rem;
  color: var(--muted);
  font-size: 0.88rem;
}
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }

.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
}
body.edit-mode .grid:has(.tile.photo) { touch-action: pan-y; }
body.edit-mode .grid.is-painting { touch-action: none; }
.grid.doors {
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
}
.grid.doors .tile { container-type: inline-size; }
.tile.photo,
.grid.doors .tile,
.viewer-frame img,
.viewer-full img {
  -webkit-touch-callout: none;
  user-select: none;
}
.sheet {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0 0.8rem 1.4rem;
}
.sheet[hidden] { display: none; }
.sheet-card {
  width: min(100%, 420px);
  display: grid;
  gap: 0.5rem;
}
.sheet-action,
.sheet-cancel {
  width: 100%;
  border: 0;
  border-radius: 14px;
  padding: 0.95rem 1rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.sheet-lead {
  margin: 0 0 0.15rem;
  color: var(--text);
  font-weight: 600;
  text-align: center;
}
.sheet-action { background: var(--card); color: var(--text); }
.sheet-action.danger { background: #3a1515; color: #f3c4c4; }
.sheet-cancel { background: var(--text); color: var(--bg); }

.cover-crop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.85rem;
  padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom));
  background: rgba(13, 13, 13, 0.92);
}
.cover-crop[hidden] { display: none; }
.cover-crop-stage {
  position: relative;
  width: min(92vw, 28rem);
  aspect-ratio: 1;
  overflow: hidden;
  touch-action: none;
  background: #111;
  border-radius: 12px;
  border: 1px solid var(--line);
}
.cover-crop-img {
  position: absolute;
  left: 0;
  top: 0;
  width: auto;
  height: auto;
  max-width: none;
  object-fit: none;
  transform-origin: 0 0;
  pointer-events: none;
  user-select: none;
}
.cover-crop .actions { justify-content: center; }

.tile {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  background: var(--card);
  border: 0;
  padding: 0;
  cursor: pointer;
  color: inherit;
}
.tile-ghost {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  font-size: 2rem;
  color: var(--accent);
}
.tile-label {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 1.6rem 0.55rem 0.5rem;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.78));
  font-size: 0.92rem;
  font-weight: 600;
}
.grid.doors .tile-label {
  inset: 7%;
  display: grid;
  place-items: center;
  padding: 0.7rem 0.85rem;
  background: rgba(16, 16, 16, 0.72);
  color: #fff;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: clamp(1.05rem, 9cqi, 1.7rem);
  font-weight: 500;
  -webkit-text-size-adjust: 100%;
  letter-spacing: 0.06em;
  line-height: 1.2;
  text-align: center;
  text-transform: uppercase;
  opacity: 0;
  transition: opacity 160ms ease;
  pointer-events: none;
}
@media (hover: hover) and (pointer: fine) {
  .grid.doors .tile:hover .tile-label { opacity: 1; }
}
.grid.doors .tile:active .tile-label,
.grid.doors .tile.is-press .tile-label { opacity: 1; }

.feed { list-style: none; margin: 0 auto; padding: 0; max-width: 470px; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-bottom: 1.2rem;
  overflow: hidden;
}
.card-head {
  display: block;
  padding: 0.7rem 0.85rem;
  font-weight: 600;
  text-decoration: none;
}
.card-image { display: block; aspect-ratio: 1; }
.card-caption { margin: 0; padding: 0.75rem 0.85rem 1rem; }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 3rem 1rem;
}
.empty .actions { justify-content: center; margin-top: 1rem; }

.form { display: grid; gap: 1rem; }
.form label { display: grid; gap: 0.4rem; font-size: 0.88rem; color: var(--muted); }
.compose-file {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}
.compose-stuck { color: var(--accent); }
.compose-ready { margin: 0; color: var(--accent); font-weight: 600; }
.compose-thumbs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(4.2rem, 1fr));
  gap: 0.35rem;
}
.compose-thumbs img {
  aspect-ratio: 1;
  border-radius: 6px;
  object-fit: cover;
}
.flash {
  max-width: 920px;
  margin: 1rem auto 0;
  padding: 0 1rem;
  color: var(--accent);
}
.form input[type="text"],
.form input[type="email"],
.form textarea,
.form input[type="file"] {
  width: 100%;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.65rem 0.7rem;
  font: inherit;
}
.hint { color: #6d6a64; font-weight: 400; }

.viewer {
  position: fixed;
  inset: 0;
  z-index: 30;
  width: 100vw;
  height: 100svh;
  background: var(--stage);
}
.viewer[hidden] { display: none; }
.viewer-scroller {
  height: 100%;
  overflow-y: auto;
  scroll-snap-type: y proximity;
  scrollbar-width: thin;
}
.viewer-slide {
  scroll-snap-align: start;
  display: flex;
  flex-direction: column;
  padding: 0.35rem 0 0.55rem;
}
.viewer-slide:first-child { padding-top: 2.8rem; }
.viewer-slide:last-child { padding-bottom: 2rem; }
.viewer-frame {
  display: grid;
  place-items: center;
}
.viewer-frame img {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 88dvh;
  object-fit: contain;
  cursor: zoom-in;
}
.viewer-caption {
  color: var(--accent);
  margin: 0.4rem 0.8rem 0;
  max-width: 40rem;
  text-align: left;
}
.viewer-caption[hidden] { display: none; }
.viewer-close,
.viewer-count {
  position: fixed;
  z-index: 33;
  color: white;
}
.viewer-slide { position: relative; }
.slide-check {
  position: absolute;
  top: 3.2rem;
  right: 0.8rem;
}
.viewer > .viewer-check {
  position: fixed;
  top: 0.7rem;
  left: 0.75rem;
  z-index: 33;
}
.viewer > .viewer-check[hidden] { display: none; }
.viewer-close {
  top: 0.55rem;
  right: 0.85rem;
  background: none;
  border: 0;
  font-size: 2rem;
  cursor: pointer;
  line-height: 1;
}
.viewer-count {
  top: 0.95rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.85rem;
  color: #c8c4bb;
  pointer-events: none;
}
.viewer-full {
  position: absolute;
  inset: 0;
  z-index: 32;
  background: var(--stage);
  display: grid;
  place-items: center;
  overflow: hidden;
}
.viewer-full[hidden] { display: none; }
.viewer-full img {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  transform-origin: center center;
  transition: opacity 180ms ease;
}
@media (orientation: landscape) {
  .viewer {
    inset: 0;
    width: 100%;
    height: 100lvh;
  }
  .viewer-close {
    top: max(0.45rem, env(safe-area-inset-top));
    right: max(0.85rem, env(safe-area-inset-right));
  }
  .viewer-count {
    top: max(0.85rem, env(safe-area-inset-top));
  }
  .viewer-slide {
    height: 100%;
    min-height: 100%;
    padding: 0;
    justify-content: center;
  }
  .viewer-slide:first-child,
  .viewer-slide:last-child { padding: 0; }
  .viewer-frame {
    flex: 1;
    width: 100%;
    height: 100%;
    min-height: 0;
  }
  .viewer-frame img {
    max-width: 100%;
    max-height: 100%;
  }
}
.viewer-prev,
.viewer-next {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: 0;
  color: white;
  font-size: 2.4rem;
  padding: 0.4rem 0.7rem;
  cursor: pointer;
  opacity: 0.7;
}
.viewer-prev { left: 0.2rem; }
.viewer-next { right: 0.2rem; }
.viewer-prev:hover,
.viewer-next:hover { opacity: 1; }

@media (max-width: 640px) {
  .profile { flex-direction: column; align-items: flex-start; }
}
