* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
  background: #05060f;
  color: #e8f1ff;
  font-family: "Courier New", ui-monospace, Menlo, Consolas, monospace;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 640px;
  margin: 0 auto;
  padding:
    max(6px, env(safe-area-inset-top))
    max(8px, env(safe-area-inset-right))
    max(6px, env(safe-area-inset-bottom))
    max(8px, env(safe-area-inset-left));
}

/* HUD */

.hud {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 2px 8px;
}

.hud-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.hud-label {
  font-size: 11px;
  letter-spacing: 2px;
  color: #8a94c2;
  white-space: nowrap;
  overflow: hidden;
}

.hud-value {
  font-size: clamp(14px, 4.6vw, 22px);
  font-weight: bold;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.score {
  color: #ffd23f;
  text-shadow: 0 0 8px rgba(255, 210, 63, 0.5);
}

.level {
  color: #ff5ee8;
  text-shadow: 0 0 8px rgba(255, 94, 232, 0.5);
}

.status {
  color: #5ef1ff;
  text-shadow: 0 0 8px rgba(94, 241, 255, 0.5);
}

.lives {
  color: #ff3b5c;
  letter-spacing: 2px;
  text-shadow: 0 0 8px rgba(255, 59, 92, 0.5);
}

.hud-btn {
  flex: none;
  width: 44px;
  height: 44px;
  font: inherit;
  font-size: 18px;
  font-weight: bold;
  color: #e8f1ff;
  background: #10142b;
  border: 2px solid #2b3670;
  border-radius: 6px;
  cursor: pointer;
}

.hud-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.sound-btn {
  display: grid;
  place-items: center;
  padding: 0;
  color: #5ef1ff;
}

.sound-btn svg {
  width: 24px;
  height: 24px;
}

.sound-btn .icon-off,
.sound-btn.muted .icon-on {
  display: none;
}

.sound-btn.muted {
  color: #8a94c2;
}

.sound-btn.muted .icon-off {
  display: block;
}

/* Playfield */

.stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: none;
}

.frame {
  position: relative;
  /* Lets overlay text scale with the playfield rather than the viewport. */
  container-type: size;
  box-shadow: 0 0 0 2px #1f2a5a, 0 0 28px rgba(80, 120, 255, 0.25);
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: none;
  outline: none;
}

#game:focus-visible {
  box-shadow: 0 0 0 3px #ffd23f;
}

/* Overlays */

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(8px, 3cqh, 16px);
  padding: 16px;
  overflow-y: auto;
  text-align: center;
  background: rgba(5, 6, 15, 0.84);
}

.overlay.hidden {
  display: none;
}

.overlay-title {
  font-size: clamp(24px, 10vw, 52px);
  font-size: clamp(22px, 11cqw, 56px);
  letter-spacing: 4px;
  color: #ff3b5c;
  text-shadow: 0 0 6px #ff3b5c, 0 0 22px rgba(255, 59, 92, 0.6);
}

.overlay-sub {
  font-size: clamp(12px, 3.8vw, 18px);
  font-size: clamp(11px, 4cqw, 20px);
  font-weight: bold;
  letter-spacing: 3px;
  color: #ffd23f;
}

.overlay-text {
  max-width: 40ch;
  font-size: clamp(12px, 3.4vw, 15px);
  font-size: clamp(11px, 3.4cqw, 16px);
  line-height: 1.6;
  color: #c4cdf0;
  white-space: pre-line;
}

.overlay-hi {
  font-size: clamp(12px, 3.8cqw, 18px);
  font-weight: bold;
  letter-spacing: 2px;
  color: #5ef1ff;
}

.overlay-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.btn {
  min-width: 120px;
  min-height: 48px;
  padding: 10px 18px;
  font: inherit;
  font-size: clamp(15px, 4.4cqw, 18px);
  font-weight: bold;
  letter-spacing: 2px;
  color: #05060f;
  background: #5ef1ff;
  border: none;
  border-radius: 6px;
  box-shadow: 0 0 16px rgba(94, 241, 255, 0.45);
  cursor: pointer;
}

.btn-alt {
  color: #5ef1ff;
  background: transparent;
  border: 2px solid #5ef1ff;
  box-shadow: none;
}

.btn-danger {
  color: #ff6b84;
  background: transparent;
  border: 2px solid #ff3b5c;
  box-shadow: none;
}

/* Overlay moods: each screen gets its own look. */

.overlay[data-mood="title"] .overlay-title {
  font-size: clamp(26px, 13cqw, 64px);
  background: linear-gradient(90deg, #ff3b5c, #ff8a3d, #ffd23f, #3ddc84, #3dc8ff, #8a6bff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: none;
  filter: drop-shadow(0 0 10px rgba(255, 94, 232, 0.45));
}

.overlay[data-mood="title"] .btn:first-child {
  animation: pulse 1.6s ease-in-out infinite;
}

.overlay[data-mood="levelclear"] .overlay-title {
  color: #3ddc84;
  text-shadow: 0 0 6px #3ddc84, 0 0 22px rgba(61, 220, 132, 0.6);
}

.overlay[data-mood="win"] {
  background: rgba(5, 6, 15, 0.35);
}

.overlay[data-mood="win"] .overlay-text,
.overlay[data-mood="win"] .overlay-sub,
.overlay[data-mood="win"] .overlay-hi {
  text-shadow: 0 0 4px #05060f, 0 0 8px #05060f;
}

.overlay[data-mood="win"] .overlay-title {
  color: #ffd23f;
  text-shadow: 0 0 8px #ffd23f, 0 0 28px rgba(255, 190, 40, 0.8);
  animation: pulse 1.2s ease-in-out infinite;
}

.overlay[data-mood="gameover"] {
  background: rgba(20, 2, 8, 0.88);
}

.overlay[data-mood="gameover"] .overlay-title {
  animation: flicker 1.4s steps(1) 1;
}

@keyframes pulse {
  50% { transform: scale(1.06); }
}

@keyframes flicker {
  0%, 20%, 40% { opacity: 1; }
  10%, 30% { opacity: 0.2; }
}

/* Very short playfields (phones in landscape): drop the supplementary text so
   the buttons always fit. */
@container (max-height: 400px) {
  .overlay-text {
    display: none;
  }
}

/* High-score panel */

.panel {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding:
    max(12px, env(safe-area-inset-top))
    max(12px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
  overflow-y: auto;
  touch-action: pan-y;
  background: rgba(5, 6, 15, 0.92);
}

.panel[hidden] {
  display: none;
}

.panel-box {
  width: 100%;
  max-width: 420px;
  margin: auto;
  padding: 18px 16px;
  text-align: center;
  background: #0b0e22;
  border: 2px solid #2b3670;
  border-radius: 10px;
  box-shadow: 0 0 28px rgba(80, 120, 255, 0.25);
}

.panel-title {
  margin-bottom: 12px;
  font-size: 26px;
  letter-spacing: 3px;
  color: #ffd23f;
  text-shadow: 0 0 10px rgba(255, 210, 63, 0.6);
}

.panel-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.panel-view[hidden] {
  display: none;
}

.panel-text {
  font-size: 15px;
  line-height: 1.5;
  color: #c4cdf0;
}

.panel-label {
  font-size: 12px;
  letter-spacing: 2px;
  color: #8a94c2;
}

.name-input {
  width: 100%;
  max-width: 260px;
  min-height: 52px;
  padding: 8px 12px;
  /* 16px+ stops iOS zooming into the field. */
  font: inherit;
  font-size: 24px;
  font-weight: bold;
  letter-spacing: 4px;
  text-align: center;
  text-transform: uppercase;
  color: #ffd23f;
  background: #05060f;
  border: 2px solid #5ef1ff;
  border-radius: 6px;
  -webkit-user-select: text;
  user-select: text;
}

.name-input:focus {
  outline: 3px solid #ffd23f;
  outline-offset: 2px;
}

.panel-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 4px;
}

.panel .btn {
  font-size: 17px;
}

.score-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
}

.score-table th {
  padding: 4px;
  font-size: 11px;
  letter-spacing: 2px;
  color: #8a94c2;
  border-bottom: 1px solid #2b3670;
}

.score-table td {
  padding: 6px 4px;
  font-weight: bold;
  color: #e8f1ff;
}

.score-table td:nth-child(2) {
  text-align: left;
  letter-spacing: 1px;
}

.score-table td:nth-child(3) {
  text-align: right;
  color: #ffd23f;
}

.score-table td:nth-child(4) {
  font-size: 12px;
  font-weight: normal;
  color: #8a94c2;
}

.score-table tr.latest td {
  color: #05060f;
  background: #5ef1ff;
}

.score-table tr.empty td {
  padding: 18px 4px;
  font-weight: normal;
  color: #8a94c2;
}

.panel-note {
  font-size: 13px;
  color: #ff8a3d;
}

.panel-privacy {
  margin-top: 14px;
  font-size: 11px;
  letter-spacing: 1px;
  color: #6f7aa8;
}

/* Short screens (phones in landscape): compact the panel so a full table
   fits without scrolling. */
@media (max-height: 500px) {
  .panel-box {
    padding: 8px 14px;
  }

  .panel-title {
    margin-bottom: 4px;
    font-size: 18px;
  }

  .panel-view {
    gap: 6px;
  }

  .score-table {
    font-size: 13px;
  }

  .score-table th {
    padding: 1px 4px;
  }

  .score-table td {
    padding: 1px 4px;
  }

  .panel-buttons {
    margin-top: 0;
  }

  .panel .btn {
    min-height: 44px;
    padding: 6px 16px;
  }

  .panel-privacy {
    margin-top: 4px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .overlay-title,
  .btn {
    animation: none !important;
  }
}

/* Overlay buttons are only focused by keyboard use, so always show the ring. */
.btn:focus,
.hud-btn:focus-visible {
  outline: 3px solid #ffd23f;
  outline-offset: 3px;
}

/* Footer */

.controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 2px 16px;
  padding-top: 8px;
  font-size: 11px;
  letter-spacing: 1px;
  color: #8a94c2;
}

/* Phones held sideways: move the HUD and hints beside the playfield so the
   portrait game world can use the full screen height. */
@media (orientation: landscape) and (max-height: 560px) {
  .app {
    flex-direction: row;
    align-items: center;
    gap: 12px;
    max-width: none;
  }

  .hud {
    flex: 0 0 120px;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 0;
  }

  .hud-item {
    flex: none;
  }

  .hud-btn {
    align-self: flex-start;
  }

  .stage {
    height: 100%;
  }

  .controls {
    flex: 0 0 120px;
    flex-direction: column;
    gap: 8px;
    padding: 0;
    text-align: left;
  }
}
