/* ==============================================
   YTsounds — Light & Dark Theme
   Toggle via data-theme="dark|light" on <html>
   ============================================== */

/* ---- Base: Dark Theme (default) ---- */
:root, [data-theme="dark"] {
  --bg: #0a0a0a;
  --surface: #18181b;
  --surface-hover: #222226;
  --border: #2e2e33;
  --text: #fafafa;
  --text-muted: #a1a1aa;
  --text-dim: #71717a;
  --nav-bg: #0d0d0d;
  --footer-bg: #0a0a0a;
  --accent: #ef4444;
  --accent-hover: #dc2626;
  --brand-gradient: linear-gradient(135deg, #ef4444, #f97316);
  --btn-bg: #27272a;
  --btn-border: #3f3f46;
  --btn-hover: #323236;
  --card-bg: #18181b;
  --input-bg: #1c1c20;
  --pagination-bg: #18181b;
  --pagination-border: #3f3f46;
  --key-badge-bg: #27272a;
  --key-badge-border: #3f3f46;
  --toast-bg: #27272a;
  --shadow: 0 2px 12px rgba(0,0,0,0.6);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.4);
  --button-frame-top: #52525b;
  --button-frame-bottom: #3f3f46;
  --button-frame-pressed-top: #3f3f46;
  --button-frame-pressed-bottom: #27272a;
  --icon-color: #d4d4d8;
  --icon-opacity: 0.65;
  --icon-hover-opacity: 1;
}

/* ---- Light Theme ---- */
[data-theme="light"] {
  --bg: #f9fafb;
  --surface: #ffffff;
  --surface-hover: #f3f4f6;
  --border: #d1d5db;
  --text: #111827;
  --text-muted: #6b7280;
  --text-dim: #9ca3af;
  --nav-bg: #ffffff;
  --footer-bg: #f9fafb;
  --accent: #ef4444;
  --accent-hover: #dc2626;
  --brand-gradient: linear-gradient(135deg, #ef4444, #f97316);
  --btn-bg: #f3f4f6;
  --btn-border: #d1d5db;
  --btn-hover: #e5e7eb;
  --card-bg: #ffffff;
  --input-bg: #f9fafb;
  --pagination-bg: #ffffff;
  --pagination-border: #d1d5db;
  --key-badge-bg: #f3f4f6;
  --key-badge-border: #d1d5db;
  --toast-bg: #1f2937;
  --shadow: 0 2px 12px rgba(0,0,0,0.06);
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --button-frame-top: #d1d5db;
  --button-frame-bottom: #9ca3af;
  --button-frame-pressed-top: #9ca3af;
  --button-frame-pressed-bottom: #6b7280;
  --icon-color: #4b5563;
  --icon-opacity: 0.55;
  --icon-hover-opacity: 0.9;
}

/* ---- Global ---- */
* { box-sizing: border-box; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  margin: 0;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
.link-secondary { color: var(--text-muted); }
.link-secondary:hover { color: var(--text); }

/* ---- Navbar ---- */
.bg-bar {
  background: var(--nav-bg) !important;
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.navbar {
  padding: 8px 16px !important;
}

.navbar-brand {
  font-weight: 700;
  font-size: 22px;
  background: var(--brand-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.5px;
}

.navbar .nav-link { color: var(--text) !important; font-size: 14px; font-weight: 500; }
.navbar .nav-link:hover { color: var(--accent) !important; }
.navbar .dropdown-menu {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 0;
  box-shadow: var(--shadow);
}
.navbar .dropdown-item {
  color: var(--text);
  font-size: 14px;
  padding: 8px 20px;
}
.navbar .dropdown-item:hover {
  background: var(--surface-hover);
  color: var(--accent);
}

/* Bootstrap dropdown arrow visibility */
[data-theme="dark"] .navbar .dropdown-toggle::after {
  border-top-color: var(--text-muted);
}
[data-theme="dark"] .navbar-toggler-icon {
  filter: brightness(0) invert(1);
}

#theme-toggle {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  transition: background 0.15s;
  color: var(--text);
  font-size: 16px;
}
#theme-toggle:hover { background: rgba(128,128,128,0.15); }

#searchbar input {
  border-radius: 10px !important;
  border: 1px solid var(--border) !important;
  padding-left: 38px !important;
  background: var(--input-bg) !important;
  color: var(--text) !important;
  font-size: 14px;
  height: 38px;
}
#searchbar input::placeholder { color: var(--text-dim); }
#searchbar input:focus { box-shadow: 0 0 0 2px rgba(239,68,68,0.3); border-color: var(--accent) !important; }
.search-form img { position: absolute; padding: 10px 12px; z-index: 5; pointer-events: none; }
.nav-icon-left { vertical-align: middle; margin: 0 5px 3px 0; }
#nav-login { max-width: 155px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

@media (max-width: 600px) { #searchbar input { width: 170px !important; } }

/* ---- Content Area ---- */
#content {
  max-width: 970px;
  margin: 24px auto 80px;
  background: var(--surface);
  border-radius: 14px;
  padding: 28px 24px;
  text-align: center;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
@media (max-width: 770px) {
  #content { margin: 12px 8px 60px; padding: 16px 12px; border-radius: 10px; }
}

/* ---- Breadcrumbs ---- */
#breadcrumbs { margin: 0 0 20px; text-align: left; }
#breadcrumbs ol { padding: 0; margin: 0; list-style: none; display: flex; flex-wrap: wrap; }
#breadcrumbs li { font-size: 13px; margin-right: 6px; color: var(--text-dim); }
#breadcrumbs li span { color: var(--text-muted); }
#breadcrumbs a { text-decoration: none; color: var(--text-dim); }
#breadcrumbs a:hover { color: var(--accent); }

/* ---- Grid ---- */
#instants_container { margin: 10px auto; text-align: center; min-height: 200px; }

.instants {
  display: flex;
  flex-wrap: wrap;
  gap: 28px 14px;
  justify-content: center;
  margin: 24px 0;
}

/* ---- Sound Card ---- */
.instant {
  width: 100px;
  text-align: center;
  word-wrap: break-word;
  padding: 10px 6px 8px;
  border-radius: 12px;
  transition: background 0.15s;
}
.instant:hover { background: var(--surface-hover); }

/* ---- 3D Sound Button ---- */
.btn-sound {
  display: block;
  width: 86px;
  height: 82px;
  margin: 0 auto 10px;
  border-radius: 50%;
  border: 7px solid var(--button-frame-bottom);
  border-top-color: var(--button-frame-top);
  border-bottom-color: var(--button-frame-bottom);
  cursor: pointer;
  position: relative;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  box-shadow:
    0 5px 0 rgba(0,0,0,0.2),
    0 6px 14px rgba(0,0,0,0.25),
    inset 0 2px 0 rgba(255,255,255,0.2),
    inset 0 -3px 0 rgba(0,0,0,0.1);
  transition: transform 0.06s, box-shadow 0.06s, border-color 0.06s;
}

.btn-sound:active,
.btn-sound.pressed {
  transform: translateY(4px);
  border-top-color: var(--button-frame-pressed-top);
  border-bottom-color: var(--button-frame-pressed-bottom);
  border-left-color: var(--button-frame-pressed-top);
  border-right-color: var(--button-frame-pressed-bottom);
  box-shadow:
    0 1px 0 rgba(0,0,0,0.15),
    0 3px 6px rgba(0,0,0,0.2),
    inset 0 2px 4px rgba(0,0,0,0.15);
}

/* Large detail page button */
.btn-sound-large {
  display: block;
  width: 180px;
  height: 170px;
  margin: 0 auto 15px;
  border-radius: 50%;
  border: 10px solid var(--button-frame-bottom);
  border-top-color: var(--button-frame-top);
  border-bottom-color: var(--button-frame-bottom);
  cursor: pointer;
  position: relative;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  box-shadow:
    0 7px 0 rgba(0,0,0,0.2),
    0 9px 20px rgba(0,0,0,0.3),
    inset 0 3px 0 rgba(255,255,255,0.2),
    inset 0 -4px 0 rgba(0,0,0,0.1);
  transition: transform 0.06s, box-shadow 0.06s;
}
.btn-sound-large:active,
.btn-sound-large.pressed {
  transform: translateY(5px);
  border-top-color: var(--button-frame-pressed-top);
  border-bottom-color: var(--button-frame-pressed-bottom);
  box-shadow:
    0 2px 0 rgba(0,0,0,0.15),
    0 4px 10px rgba(0,0,0,0.25),
    inset 0 3px 6px rgba(0,0,0,0.15);
}

/* ---- Spinner ---- */
.loader {
  display: none;
  position: absolute;
  top: -6px; left: -6px;
  width: 100px; height: 98px;
  border: 3px solid transparent;
  border-top: 3px solid var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  z-index: 5;
  pointer-events: none;
}
.loader-large {
  display: none;
  position: absolute;
  top: -8px; left: -8px;
  width: 204px; height: 194px;
  border: 5px solid transparent;
  border-top: 5px solid var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  z-index: 5;
  pointer-events: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Sound Title ---- */
.instant-link {
  font-size: 13px;
  text-decoration: none;
  display: block;
  line-height: 1.35em;
  height: 2.7em;
  overflow: hidden;
  word-break: break-word;
  color: var(--text-muted);
  font-weight: 500;
}
.instant-link:hover { color: var(--accent); text-decoration: underline; }

/* ---- Action Icons ---- */
.result-page-instant-sharebox {
  margin-top: 6px;
  display: flex;
  justify-content: center;
  gap: 4px;
}
.instant-action-button {
  padding: 3px;
  background: none;
  border: 0;
  cursor: pointer;
  line-height: 0;
  border-radius: 6px;
  transition: background 0.15s;
}
.instant-action-button:hover { background: var(--surface-hover); }
.instant-action-button-icon {
  width: 18px;
  height: 18px;
  opacity: var(--icon-opacity);
  transition: opacity 0.15s;
}
/* Invert icons for dark mode so they appear white */
[data-theme="dark"] .instant-action-button-icon {
  filter: brightness(0) invert(1);
}
[data-theme="light"] .instant-action-button-icon {
  filter: none;
}
.instant-action-button:hover .instant-action-button-icon { opacity: var(--icon-hover-opacity); }

/* Also fix detail page icons */
[data-theme="dark"] .instant-page-extra-button-icon {
  filter: brightness(0) invert(1);
}
[data-theme="light"] .instant-page-extra-button-icon {
  filter: none;
}
/* And footer install icon */
[data-theme="dark"] #install-app-desktop img {
  filter: brightness(0) invert(1);
}

/* ---- Detail Page ---- */
#instant-page-title {
  margin: 0 20px 24px;
  font-size: 38px;
  font-weight: 800;
  letter-spacing: -0.5px;
}
#instant-page-button { width: 180px; margin: 0 auto; }
#instant-image { max-width: 320px; max-height: 240px; border-radius: 12px; }
#instant-page-likes { margin: 16px 0; font-size: 14px; color: var(--text-muted); }
#instant-page-extra-buttons-container { margin: 24px 0 12px; }
.instant-page-extra-button {
  margin: 5px;
  min-width: 240px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s;
}
.instant-page-extra-button-icon { vertical-align: text-top; margin-right: 6px; }
#instant-page-description,
#instant-page-tags { margin: 16px 0; color: var(--text-muted); font-size: 14px; line-height: 1.6; }

#instant-embed {
  width: 300px; height: 55px; font-size: 11px; font-family: 'SF Mono', Monaco, monospace;
  cursor: pointer; background: var(--input-bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px; margin: 12px 0 20px; text-align: left;
  color: var(--text-dim); resize: none;
}

#recommendations { margin: 40px 0; }

@media (max-width: 600px) {
  .instant-page-extra-button { width: 90%; min-width: auto; }
  #instant-page-title { font-size: 28px; }
}

/* ---- Section Title ---- */
.instants-container-title {
  margin: 20px 0 24px;
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -0.5px;
}
@media (max-width: 600px) { .instants-container-title { font-size: 24px; } }

/* ---- Pagination ---- */
#results-pagination { margin: 40px auto 50px; display: inline-block; }
.page-item .page-link {
  color: var(--text);
  background: var(--pagination-bg);
  border-color: var(--pagination-border);
  border-radius: 8px;
  margin: 0 2px;
  font-size: 14px;
  padding: 6px 14px;
}
.page-item.active .page-link {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.page-item .page-link:hover { background: var(--btn-hover); }

/* ---- Footer ---- */
.page-footer {
  background: var(--footer-bg);
  border-top: 1px solid var(--border);
  color: var(--text);
  padding: 36px 20px !important;
}
.page-footer .container { max-width: 970px; }
.page-footer a { color: var(--text-muted); text-decoration: none; }
.page-footer a:hover { color: var(--accent); }
.page-footer li { margin: 6px 0; font-size: 14px; }
.page-footer p { font-weight: 600; color: var(--text); }
#footer-copyright { padding-bottom: 50px; font-size: 13px; color: var(--text-dim); }

/* ---- Ads ---- */
.desktop-banner-ad { width: 970px; height: 90px; }
.desktop-larger-banner-ad { width: 970px; height: 250px; margin-top: 20px; }
.mobile-banner-ad { width: 320px; height: 100px; }
.large-rectangle-ad { width: 320px; height: 250px; margin: 20px auto; }
.desktop-banner-ad, .desktop-larger-banner-ad, .mobile-banner-ad, .large-rectangle-ad {
  background: rgba(128,128,128,0.06);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-dim); font-size: 12px; margin: 0 auto;
}
#top-ad { text-align: center; margin: 0 auto 20px; }

/* ---- Cards & Forms ---- */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.form-control, .form-select {
  background: var(--input-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  padding: 10px 14px;
}
.form-control:focus, .form-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(239,68,68,0.15);
}
.form-floating > label { color: var(--text-dim); font-size: 14px; }

#instant-form { max-width: 480px; margin: 0 auto; }

/* ---- Buttons ---- */
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  border-radius: 10px;
  font-weight: 600;
  font-size: 14px;
  padding: 10px 20px;
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-outline-primary {
  border-color: var(--accent);
  color: var(--accent);
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
}
.btn-outline-primary:hover { background: var(--accent); color: #fff; }
.btn-outline-danger {
  border-color: #ef4444;
  color: #ef4444;
  border-radius: 10px;
  font-size: 13px;
}
.btn-outline-danger:hover { background: #ef4444; color: #fff; }

/* ---- Keys & Badges ---- */
.key-combo-display {
  background: var(--key-badge-bg);
  border: 1px solid var(--key-badge-border);
  border-radius: 6px;
  padding: 3px 8px;
  font-family: monospace;
  font-size: 14px;
}

/* ---- Tables ---- */
.table {
  color: var(--text);
  border-color: var(--border);
  --bs-table-bg: transparent;
  --bs-table-color: var(--text);
  --bs-table-border-color: var(--border);
  --bs-table-hover-bg: var(--surface-hover);
  --bs-table-striped-bg: var(--surface-hover);
}
.table th {
  border-color: var(--border);
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 600;
  background: transparent;
}
.table td {
  border-color: var(--border);
  vertical-align: middle;
  background: transparent;
}
.table > :not(caption) > * > * {
  background-color: transparent;
  color: var(--text);
  border-bottom-color: var(--border);
}

/* ---- Misc ---- */
#user-profile-title { font-size: 38px; font-weight: 800; margin: 0 0 20px; letter-spacing: -0.5px; }
#user-profile-menu { margin-bottom: 30px; }
#user-profile-menu li { display: inline; }
.user-profile-empty { padding: 60px 0; color: var(--text-muted); font-size: 15px; line-height: 1.8; }

@media (max-width: 480px) {
  #login-dropdown .dropdown-menu {
    display: block; position: static; border: 0 none; box-shadow: none;
    margin: 0 0 20px; width: 100%; background: transparent;
  }
  .navbar .dropdown-item { color: var(--text-muted); }
}
