/* Meatproxy War: page shell. The canvas is letterboxed at 16:9; everything else is drawn in code. */

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

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background: #1A1D21;
  color: #E8E8E6;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
}

#game {
  display: block;
  flex: none;
  width: min(100vw, calc(100vh * 16 / 9));
  height: min(100vh, calc(100vw * 9 / 16));
  /* dvh tracks the visible area as mobile browser bars show and hide. */
  width: min(100vw, calc(100dvh * 16 / 9));
  height: min(100dvh, calc(100vw * 9 / 16));
  background: #1A1D21;
  cursor: none;
  outline: none;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

/* Fallback: stays invisible while the game boots, appears if boot never finishes or fails. */
#fallback {
  position: fixed;
  left: 50%;
  top: 50%;
  width: min(560px, 88vw);
  transform: translate(-50%, -50%);
  padding: 24px 28px;
  background: #222529;
  border: 1px solid #35373B;
  border-left: 4px solid #E5383B;
  border-radius: 8px;
  line-height: 1.5;
  opacity: 0;
  pointer-events: none;
  animation: fallback-in 0.3s ease-out 2.5s forwards;
  -webkit-user-select: text;
  user-select: text;
}

#fallback h1 {
  margin: 0 0 8px;
  font-size: 20px;
}

#fallback p {
  margin: 8px 0 0;
  color: #9A9B9E;
  font-size: 14px;
}

#fallback code {
  padding: 1px 5px;
  background: #1A1D21;
  border-radius: 4px;
  color: #F2C744;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 13px;
}

#fallback-detail:empty {
  display: none;
}

body.failed #fallback {
  opacity: 1;
  pointer-events: auto;
  animation: none;
}

body.failed #game {
  cursor: default;
}

body.booted #fallback {
  display: none;
}

.noscript {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  padding: 16px;
  background: #222529;
  border-bottom: 2px solid #E5383B;
  text-align: center;
}

@keyframes fallback-in {
  to {
    opacity: 1;
    pointer-events: auto;
  }
}

/* Touch controls. Built by js/core/touch.js on the first touch, so none of this shows on desktop. */
html,
body {
  position: fixed;
  inset: 0;
}

#touch-ui,
#touch-hint,
#rotate {
  display: none;
}

body.touch[data-scene="playing"] #touch-ui {
  display: block;
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 5;
}

.stick {
  display: none;
  position: fixed;
  width: 108px;
  height: 108px;
  margin: -54px 0 0 -54px;
  border: 2px solid rgba(232, 232, 230, 0.28);
  border-radius: 50%;
  background: rgba(34, 37, 41, 0.35);
}

.stick i {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 46px;
  height: 46px;
  margin: -23px 0 0 -23px;
  border-radius: 50%;
  background: rgba(232, 232, 230, 0.5);
}

.stick.aim {
  border-color: rgba(242, 199, 68, 0.5);
}

.stick.aim i {
  background: rgba(242, 199, 68, 0.75);
}

.pad {
  position: fixed;
  right: max(8px, env(safe-area-inset-right));
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: auto;
}

.tbtn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 58px;
  height: 58px;
  border: 2px solid #F2C744;
  border-radius: 14px;
  background: rgba(43, 18, 48, 0.82);
  color: #E8E8E6;
  pointer-events: auto;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

.tbtn b {
  font-size: 22px;
  line-height: 1;
  font-weight: 400;
}

.tbtn span {
  margin-top: 3px;
  font-size: 9px;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.tbtn.cd {
  border-color: #35373B;
  opacity: 0.45;
}

.tbtn.ready {
  border-color: #2EB67D;
  box-shadow: 0 0 14px rgba(46, 182, 125, 0.7);
}

.tbtn.hit {
  transform: scale(0.9);
  background: rgba(242, 199, 68, 0.35);
}

.tbtn.pause {
  position: fixed;
  left: max(8px, env(safe-area-inset-left));
  top: max(8px, env(safe-area-inset-top));
  width: 44px;
  height: 44px;
  border-color: #35373B;
}

body.touch[data-scene="title"] #touch-hint {
  display: block;
  position: fixed;
  left: 50%;
  bottom: max(6px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: 96vw;
  padding: 6px 12px;
  border: 1px solid #35373B;
  border-radius: 999px;
  background: rgba(34, 37, 41, 0.94);
  color: #9A9B9E;
  font-size: 11px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 6;
}

#touch-hint b {
  color: #F2C744;
  font-weight: 600;
}

@media (orientation: portrait) {
  body.touch #rotate {
    display: flex;
    position: fixed;
    inset: 0;
    align-items: center;
    justify-content: center;
    background: #1A1D21;
    text-align: center;
    z-index: 10;
  }

  #rotate b {
    display: block;
    font-size: 64px;
    line-height: 1;
    color: #F2C744;
  }

  #rotate p {
    margin: 12px 0 4px;
    font-size: 20px;
    font-weight: 700;
  }

  #rotate span {
    color: #9A9B9E;
    font-size: 14px;
  }
}

/* How-to-play briefing, shown before each run. Built by js/core/howto.js. */
#howto {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 8;
  align-items: center;
  justify-content: center;
  padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  background: rgba(15, 16, 19, 0.86);
  cursor: default;
}

#howto.open {
  display: flex;
}

.howto-card {
  width: min(880px, 100%);
  max-height: 100%;
  overflow: auto;
  padding: clamp(12px, 2.4vh, 26px) clamp(14px, 2.4vw, 30px);
  background: #222529;
  border: 1px solid #35373B;
  border-top: 4px solid #F2C744;
  border-radius: 12px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}

.howto-tag {
  color: #F2C744;
  font: 700 11px ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  letter-spacing: 0.12em;
}

.howto-head h2 {
  margin: 2px 0 2px;
  font-size: clamp(20px, 3.6vh, 30px);
  line-height: 1.1;
}

.howto-head p {
  margin: 0;
  color: #9A9B9E;
  font-size: clamp(12px, 2vh, 15px);
}

.howto-steps {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: clamp(6px, 1vw, 12px);
  margin: clamp(8px, 1.8vh, 16px) 0;
  padding: 0;
  list-style: none;
  counter-reset: step;
}

.howto-steps li {
  position: relative;
  padding: 10px 10px 10px;
  background: #1A1D21;
  border: 1px solid #35373B;
  border-radius: 10px;
  counter-increment: step;
}

.howto-steps li::before {
  content: counter(step);
  position: absolute;
  top: -8px;
  left: -6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #F2C744;
  color: #151312;
  font: 700 12px/20px ui-monospace, Menlo, monospace;
  text-align: center;
}

.howto-steps .demo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  margin-bottom: 6px;
  font-size: 18px;
}

.howto-steps b {
  display: block;
  font-size: clamp(12px, 1.9vh, 14px);
}

.howto-steps em {
  display: block;
  margin-top: 3px;
  color: #9A9B9E;
  font-size: clamp(10.5px, 1.7vh, 12.5px);
  font-style: normal;
  line-height: 1.35;
}

.bub {
  padding: 5px 10px;
  border-radius: 11px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.bub.slop {
  background: #8B7CF6;
  color: #fff;
}

.bub.bogus {
  background: #D946EF;
  color: #fff;
  box-shadow: -3px 0 0 #36C5F0, 3px 0 0 #FF5C7A;
}

.bub.chip {
  background: #F2C744;
  color: #151312;
  border-radius: 6px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

.dots {
  display: inline-flex;
  gap: 4px;
  padding: 8px 10px;
  background: #35373B;
  border-radius: 11px;
}

.dots i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #E8E8E6;
  animation: howto-dot 0.9s infinite ease-in-out;
}

.dots i:nth-child(2) { animation-delay: 0.15s; }
.dots i:nth-child(3) { animation-delay: 0.3s; }

@keyframes howto-dot {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.howto-controls {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 5px 18px;
}

.howto-controls div {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  font-size: clamp(11px, 1.8vh, 13.5px);
}

.howto-controls span {
  margin-left: 4px;
  color: #E8E8E6;
}

kbd {
  flex: none;
  padding: 2px 7px;
  background: #1A1D21;
  border: 1px solid #55585e;
  border-bottom-width: 2px;
  border-radius: 5px;
  color: #F2C744;
  font: 700 11px ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  white-space: nowrap;
}

.howto-foot {
  margin: clamp(8px, 1.6vh, 14px) 0 0;
  color: #9A9B9E;
  font-size: clamp(11px, 1.8vh, 13px);
}

.howto-go {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: clamp(8px, 1.8vh, 16px);
}

.howto-btn {
  padding: clamp(8px, 1.6vh, 12px) 22px;
  background: #2EB67D;
  border-radius: 9px;
  color: #0f1512;
  font-size: clamp(13px, 2.2vh, 16px);
  font-weight: 800;
}

.howto-go small {
  color: #9A9B9E;
  font-size: 12px;
}

.only-touch { display: none; }
body.touch .only-touch { display: revert; }
body.touch .howto-controls.only-touch { display: grid; }
body.touch .only-desktop { display: none; }
body.touch #howto.open ~ #touch-hint,
body.touch:has(#howto.open) #touch-hint { display: none; }

@media (max-height: 460px) {
  .howto-steps .demo { height: 26px; margin-bottom: 3px; }
  .howto-steps li { padding: 7px 8px; }
  .howto-controls { grid-template-columns: repeat(3, 1fr); gap: 4px 10px; }
  .howto-head p { display: none; }
}

@media (max-width: 620px) {
  .howto-steps { grid-template-columns: repeat(2, 1fr); }
  .howto-controls { grid-template-columns: 1fr; }
}
