:root {
  color-scheme: dark;
  --bg: #05070b;
  --panel: rgba(8, 12, 18, 0.76);
  --line: rgba(255, 255, 255, 0.14);
  --text: #f7fafc;
  --muted: #9aa8b8;
  --cyan: #39f5d0;
  --rose: #ff4d80;
  --amber: #ffd166;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

.game-shell {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background: #05070b;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

.hud {
  position: absolute;
  z-index: 4;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 24px 90px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(20px);
}

.top-hud {
  position: absolute;
  top: 16px;
  left: 50%;
  z-index: 5;
  display: flex;
  gap: 10px;
  transform: translateX(-50%);
  pointer-events: none;
}

.top-hud div {
  display: grid;
  min-width: 118px;
  min-height: 58px;
  place-items: center;
  padding: 8px 12px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: rgba(5, 8, 12, 0.68);
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.24);
  backdrop-filter: blur(18px);
}

.top-hud strong {
  color: var(--text);
  font-size: 25px;
  line-height: 1;
}

.top-hud span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.combo-pill {
  border-color: rgba(57, 245, 208, 0.42) !important;
  box-shadow: 0 0 34px rgba(57, 245, 208, 0.12), 0 16px 50px rgba(0, 0, 0, 0.24) !important;
}

.combo-pop {
  animation: comboPop 320ms ease-out;
}

@keyframes comboPop {
  0% { transform: scale(1); }
  42% {
    transform: scale(var(--combo-scale, 1.18));
    box-shadow: 0 0 54px rgba(57, 245, 208, 0.36), 0 0 34px rgba(189, 95, 255, 0.24), 0 16px 50px rgba(0, 0, 0, 0.24);
  }
  100% { transform: scale(1); }
}

.menu-toggle {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 7;
  display: none;
}

.top-left {
  top: 16px;
  left: 16px;
  width: min(380px, calc(100vw - 32px));
  padding: 16px;
}

.top-right {
  top: 16px;
  right: 16px;
  width: 390px;
  max-width: calc(100vw - 32px);
  padding: 14px;
}

.menu-collapsed .top-right {
  display: none;
}

.menu-collapsed .menu-toggle {
  display: inline-flex;
}

.bottom-left {
  left: 16px;
  bottom: 16px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--cyan);
  font-size: 12px;
  font-weight: 950;
  letter-spacing: 0;
  text-transform: uppercase;
}

.eyebrow span {
  color: var(--amber);
}

h1 {
  margin: 0;
  font-size: 30px;
  line-height: 1;
  letter-spacing: 0;
}

.stats,
.help,
.button-row,
.input-row,
.control-hints {
  display: flex;
  gap: 8px;
}

.stats {
  flex-wrap: wrap;
  margin-top: 10px;
}

.stats span,
.help span,
.control-hints span {
  min-height: 34px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.stats strong {
  color: var(--text);
}

.controls,
.seed-form {
  display: grid;
  gap: 12px;
}

.coffee-button {
  display: block;
}

.coffee-button img {
  display: block;
  width: 100%;
  max-width: 300px;
  height: auto;
  border: 0;
}

.panel-title {
  display: grid;
  gap: 8px;
  padding-bottom: 2px;
}

.records {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 9px;
}

.records span {
  min-height: 28px;
  padding: 6px 8px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 8px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.055);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.records strong {
  color: var(--text);
}

.language-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
}

.language-switch button {
  gap: 7px;
  min-height: 32px;
  border-color: transparent;
  color: var(--muted);
  background: transparent;
  font-size: 12px;
}

.flag {
  width: 22px;
  height: 15px;
  overflow: hidden;
  border-radius: 3px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.32);
}

.language-switch button.active {
  color: #061016;
  background: var(--cyan);
}

.seed-form label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

input[type="text"] {
  min-width: 0;
  width: 100%;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 11px;
  outline: none;
  color: var(--text);
  background: rgba(255, 255, 255, 0.07);
  font-size: 13px;
  font-weight: 800;
}

input[type="text"]:focus {
  border-color: rgba(57, 245, 208, 0.8);
  box-shadow: 0 0 0 3px rgba(57, 245, 208, 0.13);
}

button,
.file-button {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 13px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  font-size: 13px;
  font-weight: 950;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

#loadButton,
#searchButton,
#runButton,
.game-over button {
  color: #061016;
  background: linear-gradient(135deg, var(--cyan), var(--amber));
}

#searchButton {
  position: relative;
  z-index: 2;
  user-select: none;
}

#runButton:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  filter: grayscale(0.4);
}

#resetButton {
  background: rgba(255, 77, 128, 0.2);
}

.button-row button {
  flex: 1;
}

.youtube-host {
  display: grid;
  min-height: 88px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  place-items: center;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.05);
  font-size: 12px;
  font-weight: 850;
  text-align: center;
}

.youtube-host iframe {
  width: 100%;
  height: 116px;
  border: 0;
}

.search-results {
  display: grid;
  gap: 6px;
  max-height: 190px;
  overflow-y: auto;
}

.search-results:empty {
  display: none;
}

.search-result {
  display: grid;
  grid-template-columns: 78px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  min-height: 52px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.055);
  text-align: left;
}

.search-result img {
  width: 78px;
  height: 44px;
  border-radius: 6px;
  object-fit: cover;
}

.search-result span {
  overflow: hidden;
  font-size: 12px;
  font-weight: 850;
  line-height: 1.25;
  text-overflow: ellipsis;
}

.search-status {
  display: block;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.05);
  font-size: 12px;
  font-weight: 850;
}

.file-picker {
  display: grid;
  grid-template-columns: 148px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  min-height: 46px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.055);
}

.file-picker input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.file-button {
  min-height: 34px;
  color: #061016;
  background: linear-gradient(135deg, var(--cyan), #75e6ff);
}

#fileName {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.audio-player {
  width: 100%;
  height: 36px;
  filter: saturate(1.2);
}

.difficulty {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
}

.difficulty button {
  min-height: 34px;
  border-color: transparent;
  color: var(--muted);
  background: transparent;
  font-size: 12px;
}

.difficulty button.active {
  color: #061016;
  background: var(--cyan);
}

.lyrics-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 38px;
  padding: 7px 9px 7px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background:
    linear-gradient(135deg, rgba(189, 95, 255, 0.22), rgba(57, 245, 208, 0.1)),
    rgba(255, 255, 255, 0.055);
  font-size: 12px;
  font-weight: 900;
  cursor: pointer;
}

.lyrics-toggle input {
  appearance: none;
  position: relative;
  width: 42px;
  height: 24px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.13);
  cursor: pointer;
}

.lyrics-toggle input::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 0 12px rgba(255, 255, 255, 0.32);
  transition: transform 160ms ease, background 160ms ease;
}

.lyrics-toggle input:checked {
  border-color: rgba(57, 245, 208, 0.65);
  background: linear-gradient(135deg, var(--cyan), #bd5fff);
}

.lyrics-toggle input:checked::after {
  transform: translateX(18px);
  background: #061016;
}

.control-hints {
  flex-wrap: wrap;
}

.control-hints span {
  flex: 1;
  text-align: center;
}

.support-note {
  display: grid;
  gap: 9px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  font-weight: 750;
}

.support-note p {
  margin: 0;
}

.support-note a {
  color: var(--cyan);
  font-weight: 950;
}

.supporters {
  display: grid;
  gap: 4px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.055);
}

.supporters strong {
  color: var(--text);
}

.support-note small {
  color: rgba(247, 250, 252, 0.72);
  font-weight: 900;
}

.lyrics-line {
  position: absolute;
  top: 22vh;
  left: 7vw;
  z-index: 3;
  width: min(520px, calc(100vw - 470px));
  transform: perspective(900px) rotateY(-16deg) rotateX(10deg);
  color: rgba(247, 250, 252, 0.88);
  text-align: left;
  text-shadow: 0 0 22px rgba(57, 245, 208, 0.72), 0 0 52px rgba(189, 95, 255, 0.36);
  font-size: clamp(19px, 2.5vw, 42px);
  font-weight: 950;
  line-height: 1.05;
  letter-spacing: 0;
  pointer-events: none;
}

.lyrics-line::before {
  content: "Lyrics Beta";
  display: block;
  margin-bottom: 8px;
  color: rgba(57, 245, 208, 0.85);
  font-size: 12px;
  text-transform: uppercase;
}

.lyrics-line:empty {
  display: none;
}

:lang(hu) .lyrics-line::before {
  content: "Dalsz\00f6veg B\00e9ta";
}

.praise-text {
  position: absolute;
  top: 42%;
  left: 50%;
  z-index: 6;
  min-width: min(560px, calc(100vw - 40px));
  transform: translate(-50%, -50%) scale(0.82);
  color: rgba(247, 250, 252, 0);
  opacity: 0;
  text-align: center;
  text-shadow: 0 0 32px rgba(57, 245, 208, 0.92), 0 0 70px rgba(189, 95, 255, 0.54);
  font-size: clamp(28px, 6vw, 78px);
  font-weight: 950;
  line-height: 1;
  letter-spacing: 0;
  pointer-events: none;
}

.praise-text.show {
  animation: praiseFlash 920ms ease-out forwards;
}

@keyframes praiseFlash {
  0% {
    transform: translate(-50%, -50%) scale(0.78) rotateX(14deg);
    color: rgba(247, 250, 252, 0);
    opacity: 0;
  }
  20% {
    transform: translate(-50%, -50%) scale(var(--praise-scale, 1.04)) rotateX(0deg);
    color: rgba(247, 250, 252, 0.95);
    opacity: 1;
  }
  100% {
    transform: translate(-50%, -54%) scale(1.18);
    color: rgba(247, 250, 252, 0);
    opacity: 0;
  }
}

.game-over,
.loading {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(5, 7, 11, 0.64);
  backdrop-filter: blur(8px);
  text-align: center;
}

.loading {
  background: rgba(5, 7, 11, 0.88);
}

.game-over.hidden,
.loading.hidden {
  display: none;
}

.game-over div,
.loading div {
  width: min(360px, calc(100vw - 40px));
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(10, 14, 22, 0.88);
  box-shadow: 0 24px 90px rgba(0, 0, 0, 0.34);
}

.game-over p,
.loading p {
  margin: 0 0 8px;
  font-size: 30px;
  font-weight: 950;
}

.game-over small,
.loading small {
  display: block;
  margin-bottom: 16px;
  color: var(--muted);
  font-weight: 800;
}

@media (max-width: 860px) {
  .top-left {
    right: 12px;
    left: 12px;
    width: auto;
  }

  .top-right {
    top: calc(env(safe-area-inset-top, 0px) + 72px);
    right: max(8px, env(safe-area-inset-right, 0px));
    bottom: max(8px, env(safe-area-inset-bottom, 0px));
    left: max(8px, env(safe-area-inset-left, 0px));
    width: auto;
    height: auto;
    max-height: calc(100dvh - 82px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px 12px max(16px, env(safe-area-inset-bottom, 0px));
    overscroll-behavior: contain;
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
  }

  body:not(.menu-collapsed) .top-right {
    display: grid;
  }

  .menu-toggle {
    display: inline-flex;
    top: calc(env(safe-area-inset-top, 0px) + 82px);
    right: max(18px, calc(env(safe-area-inset-right, 0px) + 16px));
    z-index: 9;
    min-height: 38px;
  }

  .menu-collapsed .menu-toggle {
    top: max(10px, env(safe-area-inset-top, 0px));
    right: max(10px, env(safe-area-inset-right, 0px));
  }

  .top-hud {
    top: 10px;
    gap: 5px;
    width: calc(100vw - 92px);
    justify-content: center;
  }

  .top-hud div {
    min-width: 0;
    flex: 1;
    min-height: 48px;
    padding: 6px;
  }

  .top-hud strong {
    font-size: 18px;
  }

  .bottom-left {
    right: 12px;
    bottom: 12px;
    left: 12px;
  }

  .lyrics-line {
    top: 82px;
    left: 14px;
    width: min(420px, calc(100vw - 28px));
    font-size: 23px;
  }

  .input-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(76px, auto);
  }

  .search-results {
    max-height: min(34dvh, 250px);
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  .top-right.has-search-results .search-results {
    display: grid;
    min-height: 132px;
    max-height: min(46dvh, 330px);
    padding-right: 2px;
  }

  .top-right.has-search-results .youtube-host,
  .top-right.has-search-results .file-picker,
  .top-right.has-search-results .audio-player,
  .top-right.has-search-results .button-row,
  .top-right.has-search-results .difficulty,
  .top-right.has-search-results .lyrics-toggle,
  .top-right.has-search-results .control-hints,
  .top-right.has-search-results .support-note {
    display: none;
  }

  .youtube-host {
    min-height: 76px;
  }

  .youtube-host iframe {
    height: clamp(86px, 18dvh, 116px);
  }
}

@media (max-width: 520px) {
  .file-picker,
  .difficulty {
    grid-template-columns: 1fr 1fr;
  }

  .help span {
    flex: 1;
    text-align: center;
  }

  .top-right {
    top: calc(env(safe-area-inset-top, 0px) + 66px);
    bottom: max(8px, env(safe-area-inset-bottom, 0px));
    max-height: calc(100dvh - 74px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  }

  h1 {
    font-size: 26px;
  }

  .coffee-button img {
    max-width: 280px;
  }

  .records span {
    font-size: 10px;
  }

  .search-results {
    max-height: min(30dvh, 210px);
  }

  .top-right.has-search-results .search-results {
    min-height: 160px;
    max-height: min(48dvh, 360px);
  }

  .search-result {
    grid-template-columns: 64px minmax(0, 1fr);
  }

  .search-result img {
    width: 64px;
    height: 38px;
  }

  .support-note {
    font-size: 11px;
  }
}

@media (orientation: landscape) and (max-height: 560px) {
  .top-right {
    top: calc(env(safe-area-inset-top, 0px) + 64px);
    right: 12px;
    bottom: max(8px, env(safe-area-inset-bottom, 0px));
    left: auto;
    width: min(380px, 42vw);
    max-height: calc(100dvh - 72px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    overflow-y: auto;
  }

  .menu-toggle {
    top: 76px;
    right: 22px;
  }

  .lyrics-line {
    top: 72px;
    left: 18px;
    width: min(42vw, 520px);
  }
}
