:root {
  --bg1: #0a1428;
  --bg2: #1f3150;
  --panel: rgba(6, 14, 30, 0.8);
  --line: rgba(255, 255, 255, 0.2);
  --text: #ebf4ff;
  --accent: #ffd166;
  --ok: #73f0a5;
  --bad: #ff7a7a;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 10% 10%, rgba(115, 240, 165, 0.2), transparent 38%),
    radial-gradient(circle at 85% 25%, rgba(255, 209, 102, 0.2), transparent 35%),
    linear-gradient(155deg, var(--bg1), var(--bg2));
}

.app {
  width: min(1050px, 100%);
  margin: 0 auto;
  padding: 16px;
  display: grid;
  gap: 12px;
}

.top-bar {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

h1 {
  margin: 0;
  font-size: clamp(26px, 5vw, 38px);
}

.subtitle {
  margin: 6px 0 0;
  opacity: 0.9;
}

.editor-link {
  color: #1f2f11;
  background: var(--accent);
  border: 1px solid rgba(0, 0, 0, 0.2);
  border-radius: 10px;
  padding: 9px 12px;
  text-decoration: none;
  font-weight: 700;
  white-space: nowrap;
}

.editor-link:hover,
.editor-link:focus-visible {
  outline: none;
  filter: brightness(1.04);
}

.hud {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.label {
  opacity: 0.8;
  margin-right: 6px;
}

.status-text {
  font-weight: 700;
}

.game-wrap {
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.2);
}

#game-canvas {
  display: block;
  width: 100%;
  height: min(70vh, 560px);
  touch-action: manipulation;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  background: rgba(4, 10, 22, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.2);
  padding: 16px 16px 94px;
  z-index: 8;
  backdrop-filter: blur(4px);
}

.overlay.overlay-success {
  background:
    radial-gradient(circle at 20% 20%, rgba(115, 240, 165, 0.4), transparent 42%),
    radial-gradient(circle at 82% 18%, rgba(255, 209, 102, 0.35), transparent 46%),
    rgba(4, 16, 18, 0.86);
}

.overlay.overlay-failure {
  background:
    radial-gradient(circle at 18% 22%, rgba(255, 86, 86, 0.42), transparent 42%),
    radial-gradient(circle at 84% 20%, rgba(255, 130, 77, 0.28), transparent 48%),
    rgba(20, 6, 12, 0.88);
}

.level-picker {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  background: rgba(4, 10, 22, 0.82);
  backdrop-filter: blur(4px);
  padding: 18px;
}

.level-picker-panel {
  width: min(680px, 100%);
  max-height: min(86vh, 560px);
  border: 1px solid rgba(255, 255, 255, 0.26);
  border-radius: 14px;
  background: rgba(8, 20, 36, 0.92);
  padding: 14px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 10px;
}

.level-picker-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.level-picker-texts {
  display: grid;
  gap: 6px;
}

.level-picker-title {
  margin: 0;
  font-size: clamp(24px, 4vw, 30px);
  font-weight: 800;
}

.level-picker-summary {
  margin: 0;
  opacity: 0.9;
}

.audio-settings {
  width: min(360px, 100%);
  margin: 0 auto;
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
}

.audio-settings-picker {
  margin: 0 0 0 auto;
  width: min(320px, 100%);
}

.audio-settings-overlay-bottom {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 12px;
  width: min(430px, calc(100% - 24px));
  margin: 0;
}

.audio-icon-row {
  gap: 10px;
}

.audio-icon-btn {
  position: relative;
  width: 42px;
  height: 42px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.08);
  color: #73f0a5;
  font: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.audio-icon-btn::before {
  line-height: 1;
  font-size: 20px;
}

.audio-icon-btn.music::before {
  content: "\266B";
}

.audio-icon-btn.sfx::before {
  content: "\1F50A";
}

.audio-icon-btn.is-on {
  color: #73f0a5;
  border-color: rgba(115, 240, 165, 0.64);
  background: rgba(115, 240, 165, 0.16);
}

.audio-icon-btn.is-off {
  color: rgba(201, 216, 236, 0.62);
  border-color: rgba(201, 216, 236, 0.32);
  background: rgba(138, 158, 181, 0.14);
}

.audio-icon-btn.is-off::after {
  content: "";
  position: absolute;
  width: 78%;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
  transform: rotate(-34deg);
}

.audio-icon-btn:hover,
.audio-icon-btn:focus-visible {
  outline: none;
  filter: brightness(1.08);
}

.level-picker-list {
  display: grid;
  grid-auto-rows: min-content;
  gap: 8px;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  padding: 2px 8px 16px 0;
  scroll-padding-bottom: 16px;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: rgba(155, 188, 230, 0.6) rgba(255, 255, 255, 0.08);
  -webkit-overflow-scrolling: touch;
}

.level-picker-list::-webkit-scrollbar {
  width: 10px;
}

.level-picker-list::-webkit-scrollbar-track {
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
}

.level-picker-list::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(195, 225, 255, 0.72), rgba(138, 173, 212, 0.72));
  border: 2px solid rgba(8, 20, 36, 0.9);
}

.level-picker-list .level-picker-item:last-child {
  margin-bottom: 8px;
}

.level-picker-item {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  padding: 10px 12px;
  font: inherit;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  text-align: left;
}

.level-picker-item:hover,
.level-picker-item:focus-visible {
  outline: none;
  background: rgba(255, 255, 255, 0.18);
}

.level-picker-item.done {
  border-color: rgba(122, 255, 189, 0.55);
  background: rgba(115, 240, 165, 0.16);
}

.level-picker-name {
  font-weight: 700;
}

.level-picker-status {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
}

.level-picker-badge {
  font-size: 12px;
  line-height: 1;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 6px 8px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.09);
}

.level-picker-item.done .level-picker-badge {
  border-color: rgba(122, 255, 189, 0.7);
  background: rgba(115, 240, 165, 0.22);
}

.level-picker-stars {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
}

.end-star-icon {
  width: 34px;
  height: 34px;
  background-image: url("./assets/end_star.png");
  background-size: 200% 100%;
  background-position: 0 0;
  background-repeat: no-repeat;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.35));
}

.level-picker-stars .end-star-icon {
  background-image: url("./assets/feature_star.png");
  background-size: 200% 100%;
  background-position: 0 0;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.45));
}

.level-picker-stars .end-star-icon.missed {
  background-position: 100% 0;
  opacity: 1;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.45));
}

.end-star-icon.missed {
  background-position: 100% 0;
  opacity: 0.75;
  filter: grayscale(0.18) saturate(0.78) brightness(0.92);
}

.end-star-icon.compact {
  width: 18px;
  height: 18px;
}

.end-star-icon.compact + .end-star-icon.compact {
  margin-left: -7px;
}

.hint-toast {
  position: absolute;
  left: 50%;
  top: 16px;
  transform: translateX(-50%);
  max-width: min(92%, 680px);
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(8, 20, 36, 0.86);
  color: var(--text);
  font-weight: 700;
  text-align: center;
  z-index: 7;
  pointer-events: none;
  backdrop-filter: blur(4px);
}

.mobile-controls {
  display: none;
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 6;
}

.virtual-joystick {
  --jx: 0px;
  --jy: 0px;
  position: absolute;
  right: 16px;
  bottom: 16px;
  width: 124px;
  height: 124px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(8, 20, 36, 0.38);
  background-image: url("./assets/ui_joystick_base.png");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
}

.joystick-thumb {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 74px;
  height: 74px;
  border-radius: 50%;
  border: 0;
  background: rgba(230, 242, 255, 0.18);
  background-image: url("./assets/ui_joystick_thumb.png");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  transform: translate(-50%, -50%) translate(var(--jx), var(--jy));
}

.mobile-rotations {
  position: absolute;
  left: 16px;
  bottom: 16px;
  display: grid;
  gap: 10px;
  pointer-events: auto;
}

.mobile-rotations button {
  width: 66px;
  height: 56px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.38);
  background: rgba(8, 20, 36, 0.46);
  color: transparent;
  font: inherit;
  font-size: 0;
  line-height: 0;
  cursor: pointer;
  touch-action: manipulation;
  background-size: 90% 90%;
  background-position: center;
  background-repeat: no-repeat;
}

.mobile-rotations button:active {
  background: rgba(255, 255, 255, 0.24);
}

#rotate-ccw-btn {
  background-image: url("./assets/ui_rotate_left.png");
}

#rotate-cw-btn {
  background-image: url("./assets/ui_rotate_right.png");
}

.orientation-overlay {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 9;
  place-items: center;
  text-align: center;
  padding: 18px;
  font-size: clamp(20px, 7vw, 30px);
  font-weight: 800;
  background: rgba(4, 10, 22, 0.84);
}

.hidden {
  display: none;
}

.overlay-title {
  margin: 0;
  font-size: clamp(28px, 6vw, 44px);
  font-weight: 800;
}

.overlay-end-image {
  display: block;
  width: min(108px, 24vw);
  max-height: min(108px, 24vw);
  margin: 0 auto 10px;
  object-fit: contain;
}

.overlay-stars {
  margin: 4px auto 8px;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 34px;
}

.overlay.overlay-success .overlay-title {
  color: #9affc7;
  text-shadow: 0 0 24px rgba(122, 255, 189, 0.34);
}

.overlay.overlay-failure .overlay-title {
  color: #ff9b9b;
  text-shadow: 0 0 24px rgba(255, 73, 73, 0.34);
}

.overlay-subtitle {
  margin: 8px 0 0;
  opacity: 0.95;
}

.overlay-actions {
  margin-top: 18px;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
}

.overlay-actions button {
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
  padding: 9px 14px 9px 42px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  background-size: 24px 24px;
  background-position: 12px center;
  background-repeat: no-repeat;
}

.overlay-actions button:hover,
.overlay-actions button:focus-visible {
  outline: none;
  background: rgba(255, 255, 255, 0.2);
}

.overlay.overlay-failure #overlay-restart-btn {
  background-color: rgba(255, 120, 120, 0.24);
  border-color: rgba(255, 145, 145, 0.56);
}

.overlay.overlay-success #overlay-next-btn {
  background-color: rgba(115, 240, 165, 0.28);
  border-color: rgba(138, 255, 188, 0.64);
}

#overlay-restart-btn {
  background-image: url("./assets/ui_restart.png");
}

#overlay-next-btn {
  background-image: url("./assets/ui_next.png");
}

@media (max-width: 720px) {
  .app {
    padding: 10px;
  }

  #game-canvas {
    height: min(64vh, 460px);
  }

  .level-picker-head {
    flex-direction: column;
    gap: 10px;
  }

  .audio-settings-picker {
    width: 100%;
    margin: 0;
  }

  .audio-icon-btn {
    width: 38px;
    height: 38px;
  }

  .audio-icon-btn::before {
    font-size: 18px;
  }
}

@media (hover: none) and (pointer: coarse) {
  html,
  body {
    overflow: hidden;
  }

  .app {
    width: 100%;
    min-height: 100dvh;
    margin: 0;
    padding: 0;
    gap: 0;
  }

  .top-bar,
  .hud {
    display: none;
  }

  .game-wrap {
    border: 0;
    border-radius: 0;
    width: 100vw;
    height: 100dvh;
  }

  #game-canvas {
    width: 100vw;
    height: 100dvh;
  }

  .mobile-controls {
    display: block;
  }
}


html.mobile-layout,
body.mobile-layout {
  overflow: hidden;
}

body.mobile-layout .app {
  width: 100%;
  min-height: 100dvh;
  margin: 0;
  padding: 0;
  gap: 0;
}

body.mobile-layout .top-bar,
body.mobile-layout .hud {
  display: none;
}

body.mobile-layout .game-wrap {
  border: 0;
  border-radius: 0;
  width: 100vw;
  height: 100dvh;
}

body.mobile-layout #game-canvas {
  width: 100vw;
  height: 100dvh;
}

body.mobile-layout .mobile-controls {
  display: block;
}
