:root {
  --bg-primary: #000000;
  --bg-secondary: #0a0a0f;
  --bg-tertiary: #14141f;
  --bg-card: #1a1a2e;
  --text-primary: #ffffff;
  --text-secondary: #a0a0b0;
  --text-muted: #606070;
  --accent-primary: #ff0033;
  --focus-ring: #ff3355;
  --focus-glow: rgba(255, 51, 85, 0.45);
  --danger: #ff4466;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
}

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

html { overflow: hidden; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  width: 600px;
  height: 600px;
  overflow: hidden;
}

#app {
  width: 100%;
  height: 100%;
  position: relative;
}

/* --- Screens --- */
.screen {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  position: absolute;
  top: 0;
  left: 0;
}
.screen.hidden { display: none; }

/* --- Header --- */
.header {
  display: flex;
  align-items: center;
  padding: 16px 20px;
  background: var(--bg-secondary);
  gap: 12px;
  flex-shrink: 0;
}
.header h1 {
  font-size: 22px;
  font-weight: 600;
  flex: 1;
}
.header-btn {
  background: transparent;
  color: var(--text-primary);
  font-size: 20px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
  min-width: 44px;
  min-height: 44px;
}
.back-btn {
  background: transparent;
  color: var(--text-primary);
  font-size: 22px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
  min-width: 44px;
  min-height: 44px;
}

/* --- Content Area --- */
.content {
  flex: 1;
  padding: 16px 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.section-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-top: 4px;
}

/* --- Focus States --- */
.focusable {
  transition: all 0.15s ease;
  border: 2px solid transparent;
  cursor: pointer;
  min-height: 44px;
}
.focusable:focus {
  outline: none;
  border-color: var(--focus-ring);
  box-shadow: 0 0 20px var(--focus-glow);
}

/* --- Search Row --- */
.search-row {
  display: flex;
  gap: 8px;
}
.search-row .text-input {
  flex: 1;
}
.search-btn {
  padding: 0 18px;
  background: var(--accent-primary);
  color: #fff;
  font-weight: 600;
  border-radius: var(--radius-md);
  font-size: 15px;
  min-width: 64px;
}
.kb-open-btn,
.mic-btn {
  width: 48px;
  flex-shrink: 0;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 18px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* --- On-screen keyboard --- */
.kb-content {
  flex: 1;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow: hidden;
}
.kb-display {
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  min-height: 56px;
  font-size: 22px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  display: flex;
  align-items: center;
}
.kb-display .kb-text { letter-spacing: 0.02em; }
.kb-display .kb-cursor {
  display: inline-block;
  width: 2px;
  height: 22px;
  margin-left: 2px;
  background: var(--accent-primary);
  animation: kb-blink 1s steps(2, start) infinite;
}
@keyframes kb-blink { to { visibility: hidden; } }

.kb-grid {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 6px;
}
.kb-key {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 18px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  text-transform: uppercase;
  border: 2px solid transparent;
  cursor: pointer;
  transition: all 0.12s ease;
}
.kb-key:focus {
  outline: none;
  background: var(--bg-card);
  border-color: var(--focus-ring);
  box-shadow: 0 0 16px var(--focus-glow);
  transform: scale(1.05);
}
.kb-key.kb-action {
  background: var(--bg-card);
  font-size: 16px;
}
.kb-key.kb-submit {
  background: var(--accent-primary);
  color: #fff;
}
.kb-key.kb-submit:focus {
  background: #ff3355;
}

/* --- Text Input --- */
.text-input {
  width: 100%;
  padding: 14px 16px;
  font-size: 16px;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-radius: var(--radius-md);
  border: 2px solid transparent;
}
.text-input:focus {
  border-color: var(--focus-ring);
  box-shadow: 0 0 20px var(--focus-glow);
  outline: none;
}
.text-input::placeholder { color: var(--text-muted); }

/* --- Lists --- */
.list-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.list-item {
  display: flex;
  align-items: center;
  padding: 12px 14px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 15px;
  text-align: left;
  gap: 12px;
  width: 100%;
}
.list-item:focus { background: var(--bg-card); }
.list-item-icon {
  font-size: 22px;
  flex-shrink: 0;
  width: 32px;
  text-align: center;
}
.list-item-content { flex: 1; min-width: 0; }
.list-item-title {
  display: block;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.list-item-meta {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* --- Result item with thumbnail --- */
.result-item {
  padding: 8px;
  gap: 10px;
}
.result-thumb {
  width: 96px;
  height: 54px;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  object-fit: cover;
  flex-shrink: 0;
}
.result-title {
  font-size: 14px;
  font-weight: 500;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: normal;
}
.result-channel {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* --- Navigation buttons --- */
.nav-item {
  padding: 14px 16px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 15px;
  font-weight: 500;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
}
.nav-item:focus { background: var(--bg-card); }
.nav-item.primary {
  background: var(--accent-primary);
  color: #fff;
}

/* --- Loading / Error --- */
.loading-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 40px;
  flex: 1;
}
.loading-spinner {
  width: 44px;
  height: 44px;
  border: 4px solid var(--bg-tertiary);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-size: 15px; color: var(--text-secondary); }

.error-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 28px;
  text-align: center;
}
.error-icon { font-size: 40px; }
.error-message {
  font-size: 15px;
  color: var(--text-secondary);
  max-width: 480px;
}

/* --- Help text (settings) --- */
.help-text {
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-secondary);
  background: var(--bg-tertiary);
  padding: 12px 14px;
  border-radius: var(--radius-md);
}
.help-text code {
  background: rgba(255, 255, 255, 0.08);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12px;
}

/* --- Key status banner (Settings) --- */
.key-status {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  line-height: 1.4;
}
.key-status.shared {
  background: rgba(0, 180, 216, 0.12);
  color: #8ad8e8;
  border: 1px solid rgba(0, 180, 216, 0.3);
}
.key-status.personal {
  background: rgba(0, 255, 136, 0.12);
  color: #6effb0;
  border: 1px solid rgba(0, 255, 136, 0.3);
}
.key-status.none {
  background: rgba(255, 68, 102, 0.12);
  color: #ff8aa0;
  border: 1px solid rgba(255, 68, 102, 0.3);
}
.key-status-icon {
  font-size: 20px;
  flex-shrink: 0;
}
.key-status-text { flex: 1; }
.key-status-text strong { display: block; margin-bottom: 2px; }

/* --- Error actions row --- */
.error-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
  width: 100%;
  max-width: 480px;
}
.error-actions .nav-item { flex: 1; }

/* --- Home info card (about / how to get an API key) --- */
.info-card {
  background: var(--bg-secondary);
  border: 1px solid var(--bg-tertiary);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  margin-top: 4px;
}
.info-card-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.08em;
  margin-bottom: 6px;
}
.info-card-text {
  font-size: 12px;
  line-height: 1.55;
  color: var(--text-secondary);
}
.info-card-text strong { color: var(--text-primary); }
.info-card-text em {
  font-style: normal;
  color: var(--accent-primary);
}

/* --- Settings divider --- */
.divider {
  height: 1px;
  background: var(--bg-tertiary);
  margin: 12px 0 4px;
}

/* --- My YouTube entry button (home) --- */
.mine-entry {
  justify-content: flex-start;
  gap: 10px;
  background: var(--bg-tertiary);
  font-weight: 600;
}
.mine-entry-icon { color: var(--accent-primary); }

/* --- My YouTube hub --- */
#mine-menu {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.mine-channel-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  padding: 4px 2px 8px;
}
.mine-cat {
  justify-content: flex-start;
  gap: 12px;
}
.mine-cat-icon {
  color: var(--accent-primary);
  width: 22px;
  text-align: center;
  flex-shrink: 0;
}

/* --- Channel/playlist avatar in lists --- */
.row-thumb {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--bg-card);
  flex-shrink: 0;
}

/* --- Player --- */
#player { background: #000; overflow: hidden; }
.player-mount {
  position: absolute;
  inset: 0;
  width: 600px;
  height: 600px;
  overflow: hidden;
}
.player-mount iframe {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}
.player-overlay {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 14px 18px;
  background: linear-gradient(to top, rgba(10, 10, 15, 0.92), rgba(10, 10, 15, 0));
  pointer-events: none;
  z-index: 5;
}
.player-overlay.hidden-overlay { opacity: 0; transition: opacity 0.4s ease; }
.player-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 6px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
/* --- Player progress bar --- */
.player-time {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 11px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}
.progress-track {
  flex: 1;
  height: 4px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
  overflow: hidden;
}
.progress-track .progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent-primary);
  border-radius: 2px;
  transition: width 0.4s linear;
}
.player-hint {
  font-size: 11px;
  color: var(--text-secondary);
  text-align: center;
}

/* --- Seek readout (shows how far each jump went) --- */
.seek-indicator {
  position: absolute;
  top: 38%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 10px 20px;
  background: rgba(10, 10, 15, 0.88);
  border: 2px solid rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  color: #fff;
  font-size: 18px;
  font-weight: 700;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  z-index: 7;
}

/* --- Player control bar (visible when paused) --- */
.player-controls {
  display: flex;
  justify-content: center;
  align-items: stretch;
  gap: 10px;
  margin: 10px 0 8px;
}
.player-controls.hidden { display: none; }
.pc-btn {
  pointer-events: auto;            /* overlay is pointer-events:none; re-enable here */
  flex: 1;
  max-width: 130px;
  min-height: 64px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: rgba(26, 26, 46, 0.92);
  color: var(--text-primary);
  border: 2px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}
.pc-btn .pc-ic { font-size: 24px; line-height: 1; }
.pc-btn .pc-sub { font-size: 11px; color: var(--text-secondary); }
.pc-btn.pc-main .pc-ic { font-size: 30px; }
.pc-btn:focus {
  outline: none;
  border-color: var(--focus-ring);
  box-shadow: 0 0 20px var(--focus-glow);
  transform: scale(1.08);
  background: var(--bg-card);
}
.pc-btn:focus .pc-sub { color: var(--text-primary); }

/* --- Mic / voice search button --- */
.mic-btn {
  padding: 0 14px;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 18px;
  border-radius: var(--radius-md);
  min-width: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.mic-btn:focus { background: var(--bg-card); }
.mic-btn.listening {
  background: var(--accent-primary);
  color: #fff;
  animation: pulse 1s ease infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.focus-sink {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
  border: 0;
  background: transparent;
}

/* --- Toast --- */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--bg-card);
  color: var(--text-primary);
  padding: 12px 24px;
  border-radius: var(--radius-md);
  font-size: 14px;
  border: 1px solid var(--accent-primary);
  transition: transform 0.3s ease;
  z-index: 100;
  pointer-events: none;
  max-width: 500px;
  text-align: center;
}
.toast.visible { transform: translateX(-50%) translateY(0); }

.hidden { display: none !important; }
