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

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  overflow: hidden;
}

button {
  backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, 0.42);
  border-radius: 8px;
  background: rgba(28, 52, 72, 0.74);
  box-shadow: 0 10px 28px rgba(38, 72, 96, 0.18);
  color: #f7fbff;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  min-height: 40px;
  padding: 0 16px;
  transition: background 120ms ease, border-color 120ms ease, transform 120ms ease;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

[hidden] {
  display: none !important;
}

button:hover,
button:focus-visible {
  border-color: #fff;
  outline: none;
  transform: translateY(-1px);
}

#game,
#game-canvas {
  display: block;
  height: 100vh;
  width: 100vw;
}

#game-canvas {
  background: #dff6ff;
  touch-action: none;
}

.loading-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  background: #132636;
  color: #f7fbff;
  font-size: 18px;
  font-weight: 800;
}

body:not(.is-loading) .loading-screen {
  display: none;
}

body.is-loading #hud,
body.is-loading #overlay {
  visibility: hidden;
  pointer-events: none;
}

#hud {
  align-items: flex-start;
  display: flex;
  gap: 16px;
  justify-content: space-between;
  left: 0;
  padding: 18px;
  pointer-events: none;
  position: fixed;
  right: 0;
  top: 0;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.stats > div {
  backdrop-filter: blur(16px);
  background: linear-gradient(180deg, rgba(25, 56, 78, 0.74), rgba(12, 34, 54, 0.62));
  border: 1px solid rgba(255, 255, 255, 0.34);
  border-radius: 8px;
  box-shadow: 0 12px 34px rgba(38, 72, 96, 0.2);
  min-width: 92px;
  padding: 8px 12px;
}

.stats span {
  color: #d9f2fa;
  display: block;
  font-size: 12px;
  letter-spacing: 0;
}

.stats strong {
  display: block;
  font-size: 24px;
  line-height: 1.05;
  text-shadow: 0 2px 12px rgba(255, 209, 102, 0.24);
}

.actions {
  display: flex;
  gap: 8px;
  pointer-events: auto;
}

#overlay {
  align-items: center;
  background: radial-gradient(circle at 50% 42%, rgba(255, 255, 255, 0.18), rgba(9, 34, 54, 0.6) 58%);
  display: none;
  inset: 0;
  justify-content: center;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 20px;
  position: fixed;
  -webkit-overflow-scrolling: touch;
}

#overlay.visible {
  display: flex;
}

.panel {
  backdrop-filter: blur(20px);
  background: linear-gradient(180deg, rgba(22, 55, 75, 0.9), rgba(9, 28, 44, 0.84));
  border: 1px solid rgba(255, 255, 255, 0.36);
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.42), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  max-height: calc(100vh - 40px);
  max-height: calc(100svh - 40px);
  max-height: calc(100dvh - 40px);
  max-width: 420px;
  overflow-y: auto;
  padding: 24px;
  text-align: center;
  width: min(100%, 420px);
  -webkit-overflow-scrolling: touch;
}

.panel h1 {
  max-width: 100%;
  overflow: hidden;
  font-size: clamp(30px, 7vw, 50px);
  line-height: 0.95;
  margin: 0 0 12px;
  white-space: nowrap;
  text-shadow: 0 8px 28px rgba(255, 209, 102, 0.22);
}

.panel p {
  color: #d4edf5;
  line-height: 1.45;
  margin: 0 0 20px;
}

#primary-button {
  background: linear-gradient(180deg, #19a979, #0f7f5f);
  border-color: #8df1cf;
  box-shadow: 0 14px 34px rgba(15, 127, 95, 0.24);
  color: #ffffff;
  min-width: 128px;
}

.mode-choice {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 16px;
}

.mode-choice button {
  min-height: 48px;
}

.panel .gameblocks-credit {
  margin: 18px 0 0;
  color: rgba(212, 237, 245, 0.72);
  font-size: 12px;
  line-height: 1.2;
}

.gameblocks-credit a {
  color: inherit;
  font-weight: 800;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.control-instructions {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-top: 16px;
}

.control-instructions span {
  align-items: center;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 6px;
  color: #d4edf5;
  display: block;
  font-size: 13px;
  line-height: 1.25;
  min-width: 0;
  padding: 8px 10px;
  text-align: center;
}

.control-instructions kbd {
  color: #ffffff;
  font: inherit;
  font-weight: 850;
}

#manual-button,
#auto-button {
  background: linear-gradient(180deg, #19a979, #0f7f5f);
  border-color: #8df1cf;
  box-shadow: 0 14px 34px rgba(15, 127, 95, 0.24);
  color: #ffffff;
}

@media (max-width: 620px) {
  #hud {
    align-items: stretch;
    flex-direction: column;
    padding: 12px;
  }

  .actions {
    justify-content: flex-end;
  }

  .stats > div {
    flex: 1 1 84px;
    min-width: 0;
  }

  .stats strong {
    font-size: 18px;
  }

  .mode-choice {
    grid-template-columns: 1fr;
  }

  .control-instructions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
