* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: #141517;
  color: #e4e5ea;
}

html {
  scroll-behavior: smooth;
}

body { 
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ---- Header ---- */
header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  padding: 8px 16px;
  background: #1e1f23;
  border-bottom: 1px solid #2a2b30;
  user-select: none;
  gap: 16px;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 100;
}

header .left, header .right { display: flex; align-items: center; gap: 12px; }

header .center {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.mode-dropdown {
  position: relative;
}

.mode-dropdown-menu {
  position: absolute;
  top: 100%;
  left: 0;
  background: #1e1f23;
  border: 1px solid #2a2b30;
  border-radius: 6px;
  min-width: 140px;
  margin-top: 4px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
}

.mode-dropdown-menu.hidden {
  display: none;
}

.mode-dropdown-item {
  background: transparent;
  border: none;
  color: #aaa;
  padding: 8px 14px;
  text-align: left;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.1s, color 0.1s;
  white-space: nowrap;
}

.mode-dropdown-item:hover {
  background: #28292e;
  color: #e4e5ea;
}

.mode-dropdown-item.active {
  background: #2563eb;
  color: #fff;
  font-weight: 600;
}

.logo { font-weight: 700; font-size: 15px; color: #6cb4ff; letter-spacing: .3px; }

.status { font-size: 12px; color: #888; }

.per-row-label { font-size: 12px; color: #aaa; display: flex; align-items: center; gap: 6px; }
.per-row-label select {
  background: #28292e; color: #e4e5ea; border: 1px solid #3a3b40;
  border-radius: 4px; padding: 4px 6px; font-size: 12px;
}

.fps-label { font-size: 12px; color: #aaa; display: flex; align-items: center; gap: 6px; }
.fps-label input[type="number"] {
  background: #28292e; color: #e4e5ea; border: 1px solid #3a3b40;
  border-radius: 4px; padding: 4px 6px; font-size: 12px;
  width: 68px; text-align: right;
}
.fps-label input[type="number"]:focus {
  outline: none; border-color: #2563eb;
}

.btn {
  background: #2a2b30; color: #e4e5ea; border: 1px solid #3a3b40;
  border-radius: 6px; padding: 6px 14px; font-size: 13px; font-weight: 600;
  cursor: pointer; transition: background .1s;
}
.btn:hover { background: #35363c; }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-save { background: #2563eb; border-color: #2563eb; color: #fff; }
.btn-save:hover:not(:disabled) { background: #3b7bff; }
.btn-big { padding: 10px 22px; font-size: 15px; }

/* ---- Main ---- */
#main {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
  padding: 12px;
  display: flex;
  flex-direction: column;
  background: #141517;
  min-height: 0;
}

.center-state {
  height: 100%;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center; gap: 8px; color: #888;
}
.center-state h1 { color: #e4e5ea; font-size: 24px; }
.center-state p { max-width: 400px; margin-bottom: 8px; }
.big-icon { font-size: 52px; }
.hidden { display: none !important; }

/* ---- Drop Zone ---- */
.drop-zone {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 8px;
  width: 100%; height: 100%;
  border: 2px dashed transparent;
  border-radius: 16px;
  transition: border-color .15s, background .15s;
  padding: 32px;
}

.drop-zone.drag-over {
  border-color: #2563eb;
  background: rgba(37, 99, 235, 0.07);
}

.drop-hint {
  font-size: 12px; color: #555; margin-top: 4px;
}

/* ---- Settings State ---- */
.settings-filename {
  color: #e4e5ea; font-size: 18px; font-weight: 600;
  max-width: 500px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.settings-info {
  font-size: 13px; color: #888; margin-bottom: 12px;
}

.settings-panel {
  display: flex; flex-direction: column; gap: 16px;
  background: #1e1f23; border: 1px solid #2a2b30; border-radius: 10px;
  padding: 20px 28px; min-width: 320px;
}

.settings-group {
  display: flex; flex-direction: column; gap: 8px;
}

.settings-label {
  font-size: 12px; color: #aaa; font-weight: 600; text-transform: uppercase; letter-spacing: .5px;
}

.settings-modes {
  display: flex; gap: 8px;
}

.mode-btn {
  flex: 1; padding: 8px 12px; font-size: 13px; text-align: center;
  border-radius: 6px; transition: background .1s, border-color .1s;
}
.mode-btn.active {
  background: #2563eb; border-color: #2563eb; color: #fff;
}

.settings-input {
  background: #28292e; color: #e4e5ea; border: 1px solid #3a3b40;
  border-radius: 6px; padding: 8px 12px; font-size: 14px; width: 100%;
}
.settings-input:focus { outline: none; border-color: #2563eb; }

.btn-start {
  margin-top: 16px;
  padding: 12px 36px; font-size: 16px; font-weight: 700;
  background: #16a34a; border-color: #16a34a; color: #fff;
  border-radius: 8px;
}
.btn-start:hover { background: #22c55e; }

.btn-pick-another {
  margin-top: 4px;
  font-size: 12px; color: #777; background: transparent; border-color: transparent;
  padding: 4px 8px;
}
.btn-pick-another:hover { color: #aaa; background: transparent; }

/* ---- Progress ---- */
.progress-track { width: 360px; height: 8px; background: #28292e; border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; width: 0%; background: #2563eb; transition: width .2s ease; }

@keyframes indeterminate {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(400%); }
}
.progress-fill.indeterminate {
  width: 25% !important;
  animation: indeterminate 1.4s ease-in-out infinite;
  transition: none;
}

.progress-filename {
  font-size: 13px; color: #c8c9ce; font-weight: 600;
  max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.progress-detail {
  font-size: 13px; color: #e4e5ea; font-variant-numeric: tabular-nums;
}
.progress-sub {
  font-size: 11px; color: #666; font-variant-numeric: tabular-nums;
  min-height: 16px;
}

/* ---- Loading overlay (ffmpeg init) ---- */
.loading-banner {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
  background: #1e1f23; border: 1px solid #2a2b30; border-radius: 8px;
  padding: 10px 20px; font-size: 13px; color: #aaa;
  display: flex; align-items: center; gap: 10px; z-index: 100;
  box-shadow: 0 4px 24px rgba(0,0,0,.5);
}
.loading-spinner {
  width: 14px; height: 14px;
  border: 2px solid #3a3b40;
  border-top-color: #6cb4ff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

#downloadSectionInProgress {
  display: none;
}

#downloadSection {
  display: none;
}

/* ---- Grid ---- */
.grid {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(var(--cols, 4), 1fr);
  grid-auto-rows: auto;
}

@supports (aspect-ratio: 1) {
  .grid[style*="--cols: 1"] {
    grid-auto-rows: 1fr;
  }
  
  .grid[style*="--cols: 1"] .cell {
    aspect-ratio: 16 / 9;
  }
}

.cell {
  position: relative;
  background: #0c0d0f;
  border: 3px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  overflow: hidden;
  transition: border-color .08s;
}
.cell.selected { border-color: #2563eb; }

.cell img {
  display: block;
  width: 100%;
  height: auto;
  pointer-events: none;
  user-select: none;
}

.cell .meta {
  display: flex; justify-content: space-between;
  padding: 3px 6px; font-size: 10px; color: #777;
  background: #111215; pointer-events: none;
}

.cell .check {
  position: absolute; top: 5px; right: 5px;
  width: 18px; height: 18px; border-radius: 50%;
  background: rgba(0,0,0,.5); border: 1.5px solid rgba(255,255,255,.5);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; color: transparent; pointer-events: none;
}
.cell.selected .check { background: #2563eb; border-color: #2563eb; color: #fff; }

/* ---- Toolbar above grid ---- */
.grid-toolbar {
  display: flex; align-items: center; gap: 10px;
  padding: 0 0 10px 0;
  flex-shrink: 0;
}

/* ---- Manual Mode ---- */
.manual-state {
  display: flex; flex-direction: column;
  height: 100%;
}

.manual-video-wrap {
  flex: 1;
  display: flex; align-items: center; justify-content: center;
  background: #000;
  overflow: hidden;
  min-height: 0;
}

.manual-video {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.manual-controls {
  background: #1e1f23;
  border-top: 1px solid #2a2b30;
  padding: 12px 20px;
  flex-shrink: 0;
}

.manual-slider-row {
  display: flex; align-items: center; gap: 12px;
}

.manual-time {
  font-size: 12px; color: #aaa; font-variant-numeric: tabular-nums;
  min-width: 70px;
}

.manual-slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  background: #28292e;
  border-radius: 3px;
  outline: none;
  cursor: pointer;
}

.manual-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px; height: 14px;
  background: #2563eb;
  border-radius: 50%;
  cursor: grab;
}

.manual-slider::-webkit-slider-thumb:active {
  cursor: grabbing;
  background: #3b7bff;
}

.manual-buttons-control-row {
  display: flex; align-items: center; gap: 6px;
  margin-top: 10px;
  flex-wrap: nowrap;
  overflow-x: hidden;
}

.manual-buttons-bottom-row {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  margin-top: 8px;
}

.manual-nav-btn {
  padding: 6px 10px; font-size: 12px; font-weight: 600;
  flex-shrink: 0;
  white-space: nowrap;
}

.manual-speed-group {
  display: flex; align-items: center; gap: 2px;
  margin-left: 8px;
  flex-shrink: 0;
}

.manual-speed-label {
  font-size: 11px; color: #aaa; margin-right: 4px;
  flex-shrink: 0;
}

.speed-btn {
  padding: 4px 6px; font-size: 10px; font-weight: 600;
  border-radius: 4px; min-width: 28px; text-align: center;
  flex-shrink: 0;
}
.speed-btn.active {
  background: #2563eb; border-color: #2563eb; color: #fff;
}

.manual-time {
  font-size: 12px; color: #aaa; font-variant-numeric: tabular-nums;
  min-width: 65px;
}

.manual-frame-info {
  font-size: 12px; color: #aaa; font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.manual-save-btn {
  padding: 6px 16px; font-size: 12px;
  white-space: nowrap;
}

.manual-save-status {
  font-size: 11px; color: #16a34a; font-weight: 600;
  white-space: nowrap;
}

/* ---- Modal ---- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal { background: #1e1f23; border: 1px solid #2a2b30; border-radius: 10px; padding: 24px; width: 360px; max-width: 90vw; }
.modal h2 { margin-bottom: 8px; font-size: 16px; }
.modal p { color: #aaa; font-size: 13px; margin-bottom: 16px; line-height: 1.4; white-space: pre-wrap; word-break: break-word; }
.modal-btns { display: flex; justify-content: flex-end; gap: 8px; }

/* ---- Faces not available notice ---- */
.faces-notice {
  font-size: 12px; color: #e59e0b; background: rgba(229,158,11,.1);
  border: 1px solid rgba(229,158,11,.25); border-radius: 6px;
  padding: 8px 12px; max-width: 320px; text-align: left; line-height: 1.5;
}

/* ---- Scrollbar ---- */
#main::-webkit-scrollbar { width: 10px; }
#main::-webkit-scrollbar-track { background: #141517; }
#main::-webkit-scrollbar-thumb { background: #2a2b30; border-radius: 5px; }

/* ---- Responsive: hide FPS header control on narrow screens ---- */
@media (max-width: 600px) {
  .fps-label { display: none; }
  header .right { gap: 6px; }
}
