/* ── Reset & Layout ──────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: #1a1b26;
  background: radial-gradient(circle at 50% 30%, #1f2335 0%, #16161e 100%);
  color: #c0caf5;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ── Toolbar ────────────────────────────────────────────────── */
#toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: rgba(22, 22, 30, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(41, 46, 66, 0.5);
  flex-shrink: 0;
  gap: 12px;
  z-index: 10;
}

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

.toolbar-center {
  justify-content: center;
}

/* ── File Picker ────────────────────────────────────────────── */
.file-picker-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background: #292e42;
  border: 1px solid #3b4261;
  border-radius: 6px;
  color: #7aa2f7;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.file-picker-btn:hover {
  background: #3b4261;
  border-color: #7aa2f7;
}

.file-picker-btn input[type="file"] {
  display: none;
}

/* ── Buttons ────────────────────────────────────────────────── */
.ctrl-btn {
  width: 36px;
  height: 36px;
  border: 1px solid #3b4261;
  border-radius: 6px;
  background: #292e42;
  color: #c0caf5;
  font-size: 15px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}

.ctrl-btn:hover:not(:disabled) {
  background: #3b4261;
  border-color: #7aa2f7;
}

.ctrl-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.ctrl-btn.playing {
  color: #f7768e;
  border-color: #f7768e;
}

.ctrl-btn.small {
  width: 28px;
  height: 28px;
  font-size: 12px;
}

.help-btn {
  font-weight: bold;
  font-size: 16px;
}

.github-btn {
  text-decoration: none;
  color: #9aa5ce;
}

.github-btn:hover {
  color: #c0caf5;
  border-color: #7aa2f7;
}

/* ── Filter buttons ─────────────────────────────────────────── */
.filter-group {
  display: flex;
  gap: 4px;
}

.filter-btn {
  padding: 4px 10px;
  border: 1px solid #3b4261;
  border-radius: 4px;
  background: #292e42;
  color: #565f89;
  font-size: 11px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.filter-btn.active {
  color: #c0caf5;
  border-color: #7aa2f7;
  background: #1f2335;
}

.filter-btn:hover {
  border-color: #7aa2f7;
}

/* ── Speed Slider ───────────────────────────────────────────── */
.speed-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: #9aa5ce;
  white-space: nowrap;
}

#speed-display {
  min-width: 30px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

#speed-slider {
  width: 100px;
  accent-color: #7aa2f7;
  cursor: pointer;
}

/* ── Badges ─────────────────────────────────────────────────── */
.session-badge,
.progress-badge {
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 4px;
  background: #292e42;
  color: #9aa5ce;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.session-badge:empty {
  display: none;
}

/* ── Scrubber ───────────────────────────────────────────────── */
#scrubber-bar {
  position: relative;
  height: 22px;
  background: rgba(22, 22, 30, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(41, 46, 66, 0.5);
  flex-shrink: 0;
  padding: 0 4px;
}

#scrubber {
  width: 100%;
  height: 100%;
  accent-color: #7aa2f7;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  position: relative;
  z-index: 2;
}

#scrubber::-webkit-slider-runnable-track {
  height: 4px;
  background: #292e42;
  border-radius: 2px;
}

#scrubber::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #7aa2f7;
  margin-top: -4px;
  cursor: pointer;
}

#scrubber:disabled {
  opacity: 0.3;
}

#scrubber-markers {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
}

.scrubber-mark {
  position: absolute;
  top: 2px;
  width: 2px;
  height: 18px;
  border-radius: 1px;
  opacity: 0.6;
}

.scrubber-mark.user { background: #7dcfff; }
.scrubber-mark.error { background: #f7768e; }

/* ── Terminal (see Terminal Window Frame section below) ──────── */

/* ── Drop Overlay ───────────────────────────────────────────── */
.drop-overlay {
  position: fixed;
  inset: 0;
  background: rgba(26, 27, 38, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  transition: opacity 0.2s;
}

.drop-overlay.hidden {
  display: none;
}

.drop-message {
  font-size: 24px;
  color: #7aa2f7;
  border: 3px dashed #7aa2f7;
  border-radius: 16px;
  padding: 48px 64px;
  text-align: center;
}

.drop-hint {
  font-size: 13px;
  color: #565f89;
  margin-top: 12px;
}

.drop-hint kbd {
  display: inline-block;
  padding: 2px 8px;
  background: #292e42;
  border: 1px solid #3b4261;
  border-radius: 4px;
  font-family: 'Cascadia Code', monospace;
  font-size: 12px;
  color: #e0af68;
}

/* ── Help / Shortcuts Overlay ───────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(26, 27, 38, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  transition: opacity 0.2s;
}

.overlay.hidden {
  display: none;
}

.overlay-content {
  background: #1f2335;
  border: 1px solid #3b4261;
  border-radius: 12px;
  padding: 32px 40px;
  max-width: 480px;
  width: 90%;
}

.overlay-content h2 {
  color: #7aa2f7;
  font-size: 18px;
  margin-bottom: 16px;
}

.shortcuts-table {
  width: 100%;
  border-collapse: collapse;
}

.shortcuts-table td {
  padding: 6px 8px;
  border-bottom: 1px solid #292e42;
  font-size: 13px;
}

.shortcuts-table td:first-child {
  width: 120px;
}

.shortcuts-table kbd {
  display: inline-block;
  padding: 2px 8px;
  background: #292e42;
  border: 1px solid #3b4261;
  border-radius: 4px;
  font-family: 'Cascadia Code', monospace;
  font-size: 12px;
  color: #bb9af7;
}

.overlay-hint {
  margin-top: 16px;
  text-align: center;
  font-size: 12px;
  color: #565f89;
}

.overlay-hint kbd {
  display: inline-block;
  padding: 1px 6px;
  background: #292e42;
  border: 1px solid #3b4261;
  border-radius: 3px;
  font-family: 'Cascadia Code', monospace;
  font-size: 11px;
  color: #bb9af7;
}

/* ── Search Bar (see Terminal Window Frame section for positioning) */

.search-bar.hidden {
  display: none;
}

.search-bar input {
  background: #292e42;
  border: 1px solid #3b4261;
  border-radius: 4px;
  color: #c0caf5;
  padding: 4px 10px;
  font-size: 13px;
  width: 220px;
  outline: none;
}

.search-bar input:focus {
  border-color: #7aa2f7;
}

.search-count {
  font-size: 11px;
  color: #565f89;
  min-width: 50px;
  text-align: center;
}

.search-scopes {
  display: flex;
  gap: 8px;
  padding: 0 4px;
}

.search-scope {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  color: #9aa5ce;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}

.search-scope input[type="checkbox"] {
  accent-color: #7aa2f7;
  width: 13px;
  height: 13px;
  cursor: pointer;
}

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 900px) {
  .filter-group {
    display: none;
  }
}

@media (max-width: 700px) {
  #toolbar {
    flex-wrap: wrap;
    gap: 6px;
    padding: 6px 10px;
  }
  .toolbar-left,
  .toolbar-center,
  .toolbar-right {
    flex: 1 1 100%;
    justify-content: center;
  }
}

/* ================================================================
   Terminal Window Frame
   ================================================================ */

#main-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 28px 24px;
  min-height: 0;
  position: relative;
}

.terminal-window {
  width: 100%;
  max-width: 1400px;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: #1a1b26;
  border: 1px solid #292e42;
  border-radius: 12px;
  box-shadow:
    0 0 0 1px rgba(122, 162, 247, 0.04),
    0 8px 24px rgba(0, 0, 0, 0.35),
    0 24px 48px rgba(0, 0, 0, 0.2);
  position: relative;
  overflow: hidden;
}

/* ── Title bar ──────────────────────────────────────────────── */
.terminal-titlebar {
  height: 40px;
  background: linear-gradient(to bottom, #24283b, #1f2335);
  border-bottom: 1px solid #16161e;
  display: flex;
  align-items: center;
  padding: 0 16px;
  flex-shrink: 0;
  user-select: none;
  -webkit-app-region: drag;
}

.titlebar-dots {
  display: flex;
  gap: 8px;
}

.titlebar-dots .dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  opacity: 0.85;
  transition: opacity 0.15s;
}

.titlebar-dots .dot:hover {
  opacity: 1;
}

.dot-red    { background: #f7768e; }
.dot-yellow { background: #e0af68; }
.dot-green  { background: #9ece6a; }

.titlebar-title {
  flex: 1;
  text-align: center;
  color: #565f89;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.3px;
}

.titlebar-spacer {
  width: 52px; /* balance the dots on the left */
}

/* ── Terminal container inside window ───────────────────────── */
#terminal-container {
  flex: 1;
  padding: 8px 4px 4px 8px;
  background: #1a1b26;
  overflow: hidden;
  border-radius: 0 0 12px 12px;
}

#terminal-container .xterm {
  height: 100%;
}

/* ── Scrollbar theme (xterm viewport + global) ─────────────── */
.xterm .xterm-viewport {
  scrollbar-width: thin;
  scrollbar-color: #292e42 transparent;
  /* Narrow viewport to just the scrollbar column so it sits above
     .xterm-screen and receives click/drag events on the scrollbar.
     Without this, .xterm-screen (position:relative, later in DOM)
     paints on top and intercepts scrollbar clicks. */
  left: auto !important;
  width: 14px !important;
  z-index: 5;
}

.xterm .xterm-viewport::-webkit-scrollbar {
  width: 8px;
}

.xterm .xterm-viewport::-webkit-scrollbar-track {
  background: transparent;
}

.xterm .xterm-viewport::-webkit-scrollbar-thumb {
  background: #292e42;
  border-radius: 4px;
}

.xterm .xterm-viewport::-webkit-scrollbar-thumb:hover {
  background: #3b4261;
}

/* ── Search bar (positioned inside main-area) ──────────────── */
.search-bar {
  position: absolute;
  top: 32px;
  right: 44px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: #1f2335;
  border: 1px solid #3b4261;
  border-radius: 8px;
  z-index: 20;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

