/* ===== Reset & tokens ===================================================== */
:root{
  /* safe areas */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);

  /* sizing */
  --appbar-h: 56px;
  --radius-xl: 16px;
  --radius-md: 12px;

  /* dark theme (default) */
  --bg: #0b0b0b;
  --panel: #121317;
  --panel-2: #0f1115;
  --text: #e9eef5;
  --muted-1: rgba(255,255,255,.08);
  --muted-2: rgba(255,255,255,.12);
  --focus: #5fb8ff;

  /* accents */
  --btn-blue: #2aa8ff;
  --btn-red:  #ff5a6b;
}

/* Light theme when system preference (and no explicit theme set) */
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --bg: #f6f7fb;
    --panel: #ffffff;
    --panel-2: #ffffff;
    --text: #0f1115;
    --muted-1: rgba(0,0,0,.08);
    --muted-2: rgba(0,0,0,.12);
    --focus: #1e88ff;
    --btn-blue: #1976d2;
    --btn-red:  #e53935;
  }
}

[data-theme="light"] {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --panel-2: #ffffff;
  --text: #0f1115;
  --muted-1: rgba(0,0,0,.08);
  --muted-2: rgba(0,0,0,.12);
  --focus: #1e88ff;
  --btn-blue: #1976d2;
  --btn-red:  #e53935;
}

/* Basic reset */
* { box-sizing: border-box; }
html, body { height: 100%; }
body{
  margin: 0;
  background: var(--bg);
  color: var(--text);
  padding: var(--safe-top) var(--safe-right) max(16px,var(--safe-bottom)) var(--safe-left);
  font: 14px/1.4 system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
}

/* ===== Header (sticky, never over browser banners) ======================== */
.appbar{
  position: sticky;
  top: var(--safe-top);
  z-index: 90;
  height: var(--appbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--muted-1);
}
.appbar__left{ display:flex; gap:12px; align-items:center; min-width:0; }
.appbar__logo{ width:28px; height:28px; border-radius:8px; }
.appbar__titles{ line-height:1.1; min-width:0; }
.appbar__title{ font-weight:600; font-size:16px; color:var(--text); }
.appbar__subtitle{ font-size:12px; opacity:.7; color:var(--text); }
.appbar__actions{ display:flex; gap:8px; }

/* ===== Layout ============================================================== */
.main{
  width: min(100%, 980px);
  margin-inline: auto;
  padding-inline: clamp(12px, 4vw, 24px);
}

.card{
  background: var(--panel);
  border: 1px solid var(--muted-1);
  border-radius: var(--radius-xl);
  margin: 12px auto;
  padding: 16px;
  overflow: visible; /* native <select> popups won't get clipped */
}
.row{ display:flex; gap:12px; flex-wrap:wrap; align-items: center; }
.row > * { flex: 1 1 auto; min-width: 180px; }

/* ===== Inputs ============================================================= */
input[type="text"], input[type="url"], .input, textarea{
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--muted-2);
  background: var(--panel-2);
  color: var(--text);
  outline: none;
}
input:focus, .input:focus, textarea:focus{
  border-color: var(--focus);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 30%, transparent);
}

/* Buttons */
.btn{
  appearance: none;
  border: 1px solid var(--muted-2);
  background: var(--panel-2);
  color: var(--text);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  cursor: pointer;
}
.btn:disabled{ opacity:.6; cursor:not-allowed; }

.btn--primary{
  background: linear-gradient(180deg, color-mix(in srgb, var(--btn-blue) 85%, #fff), var(--btn-blue));
  border-color: color-mix(in srgb, var(--btn-blue) 40%, transparent);
  color: #fff;
}
.btn--danger{
  background: linear-gradient(180deg, color-mix(in srgb, var(--btn-red) 85%, #fff), var(--btn-red));
  border-color: color-mix(in srgb, var(--btn-red) 40%, transparent);
  color: #fff;
}

/* ===== Selects (fix repeated ▼, unify in light/dark) ====================== */
select{
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  background-color: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--muted-2);
  border-radius: var(--radius-md);
  padding: 10px 40px 10px 12px;
  line-height: 1.2;
  outline: none;

  /* one chevron, no tiling */
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2390A3B5' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px;
}
select:focus{
  border-color: var(--focus);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 30%, transparent);
}
select::-ms-expand{ display:none; } /* old IE */

/* Label blocks */
.label { font-size: 12px; opacity:.75; margin-bottom:6px; }

/* Status pill/area */
.status{
  background: var(--panel-2);
  border: 1px solid var(--muted-1);
  border-radius: var(--radius-md);
  padding: 12px 14px;
}

/* API list styles */
.api code{
  background: var(--panel-2);
  border: 1px solid var(--muted-1);
  padding: 2px 6px;
  border-radius: 6px;
}

/* Ensure no ancestor breaks sticky or clips popups */
body > * { transform: none !important; }

/* ===== Theme Toggle ======================================================== */
.theme-toggle {
	position: relative;
	cursor: pointer;
	outline: none;
	user-select: none;
}

.theme-toggle-track {
	width: 52px;
	height: 28px;
	background: var(--muted-1);
	border: 1px solid var(--muted-2);
	border-radius: 14px;
	position: relative;
	transition: all 0.3s ease;
}

.theme-toggle-thumb {
	width: 24px;
	height: 24px;
	background: linear-gradient(135deg, #667eea, #764ba2);
	border-radius: 12px;
	position: absolute;
	top: 2px;
	left: 2px;
	transition: all 0.3s ease;
	display: flex;
	align-items: center;
	justify-content: center;
	box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.theme-icon {
	width: 14px;
	height: 14px;
	color: white;
	position: absolute;
	transition: all 0.3s ease;
}

.theme-icon-sun {
	opacity: 1;
	transform: rotate(0deg);
}

.theme-icon-moon {
	opacity: 0;
	transform: rotate(180deg);
}

[data-theme="light"] .theme-toggle-thumb {
	transform: translateX(24px);
	background: linear-gradient(135deg, #fbbf24, #f59e0b);
}

[data-theme="light"] .theme-icon-sun {
	opacity: 0;
	transform: rotate(-180deg);
}

[data-theme="light"] .theme-icon-moon {
	opacity: 1;
	transform: rotate(0deg);
}

.theme-toggle:focus-visible .theme-toggle-track {
	outline: 2px solid var(--focus);
	outline-offset: 2px;
}

/* ===== Form Layout ========================================================= */
.form-section {
	margin-bottom: 24px;
}

.form-row {
	display: flex;
	gap: 12px;
	align-items: stretch;
	flex-wrap: wrap;
	margin-bottom: 16px;
}

.input-group {
	flex: 1;
	min-width: 280px;
}

.button-group {
	display: flex;
	gap: 12px;
	flex-wrap: wrap;
}

.options-grid {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
	gap: 16px;
	margin-bottom: 24px;
}

.option-group {
	display: flex;
	flex-direction: column;
}

/* ===== Status & Toast ===================================================== */
.status-section {
	margin: 24px 0;
	padding: 16px;
	background: var(--panel-2);
	border: 1px solid var(--muted-1);
	border-radius: var(--radius-md);
}

.status-indicator {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	font-size: 14px;
	font-weight: 500;
}

.status-info {
	display: flex;
	align-items: center;
	gap: 8px;
}

.status-dot {
	width: 8px;
	height: 8px;
	border-radius: 50%;
	background: var(--muted-2);
}

.status-dot.online {
	background: #34d399;
}

.status-dot.offline {
	background: #ff5c66;
}

.refresh-button {
	background: none;
	border: 1px solid var(--muted-2);
	border-radius: 6px;
	padding: 4px;
	color: var(--text);
	cursor: pointer;
	transition: all 0.2s ease;
	min-height: auto;
	display: flex;
	align-items: center;
	justify-content: center;
}

.refresh-button svg {
	width: 16px;
	height: 16px;
	transition: transform 0.3s ease;
}

.refresh-button:hover:not(:disabled) {
	color: var(--focus);
	border-color: var(--focus);
}

.refresh-button:active:not(:disabled) svg {
	transform: rotate(180deg);
}

.refresh-button:disabled {
	opacity: 0.4;
	cursor: not-allowed;
}

.separator {
	height: 1px;
	background: var(--muted-1);
	margin: 24px 0;
}

.toast {
	position: fixed;
	top: 24px;
	right: 24px;
	background: var(--panel);
	border: 1px solid var(--muted-1);
	color: var(--text);
	padding: 16px 20px;
	border-radius: var(--radius-md);
	box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
	opacity: 0;
	transform: translateX(100%);
	transition: all 0.3s ease;
	z-index: 1000;
	max-width: 320px;
}

.toast.show {
	opacity: 1;
	transform: translateX(0);
}

.toast.success {
	border-color: #34d399;
}

.toast.error {
	border-color: #ff5c66;
}

.toast.warning {
	border-color: #fbbf24;
}

/* ===== Video Components ==================================================== */
.video-info, .video-controls {
	margin-top: 20px;
	padding: 20px;
	background: var(--panel-2);
	border: 1px solid var(--muted-1);
	border-radius: var(--radius-xl);
	animation: slideIn 0.3s ease-out;
}

.video-info h3, .video-controls h3 {
	margin: 0 0 16px 0;
	font-size: 18px;
	font-weight: 600;
	color: var(--text);
	text-align: center;
}

.video-details {
	display: flex;
	gap: 16px;
	align-items: flex-start;
}

.video-thumbnail {
	position: relative;
	flex-shrink: 0;
	width: 120px;
	height: 68px;
	border-radius: 8px;
	overflow: hidden;
	background: var(--muted-1);
}

.video-thumbnail img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	border-radius: 8px;
}

.video-duration {
	position: absolute;
	bottom: 4px;
	right: 4px;
	background: rgba(0, 0, 0, 0.8);
	color: white;
	padding: 2px 6px;
	border-radius: 4px;
	font-size: 12px;
	font-weight: 500;
}

.video-metadata {
	flex: 1;
	min-width: 0;
}

.video-metadata h4 {
	margin: 0 0 8px 0;
	font-size: 16px;
	font-weight: 600;
	color: var(--text);
	line-height: 1.3;
}

.video-metadata p {
	margin: 0 0 8px 0;
	font-size: 14px;
	color: var(--text);
	opacity: 0.7;
	font-weight: 500;
}

.video-stats {
	display: flex;
	gap: 12px;
	font-size: 13px;
	color: var(--text);
	opacity: 0.7;
}

.video-stats span:not(:empty):after {
	content: "•";
	margin-left: 12px;
	opacity: 0.5;
}

.video-stats span:last-child:after {
	display: none;
}

.video-url {
	margin-top: 8px;
	padding: 8px 12px;
	background: color-mix(in srgb, var(--focus) 10%, transparent);
	border: 1px solid color-mix(in srgb, var(--focus) 20%, transparent);
	border-radius: 6px;
	font-size: 13px;
	font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
	word-break: break-all;
	color: var(--focus);
	cursor: pointer;
	transition: all 0.2s ease;
}

.video-url:hover {
	background: color-mix(in srgb, var(--focus) 15%, transparent);
	border-color: color-mix(in srgb, var(--focus) 30%, transparent);
}

.video-url:empty {
	display: none;
}

.video-description {
	margin-top: 12px;
	padding: 12px;
	background: var(--muted-1);
	border-radius: 8px;
	font-size: 14px;
	line-height: 1.4;
	color: var(--text);
	opacity: 0.8;
	max-height: 80px;
	overflow-y: auto;
}

.video-description:empty {
	display: none;
}

.video-tags {
	margin-top: 8px;
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
}

.video-tag {
	background: color-mix(in srgb, var(--focus) 10%, transparent);
	color: var(--focus);
	padding: 4px 8px;
	border-radius: 12px;
	font-size: 12px;
	font-weight: 500;
	border: 1px solid color-mix(in srgb, var(--focus) 20%, transparent);
}

.video-extra-info {
	margin-top: 12px;
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
	gap: 8px;
	font-size: 13px;
}

.video-extra-info > div {
	padding: 8px 12px;
	background: var(--muted-1);
	border-radius: 6px;
	color: var(--text);
	opacity: 0.8;
	text-align: center;
}

.video-extra-info > div:empty {
	display: none;
}

.video-progress {
	margin-top: 16px;
	padding: 12px;
	background: var(--muted-1);
	border-radius: 8px;
}

.progress-info {
	display: flex;
	justify-content: space-between;
	margin-bottom: 8px;
	font-size: 13px;
	color: var(--text);
	opacity: 0.8;
	font-weight: 500;
}

.progress-bar {
	height: 6px;
	background: var(--muted-2);
	border-radius: 3px;
	overflow: hidden;
	position: relative;
}

.progress-fill {
	height: 100%;
	background: linear-gradient(90deg, var(--focus), #64b5f6);
	border-radius: 3px;
	width: 0%;
	transition: width 0.3s ease;
}

/* ===== Video Controls ====================================================== */
.skip-interval-controls {
	margin-bottom: 16px;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 8px;
}

.skip-interval-controls label {
	font-size: 14px;
	font-weight: 500;
	color: var(--text);
	margin-bottom: 0;
}

.overlay-controls {
	margin-top: 24px;
	padding-top: 20px;
	border-top: 1px solid var(--muted-1);
}

.overlay-controls h4 {
	margin: 0 0 12px 0;
	font-size: 16px;
	font-weight: 600;
	color: var(--text);
	text-align: center;
}

.mm-select {
	position: relative;
	display: inline-block;
	width: auto;
	min-width: 180px;
}

.mm-select__button {
	width: 100%;
	padding: 10px 12px;
	border-radius: var(--radius-md);
	border: 1px solid var(--muted-2);
	background: var(--panel-2);
	color: var(--text);
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	font-size: 14px;
	font-weight: 500;
	cursor: pointer;
	transition: all 0.2s ease;
	min-height: auto;
}

.mm-select__button:hover {
	background: var(--muted-1);
	border-color: var(--focus);
}

.mm-select__button:focus {
	border-color: var(--focus);
	box-shadow: 0 0 0 2px color-mix(in srgb, var(--focus) 30%, transparent);
	outline: none;
}

.mm-select__button .chev {
	font-size: 12px;
	opacity: 0.7;
	transition: transform 0.2s ease;
}

.mm-select.open .mm-select__button .chev {
	transform: rotate(180deg);
}

.mm-select__menu {
	position: absolute;
	top: calc(100% + 6px);
	left: 0;
	right: 0;
	z-index: 99999;
	max-height: 240px;
	overflow: hidden;
	margin: 0;
	padding: 6px;
	list-style: none;
	background: var(--panel);
	backdrop-filter: blur(10px);
	border: 1px solid var(--muted-2);
	border-radius: var(--radius-md);
	box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
	display: none;
	animation: slideIn 0.2s ease-out;
}

.mm-select.open .mm-select__menu {
	display: block;
}

.mm-select__menu li {
	padding: 8px 10px;
	border-radius: 8px;
	cursor: pointer;
	font-size: 14px;
	color: var(--text);
	transition: all 0.2s ease;
}

.mm-select__menu li[aria-selected="true"] {
	background: color-mix(in srgb, var(--focus) 15%, transparent);
	color: var(--focus);
}

.mm-select__menu li:hover {
	background: var(--muted-1);
}

.mm-select__menu li[aria-selected="true"]:hover {
	background: color-mix(in srgb, var(--focus) 20%, transparent);
}

.control-buttons {
	display: flex;
	gap: 12px;
	justify-content: center;
	align-items: center;
}

.button-control {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 6px;
	padding: 12px 16px;
	background: var(--muted-1);
	border: 1px solid var(--muted-2);
	border-radius: var(--radius-md);
	color: var(--text);
	font-size: 14px;
	font-weight: 500;
	cursor: pointer;
	transition: all 0.2s ease;
	min-height: auto;
	min-width: 80px;
}

.button-control svg {
	width: 20px;
	height: 20px;
	color: var(--focus);
}

.button-control:hover:not(:disabled) {
	background: var(--muted-2);
	border-color: var(--focus);
	transform: translateY(-1px);
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.button-control:active:not(:disabled) {
	transform: translateY(0);
}

.button-control.paused .pause-icon {
	display: none;
}

.button-control.paused .play-icon {
	display: block !important;
}

/* ===== Chrome Banner ======================================================= */
.chrome-banner {
	position: fixed;
	top: calc(var(--appbar-h) + var(--safe-top));
	left: 0;
	right: 0;
	background: linear-gradient(135deg, #ff6b35, #f7931e);
	color: white;
	padding: 12px 16px;
	box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
	z-index: 9999;
	animation: slideDown 0.3s ease-out;
}

.chrome-banner-content {
	display: flex;
	align-items: center;
	gap: 12px;
	max-width: 820px;
	margin: 0 auto;
}

.chrome-banner-icon {
	flex-shrink: 0;
	width: 24px;
	height: 24px;
	opacity: 0.9;
}

.chrome-banner-icon svg {
	width: 100%;
	height: 100%;
}

.chrome-banner-text {
	flex: 1;
	min-width: 0;
}

.chrome-banner-text strong {
	display: block;
	font-size: 14px;
	font-weight: 600;
	margin-bottom: 2px;
}

.chrome-banner-text p {
	font-size: 13px;
	margin: 0;
	opacity: 0.9;
	line-height: 1.3;
}

.chrome-banner-close {
	background: none;
	border: none;
	color: white;
	cursor: pointer;
	padding: 4px;
	border-radius: 4px;
	opacity: 0.8;
	transition: all 0.2s ease;
	min-height: auto;
	flex-shrink: 0;
}

.chrome-banner-close:hover {
	opacity: 1;
	background: rgba(255, 255, 255, 0.1);
}

.chrome-banner-close svg {
	width: 16px;
	height: 16px;
}

/* ===== Animations ========================================================== */
@keyframes slideDown {
	from {
		transform: translateY(-100%);
		opacity: 0;
	}
	to {
		transform: translateY(0);
		opacity: 1;
	}
}

@keyframes slideIn {
	from {
		opacity: 0;
		transform: translateY(20px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

/* ===== Utilities =========================================================== */
.sr-only {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

.loading {
	display: inline-block;
	width: 16px;
	height: 16px;
	border: 2px solid var(--muted-2);
	border-radius: 50%;
	border-top-color: var(--focus);
	animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
	to { transform: rotate(360deg); }
}

/* ===== Mobile Responsive =================================================== */
@media (max-width: 768px) {
	.video-details {
		flex-direction: column;
		gap: 12px;
	}
	
	.video-thumbnail {
		width: 100%;
		height: 180px;
	}
	
	.control-buttons {
		flex-wrap: wrap;
		gap: 8px;
	}
	
	.button-control {
		min-width: 70px;
		padding: 10px 12px;
	}
}

@media (max-width: 480px) {
	.appbar__titles {
		/* Keep titles visible but make them more compact */
		line-height: 1.0;
	}
	
	.appbar__title {
		font-size: 14px;
		font-weight: 600;
	}
	
	.appbar__subtitle {
		font-size: 11px;
		opacity: 0.6;
	}
	
	.form-row {
		flex-direction: column;
	}
	
	.input-group {
		min-width: auto;
	}
	
	.button-group {
		flex-direction: column;
	}
	
	.options-grid {
		grid-template-columns: 1fr;
	}
	
	.video-stats {
		flex-direction: column;
		gap: 4px;
	}
	
	.video-stats span:after {
		display: none;
	}
	
	.control-buttons {
		justify-content: space-between;
	}
}
