:root {
  --bg: #07070d;
  --card: rgba(18, 18, 30, 0.8);
  --text: #eee;
  --text-dim: #888;
  --pink: #ff00aa;
  --cyan: #00e5ff;
  --purple: #8e2de2;
  --gold: #ffc107;
  --radius: 14px;
  --gap: 1rem;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, sans-serif;
}

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

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.55;
  min-height: 100vh;
  overflow-x: hidden;
}

.hidden { display: none !important; }

body::before {
  content: '';
  position: fixed; inset: 0; z-index: -1;
  background:
    radial-gradient(ellipse 600px 400px at 20% 30%, rgba(255,0,170,.12), transparent),
    radial-gradient(ellipse 500px 500px at 80% 70%, rgba(0,229,255,.10), transparent),
    radial-gradient(ellipse 400px 300px at 50% 50%, rgba(142,45,226,.08), transparent);
  animation: bgShift 20s ease-in-out infinite alternate;
}

@keyframes bgShift {
  0%   { filter: hue-rotate(0deg); }
  100% { filter: hue-rotate(25deg); }
}

/* ═══════ HOME ═══════ */

#home {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1.5rem 1rem;
  animation: fadeUp .5s ease-out;
}

#home-content {
  text-align: center;
  max-width: 560px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
}

#logo-icon {
  font-size: 3.5rem;
  filter: drop-shadow(0 0 18px var(--pink));
  animation: pulse 2.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

#logo-area h1 {
  font-size: 2.4rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--pink), var(--cyan));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

#subtitle {
  font-size: 1rem;
  color: var(--text-dim);
  margin-top: -.3rem;
}

/* ── Config Card ── */

#home-config {
  text-align: left;
  width: 100%;
}

#home-config h3, .cfg-section-title {
  font-size: .85rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .07em;
  margin-bottom: .7rem;
  margin-top: 0;
}

.cfg-section-title {
  margin-top: 1.1rem;
}

/* ── Channel Grid ── */

.channel-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .6rem;
}

.channel-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .3rem;
  padding: .75rem .5rem;
  border-radius: var(--radius);
  border: 2px solid rgba(255,255,255,.08);
  background: rgba(255,255,255,.03);
  cursor: pointer;
  transition: all .2s;
  font-family: inherit;
  font-size: inherit;
  color: var(--text);
  text-align: center;
  -webkit-appearance: none;
  appearance: none;
  outline: none;
  position: relative;
}

.channel-card:hover {
  border-color: rgba(255,255,255,.2);
  background: rgba(255,255,255,.06);
}

.channel-card.active {
  border-color: var(--channel-clr, var(--pink));
  background: var(--channel-bg, rgba(255,0,170,.10));
  box-shadow: 0 0 14px var(--channel-shadow, rgba(255,0,170,.15));
}

.channel-card[data-channel="all"].active {
  --channel-clr: #8e2de2; --channel-bg: rgba(142,45,226,.10); --channel-shadow: rgba(142,45,226,.15);
}
.channel-card[data-channel="primary"].active {
  --channel-clr: #ff00aa; --channel-bg: rgba(255,0,170,.10); --channel-shadow: rgba(255,0,170,.15);
}
.channel-card[data-channel="secondary"].active {
  --channel-clr: #00e5ff; --channel-bg: rgba(0,229,255,.08); --channel-shadow: rgba(0,229,255,.12);
}
.channel-card[data-channel="custom"].active {
  --channel-clr: #8e2de2; --channel-bg: rgba(142,45,226,.10); --channel-shadow: rgba(142,45,226,.15);
}

.channel-dot {
  width: 14px; height: 14px;
  border-radius: 50%;
  display: inline-block;
}

.channel-name {
  font-size: .9rem;
  font-weight: 600;
}

.channel-desc {
  font-size: .7rem;
  color: var(--text-dim);
}

/* ── Custom Channel Area ── */

#custom-channel-area {
  margin-top: .7rem;
}

#custom-input-row {
  display: flex;
  gap: .4rem;
}

#custom-input-row input {
  flex: 1;
  padding: .55rem .75rem;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,.1);
  background: rgba(255,255,255,.04);
  color: var(--text);
  font-size: .88rem;
  font-family: inherit;
  outline: none;
  transition: border-color .2s;
}

#custom-input-row input:focus {
  border-color: var(--purple);
}

#custom-add-btn {
  padding: .55rem .9rem;
  font-size: 1.1rem;
  min-width: 40px;
}

#custom-list {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
  margin-top: .45rem;
  min-height: 1px;
}

.custom-chip {
  display: flex;
  align-items: center;
  gap: .3rem;
  background: rgba(142,45,226,.15);
  border: 1px solid rgba(142,45,226,.3);
  border-radius: 8px;
  padding: .2rem .5rem .2rem .65rem;
  font-size: .78rem;
  color: var(--text);
  animation: fadeUp .2s ease-out;
}

.custom-chip-remove {
  background: none;
  border: none;
  color: rgba(255,255,255,.35);
  cursor: pointer;
  font-size: .85rem;
  padding: 0 .1rem;
  font-family: inherit;
  line-height: 1;
  transition: color .15s;
  appearance: none;
  -webkit-appearance: none;
}

.custom-chip-remove:hover {
  color: #ff6b6b;
}

#custom-include-area {
  margin-top: .9rem;
}

.cfg-label {
  display: block;
  font-size: .78rem;
  color: var(--text-dim);
  margin-bottom: .2rem;
  margin-top: .5rem;
}

/* ── Num Videos ── */

.config-num-row {
  display: flex;
  align-items: center;
  gap: .5rem;
}

.config-num-row input {
  width: 80px;
  padding: .45rem .6rem;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,.1);
  background: rgba(255,255,255,.04);
  color: var(--text);
  font-size: .95rem;
  font-family: inherit;
  outline: none;
  text-align: center;
  transition: border-color .2s;
  -moz-appearance: textfield;
}

.config-num-row input::-webkit-inner-spin-button,
.config-num-row input::-webkit-outer-spin-button {
  opacity: 1;
}

.config-num-row input:focus {
  border-color: var(--cyan);
}

.config-num-label {
  font-size: .78rem;
  color: var(--text-dim);
}

/* ── Toggles ── */

.config-toggles {
  display: flex;
  flex-direction: column;
  gap: .5rem;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: .6rem;
  cursor: pointer;
  user-select: none;
  padding: .15rem 0;
}

.toggle-row input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

.toggle-switch {
  width: 38px; height: 22px;
  background: rgba(255,255,255,.1);
  border-radius: 50px;
  position: relative;
  transition: background .25s;
  flex-shrink: 0;
  display: block;
}

.toggle-knob {
  width: 16px; height: 16px;
  background: #fff;
  border-radius: 50%;
  position: absolute;
  top: 3px; left: 3px;
  transition: transform .22s;
  display: block;
  pointer-events: none;
}

.toggle-row input:checked + .toggle-switch {
  background: var(--pink);
}

.toggle-row input:checked + .toggle-switch .toggle-knob {
  transform: translateX(16px);
}

.toggle-text {
  font-size: .9rem;
}

.config-hint {
  font-size: .74rem;
  color: var(--text-dim);
  margin-top: .3rem;
  line-height: 1.35;
}

/* ── Start Button ── */

#start-btn {
  font-size: 1.15rem;
  padding: .9rem 3.2rem;
  border-radius: 50px;
}

.btn-glow {
  animation: glow 2.5s ease-in-out infinite alternate;
}

@keyframes glow {
  from { box-shadow: 0 0 8px var(--pink), 0 0 18px rgba(255,0,170,.2); }
  to   { box-shadow: 0 0 14px var(--cyan), 0 0 28px rgba(0,229,255,.25); }
}

#home-stats {
  font-size: .8rem;
  color: var(--text-dim);
}

/* ── Home Buttons ── */

#home-buttons {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .75rem;
}

.btn-icon-info {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,.15);
  background: rgba(255,255,255,.04);
  color: var(--text-dim);
  font-family: inherit;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: all .2s;
  appearance: none;
  -webkit-appearance: none;
}

.btn-icon-info:hover {
  border-color: var(--purple);
  color: var(--purple);
  background: rgba(142,45,226,.1);
}

/* ── Copyright ── */

#copyright {
  font-size: .72rem;
  color: rgba(255,255,255,.3);
  margin-top: .3rem;
}

#copyright a {
  color: rgba(255,255,255,.4);
  text-decoration: none;
  transition: color .2s;
}

#copyright a:hover {
  color: var(--pink);
}

/* ── Info Modal ── */

#info-modal {
  position: fixed; inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

#info-backdrop {
  position: absolute; inset: 0;
  background: rgba(7,7,13,.88);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

#info-content {
  position: relative;
  max-width: 520px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  z-index: 1;
  text-align: left;
}

#info-content h2 {
  font-size: 1.35rem;
  margin-bottom: .5rem;
  background: linear-gradient(135deg, var(--pink), var(--cyan));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

#info-content h3 {
  font-size: 1rem;
  color: var(--cyan);
  margin-bottom: .5rem;
  margin-top: .2rem;
}

#info-content hr {
  border: none;
  border-top: 1px solid rgba(255,255,255,.06);
  margin: .8rem 0;
}

.info-steps p,
.info-modes p {
  font-size: .88rem;
  line-height: 1.6;
  margin-bottom: .6rem;
  color: var(--text-dim);
}

.info-steps p strong,
.info-modes p strong {
  color: var(--text);
}

#info-close {
  float: right;
}

#info-author {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .3rem 0;
}

#info-author img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  transition: transform .2s;
}

#info-author img:hover {
  transform: scale(1.1);
}

#info-author a {
  color: var(--cyan);
  text-decoration: none;
  font-weight: 600;
}

#info-author a:hover {
  text-decoration: underline;
}

#info-author p {
  font-size: .88rem;
  color: var(--text-dim);
}

/* ═══════ GAME ═══════ */

#app {
  max-width: 780px;
  margin: 0 auto;
  padding: var(--gap);
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  animation: fadeUp .4s ease-out;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .4rem 0;
}

header h1 {
  font-size: 1.25rem;
  font-weight: 700;
  background: linear-gradient(90deg, var(--pink), var(--cyan));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.btn-icon {
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.1);
  color: var(--text-dim);
  width: 34px; height: 34px;
  border-radius: 50%;
  cursor: pointer;
  font-size: .95rem;
  display: grid;
  place-items: center;
  transition: all .2s;
  font-family: inherit;
}

.btn-icon:hover {
  background: rgba(255,0,170,.15);
  border-color: var(--pink);
  color: var(--pink);
}

#player-container {
  width: 0; height: 0; overflow: hidden;
  position: absolute; left: -9999px;
}

.card {
  background: var(--card);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: var(--gap);
  border-radius: var(--radius);
  border: 1px solid rgba(255,255,255,.06);
  box-shadow: 0 4px 20px rgba(0,0,0,.3);
}

/* ── Controls ── */

#controls {
  display: flex;
  flex-direction: column;
  gap: .6rem;
  align-items: center;
}

#attempt-info {
  font-size: 1rem;
  color: var(--cyan);
  font-weight: 500;
}

/* ── Selector ── */

#selector {
  display: flex;
  flex-direction: column;
  gap: .6rem;
}

#selected-info {
  font-size: .8rem;
  min-height: 1.1rem;
  color: var(--text-dim);
  transition: color .2s;
}

#search {
  width: 100%;
  padding: .65rem .9rem;
  border-radius: var(--radius);
  border: 1px solid rgba(255,255,255,.1);
  background: rgba(255,255,255,.04);
  color: var(--text);
  font-size: .92rem;
  font-family: inherit;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}

#search:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px rgba(0,229,255,.15);
}

#video-select {
  width: 100%;
  height: 185px;
  background: rgba(255,255,255,.03);
  color: var(--text);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: var(--radius);
  padding: .4rem;
  font-size: .86rem;
  font-family: inherit;
  outline: none;
  overflow-y: auto;
}

#video-select:focus { border-color: var(--cyan); }

#video-select option {
  padding: .4rem .5rem;
  cursor: pointer;
}

/* ── Buttons ── */

.btn {
  background: linear-gradient(135deg, var(--pink), var(--purple));
  border: none;
  color: #fff;
  padding: .65rem 1.4rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: .95rem;
  font-weight: 600;
  font-family: inherit;
  transition: transform .18s, box-shadow .18s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  -webkit-appearance: none;
  appearance: none;
}

.btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 22px rgba(255,0,170,.35);
}

.btn:active:not(:disabled) { transform: translateY(0); }

.btn:disabled {
  opacity: .4;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-secondary {
  background: transparent;
  border: 2px solid var(--cyan);
  color: var(--cyan);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--cyan);
  color: var(--bg);
  box-shadow: 0 6px 18px rgba(0,229,255,.3);
}

/* ── Result ── */

#result { animation: fadeUp .4s ease-out; }

#result h2 {
  font-size: 1.15rem;
  color: var(--cyan);
  margin-bottom: .7rem;
}

#result-thumb {
  width: 100%;
  max-width: 420px;
  border-radius: var(--radius);
  box-shadow: 0 4px 14px rgba(0,0,0,.4);
}

#score-info {
  font-size: .95rem;
  color: var(--text-dim);
  margin: .6rem 0;
  line-height: 1.7;
}

#score-info strong { color: #fff; }

#embed-container { margin: .8rem 0; }

#embed-container iframe {
  width: 100%;
  height: 280px;
  border: none;
  border-radius: var(--radius);
  box-shadow: 0 4px 14px rgba(0,0,0,.4);
}

#result-buttons {
  display: flex;
  gap: .6rem;
  flex-wrap: wrap;
  margin-top: .4rem;
}

#result-buttons .btn { flex: 1; min-width: 130px; }

/* ── Stats ── */

footer { padding: .4rem 0; }

#stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .5rem;
  text-align: center;
  padding: .7rem;
}

#stats p { color: var(--text-dim); font-size: .8rem; margin: 0; }
#stats strong { color: var(--cyan); font-size: 1.05rem; display: block; }

/* ── Loading ── */

#loading-overlay {
  position: fixed; inset: 0;
  background: rgba(7,7,13,.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  z-index: 1000;
  color: var(--text-dim);
  font-size: 1rem;
}

.spinner {
  width: 34px; height: 34px;
  border: 3px solid rgba(255,255,255,.1);
  border-top-color: var(--pink);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

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

/* ── Animations ── */

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

/* ── Responsive ── */

@media (min-width: 640px) {
  #video-select { height: 230px; }
  #embed-container iframe { height: 340px; }
  #controls { flex-direction: row; justify-content: space-between; }
  #result {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    align-items: start;
  }
  #result h2,
  #result-buttons { grid-column: 1 / -1; }
}

@media (max-width: 480px) {
  #logo-area h1 { font-size: 1.9rem; }
  .channel-grid { gap: .45rem; }
  .channel-card { padding: .65rem .4rem; }
  #start-btn { padding: .8rem 2.2rem; font-size: 1.05rem; }
}

/* ── A11y ── */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}
