* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --bg: #0f0f1a; --surface: #1a1a2e; --surface2: #16213e;
  --primary: #e94560; --primary-hover: #ff6b81;
  --text: #eaeaea; --text-muted: #8888aa; --border: #2a2a4a;
  --success: #2ecc71; --radius: 12px;
}
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; }
.hidden { display: none !important; }
#login-screen { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 1rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem; }
#login-screen .card { max-width: 360px; width: 100%; text-align: center; padding: 2rem; }
#login-screen h1 { color: var(--text-muted); font-size: 1.3rem; font-weight: 500; }
#login-form button { background: var(--surface2); color: var(--text-muted); border: 1px solid var(--border); }
#login-form button:hover { background: var(--border); color: var(--text); }
h1 { font-size: 1.6rem; color: var(--primary); }
.subtitle { color: var(--text-muted); margin: 0.4rem 0 1.5rem; font-size: 0.9rem; }
h2 { font-size: 1.05rem; font-weight: 600; }
input, textarea { width: 100%; padding: 0.7rem 0.9rem; background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-size: 0.9rem; outline: none; font-family: inherit; margin-bottom: 0.75rem; }
input:focus, textarea:focus { border-color: var(--primary); }
textarea { resize: vertical; margin-bottom: 0; }
button { cursor: pointer; border: none; border-radius: 8px; font-size: 0.9rem; font-weight: 500; transition: background 0.2s, opacity 0.2s; }
button:disabled { opacity: 0.4; cursor: not-allowed; }
#login-form button { width: 100%; padding: 0.7rem; background: var(--primary); color: #fff; margin-top: 0.25rem; }
#login-form button:hover { background: var(--primary-hover); }
.error { color: var(--primary); font-size: 0.85rem; margin-top: 0.5rem; }
header { display: flex; align-items: center; justify-content: space-between; padding: 0.75rem 1.5rem; background: var(--surface); border-bottom: 1px solid var(--border); }
header h1 { margin: 0; font-size: 1.25rem; }
header h1 .home-link { color: inherit; text-decoration: none; }
nav { display: flex; align-items: center; gap: 0.75rem; color: var(--text-muted); font-size: 0.85rem; }
.btn-small { padding: 0.35rem 0.7rem; background: var(--surface2); color: var(--text-muted); font-size: 0.8rem; border: 1px solid var(--border); border-radius: 6px; }
.btn-small:hover { color: var(--text); border-color: var(--text-muted); }
#user-menu { position: relative; }
#menu-dropdown { position: absolute; right: 0; top: 100%; margin-top: 0.3rem; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; min-width: 140px; overflow: hidden; z-index: 100; }
#menu-dropdown button { display: block; width: 100%; padding: 0.5rem 0.9rem; background: none; color: var(--text-muted); font-size: 0.85rem; text-align: left; border-radius: 0; }
#menu-dropdown button:hover { background: var(--surface2); color: var(--text); }
.btn-primary { padding: 0.55rem 1rem; background: var(--primary); color: #fff; font-weight: 600; border-radius: 8px; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { padding: 0.55rem 1rem; background: var(--surface2); color: var(--text); font-weight: 500; border: 1px solid var(--border); border-radius: 8px; }
.btn-secondary:hover { background: var(--border); }
#status-bar { display: flex; align-items: center; gap: 0.4rem; padding: 0.4rem 1.5rem; font-size: 0.75rem; color: var(--text-muted); background: var(--surface2); border-bottom: 1px solid var(--border); }
#comfyui-dot { width: 8px; height: 8px; border-radius: 50%; background: #666; display: inline-block; flex-shrink: 0; }
main { max-width: 620px; margin: 1.5rem auto; padding: 0 1rem; display: flex; flex-direction: column; gap: 1.5rem; }
#toolbar { display: flex; gap: 0.75rem; flex-wrap: wrap; }
#history-section { display: flex; flex-direction: column; gap: 0.75rem; }
.history-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.25rem; cursor: pointer; transition: border-color 0.2s; }
.history-card:hover { border-color: var(--primary); }
.history-card .hc-top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 0.4rem; }
.history-card .hc-action { font-weight: 600; font-size: 0.85rem; padding: 0.15rem 0.5rem; border-radius: 5px; }
.hc-action.edit { background: #2d4a3e; color: var(--success); }
.hc-action.video { background: #3a2d4a; color: #b39ddb; }
.hc-action.longvideo { background: #3a2d4a; color: #b39ddb; }
.hc-action.generate { background: #2d3a4a; color: #64b5f6; }
.checkbox-label { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.75rem; cursor: pointer; font-size: 0.9rem; color: var(--text-muted); }
.checkbox-label input[type="checkbox"] { width: auto; margin: 0; accent-color: var(--primary); }
.gen-options { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.75rem; }
.gen-options select { flex: 1 1 0; min-width: 0; max-width: 100%; overflow: hidden; text-overflow: ellipsis; padding: 0.55rem 0.75rem; background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-size: 0.9rem; outline: none; font-family: inherit; }
.gen-options select:focus { border-color: var(--primary); }
.steps-field { display: flex; align-items: center; gap: 0.5rem; flex: 0 0 auto; }
.steps-field span { font-size: 0.85rem; color: var(--text-muted); white-space: nowrap; }
.steps-field input { width: 5.5rem; margin: 0; }
.seed-field input { width: 9rem; }
.strength-field input { width: 5rem; }
/* Advanced generation options collapse into a native <details> so the form
   stays compact now that steps, seed, loop and LoRA all live there. The
   summary lists non-default settings so a collapsed panel hides nothing. */
.gen-advanced { margin-bottom: 0.75rem; }
.gen-advanced > summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: 0.4rem; padding: 0.35rem 0; font-size: 0.85rem; color: var(--text-muted); user-select: none; }
.gen-advanced > summary::-webkit-details-marker { display: none; }
.gen-advanced > summary::before { content: '▸'; display: inline-block; transition: transform 0.15s; }
.gen-advanced[open] > summary::before { transform: rotate(90deg); }
.gen-advanced > summary:hover { color: var(--text); }
.gen-advanced[open] > summary { margin-bottom: 0.5rem; color: var(--text); }
/* Stack the video option selects on narrow screens: their intrinsic
   min-content width (driven by the longest <option> label) is wider than a
   phone viewport and would otherwise force a horizontal scrollbar on the
   whole page. Flow/size selects keep their two-up layout - their labels are
   short enough to fit. */
@media (max-width: 560px) {
  #video-options { flex-direction: column; }
  #video-options select { flex: 0 0 auto; width: 100%; }
}
#long-controls { margin-bottom: 0.75rem; }
.segment-row { display: flex; gap: 0.5rem; align-items: flex-start; margin-bottom: 0.5rem; }
.segment-row .segment-input { flex: 1; }
.segment-row .segment-remove { flex-shrink: 0; }
#add-segment-btn { margin-bottom: 0.25rem; }
.history-card .hc-status { font-size: 0.75rem; padding: 0.15rem 0.5rem; border-radius: 5px; }
.hc-status.running { background: #4a3d2d; color: #ffb74d; }
.hc-status.complete { background: #2d4a3e; color: var(--success); }
.hc-status.error { background: #4a2d2d; color: var(--primary); }
.history-card .hc-prompt { font-size: 0.85rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-card .hc-prompt-row { display: flex; align-items: center; gap: 0.5rem; }
.history-card .hc-prompt-row .hc-prompt { flex: 1; min-width: 0; }
.history-card .hc-delete { flex-shrink: 0; padding: 0.2rem 0.5rem; background: transparent; color: var(--text-muted); border: 1px solid var(--border); border-radius: 6px; font-size: 0.72rem; }
.history-card .hc-delete:hover { color: var(--primary); border-color: var(--primary); }
.history-card .hc-time { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.3rem; }
.history-card .hc-thumb { display: none; }
.empty-state { text-align: center; color: var(--text-muted); padding: 2rem; font-size: 0.9rem; }

@media (min-width: 768px) {
  main { max-width: 1400px; padding: 0 2rem; }
  #history-section {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 1rem;
  }
  .history-card {
    padding: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  .history-card .hc-thumb {
    display: block;
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    background: var(--surface2);
  }
  .history-card .hc-thumb-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    aspect-ratio: 1;
    background: var(--surface2);
    color: var(--text-muted);
    font-size: 2.5rem;
  }
  .history-card .hc-body {
    padding: 0.8rem 1rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    flex: 1;
  }
  .history-card .hc-top { margin-bottom: 0; }
  .history-card .hc-time { margin-top: auto; padding-top: 0.4rem; }
  .empty-state { grid-column: 1 / -1; }
}
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; gap: 0.4rem; }
.upload-area { border: 2px dashed var(--border); border-radius: var(--radius); padding: 1.5rem; text-align: center; cursor: pointer; margin-bottom: 0.75rem; }
.upload-area:hover { border-color: var(--primary); }
.upload-icon { font-size: 2rem; color: var(--text-muted); display: block; margin-bottom: 0.3rem; }
.upload-area p { color: var(--text-muted); font-size: 0.85rem; }
#preview { max-width: 100%; max-height: 240px; border-radius: 8px; }
.actions { display: flex; gap: 0.5rem; margin-top: 0.75rem; }
.btn-action { flex: 1; padding: 0.6rem; background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-action:hover:not(:disabled) { background: var(--primary); border-color: var(--primary); }
#progress-log, #detail-log { list-style: none; max-height: 280px; overflow-y: auto; padding: 0.25rem 0; }
#progress-log li, #detail-log li { padding: 0.35rem 0.5rem; border-bottom: 1px solid var(--border); font-size: 0.8rem; color: var(--text-muted); display: flex; align-items: flex-start; gap: 0.5rem; transition: background 0.3s; }
#progress-log li.current, #detail-log li.current { background: var(--surface2); color: var(--text); }
.step-num { flex-shrink: 0; width: 22px; height: 22px; display: inline-flex; align-items: center; justify-content: center; background: var(--surface2); border-radius: 50%; font-size: 0.7rem; color: var(--text-muted); font-weight: 600; }
#progress-log li.current .step-num, #detail-log li.current .step-num { background: var(--primary); color: #fff; }
.spinner { width: 22px; height: 22px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite; margin: 0.75rem auto; }
@keyframes spin { to { transform: rotate(360deg); } }
#upload-result img, #upload-result video, #detail-result img, #detail-result video { max-width: 100%; border-radius: 8px; }
#upload-result video, #detail-result video { width: 100%; max-height: 350px; }
#upload-result a, #detail-result a { color: var(--primary); text-decoration: none; display: inline-block; margin: 0.4rem 0; font-size: 0.85rem; }
#upload-result a:hover, #detail-result a:hover { text-decoration: underline; }
#detail-meta { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.75rem; }
#detail-render-time { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.75rem; }
.render-time { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.5rem; }
.detail-section-label { font-size: 0.8rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 0.4rem; }
.loop-hint { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.75rem; }
.seed-label { font-size: 0.72rem; color: var(--text-muted); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; padding: 0.3rem 0.4rem 0; user-select: all; -webkit-user-select: all; }
.prompt-tools { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.4rem; }
.ai-status { font-size: 0.8rem; color: var(--text-muted); }
#pack-select { width: 100%; padding: 0.55rem 0.75rem; background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-size: 0.9rem; outline: none; font-family: inherit; margin-bottom: 0.75rem; }
#pack-select:focus { border-color: var(--primary); }
#pack-list { display: flex; flex-direction: column; gap: 0.6rem; margin-top: 1rem; }
.pack-row { display: flex; align-items: flex-start; gap: 0.75rem; background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; padding: 0.7rem 0.85rem; }
.pack-row-body { flex: 1; min-width: 0; }
.pack-row-name { font-weight: 600; font-size: 0.9rem; margin-bottom: 0.2rem; }
.pack-row-preview { font-size: 0.8rem; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.pack-row-negative { margin-top: 0.2rem; opacity: 0.8; }
.pack-row-actions { display: flex; flex-direction: column; gap: 0.35rem; flex-shrink: 0; }
.pool-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 0.75rem; margin-top: 0.5rem; }
.pool-card { background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; display: flex; flex-direction: column; }
.pool-thumb { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; background: var(--surface); }
.pool-name { font-size: 0.75rem; color: var(--text-muted); padding: 0.4rem 0.55rem 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pool-actions { display: flex; flex-wrap: wrap; gap: 0.25rem; padding: 0.4rem 0.55rem 0.55rem; margin-top: auto; }
.pool-actions .btn-small { flex: 1; text-align: center; }
.pool-actions a.pool-dl { text-decoration: none; }
