:root {
  --bg-primary: #000000; /* pure black = transparent on additive display, lets real world show through */
  --bg-secondary: #0a0a0f;
  --bg-tertiary: #14141f;
  --bg-card: #1a1a2e;
  --text-primary: #ffffff;
  --text-secondary: #a0a0b0;
  --text-muted: #606070;
  --accent-primary: #00d4ff;
  --accent-red: #ff3355;
  --danger: #ff4466;
  --focus-ring: #00d4ff;
  --focus-glow: rgba(0, 212, 255, 0.4);
  --success: #00ff88;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
}

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

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

#app {
  width: 100%;
  height: 100%;
  position: relative;
  padding: 8px; /* safe margin — edge elements get clipped by rubberbanding */
}

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

/* --- Header --- */
.header {
  display: flex;
  align-items: center;
  padding: 14px 20px;
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  gap: 12px;
  flex-shrink: 0;
}
.header h1 {
  font-size: 22px;
  font-weight: 600;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.header-meta {
  font-size: 13px;
  color: var(--text-secondary);
}
.back-btn {
  background: transparent;
  color: var(--text-primary);
  font-size: 22px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
  flex-shrink: 0;
}

/* --- Content Area --- */
.content {
  flex: 1;
  padding: 12px 4px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}

/* --- Focus States (critical for EMG/D-pad) --- */
.focusable {
  transition:
    transform 475ms cubic-bezier(0.6, 0, 0.4, 1),
    border-color 300ms cubic-bezier(0.4, 0.04, 0.5, 1),
    box-shadow 300ms cubic-bezier(0.4, 0.04, 0.5, 1);
  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);
}

/* --- Navigation Bar --- */
.nav-bar {
  display: flex;
  gap: 8px;
  padding: 10px 4px;
  flex-shrink: 0;
}
.nav-item {
  flex: 1;
  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;
  gap: 8px;
}
.nav-item:focus { background: var(--bg-card); }
.nav-item.primary {
  background: var(--accent-primary);
  color: #0a0a0f;
}
.nav-item.primary:focus { background: #33ddff; }

/* --- Tabs --- */
.tab-bar {
  display: flex;
  gap: 4px;
  padding: 4px;
  margin-top: 8px;
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  flex-shrink: 0;
}
.tab-item {
  flex: 1;
  padding: 10px 4px;
  background: transparent;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  text-align: center;
  min-height: 44px;
}
.tab-item.active {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}
.tab-item:focus {
  background: var(--bg-card);
  color: var(--text-primary);
}

/* --- Video List --- */
.list-wrap { position: relative; padding: 8px 4px; overflow: hidden; }
.list-wrap::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 64px;
  background: linear-gradient(to top, var(--bg-secondary) 0%, transparent 100%);
  pointer-events: none;
  z-index: 10;
  opacity: 0.9;
}
.list-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  height: 100%;
  padding-bottom: 56px; /* keep last item above the scrim */
}
.list-item {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 15px;
  text-align: left;
  gap: 12px;
  flex-shrink: 0;
}
.list-item:focus { background: var(--bg-card); }
.list-item .content-inner { opacity: 0.8; transition: opacity 300ms cubic-bezier(0.4, 0.04, 0.5, 1); }
.list-item:focus .content-inner { opacity: 1; }
.thumb {
  width: 96px;
  height: 54px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  flex-shrink: 0;
  background: var(--bg-card);
}
.list-item-content { flex: 1; min-width: 0; }
.list-item-title {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.list-item-meta {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.fav-mark {
  color: var(--accent-red);
  font-size: 18px;
  flex-shrink: 0;
}

/* --- Player --- */
.player-title { font-size: 18px; }
.player-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px 4px;
  min-height: 0;
}
.player-video {
  position: relative;
  width: 100%;
  height: 320px;
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  overflow: hidden;
  flex-shrink: 0;
}
.player-video iframe {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}
.player-overlay {
  position: absolute;
  inset: 0;
  background: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
  padding: 20px;
  z-index: 5;
}
.player-progress { flex-shrink: 0; padding: 0 4px; }
.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--bg-tertiary);
  border-radius: 3px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent-red);
  border-radius: 3px;
  transition: width 0.3s linear;
}
.time-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 6px;
}
.player-controls {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-shrink: 0;
}
.ctrl-btn {
  width: 92px;
  height: 68px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-lg);
  color: var(--text-primary);
  font-size: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ctrl-btn:focus { background: var(--bg-card); }
.ctrl-btn.primary { background: var(--accent-red); }
.ctrl-btn.primary:focus { background: #ff5577; }
.ctrl-btn.fav-on { color: var(--accent-red); }

/* --- Loading / Error --- */
.loading-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 40px;
  flex: 1;
}
.loading-spinner {
  width: 48px;
  height: 48px;
  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: 16px; color: var(--text-secondary); }
.error-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 40px;
  text-align: center;
}
.error-icon { font-size: 48px; }
.error-message {
  font-size: 16px;
  color: var(--text-secondary);
  max-width: 400px;
}

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

/* --- Add Screen --- */
.hint-text {
  font-size: 15px;
  color: var(--text-secondary);
  line-height: 1.5;
  padding: 0 4px;
}
.hint-text.muted { font-size: 13px; color: var(--text-muted); }
.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); }

/* --- Utility --- */
.hidden { display: none !important; }
