*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #060a13;
  color: #e2e8f0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  padding: 4px 8px;
  gap: 4px;
  background: radial-gradient(circle at 50% 20%, #0f172a 0%, #060a13 85%);
}

#app:fullscreen,
#app:-webkit-full-screen,
body[data-fullscreen="1"] #app {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: 9999;
  padding: 8px 14px;
  background: #050811;
}

#hud {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 4px 10px;
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid rgba(56, 189, 248, 0.28);
  border-radius: 7px;
}

.hud-cell {
  display: flex;
  flex-direction: column;
  min-width: 84px;
  gap: 1px;
}

.hud-label {
  font-size: 8.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #94a3b8;
}

.hud-cell strong {
  font-size: 11px;
  font-weight: 800;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  color: #f8fafc;
  white-space: nowrap;
}

.hud-flood-cell {
  min-width: 126px;
}

.hud-flood-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 6px;
}

.flood-meter {
  width: 100%;
  height: 6px;
  background: #0f172a;
  border: 1px solid #1e293b;
  border-radius: 999px;
  overflow: hidden;
  margin-top: 2px;
}

.flood-bar {
  height: 100%;
  background: linear-gradient(90deg, #10b981, #00f5d4);
  transition: width 120ms linear;
}

body[data-flood-active="1"] .flood-bar {
  background: linear-gradient(90deg, #f59e0b, #ef4444);
}

.btn-exit-fs {
  background: rgba(220, 38, 38, 0.22);
  border: 1px solid #f87171;
  color: #fecaca;
  font-size: 10.5px;
  font-weight: 800;
  padding: 3px 9px;
  border-radius: 6px;
  cursor: pointer;
}

.btn-exit-fs:hover {
  background: rgba(220, 38, 38, 0.4);
}

#stage {
  position: relative;
  container-type: size;
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 48px;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

#game {
  display: block;
  width: min(100cqw, calc(100cqh * 16 / 9));
  height: min(100cqh, calc(100cqw * 9 / 16));
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 960 / 540;
  background: #090e1a;
  border: 1.5px solid rgba(0, 245, 212, 0.38);
  border-radius: 6px;
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.65);
  outline: none;
  cursor: crosshair;
}

#game:focus-visible {
  border-color: #00f5d4;
  box-shadow: 0 0 0 2px rgba(0, 245, 212, 0.45);
}

#panel {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 5px 8px;
  background: rgba(15, 23, 42, 0.94);
  border: 1px solid rgba(56, 189, 248, 0.25);
  border-radius: 7px;
}

.control-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 5px;
}

.btn-group {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

button {
  appearance: none;
  background: #1e293b;
  color: #e2e8f0;
  border: 1px solid #334155;
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 10.5px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 120ms ease, border-color 120ms ease;
}

button:hover:not(:disabled) {
  background: #334155;
  border-color: #38bdf8;
}

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

button[aria-pressed="true"] {
  background: rgba(16, 185, 129, 0.24);
  border-color: #10b981;
  color: #ecfdf5;
}

.btn-primary {
  background: #059669;
  border-color: #34d399;
  color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
  background: #10b981;
}

.touch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.dpad,
.tactical-pad {
  display: flex;
  gap: 4px;
}

.btn-fire {
  background: rgba(239, 68, 68, 0.26);
  border-color: #f87171;
  color: #fee2e2;
}

.hint {
  font-size: 9.5px;
  color: #94a3b8;
  text-align: center;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

kbd {
  display: inline-block;
  padding: 0 3px;
  font-size: 9px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: #e2e8f0;
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 3px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Ultra-compact mode for 16:9 landscape iframe embedded on a phone screen */
@media (max-height: 360px), (max-width: 640px) {
  #app {
    padding: 2px 4px;
    gap: 2px;
  }
  #hud {
    padding: 2px 4px;
    gap: 4px;
    flex-wrap: nowrap;
    overflow-x: auto;
  }
  .hud-cell {
    min-width: 0;
  }
  .hud-label {
    display: none;
  }
  .hud-cell strong {
    font-size: 8.5px;
  }
  .hud-flood-cell {
    min-width: 58px;
  }
  .flood-meter {
    height: 4px;
  }
  #panel {
    padding: 2px 4px;
    gap: 2px;
  }
  .control-row,
  .touch-row,
  .btn-group,
  .dpad,
  .tactical-pad {
    flex-wrap: nowrap;
    gap: 2px;
    overflow-x: auto;
  }
  button {
    padding: 1px 4px;
    font-size: 8px;
    border-radius: 4px;
  }
  .hint {
    display: none;
  }
}
