:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #111722;
  color: #e9eef7;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
}

button,
select {
  border: 1px solid #465268;
  border-radius: 7px;
  background: #283348;
  color: inherit;
  font: inherit;
}

button {
  padding: 8px 13px;
  cursor: pointer;
}

button:disabled {
  border-color: #303949;
  background: #202838;
  color: #697488;
  cursor: default;
}

button:hover,
button:focus-visible,
select:hover,
select:focus-visible {
  border-color: #79b8ff;
  background: #34425b;
  outline: none;
}

button.primary {
  border-color: #4e91d9;
  background: #2767a8;
}

button.success {
  border-color: #52b988;
  background: #267653;
}

button#build-view:not(.hidden) {
  border-color: #ffd16a;
  background: #9a641f;
  color: #fff7df;
  box-shadow: 0 0 0 0 rgba(255, 195, 82, 0.5);
  animation: build-view-pulse 1.4s ease-out infinite;
}

@keyframes build-view-pulse {
  0% { box-shadow: 0 0 0 0 rgba(255, 195, 82, 0.5); }
  70%, 100% { box-shadow: 0 0 0 9px rgba(255, 195, 82, 0); }
}

@media (prefers-reduced-motion: reduce) {
  button#build-view:not(.hidden) {
    animation: none;
  }
}

@media (pointer: coarse) {
  button,
  select {
    min-height: 44px;
  }

  button {
    padding-inline: 16px;
  }
}

.hidden {
  display: none;
}

select {
  margin-left: 6px;
  padding: 7px 28px 7px 9px;
}

#app {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: 100%;
  height: 100%;
  height: 100dvh;
}

#app.hidden {
  display: none;
}

.menu-screen {
  display: grid;
  width: 100%;
  height: 100%;
  height: 100dvh;
  place-items: safe center;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
  padding: max(32px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) max(32px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
  background:
    radial-gradient(circle at 50% 25%, rgba(66, 99, 143, 0.38), transparent 42%),
    #111722;
}

.menu-screen.hidden {
  display: none;
}

.menu-card {
  width: min(760px, 100%);
  padding: 38px;
  border: 1px solid #344158;
  border-radius: 20px;
  background: rgba(23, 31, 45, 0.94);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.32);
  text-align: center;
}

.menu-card h1 {
  font-size: clamp(28px, 5vw, 46px);
}

.eyebrow {
  margin: 0 0 10px;
  color: #7ebcff;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.18em;
}

.menu-copy {
  margin: 10px 0 28px;
  color: #aeb9ca;
}

.grid-options {
  display: grid;
  gap: 28px;
}

.mode-section h2 {
  margin: 0 0 5px;
  font-size: 21px;
}

.mode-description {
  margin: 0 0 14px;
  color: #929fb3;
  font-size: 14px;
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 14px;
}

.grid-option {
  min-height: 130px;
  padding: 20px;
  background: linear-gradient(145deg, #2b3a52, #202a3d);
}

.grid-option strong,
.grid-option span {
  display: block;
}

.grid-option strong {
  margin-bottom: 10px;
  font-size: 27px;
}

.grid-option span {
  color: #aebbd0;
}

.level-card {
  position: relative;
}

.back-button {
  position: absolute;
  top: 24px;
  left: 24px;
}

.level-options {
  display: grid;
  grid-template-columns: repeat(4, minmax(70px, 1fr));
  gap: 12px;
}

.level-option {
  position: relative;
  aspect-ratio: 1;
  min-height: 70px;
  font-size: 21px;
  font-weight: 800;
}

.level-option small {
  display: block;
  margin-top: 4px;
  color: #92a1b8;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
}

.level-option.solved {
  border-color: #4fba83;
  background: #245d45;
}

.level-option.locked {
  opacity: 0.48;
}

.toolbar,
.status-bar {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  background: rgba(22, 29, 42, 0.96);
  box-shadow: 0 5px 24px rgba(0, 0, 0, 0.24);
}

.toolbar {
  min-height: 68px;
  padding: 12px 20px;
}

.title-group,
.controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

h1 {
  margin: 0;
  font-size: 20px;
  letter-spacing: 0.02em;
}

.badge {
  padding: 4px 8px;
  border: 1px solid #3d587a;
  border-radius: 999px;
  color: #9ecbff;
  font-size: 12px;
}

.controls label {
  color: #b9c4d6;
  font-size: 14px;
}

.separator {
  width: 1px;
  height: 28px;
  margin: 0 2px;
  background: #3b4659;
}

#game-root {
  position: relative;
  min-height: 0;
  background: radial-gradient(circle at 50% 40%, #26354a 0, #151d2a 56%, #0d121b 100%);
}

#game-root canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: pointer;
  touch-action: none;
}

.status-bar {
  min-height: 42px;
  padding: 8px 20px;
  color: #aeb9ca;
  font-size: 13px;
  box-shadow: 0 -5px 24px rgba(0, 0, 0, 0.2);
}

#selection,
#camera-angle {
  min-width: 120px;
  color: #dce8fa;
}

#game-status {
  flex: 1;
  text-align: center;
}

#game-status.error {
  color: #ff9b8f;
}

#game-status.success {
  color: #7de2a9;
  font-weight: 700;
}

#camera-angle {
  text-align: right;
}

@media (max-width: 760px) {
  .menu-screen {
    align-items: start;
  }

  .toolbar {
    align-items: flex-start;
    gap: 8px;
    padding-inline: 12px;
  }

  .title-group {
    flex: 0 0 auto;
  }

  .title-group h1,
  .title-group .badge {
    display: none;
  }

  #back-to-levels {
    width: 44px;
    padding-inline: 0;
  }

  .controls {
    flex: 1 1 auto;
    flex-wrap: wrap;
  }

  .status-bar span:nth-child(2) {
    display: none;
  }

  .menu-card {
    padding: 28px 18px;
  }

  .level-options {
    grid-template-columns: repeat(3, minmax(70px, 1fr));
  }
}
