/* SHRIMP RAID: page and UI styles. Owner: ui.
 *
 * Page structure this file expects (index.html is the conductor's):
 *   <body>
 *     <div id="stage" class="stage">
 *       <canvas id="game" width="180" height="320"></canvas>
 *       <div id="ui"></div>
 *     </div>
 *   </body>
 * initUI() sizes #stage (integer scale on desktop, fills the screen on phones) and sets --k, the CSS pixels per game pixel.
 * Everything inside #ui is laid out in game pixels (a 180x320 box scaled by --k), so DOM buttons line up with the canvas HUD.
 * Text in the UI is drawn with js/font.js onto small canvases, so the pixel look is the same everywhere.
 */

:root {
  --k: 2;
  --navy: #050d1c;
  --deep: #0a1c3c;
  --panel: #0f2a52;
  --panel-hi: #1d4a8c;
  --coral: #ff7a8f;
  --coral-hi: #ffb3c0;
  --coral-lo: #c24a63;
  --gold: #ffd23f;
  --green: #6fe38a;
  --red: #ff5a4d;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  background: #03070f;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* fallback size until initUI() runs */
.stage {
  position: relative;
  flex: none;
  overflow: hidden;
  background: #06142c;
  width: min(100vw, calc(100vh * 9 / 16));
  aspect-ratio: 9 / 16;
  touch-action: none;
}

.stage > canvas {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  image-rendering: -moz-crisp-edges;
  touch-action: none;
}

#ui {
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  overflow: hidden;
  pointer-events: none;
}

.ui-inner {
  position: absolute;
  left: 0;
  top: 0;
  width: 180px;
  height: 320px;
  transform: scale(var(--k));
  transform-origin: 0 0;
  font-size: 0;
  line-height: 0;
}

.ui-inner canvas,
.ui-inner .px {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  pointer-events: none;
}

/* ------------------------------------------------------------ screens */

.screen {
  position: absolute;
  left: 0;
  top: 0;
  width: 180px;
  height: 320px;
  display: none;
  flex-direction: column;
  align-items: center;
  pointer-events: auto;
}

.screen.on {
  display: flex;
  animation: screen-in 0.18s steps(3) both;
}

@keyframes screen-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.stack {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.col-gap-2 > * + * {
  margin-top: 2px;
}
.col-gap-3 > * + * {
  margin-top: 3px;
}
.col-gap-4 > * + * {
  margin-top: 4px;
}
.col-gap-6 > * + * {
  margin-top: 6px;
}

/* ------------------------------------------------------------ buttons */

.btn {
  pointer-events: auto;
  appearance: none;
  -webkit-appearance: none;
  border: 0;
  margin: 0;
  padding: 0 8px;
  font: inherit;
  cursor: pointer;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 24px;
  min-width: 24px;
  background: var(--coral);
  box-shadow: 0 0 0 1px var(--navy), inset 0 1px 0 var(--coral-hi), inset 0 -3px 0 var(--coral-lo);
  touch-action: manipulation;
  outline: none;
}

.btn:active,
.btn.down {
  transform: translateY(1px);
  box-shadow: 0 0 0 1px var(--navy), inset 0 3px 0 var(--coral-lo);
}

.btn:focus-visible {
  outline: 1px solid #fff;
  outline-offset: 2px;
}

.btn.big {
  height: 32px;
  min-width: 112px;
}

.btn.wide {
  width: 148px;
}

.btn.half {
  width: 72px;
  padding: 0 2px;
}

.btn.square {
  width: 22px;
  height: 22px;
  padding: 0;
  min-width: 22px;
}

.btn.blue {
  background: #2f6fd0;
  box-shadow: 0 0 0 1px var(--navy), inset 0 1px 0 #7db0f5, inset 0 -3px 0 #1b468c;
}
.btn.blue:active,
.btn.blue.down {
  box-shadow: 0 0 0 1px var(--navy), inset 0 3px 0 #1b468c;
}

.btn.dark {
  background: var(--panel);
  box-shadow: 0 0 0 1px var(--navy), inset 0 1px 0 var(--panel-hi), inset 0 -3px 0 #08183a;
}
.btn.dark:active,
.btn.dark.down {
  box-shadow: 0 0 0 1px var(--navy), inset 0 3px 0 #08183a;
}

.btn.gold {
  background: var(--gold);
  box-shadow: 0 0 0 1px var(--navy), inset 0 1px 0 #fff2a8, inset 0 -3px 0 #c8920a;
}
.btn.gold:active,
.btn.gold.down {
  box-shadow: 0 0 0 1px var(--navy), inset 0 3px 0 #c8920a;
}

.btn.locked {
  pointer-events: none;
  filter: saturate(0.4) brightness(0.8);
}

.btn.pulse {
  animation: pulse 0.9s steps(2) infinite;
}

@keyframes pulse {
  50% {
    transform: translateY(1px);
    filter: brightness(1.12);
  }
}

/* ------------------------------------------------------------ title */

.title {
  justify-content: flex-end;
  background: linear-gradient(to bottom, rgba(5, 13, 28, 0.7) 0, rgba(5, 13, 28, 0) 22%, rgba(5, 13, 28, 0) 38%, rgba(5, 13, 28, 0.82) 60%, rgba(5, 13, 28, 0.94) 100%);
  padding-bottom: 12px;
}

.title .mute-slot {
  position: absolute;
  right: 6px;
  top: 6px;
}

.title .logo-wrap {
  animation: bob 1.6s steps(4) infinite;
}

@keyframes bob {
  50% {
    transform: translateY(2px);
  }
}

.panel {
  background: rgba(15, 42, 82, 0.82);
  box-shadow: 0 0 0 1px var(--navy), inset 0 1px 0 rgba(125, 176, 245, 0.45);
  padding: 5px 8px 6px;
}

.title .boss-card {
  width: 148px;
  align-items: center;
}

.blink {
  animation: blink 0.8s steps(2) infinite;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

.flash {
  animation: flash 0.6s steps(2) infinite;
}

@keyframes flash {
  50% {
    filter: brightness(1.6);
  }
}

/* ------------------------------------------------------------ pause and results */

.dim {
  background: rgba(3, 8, 20, 0.78);
  justify-content: center;
}

.results {
  background: rgba(3, 8, 20, 0.84);
  justify-content: center;
}

.pop {
  animation: pop 0.35s steps(4) both;
}

@keyframes pop {
  from {
    transform: scale(0.4);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

.rank-badge {
  background: rgba(5, 13, 28, 0.75);
  padding: 4px 8px;
  box-shadow: 0 0 0 1px var(--navy), 0 0 0 3px currentColor;
}

.row {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
}
.row > * + * {
  margin-left: 4px;
}

/* ------------------------------------------------------------ run layer (touch buttons) */

.runlayer {
  position: absolute;
  left: 0;
  top: 0;
  width: 180px;
  height: 320px;
  display: none;
  pointer-events: none;
}
.runlayer.on {
  display: block;
}

/* the canvas HUD draws the meter under this button, so the hit area covers it */
.run-army {
  position: absolute;
  left: 64px;
  top: 288px;
  width: 114px;
  height: 30px;
  pointer-events: auto;
  background: transparent;
  border: 0;
  padding: 0;
  margin: 0;
  touch-action: none;
  outline: none;
}
.run-army:active {
  background: rgba(255, 255, 255, 0.12);
}
.run-army.ready {
  background: rgba(255, 210, 63, 0.1);
}

.run-pause {
  position: absolute;
  left: 2px;
  top: 2px;
  width: 22px;
  height: 22px;
  min-width: 22px;
  padding: 0;
  opacity: 0.85;
}

/* ------------------------------------------------------------ community panel, board, player form */

.title .boss-card {
  width: 160px;
  padding: 4px 6px 5px;
}

.between {
  justify-content: space-between;
  width: 148px;
}
.between > * + * {
  margin-left: 0;
}

.btn.mini {
  height: 16px;
  min-width: 40px;
  padding: 0 4px;
}

.board {
  justify-content: center;
}

.board-row {
  display: block;
  pointer-events: auto;
  text-decoration: none;
  height: 14px;
  background: rgba(15, 42, 82, 0.55);
  box-shadow: 0 0 0 1px rgba(5, 13, 28, 0.9);
  cursor: pointer;
  touch-action: manipulation;
}
.board-row:active {
  background: rgba(47, 111, 208, 0.6);
}
.board-row.empty {
  cursor: default;
  background: rgba(15, 42, 82, 0.25);
}
.board-rows > * + * {
  margin-top: 1px;
}

/* Text links drawn with the pixel font (RULES, EDIT) */
.linkbtn {
  pointer-events: auto;
  display: inline-block;
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  border: 0;
  padding: 3px 3px;
  margin: 0;
  cursor: pointer;
  text-decoration: none;
  touch-action: manipulation;
  outline: none;
}
.linkbtn:active {
  filter: brightness(1.5);
}
.linkbtn:focus-visible {
  outline: 1px solid #fff;
}

.form {
  width: 164px;
  padding: 4px 6px 5px;
  pointer-events: auto;
}

/* A real input is 16 px tall and drawn at half size, so phones do not zoom in when it gets focus. */
.field {
  position: relative;
  width: 148px;
  height: 13px;
  pointer-events: auto;
}
.field input {
  position: absolute;
  left: 0;
  top: 0;
  width: 296px;
  height: 26px;
  margin: 0;
  padding: 0 6px;
  transform: scale(0.5);
  transform-origin: 0 0;
  font: 700 16px/26px ui-monospace, 'Courier New', Consolas, monospace;
  letter-spacing: 1px;
  color: #ffffff;
  background: #050d1c;
  border: 2px solid #2f6fd0;
  border-radius: 0;
  outline: none;
  -webkit-user-select: text;
  user-select: text;
  -webkit-appearance: none;
  appearance: none;
  line-height: 22px;
  touch-action: manipulation;
}
.field input:focus {
  border-color: #ffd23f;
}
.field input::placeholder {
  color: #4a6a9a;
}
.field input.bad {
  border-color: #ff5a4d;
}

.results.form-open .ofl {
  display: none;
}
.results.form-open .resword-small {
  transform: scale(0.8);
}

/* ------------------------------------------------------------ misc */

@media (prefers-reduced-motion: reduce) {
  .blink,
  .flash,
  .pulse,
  .title .logo-wrap,
  .screen.on {
    animation: none;
  }
}
