:root {
  --bg: #1a1a1a;
  --bg2: #111;
  --panel: #222;
  --btn: #2d2d2d;
  --btn-hover: #3a3a3a;
  --ok: #7ec87e;
  --ok-bg: #3d6b3d;
  --danger: #ff9999;
  --danger-bg: #5a2d2d;
  --muted: #666;
  --text: #ccc;
  --dim: #555;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, sans-serif;
  overflow: hidden;
}
button {
  font-family: inherit;
  cursor: pointer;
  border: 0;
  background: var(--btn);
  color: var(--text);
  border-radius: 6px;
}
button:hover { background: var(--btn-hover); color: #fff; }
button:disabled { opacity: .4; cursor: default; }
input, select {
  font-family: inherit;
  background: #1b1b1b;
  color: #eee;
  border: 1px solid #333;
  border-radius: 6px;
  padding: 8px 10px;
}

/* login */
#login-screen {
  position: fixed; inset: 0;
  background: #0d0d0d;
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
}
.login-card {
  width: 360px; max-width: calc(100% - 32px);
  background: #181818;
  border: 1px solid #2a2a2a;
  border-radius: 12px;
  padding: 28px 24px;
}
.login-card h1 { margin: 0 0 6px; font-size: 20px; font-weight: 600; color: #eee; }
.login-card p { margin: 0 0 18px; color: var(--muted); font-size: 13px; }
.login-card label { display: block; font-size: 12px; color: #888; margin: 10px 0 4px; }
.login-card input { width: 100%; }
.login-card button { width: 100%; margin-top: 16px; padding: 10px; background: #2f5d2f; color: #dff5df; }
.login-card button:hover { background: #3d6b3d; }
.error { color: #f3a0a0; font-size: 13px; min-height: 18px; margin-top: 10px; }

/* layout */
#app { display: none; height: 100%; flex-direction: column; }
#app.ready { display: flex; }
.topbar {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg2); padding: 8px 12px; flex-shrink: 0;
}
.topbar .spacer { flex: 1; }
.topbar button { padding: 7px 12px; }
.lbl { color: var(--dim); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lbl.ok { color: var(--ok); }
.counter { color: #888; font-size: 13px; }

.main { display: flex; flex: 1; min-height: 0; }
.stage {
  flex: 1; background: var(--bg2); position: relative;
  display: flex; align-items: center; justify-content: center;
}
.stage img {
  max-width: 100%; max-height: 100%;
  object-fit: contain; user-select: none;
}
.stage .empty {
  color: var(--ok); font-size: 18px; text-align: center; padding: 24px;
}
.stage .hint { color: var(--dim); font-size: 14px; }
.filename {
  position: absolute; left: 0; right: 0; bottom: 8px;
  text-align: center; color: #666; font-size: 13px; pointer-events: none;
}

.sidebar {
  width: 200px; background: var(--panel);
  display: flex; flex-direction: column; flex-shrink: 0;
}
.sidebar h2 {
  margin: 0; padding: 10px 12px 6px;
  font-size: 11px; letter-spacing: .06em; color: var(--dim); font-weight: 600;
}
#targets { flex: 1; overflow: auto; padding: 0 8px 8px; }
.target-btn {
  width: 100%; text-align: left; padding: 10px 8px; margin: 3px 0;
  background: var(--btn); color: var(--text);
}
.target-btn:hover { background: var(--ok-bg); color: var(--ok); }
.side-actions { padding: 8px; }
.side-actions button { width: 100%; padding: 10px; background: #222; color: #555; }
.side-actions button:hover { background: #2d2d2d; color: #888; }

/* slideshow bar */
.slidebar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: #161616; border-top: 1px solid #2a2a2a;
  padding: 8px 12px; font-size: 13px; color: #999;
}
.slidebar label { display: flex; align-items: center; gap: 6px; }
.slidebar input[type="number"] { width: 64px; padding: 4px 6px; }
.slidebar .on { color: var(--ok); }

/* modal */
.modal {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.65); z-index: 40;
  align-items: center; justify-content: center;
}
.modal.open { display: flex; }
.modal-card {
  width: 520px; max-width: calc(100% - 24px); max-height: min(80vh, 640px);
  background: #1c1c1c; border: 1px solid #333; border-radius: 10px;
  display: flex; flex-direction: column;
}
.modal-card header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; border-bottom: 1px solid #2a2a2a;
}
.modal-card header h3 { margin: 0; font-size: 15px; }
.crumbs { padding: 8px 14px; color: #888; font-size: 12px; word-break: break-all; }
.dir-list { flex: 1; overflow: auto; padding: 6px; }
.dir-item {
  width: 100%; text-align: left; padding: 8px 10px; margin: 1px 0;
  background: transparent; color: #ddd;
}
.dir-item:hover { background: #2a2a2a; }
.dir-item .meta { color: #666; font-size: 12px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; padding: 10px 14px; }
.modal-actions button { padding: 8px 12px; }
.primary { background: #2f5d2f; color: #dff5df; }
.primary:hover { background: #3d6b3d; }
.danger { background: var(--btn); color: var(--danger); }
.danger:hover { background: var(--danger-bg); }

.peek, .mobile-scrim { display: none; }

@media (max-width: 800px) {
  .peek {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    z-index: 25;
    width: 42px;
    height: 28px;
    padding: 0;
    border-radius: 8px;
    background: rgba(20, 20, 20, .45);
    color: rgba(255, 255, 255, .8);
    font-size: 16px;
    line-height: 1;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    border: 1px solid rgba(255,255,255,.12);
  }
  .peek:hover { background: rgba(40, 40, 40, .55); color: #fff; }
  .peek-top {
    top: calc(8px + env(safe-area-inset-top, 0px));
    left: 50%;
    transform: translateX(-50%);
  }
  .peek-right {
    right: calc(8px + env(safe-area-inset-right, 0px));
    top: 50%;
    transform: translateY(-50%);
    width: 28px;
    height: 42px;
  }
  .peek-bottom {
    bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    left: 50%;
    transform: translateX(-50%);
  }
  #app.panel-top .peek-top,
  #app.panel-side .peek-right,
  #app.panel-slide .peek-bottom {
    background: rgba(60, 110, 60, .55);
  }

  .mobile-scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 26;
    background: rgba(0,0,0,.35);
  }
  .mobile-scrim[hidden] { display: none; }

  .topbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 30;
    flex-wrap: wrap;
    max-height: 45vh;
    overflow: auto;
    padding-top: calc(8px + env(safe-area-inset-top, 0px));
    transform: translateY(calc(-100% - 8px));
    transition: transform .22s ease;
    box-shadow: 0 8px 24px rgba(0,0,0,.4);
  }
  #app.panel-top .topbar { transform: translateY(0); }

  .main { flex-direction: row; }
  .sidebar {
    position: fixed;
    top: 0; right: 0; bottom: 0;
    width: min(78vw, 280px);
    z-index: 30;
    transform: translateX(calc(100% + 8px));
    transition: transform .22s ease;
    box-shadow: -8px 0 24px rgba(0,0,0,.4);
    padding-top: env(safe-area-inset-top, 0px);
  }
  #app.panel-side .sidebar { transform: translateX(0); }

  .slidebar {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 30;
    transform: translateY(calc(100% + 8px));
    transition: transform .22s ease;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -8px 24px rgba(0,0,0,.4);
  }
  #app.panel-slide .slidebar { transform: translateY(0); }

  .filename {
    bottom: calc(40px + env(safe-area-inset-bottom, 0px));
    font-size: 12px;
  }
  .lbl { max-width: 100%; }
  .stage img { max-height: 100dvh; }
}
