:root {
  color-scheme: dark;
  --bg: #14151a; --panel: #1d1f26; --line: #2a2d36; --line2: #33363f;
  --fg: #e6e6ea; --muted: #8a8d98; --accent: #2c5a8f; --danger: #e07a7a;
  font-family: system-ui, -apple-system, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--fg); }
button, .button, input, select { font: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.spacer { flex: 1; }

button, .button {
  cursor: pointer; border: 1px solid var(--line2); background: var(--panel);
  color: var(--fg); border-radius: 8px; padding: .5rem .8rem; text-decoration: none;
}
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); }
button.secondary { background: transparent; }
button.small, .button.small { padding: .3rem .6rem; font-size: .85rem; }

/* --- login --- */
#login { max-width: 22rem; margin: 10vh auto; padding: 0 1rem; }
#login-form { display: grid; gap: .6rem; }
#login input, #login button { padding: .55rem .7rem; border-radius: 8px;
  border: 1px solid var(--line2); background: var(--panel); color: inherit; font-size: 1rem; }
#login button { background: var(--accent); border-color: var(--accent); }
.hint { font-size: .8rem; color: var(--muted); margin: 0; }
#status { min-height: 1.2rem; font-size: .9rem; color: var(--muted); }
#status.error { color: var(--danger); }

/* --- shell --- */
.topbar { display: flex; align-items: center; gap: .6rem; padding: .6rem 1rem;
  border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--bg); z-index: 5; }
.brand { font-weight: 600; }
.who { color: var(--muted); font-size: .9rem; }
.menu-btn { display: none; font-size: 1.1rem; line-height: 1; }
.backdrop { display: none; }
.layout { display: grid; grid-template-columns: 17rem 1fr; min-height: calc(100vh - 3rem); }
.sidebar { border-right: 1px solid var(--line); padding: 1rem; overflow-y: auto;
  max-height: calc(100vh - 3rem); position: sticky; top: 3rem; }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; margin: 1rem 0 .4rem; }
.sidebar-head:first-child { margin-top: 0; }
.sidebar-head h2 { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0; }
.nav-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .2rem; }
.nav-list li { padding: .45rem .55rem; border-radius: 8px; cursor: pointer; border: 1px solid transparent; }
.nav-list li:hover { background: var(--panel); }
.nav-list li.active { background: var(--panel); border-color: var(--line2); }
.nav-list .name { font-size: .92rem; }
.nav-list .meta { font-size: .75rem; color: var(--muted); }

.content { padding: 1rem 1.5rem; }
.empty { color: var(--muted); padding: 3rem 1rem; text-align: center; }
.view-head { display: flex; align-items: center; gap: 1rem; margin-bottom: 1rem; }
.view-head h2 { margin: 0; font-size: 1.2rem; }
.view-actions { margin-left: auto; }

/* --- runs + thumbs --- */
.run { border: 1px solid var(--line); border-radius: 12px; padding: 1rem; margin-bottom: 1rem; }
.run-head { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin-bottom: .4rem; }
.run-head .when { color: var(--muted); font-size: .85rem; }
.run-head .count { color: var(--muted); font-size: .8rem; margin-left: auto; }
.run-desc { margin-bottom: .6rem; }
.run-desc > summary { cursor: pointer; color: #c9ccd6; font-size: .88rem; list-style: none; padding: .25rem 0; }
.run-desc > summary::-webkit-details-marker { display: none; }
.run-desc > summary::before { content: "▸ "; color: var(--muted); }
.run-desc[open] > summary::before { content: "▾ "; }
.run-desc[open] > summary .prompt-preview { display: none; }
.run-desc .prompt { font-size: .9rem; color: #c9ccd6; margin: .2rem 0 .6rem; white-space: pre-wrap; }
.run-config summary { cursor: pointer; color: var(--muted); font-size: .85rem; margin-bottom: .5rem; }
.config-dump { background: #0e0f13; border: 1px solid var(--line); border-radius: 8px;
  padding: .6rem; font-size: .78rem; overflow-x: auto; max-height: 16rem; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .5rem; }
.thumb { aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--panel);
  cursor: pointer; position: relative; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block;
  opacity: 0; transition: opacity .2s; }
.thumb img.loaded { opacity: 1; }
.thumb.failed { outline: 1px solid var(--danger); }

/* --- lightbox --- */
.lightbox { position: fixed; inset: 0; height: 100vh; height: 100dvh;
  background: rgba(8,9,12,.94); z-index: 50;
  display: grid; grid-template-rows: 1fr auto; align-items: center; }
#lightbox:fullscreen, #lightbox:-webkit-full-screen { background: #08090c; }
.lb-stage { display: flex; align-items: center; justify-content: center; gap: 1rem;
  overflow: hidden; padding: 1rem; height: 100%; }
#lb-img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 6px; }
.lb-nav { position: fixed; top: 50%; transform: translateY(-50%); font-size: 2.5rem;
  width: 3rem; height: 4rem; background: rgba(0,0,0,.3); border: none; color: #fff; }
.lb-prev { left: .5rem; } .lb-next { right: .5rem; }
.lb-nav:disabled { opacity: .25; cursor: default; }
.lb-close { position: fixed; top: max(.6rem, env(safe-area-inset-top)); right: .8rem;
  font-size: 1.3rem; background: none; border: none; color: #fff; z-index: 51; }
.lb-bar { display: flex; align-items: center; gap: .8rem;
  padding: .7rem 1rem max(.7rem, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); background: var(--bg); flex-wrap: wrap; }
.lb-counter { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 4rem; }
.lb-secs input { width: 3.5rem; padding: .2rem .3rem; border-radius: 6px;
  border: 1px solid var(--line2); background: var(--panel); color: inherit; }
.check { display: inline-flex; align-items: center; gap: .3rem; color: var(--muted); font-size: .9rem; }
.lb-info { align-self: stretch; max-width: 22rem; overflow-y: auto; background: var(--panel);
  border-radius: 10px; padding: 1rem; }
.lb-info-head { margin-bottom: .5rem; }
#lb-info-table { width: 100%; border-collapse: collapse; font-size: .82rem; }
#lb-info-table th { text-align: left; color: var(--muted); font-weight: 500; padding: .2rem .5rem .2rem 0;
  vertical-align: top; white-space: nowrap; }
#lb-info-table td { padding: .2rem 0; word-break: break-word; }
#lb-info-table .seed-row th, #lb-info-table .seed-row td { color: #7fd18c; font-weight: 600; }

.view-actions { margin-left: auto; display: flex; gap: .4rem; align-items: center; }
#album-actions { display: flex; gap: .4rem; }

/* + Album menu (lightbox) */
.lb-album-wrap { position: relative; }
.lb-album-menu { position: absolute; bottom: 2.6rem; right: 0; min-width: 12rem; max-height: 15rem;
  overflow-y: auto; background: var(--panel); border: 1px solid var(--line2); border-radius: 10px;
  padding: .4rem; display: grid; gap: .1rem; box-shadow: 0 8px 24px rgba(0,0,0,.4); z-index: 60; }
.lb-album-menu .row { display: flex; align-items: center; gap: .5rem; padding: .35rem .4rem;
  border-radius: 6px; cursor: pointer; font-size: .9rem; }
.lb-album-menu .row:hover { background: var(--bg); }
.lb-album-menu .newalbum { margin-top: .3rem; width: 100%; text-align: left; }

/* toast */
.toast { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%);
  background: #22303f; color: #e6e6ea; border: 1px solid var(--line2); border-radius: 999px;
  padding: .5rem 1rem; font-size: .88rem; z-index: 80; }
.toast.err { background: #4a2020; border-color: var(--danger); }

@media (max-width: 720px) {
  .layout { grid-template-columns: 1fr; }
  .lb-album-menu { bottom: auto; top: 2.6rem; }
  .menu-btn { display: inline-block; }
  .content { padding: 1rem; }

  /* sidebar becomes an off-canvas drawer */
  .sidebar {
    position: fixed; top: 2.9rem; bottom: 0; left: 0; width: 15rem; z-index: 20;
    max-height: none; background: var(--bg); border-right: 1px solid var(--line2);
    transform: translateX(-100%); transition: transform .2s ease;
  }
  body.nav-open .sidebar { transform: translateX(0); }
  .backdrop { position: fixed; inset: 2.9rem 0 0 0; background: rgba(0,0,0,.5); z-index: 15; }
  body.nav-open .backdrop { display: block; }

  .thumbs { grid-template-columns: repeat(auto-fill, minmax(30vw, 1fr)); gap: .35rem; }

  /* bigger tap targets */
  button, .button { min-height: 2.5rem; }
  .nav-list li { padding: .6rem .55rem; }

  /* lightbox: stack the info panel, roomier controls */
  .lb-stage { flex-direction: column; padding: .4rem; }
  .lb-info { max-width: none; width: 100%; max-height: 40vh; }
  .lb-nav { font-size: 2rem; width: 2.2rem; height: 3rem; background: rgba(0,0,0,.45); }
  .lb-bar { gap: .5rem .6rem; padding: .6rem .7rem max(.6rem, env(safe-area-inset-bottom)); font-size: .9rem; }
  .lb-secs input { width: 3rem; }
  .who { display: none; }
}
