* {
  box-sizing: border-box;
}

:root {
  --bg0: #05060a;
  --bg1: #0c0e14;
  --card: rgba(18, 22, 32, 0.72);
  --card-border: rgba(255, 255, 255, 0.08);
  --text: #f0f2f7;
  --muted: #8b93a7;
  --accent: #5eead4;
  --accent-dim: rgba(94, 234, 212, 0.15);
  --danger: #fb7185;
  --ok: #86efac;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: "Outfit", system-ui, sans-serif;
  background: radial-gradient(120% 80% at 50% -20%, #152032 0%, var(--bg0) 45%, var(--bg1) 100%);
  color: var(--text);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

#c {
  position: fixed;
  inset: 0;
  z-index: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: manipulation;
}

#impact-overlay {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  opacity: 0;
  transition: opacity 180ms ease-out;
  mix-blend-mode: screen;
}

#impact-overlay.show {
  opacity: 1;
}

#impact-overlay.win {
  background:
    radial-gradient(60% 45% at 50% 70%, rgba(110, 255, 170, 0.55), rgba(0, 0, 0, 0) 72%),
    linear-gradient(180deg, rgba(18, 255, 163, 0.24), rgba(0, 0, 0, 0));
}

#impact-overlay.lose {
  background:
    radial-gradient(66% 50% at 50% 64%, rgba(255, 62, 62, 0.7), rgba(0, 0, 0, 0) 72%),
    linear-gradient(180deg, rgba(255, 0, 0, 0.28), rgba(0, 0, 0, 0));
}

#boot {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg0);
  transition: opacity 0.45s ease, visibility 0.45s ease;
}

#boot.done {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.boot-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.boot-ring {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.08);
  border-top-color: var(--accent);
  animation: spin 0.7s linear infinite;
}

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

.boot-text {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

#top-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1.25rem;
  pointer-events: none;
  background: linear-gradient(to bottom, rgba(5, 6, 10, 0.92), transparent);
}

#top-bar > * {
  pointer-events: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-mark {
  width: 10px;
  height: 36px;
  border-radius: 4px;
  background: linear-gradient(180deg, var(--accent), #38bdf8);
  box-shadow: 0 0 24px rgba(94, 234, 212, 0.35);
}

.brand-text h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.tagline {
  margin: 0.1rem 0 0;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.difficulty-field {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.35rem;
}

.difficulty-line {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.custom-panel {
  margin-top: 0.5rem;
  width: min(92vw, 30rem);
  padding: 0.55rem 0.62rem;
  border-radius: 12px;
  background: rgba(10, 14, 22, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.08);
  display: grid;
  gap: 0.34rem;
}

#custom-panel[hidden] {
  display: none !important;
}

.custom-row {
  display: grid;
  grid-template-columns: 7.6rem minmax(9rem, 1fr) 3.2rem;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.68rem;
  color: #c8d0df;
}

.custom-row span {
  white-space: nowrap;
}

.custom-row strong {
  text-align: right;
  font-size: 0.66rem;
  color: var(--accent);
  font-family: "JetBrains Mono", monospace;
}

.custom-row input[type="range"] {
  width: 100%;
  accent-color: #5eead4;
}

.sound-btn {
  border: 1px solid var(--card-border);
  background: rgba(12, 14, 22, 0.75);
  color: var(--muted);
  border-radius: 999px;
  padding: 0.35rem 0.6rem;
  font: inherit;
  font-size: 0.74rem;
  font-weight: 600;
  cursor: pointer;
}

.sound-btn.on {
  color: #042f2e;
  border-color: transparent;
  background: linear-gradient(135deg, #5eead4, #2dd4bf);
  box-shadow: 0 0 16px rgba(94, 234, 212, 0.3);
}

#mobile-options-overlay,
#mobile-switcher {
  display: none;
}

#session-stats {
  display: flex;
  gap: 0.45rem;
  align-items: center;
  justify-content: center;
}

.stat {
  min-width: 4.2rem;
  padding: 0.35rem 0.5rem;
  border-radius: 10px;
  background: rgba(10, 14, 22, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.06);
  text-align: center;
}

.stat small {
  display: block;
  font-size: 0.6rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.stat strong {
  font-size: 0.86rem;
  font-weight: 700;
}

.field-label {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
}

#difficulty-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  justify-content: flex-end;
  max-width: min(52vw, 20rem);
}

.diff-tab {
  padding: 0.4rem 0.65rem;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  border: 1px solid var(--card-border);
  border-radius: 999px;
  background: rgba(12, 14, 22, 0.65);
  color: var(--muted);
  cursor: pointer;
  transition:
    color 0.2s ease,
    border-color 0.2s ease,
    background 0.2s ease,
    box-shadow 0.2s ease;
}

.diff-tab:hover {
  color: var(--text);
  border-color: rgba(255, 255, 255, 0.14);
  background: rgba(24, 28, 40, 0.85);
}

.diff-tab[aria-selected="true"] {
  color: #042f2e;
  background: linear-gradient(135deg, #5eead4, #2dd4bf);
  border-color: transparent;
  box-shadow: 0 0 20px rgba(94, 234, 212, 0.25);
}


#hud {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.75rem 1rem 1.35rem;
  pointer-events: none;
  background: linear-gradient(transparent, rgba(5, 6, 10, 0.88));
}

.hud-card {
  pointer-events: auto;
  width: min(100%, 22rem);
  padding: 1rem 1.15rem 1.1rem;
  text-align: center;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
  transition: transform 220ms ease, box-shadow 220ms ease, border-color 220ms ease;
}

body.state-win .hud-card {
  border-color: rgba(134, 239, 172, 0.55);
  box-shadow:
    0 0 0 1px rgba(134, 239, 172, 0.35) inset,
    0 18px 65px rgba(54, 189, 112, 0.45);
  transform: translateY(-2px) scale(1.012);
}

body.state-lose .hud-card {
  border-color: rgba(255, 80, 80, 0.6);
  box-shadow:
    0 0 0 1px rgba(255, 80, 80, 0.35) inset,
    0 18px 65px rgba(180, 34, 34, 0.5);
  animation: shake-card 0.33s ease;
}

@keyframes shake-card {
  0% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  50% { transform: translateX(6px); }
  75% { transform: translateX(-4px); }
  100% { transform: translateX(0); }
}

#hud p {
  margin: 0;
}

#instruction {
  font-size: 0.92rem;
  font-weight: 500;
  color: #c5cad8;
}

#result {
  margin-top: 0.65rem !important;
  font-size: 1.05rem;
  font-weight: 700;
  min-height: 1.35em;
  letter-spacing: -0.01em;
}

.btn-primary {
  pointer-events: auto;
  margin-top: 0.85rem;
  width: 100%;
  padding: 0.65rem 1rem;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  border: none;
  border-radius: 12px;
  color: #042f2e;
  background: linear-gradient(135deg, #5eead4, #2dd4bf);
  cursor: pointer;
  box-shadow: 0 4px 24px rgba(45, 212, 191, 0.25);
  transition: transform 0.15s ease, filter 0.15s ease;
}

.btn-primary:hover {
  filter: brightness(1.06);
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(0);
}

.hint {
  margin: 0.65rem 0 0;
  max-width: 26rem;
  padding: 0 0.5rem;
  font-size: 0.68rem;
  line-height: 1.45;
  color: var(--muted);
  text-align: center;
  opacity: 0.75;
}

.hint code {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.62rem;
  color: #a5b4c8;
}

kbd {
  display: inline-block;
  padding: 0.12em 0.4em;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.78em;
  font-weight: 500;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(0, 0, 0, 0.35);
  color: var(--accent);
}

@media (max-width: 520px) {
  #top-bar {
    flex-wrap: wrap;
    gap: 0.45rem;
    justify-content: center;
  }

  #session-stats {
    order: 3;
    width: 100%;
  }

  .stat {
    min-width: 3.6rem;
    padding: 0.3rem 0.35rem;
  }

  .stat strong {
    font-size: 0.78rem;
  }

  .difficulty-line {
    gap: 0.35rem;
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .brand-text h1 {
    font-size: 1rem;
  }

  #difficulty-tabs {
    max-width: 100%;
  }

  .custom-panel {
    width: min(100vw - 1.6rem, 32rem);
    padding: 0.5rem 0.55rem;
  }

  .custom-row {
    grid-template-columns: 1fr;
    gap: 0.2rem;
    font-size: 0.72rem;
  }

  .custom-row strong {
    text-align: left;
    font-size: 0.7rem;
  }

  .custom-row input[type="range"] {
    min-height: 28px;
  }

  .diff-tab {
    padding: 0.35rem 0.5rem;
    font-size: 0.72rem;
  }

  .hud-card {
    width: min(100%, 24rem);
    padding: 0.8rem 0.9rem 0.9rem;
  }

  .hint {
    display: none;
  }
}

@media (max-width: 820px) {
  #mobile-options-overlay {
    position: fixed;
    left: 0;
    right: 0;
    top: 4.2rem;
    bottom: 4.6rem;
    z-index: 8;
    display: block;
    opacity: 0;
    pointer-events: none;
    transition: opacity 180ms ease;
    background: rgba(4, 8, 14, 0.72);
    backdrop-filter: blur(14px);
    padding: 0.8rem;
    overflow: auto;
  }

  #mobile-options-content {
    width: 100%;
    display: grid;
    justify-items: stretch;
  }

  #mobile-switcher {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.45rem;
    padding: 0.5rem 0.7rem calc(0.5rem + env(safe-area-inset-bottom, 0px));
    background: linear-gradient(180deg, rgba(5, 6, 10, 0.32), rgba(5, 6, 10, 0.95));
  }

  .mobile-switch-btn {
    border: 1px solid var(--card-border);
    background: rgba(12, 14, 22, 0.82);
    color: var(--muted);
    border-radius: 10px;
    min-height: 2.5rem;
    font: inherit;
    font-size: 0.86rem;
    font-weight: 600;
  }

  .mobile-switch-btn.active {
    color: #042f2e;
    background: linear-gradient(135deg, #5eead4, #2dd4bf);
    border-color: transparent;
  }

  body.mobile-options-open #mobile-options-overlay {
    opacity: 1;
    pointer-events: auto;
  }

  body.mobile-options-open #hud {
    opacity: 0;
    pointer-events: none;
  }

  body.mobile-options-open #instruction,
  body.mobile-options-open #result,
  body.mobile-options-open #retry {
    visibility: hidden;
  }

  .mobile-options-mounted {
    width: 100%;
    align-items: stretch;
    gap: 0.55rem;
  }

  .mobile-options-mounted .field-label {
    font-size: 0.72rem;
  }

  .mobile-options-mounted .difficulty-line {
    justify-content: flex-start;
  }

  .mobile-options-mounted #difficulty-tabs {
    max-width: 100%;
    justify-content: flex-start;
  }

  .mobile-options-mounted .custom-panel {
    width: 100%;
    margin-top: 0.35rem;
  }
}
