:root {
  --bg: #05060a;
  --panel: #10141f;
  --panel-2: #171d2d;
  --line: #262f45;
  --text: #dfe6f5;
  --dim: #7a86a3;
  --accent: #f2b53b;
  --accent-2: #58c2ff;
  --danger: #ff5470;
  --shadow: 0 10px 30px rgba(0, 0, 0, .55);
  --pad: 10px;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  touch-action: manipulation;
}

body {
  display: flex;
  justify-content: center;
  background:
    radial-gradient(120% 80% at 50% 0%, #141a2b 0%, #05060a 60%),
    var(--bg);
}

#app {
  width: 100%;
  max-width: 720px;
  display: flex;
  flex-direction: column;
  gap: var(--pad);
  padding: max(var(--pad), env(safe-area-inset-top)) var(--pad) max(var(--pad), env(safe-area-inset-bottom));
  /* A definite height all the way down, so the play field can be measured and
     sized to fill whatever is left between the HUD and the buttons. */
  height: 100%;
  height: 100dvh;
  overflow: hidden;
}

/* ---------------------------------------------------------------- HUD */
#hud {
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
  flex: 0 0 auto;
}

.hud-row { display: flex; align-items: center; gap: 14px; padding: 8px 12px; }
.hud-main { border-bottom: 1px solid var(--line); }

.stat { display: flex; flex-direction: column; line-height: 1.1; }
.stat-right { margin-left: auto; text-align: right; }
.stat-label,
.gear-label {
  font-size: 9px;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--dim);
}
.stat-value {
  font-size: 19px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: .06em;
}
.stat-value.dim { color: var(--dim); font-size: 15px; }
.stat-value.accent { color: var(--accent); }

.hud-gear { gap: 12px; flex-wrap: wrap; }
.gear { display: flex; flex-direction: column; gap: 4px; }
/* A light chip behind the sprite icons: most of the artwork is black line work
   that would disappear against the dark panel. */
.icons {
  display: flex; align-items: center; gap: 4px;
  height: 22px; padding: 2px 5px;
  background: #cfd8ea;
  border: 1px solid #8b98b5;
  border-radius: 5px;
}
.icons canvas { image-rendering: pixelated; display: block; }
.icons .more { font-size: 11px; font-weight: 700; color: #2a3348; align-self: center; }

.chevrons { font-size: 11px; color: var(--accent-2); letter-spacing: -1px; height: 20px; line-height: 20px; }

.shield .bar {
  width: 74px; height: 8px;
  background: #0a0e18;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 5px;
}
.shield .bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #3aa0ff, #8fd6ff);
  transition: width .12s linear;
}
.shield.off { opacity: .35; }

.badges { margin-left: auto; display: flex; gap: 6px; }
.badge {
  display: flex; align-items: baseline; gap: 6px;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 10px;
  letter-spacing: .1em;
  border: 1px solid transparent;
}
.badge-value { font-weight: 700; font-variant-numeric: tabular-nums; }
.badge.freeze { color: #9fe4ff; background: rgba(60, 160, 255, .12); border-color: rgba(60, 160, 255, .4); }
.badge.power { color: #ffd479; background: rgba(242, 181, 59, .12); border-color: rgba(242, 181, 59, .4); }

/* ------------------------------------------------------------- Screen */
#stagearea {
  position: relative;
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  overflow: hidden;
}

#viewport {
  position: relative;
  width: 100%;
  /* Overwritten from JS whenever the number of visible map rows changes. */
  aspect-ratio: 256 / 176;
  max-height: 100%;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  box-shadow: var(--shadow), inset 0 0 0 1px rgba(255, 255, 255, .03);
  background: #000;
}

#screen {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* ------------------------------------------------- Touch: point to move */
#touch-move {
  position: absolute;
  inset: 0;
  z-index: 2;
  touch-action: none;
}

/* Reticle for where the knight is being sent. It sits a good distance ahead of
   the finger, so it is drawn as a hollow halo that frames him rather than a
   marker that would cover him up. */
#target {
  position: absolute;
  width: 36px; height: 36px;
  margin: -18px 0 0 -18px;
  z-index: 2;
  border-radius: 50%;
  border: 2px solid rgba(242, 181, 59, .7);
  box-shadow: 0 0 12px rgba(242, 181, 59, .45);
  opacity: 0;
  transform: scale(1.5);
  transition: opacity .14s ease, transform .14s ease;
  pointer-events: none;
}
#target.on { opacity: 1; transform: scale(1); }

/* ------------------------------------------------------------ Overlay */
#overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background:
    radial-gradient(90% 60% at 50% 12%, rgba(242, 181, 59, .10), transparent 70%),
    linear-gradient(180deg, rgba(5, 6, 10, .93), rgba(5, 6, 10, .985));
  backdrop-filter: blur(3px);
  overflow: auto;
  overscroll-behavior: contain;
}
#overlay.visible { display: flex; }

.title-card { text-align: center; width: 100%; max-width: 430px; margin: auto; }
.wordmark {
  image-rendering: pixelated;
  width: min(430px, 100%);
  height: auto;
  filter: drop-shadow(0 0 14px rgba(242, 181, 59, .35));
}
.logo { image-rendering: pixelated; width: min(150px, 42%); height: auto; opacity: .5; margin-top: 10px; }
.tag { font-size: 9px; color: var(--dim); line-height: 1.6; margin: 10px 0 16px; }

button.primary {
  font: inherit;
  font-weight: 700;
  letter-spacing: .18em;
  color: #1a1305;
  background: linear-gradient(180deg, #ffd873, var(--accent));
  border: 0;
  border-radius: 10px;
  padding: 11px 26px;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(242, 181, 59, .3);
}
button.primary:active { transform: translateY(1px); }

.options { display: grid; gap: 8px; margin: 16px 0 12px; text-align: left; }
.opt { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.opt-label { font-size: 10px; letter-spacing: .14em; text-transform: uppercase; color: var(--dim); }

.seg, .stepper { display: flex; gap: 4px; }
.seg button, .stepper button, .stepper span {
  font: inherit;
  font-size: 11px;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 5px 10px;
  cursor: pointer;
}
.stepper span { min-width: 34px; text-align: center; cursor: default; }
.seg button.on { background: rgba(242, 181, 59, .16); border-color: var(--accent); color: var(--accent); }

.hint { font-size: 9px; color: var(--dim); margin-top: 6px; line-height: 1.6; }

#boot {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  letter-spacing: .2em;
  color: var(--dim);
  background: #000;
}

/* ----------------------------------------------------------- Controls */
#controls {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.ctl, .fire {
  font: inherit;
  font-size: 11px;
  letter-spacing: .1em;
  color: var(--text);
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
}
.ctl.on { color: var(--accent); border-color: var(--accent); background: rgba(242, 181, 59, .12); }
.ctl:active, .fire:active { transform: translateY(1px); }

.fire {
  margin-left: auto;
  font-weight: 700;
  letter-spacing: .16em;
  color: #2a0d13;
  background: linear-gradient(180deg, #ff8298, var(--danger));
  border-color: #ff8298;
  padding: 10px 26px;
  touch-action: none;
}

@media (max-width: 560px) {
  :root { --pad: 6px; }
  /* Picture at the top, thumb strip underneath. */
  #stagearea { align-items: flex-start; }
  .stat-value { font-size: 16px; }
  .stat-value.dim { font-size: 13px; }
  .hud-row { gap: 10px; padding: 7px 10px; }
  .hud-gear { gap: 10px; }
  .shield .bar { width: 56px; }
  .badges { width: 100%; margin-left: 0; }
  .ctl { padding: 8px 9px; min-width: 40px; min-height: 40px; }
  .fire { padding: 8px 18px; }
  #controls { gap: 6px; }
}

@media (orientation: landscape) and (max-height: 520px) {
  #app { max-width: none; flex-direction: row; align-items: stretch; }
  #hud { width: 148px; flex: 0 0 auto; }
  .hud-row { flex-direction: column; align-items: flex-start; }
  .hud-main { border-bottom: 1px solid var(--line); }
  .stat-right { margin-left: 0; text-align: left; }
  .badges { margin-left: 0; }
  #controls { flex-direction: column; width: 74px; flex: 0 0 auto; }
  .hud-row { padding: 6px 9px; gap: 8px; }
  .stat-value { font-size: 15px; }
  .fire { margin-left: 0; margin-top: auto; width: 100%; }
  .ctl { width: 100%; }
  #viewport { max-height: 100%; }
}
