:root {
  --ink: #1b1b1b;
  --paper: #fdfcf6;
  --font: 'Comic Sans MS', 'Chalkboard SE', 'Trebuchet MS', Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  user-select: none;
}

[hidden] {
  display: none !important;
}

#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

/* Hand-drawn box: uneven corner radii. */
.panel {
  background: var(--paper);
  border: 2.5px solid var(--ink);
  border-radius: 255px 15px 225px 15px / 15px 225px 15px 255px;
  box-shadow: 3px 4px 0 rgba(0, 0, 0, 0.15);
}

#feed {
  position: fixed;
  top: 10px;
  left: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
  max-width: min(46vw, 460px);
  pointer-events: none;
}

#feed li {
  margin-bottom: 4px;
  padding: 2px 8px;
  width: fit-content;
  background: rgba(253, 252, 246, 0.85);
  border-bottom: 2px solid var(--ink);
  font-size: 14px;
  overflow-wrap: anywhere;
}

#feed li.old {
  opacity: 0;
  transition: opacity 0.8s;
}

#board {
  position: fixed;
  top: 10px;
  right: 12px;
  width: 240px;
  padding: 8px 14px 10px;
  pointer-events: none;
}

#board h2 {
  margin: 0 0 4px;
  font-size: 15px;
  text-decoration: underline wavy;
}

#board ol {
  margin: 0;
  padding-left: 22px;
  font-size: 14px;
}

#board li {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#board .k {
  float: right;
  margin-left: 8px;
  font-weight: bold;
}

#board .empty {
  list-style: none;
  margin-left: -22px;
  font-size: 12px;
  opacity: 0.7;
}

#minimap {
  position: fixed;
  right: 12px;
  bottom: 52px;
  width: 150px;
  height: 150px;
  pointer-events: none;
}

#storm-info {
  position: fixed;
  right: 12px;
  bottom: 28px;
  width: 150px;
  margin: 0;
  text-align: center;
  font-size: 13px;
  white-space: nowrap;
}

/* Position and players online, under the minimap. */
#where {
  position: fixed;
  right: 12px;
  bottom: 8px;
  width: 260px;
  margin: 0;
  text-align: right;
  font-size: 12px;
  opacity: 0.75;
  white-space: nowrap;
}

/* The player's own row: highlighted in the top 10, or added under it. */
#board li.me {
  background: rgba(255, 214, 64, 0.55);
  border-radius: 4px;
  font-weight: bold;
}

#board li.me.out {
  margin-top: 4px;
  outline: 1.5px dashed rgba(0, 0, 0, 0.4);
}

#status {
  position: fixed;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 18px;
  font-size: 15px;
  white-space: nowrap;
}

#hp-bar {
  position: relative;
  width: 170px;
  height: 20px;
  border: 2px solid var(--ink);
  border-radius: 6px 3px 7px 4px;
  overflow: hidden;
}

#hp-fill {
  height: 100%;
  width: 100%;
  background: #666;
}

#hp-text {
  position: absolute;
  inset: 0;
  text-align: center;
  font-size: 13px;
  line-height: 17px;
  color: var(--ink);
  text-shadow: 0 0 3px var(--paper), 0 0 3px var(--paper);
}

#dash.cooling {
  opacity: 0.45;
}

#storm-warning {
  position: fixed;
  left: 50%;
  top: 18%;
  transform: translateX(-50%) rotate(-2deg);
  margin: 0;
  padding: 6px 16px;
  background: var(--ink);
  color: var(--paper);
  font-size: 20px;
  font-weight: bold;
  white-space: nowrap;
}

#menu {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) rotate(-1deg);
  width: min(92vw, 380px);
  padding: 22px 28px 16px;
  text-align: center;
}

#menu h1 {
  margin: 0 0 12px;
  font-size: 28px;
  text-decoration: underline wavy;
  text-underline-offset: 6px;
}

#death {
  margin: 0 0 12px;
  font-size: 15px;
  overflow-wrap: anywhere;
}

#name,
#play {
  width: 100%;
  padding: 9px 12px;
  font: inherit;
  font-size: 18px;
  color: var(--ink);
  border: 2.5px solid var(--ink);
  border-radius: 12px 4px 14px 5px;
  user-select: text;
}

#name {
  background: #fff;
  text-align: center;
}

#play {
  margin-top: 10px;
  background: var(--ink);
  color: var(--paper);
  font-weight: bold;
  cursor: pointer;
}

#play:disabled {
  opacity: 0.5;
  cursor: wait;
}

#error {
  min-height: 20px;
  margin: 8px 0 0;
  font-size: 14px;
  font-weight: bold;
}

.help {
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
  text-align: left;
  font-size: 13.5px;
  line-height: 1.6;
}

.tip {
  margin: 8px 0 0;
  font-size: 12.5px;
  line-height: 1.5;
  opacity: 0.75;
}

/* ---- hints: keyboard by default, touch hint on touch devices ---- */
.touch-help {
  display: none;
}

body.touch .kb-help {
  display: none;
}

body.touch .touch-help {
  display: block;
}

#name,
#play {
  touch-action: manipulation;
}

/* ---- touch controls ---- */
#touch {
  position: fixed;
  inset: 0;
  pointer-events: none;
  -webkit-user-select: none;
}

#joy-zone {
  position: absolute;
  left: 0;
  top: 0;
  width: 50%;
  height: 100%;
  pointer-events: auto;
  touch-action: none;
}

#joy {
  position: fixed;
  width: 112px;
  height: 112px;
  margin: -56px 0 0 -56px;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background: rgba(253, 252, 246, 0.55);
  pointer-events: none;
}

#joy-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--ink);
  opacity: 0.8;
  transform: translate(-50%, -50%);
}

#touch button {
  position: absolute;
  pointer-events: auto;
  touch-action: none;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background: rgba(253, 252, 246, 0.8);
  color: var(--ink);
  font: inherit;
  font-weight: bold;
  box-shadow: 3px 4px 0 rgba(0, 0, 0, 0.18);
  -webkit-user-select: none;
  user-select: none;
}

#touch button.down {
  background: var(--ink);
  color: var(--paper);
}

#btn-attack {
  right: calc(18px + env(safe-area-inset-right));
  bottom: calc(86px + env(safe-area-inset-bottom));
  width: 104px;
  height: 104px;
  font-size: 22px;
}

#btn-dash {
  right: calc(134px + env(safe-area-inset-right));
  bottom: calc(60px + env(safe-area-inset-bottom));
  width: 78px;
  height: 78px;
  font-size: 16px;
}

/* A phone has less room: slimmer panels, the minimap tucked under the leaderboard. */
body.touch #board {
  width: 150px;
  padding: 6px 10px 8px;
  top: calc(8px + env(safe-area-inset-top));
  right: calc(8px + env(safe-area-inset-right));
}

body.touch #board h2 {
  font-size: 13px;
}

body.touch #board ol {
  font-size: 12px;
}

/* The minimap sits under the board on a phone: top 5 plus the player's own row. */
body.touch #board li:nth-child(n + 6):not(.me) {
  display: none;
}

body.touch #board .k small {
  display: none;
}

body.touch #board li:nth-child(n + 7) {
  display: none;
}

body.touch #feed {
  top: calc(8px + env(safe-area-inset-top));
  left: calc(8px + env(safe-area-inset-left));
  max-width: 42vw;
}

body.touch #feed li {
  font-size: 12px;
}

body.touch #minimap {
  top: calc(150px + env(safe-area-inset-top));
  right: calc(8px + env(safe-area-inset-right));
  bottom: auto;
  width: 86px;
  height: 86px;
}

body.touch #where {
  display: none; /* no room on a phone */
}

body.touch #storm-info {
  top: calc(240px + env(safe-area-inset-top));
  bottom: auto;
  right: calc(8px + env(safe-area-inset-right));
  width: 86px;
  font-size: 11px;
}

body.touch #status {
  width: max-content; /* left: 50% would otherwise cap the width at half the screen */
  bottom: calc(8px + env(safe-area-inset-bottom));
  max-width: 96vw;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 10px;
  padding: 5px 12px;
  font-size: 13px;
}

body.touch #dash {
  display: none;
}

#touch button.cooling {
  opacity: 0.5;
}

body.touch #hp-bar {
  width: 120px;
}

body.touch #storm-warning {
  top: 12%;
  max-width: 92vw;
  white-space: normal;
  text-align: center;
  font-size: 16px;
}

/* Short landscape screens: the name screen must still fit. */
@media (max-height: 520px) {
  #menu {
    padding: 10px 18px 8px;
    max-height: 96vh;
    overflow: auto;
    touch-action: pan-y;
  }

  #menu h1 {
    font-size: 20px;
    margin-bottom: 6px;
  }

  .help,
  .tip {
    font-size: 11.5px;
    line-height: 1.4;
  }

  /* Landscape: the right edge belongs to the buttons, so the minimap moves to the left. */
  body.touch #minimap {
    top: auto;
    right: auto;
    left: calc(8px + env(safe-area-inset-left));
    bottom: calc(26px + env(safe-area-inset-bottom));
  }

  body.touch #storm-info {
    top: auto;
    right: auto;
    left: calc(8px + env(safe-area-inset-left));
    bottom: calc(8px + env(safe-area-inset-bottom));
  }
}

/* sound controls */
.sound { position: fixed; z-index: 5; left: calc(10px + env(safe-area-inset-left)); bottom: calc(10px + env(safe-area-inset-bottom)); padding: 2px 6px; pointer-events: auto; }
.sound button, .sound-row button { background: none; border: 0; font-size: 20px; cursor: pointer; min-width: 36px; min-height: 36px; }
.sound-row { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 8px; font-size: 14px; flex-wrap: wrap; }
.sound-row input[type='range'] { width: 90px; vertical-align: middle; }
