/* Armagetron Advanced, browser port. Copyright (C) 2026 Andreas Nägeli.
   Based on Armagetron Advanced, Copyright (C) Manuel Moos and the Armagetron Advanced team.
   GNU GPL version 2 or later, see COPYING.txt. Source: https://github.com/Kaliumhexacyanoferrat/armagetron-advanced-browser */

/* The look of the original's menus: black, the slowly drifting grid, titles in
   periwinkle (.6,.6,1), items in white, the selected one a pulsing red (.8,.3,.3). */

@font-face {
  font-family: Armagetronad;
  src: url(../fonts/Armagetronad.ttf) format("truetype");
  font-display: swap;
}

:root {
  color-scheme: dark;
  --title: #9999ff;
  --ink: #f2f2f7;
  --dim: #9a9ab8;
  --panel: rgba(6, 7, 20, 0.78);
  --line: rgba(153, 153, 255, 0.28);
  --red: #cc4d4d;
  --red-hot: #ff6464;
  --good: #55ee77;
  --bad: #ff6060;
  --font-game: Armagetronad, "DejaVu Sans Mono", "Menlo", monospace;
  --font-text: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #000;
  color: var(--ink);
  font: 15px/1.5 var(--font-text);
}

a { color: var(--title); }

[hidden] { display: none !important; }

h1, h2, h3 {
  font-family: var(--font-game);
  font-weight: normal;
  color: var(--title);
  letter-spacing: 0.02em;
}

.dim { color: var(--dim); }
.small { font-size: 0.85rem; }

#grid {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
}

/* ------------------------------------------------------------ buttons, inputs */

button {
  font: inherit;
  font-family: var(--font-game);
  color: var(--ink);
  background: rgba(20, 22, 50, 0.85);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.45rem 1rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

button:hover, button:focus-visible {
  border-color: var(--title);
  outline: none;
  color: #fff;
}

button.primary {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
  animation: throb 0.63s ease-in-out infinite alternate;
}

button.primary:hover { background: var(--red-hot); border-color: var(--red-hot); }

button.danger { background: #8a2020; border-color: #c33; }

button.big { font-size: 1.15rem; padding: 0.7rem 1.4rem; }

button.small-button { font-size: 0.8rem; padding: 0.25rem 0.6rem; }

@keyframes throb {
  from { filter: brightness(0.85); }
  to { filter: brightness(1.2); }
}

input, select {
  font: inherit;
  color: var(--ink);
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.45rem 0.6rem;
}

input:focus, select:focus { outline: none; border-color: var(--title); }

input[type=range] { padding: 0; accent-color: var(--title); }
input[type=checkbox] { accent-color: var(--title); }

kbd {
  font: 0.8rem var(--font-game);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0.05rem 0.35rem;
  background: rgba(255, 255, 255, 0.05);
}

/* ------------------------------------------------------------ the front page */

#lobby {
  position: relative;
  z-index: 1;
  max-width: 76rem;
  margin: 0 auto;
  padding: 1.5rem 1rem 2rem;
  min-height: 100%;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 26rem) minmax(0, 1fr);
  gap: 2rem;
  align-items: center;
  margin-bottom: 1.5rem;
}

.hero img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--line);
  box-shadow: 0 0 60px rgba(90, 90, 255, 0.25);
}

.hero h1 {
  font-size: clamp(2rem, 4.5vw, 3.4rem);
  line-height: 1.1;
  margin: 0 0 0.5rem;
  text-shadow: 0 0 24px rgba(120, 120, 255, 0.55);
}

.hero p { font-size: 1.1rem; max-width: 36rem; }

.actions { display: flex; gap: 0.75rem; flex-wrap: wrap; align-items: center; margin: 1rem 0; }
.actions.right { justify-content: flex-end; margin-bottom: 0; }

.lobby-grid {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
  grid-template-areas: "servers profile" "servers howto";
  gap: 1rem;
}

#servers-panel { grid-area: servers; }
#profile { grid-area: profile; }
#howto { grid-area: howto; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1rem 1.2rem;
  backdrop-filter: blur(3px);
}

.panel h2 { margin: 0 0 0.6rem; font-size: 1.3rem; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; }

.servers { display: grid; gap: 0.5rem; }

.server {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 1rem;
  align-items: center;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
}

.server:hover { border-color: var(--title); }
.server .title { font-family: var(--font-game); font-size: 1.05rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.server .meta { font-size: 0.85rem; color: var(--dim); }
.server .count { font-family: var(--font-game); text-align: right; white-space: nowrap; }
.server .count small { display: block; font-family: var(--font-text); color: var(--dim); }
.server .lock { color: #ffd479; }
.server.mine { border-color: rgba(255, 212, 121, 0.5); }
.server.idle { opacity: 0.7; }
.server.idle:focus-within, .server.idle:hover { opacity: 1; }
.servers .more { text-align: center; margin: 0.3rem 0 0; }

.empty-list { padding: 1.2rem; text-align: center; color: var(--dim); border: 1px dashed var(--line); border-radius: 8px; }

.field { display: grid; gap: 0.3rem; margin-bottom: 0.8rem; }
.field > span { font-size: 0.85rem; color: var(--dim); }
.field.inline { grid-template-columns: 7rem 1fr; align-items: center; }

.color-row { display: flex; gap: 1rem; align-items: center; }
#swatch { width: 96px; height: 96px; border-radius: 8px; border: 1px solid var(--line); background: #000; }
.sliders { display: grid; gap: 0.3rem; flex: 1; }
.sliders label { display: grid; grid-template-columns: 1.2rem 1fr; align-items: center; font-family: var(--font-game); }
.presets { display: flex; gap: 0.35rem; flex-wrap: wrap; margin-top: 0.4rem; }
.presets button { width: 1.8rem; height: 1.8rem; padding: 0; border-radius: 50%; }
.presets button:focus-visible { outline: 2px solid var(--title); outline-offset: 2px; }
.presets .dice { background: conic-gradient(#f33, #ff3, #3f3, #3ff, #33f, #f3f, #f33); color: #000; font-family: var(--font-game); font-weight: bold; }
.server:focus-within { border-color: var(--title); }

.keys { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.keys td { padding: 0.2rem 0; vertical-align: top; }
.keys td:first-child { white-space: nowrap; padding-right: 0.8rem; }

footer { margin-top: 1.5rem; text-align: center; color: var(--dim); font-size: 0.85rem; }

@media (max-width: 860px) {
  .hero { grid-template-columns: 1fr; }
  .hero img { max-height: 16rem; aspect-ratio: auto; object-position: center 20%; }
  .lobby-grid { grid-template-columns: 1fr; grid-template-areas: "servers" "profile" "howto"; }
}

/* ------------------------------------------------------------ dialogs */

dialog {
  color: var(--ink);
  background: rgba(8, 9, 26, 0.96);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1.2rem 1.4rem;
  width: min(34rem, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  box-shadow: 0 0 80px rgba(80, 80, 255, 0.25);
}

dialog.wide { width: min(60rem, calc(100vw - 2rem)); }
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog h2 { margin: 0 0 0.6rem; }
dialog h3 { margin: 1rem 0 0.4rem; font-size: 1.05rem; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 1rem; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid .hint { font-size: 0.75rem; color: var(--dim); }

.tabs { display: grid; grid-template-columns: repeat(auto-fit, minmax(22rem, 1fr)); gap: 1.5rem; }

.error { color: var(--bad); min-height: 1.4em; margin: 0.4rem 0; }
.check { display: flex; gap: 0.5rem; align-items: center; margin: 0.3rem 0; }

.bindings { width: 100%; border-collapse: collapse; }
.bindings td { padding: 0.15rem 0.3rem; }
.bindings td:first-child { color: var(--dim); white-space: nowrap; }
.bindings button { font-size: 0.8rem; padding: 0.15rem 0.5rem; min-width: 4.5rem; }
.bindings button.listening { border-color: var(--red-hot); color: var(--red-hot); }

.admin-players { width: 100%; border-collapse: collapse; }
.admin-players td { padding: 0.25rem 0.3rem; border-bottom: 1px solid rgba(153, 153, 255, 0.12); }
.admin-players td:last-child { text-align: right; white-space: nowrap; }
.admin-players button { font-size: 0.75rem; padding: 0.15rem 0.5rem; }

/* ------------------------------------------------------------ the game */

#game {
  position: fixed;
  inset: 0;
  z-index: 2;
  background: #000;
  overflow: hidden;
  cursor: none;
}

#game.pointer { cursor: default; }

#view, #cockpit {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#cockpit { pointer-events: none; }

#tags { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }

.tag {
  position: absolute;
  left: 0;
  top: 0;
  font: 3.3vmin var(--font-game);
  color: #fff;
  white-space: nowrap;
  text-shadow: 0 0 4px #000;
  will-change: transform, opacity;
  transition: opacity 0.2s;
}

/* the console: top left, on a half transparent black layer (CHAT_LAYER .5) */
#console {
  position: absolute;
  left: 2.5vw;
  top: 0.5vh;
  max-width: 60vw;
  padding: 0.2rem 0.6rem 0.4rem;
  background: rgba(0, 0, 0, 0.5);
  font: max(13px, 2.3vmin)/1.25 var(--font-game);
  pointer-events: none;
  overflow-wrap: anywhere;
}

#console.empty { display: none; }

#center {
  position: absolute;
  left: 0;
  right: 0;
  top: 75%;
  transform: translateY(-50%);
  text-align: center;
  font: 9vmin var(--font-game);
  color: #fff;
  pointer-events: none;
  text-shadow: 0 0 18px rgba(0, 0, 0, 0.9);
  opacity: 0;
}

#status {
  position: absolute;
  left: 50%;
  top: 40%;
  transform: translate(-50%, -50%);
  font: 3vmin var(--font-game);
  color: #fff;
  background: rgba(0, 0, 0, 0.55);
  padding: 0.5rem 1rem;
  border-radius: 6px;
  pointer-events: none;
  text-align: center;
}

/* the score table (ePlayerNetID::RankingGraph) */
#scores {
  position: absolute;
  left: 50%;
  top: 18%;
  transform: translateX(-50%);
  min-width: min(44rem, 94vw);
  background: rgba(0, 0, 0, 0.6);
  padding: 0.6rem 1rem;
  font: max(13px, 2.4vmin) var(--font-game);
  pointer-events: none;
}

#scores table { width: 100%; border-collapse: collapse; }
#scores th { color: #ff8080; text-align: left; font-weight: normal; padding: 0 0.8rem 0.3rem 0; }
#scores td { padding: 0.1rem 0.8rem 0.1rem 0; white-space: nowrap; }
#scores td:nth-child(3), #scores td:nth-child(4), #scores td:nth-child(5),
#scores th:nth-child(3), #scores th:nth-child(4), #scores th:nth-child(5) { text-align: right; }
#scores .yes { color: #7fff7f; }
#scores .no { color: #ff7f7f; }
#scores .dim { color: var(--dim); font-size: 0.8em; }
#scores tr.you td.name { text-decoration: underline; text-underline-offset: 0.2em; }

#chat {
  position: absolute;
  left: 2.5vw;
  bottom: 22vh;
  width: min(40rem, 90vw);
  display: flex;
  gap: 0.5rem;
  align-items: center;
  font: max(14px, 2.5vmin) var(--font-game);
  background: rgba(0, 0, 0, 0.6);
  padding: 0.3rem 0.6rem;
}

#chat input { flex: 1; font: inherit; background: transparent; border: 0; padding: 0.2rem; color: #fff; }

/* the in-game menu over the running game */
#menu {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: default;
}

#menu h2 { color: var(--title); font-size: 6.5vmin; margin: 0 0 3vmin; text-align: center; }
#menu ul { list-style: none; margin: 0; padding: 0; text-align: center; }
#menu li { margin: 0.4vmin 0; }

#menu button {
  font: 5vmin var(--font-game);
  background: none;
  border: 0;
  color: #fff;
  padding: 0.2vmin 1rem;
}

#menu button:focus {
  outline: none;
  color: var(--red);
  animation: throb-text 0.63s ease-in-out infinite alternate;
}

@keyframes throb-text {
  from { color: #a33; }
  to { color: #ff5a5a; }
}

#menu .help { color: #ffcccc; font-size: 0.9rem; min-height: 1.5em; margin-top: 3vmin; max-width: 40rem; text-align: center; }

/* touch screens: the lower third is three big zones, each with a pad to show where it is */
#touch {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: 1fr 0.6fr 1fr;
  height: 34vh;
}

#touch button {
  --pad: clamp(52px, 15vmin, 80px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0 0 max(10px, env(safe-area-inset-bottom));
  background: none;
  border: 0;
  border-radius: 0;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

#touch [data-touch="left"] { justify-content: flex-start; padding-left: max(14px, env(safe-area-inset-left)); }
#touch [data-touch="right"] { justify-content: flex-end; padding-right: max(14px, env(safe-area-inset-right)); }
/* above the speed gauge */
#touch [data-touch="brake"] { --pad: clamp(40px, 11vmin, 60px); align-items: flex-start; padding: 6px 0 0; }

#touch .pad {
  display: grid;
  place-items: center;
  width: var(--pad);
  height: var(--pad);
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.45);
  background: rgba(0, 0, 0, 0.35);
  color: rgba(255, 255, 255, 0.85);
  font-size: calc(var(--pad) * 0.42);
  line-height: 1;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.6);
  transition: background 0.08s, border-color 0.08s, transform 0.08s;
}

#touch button.down .pad {
  background: rgba(255, 255, 255, 0.3);
  border-color: #fff;
  color: #fff;
  transform: scale(0.94);
}

/* phones: the game's text smaller, so it leaves room for the grid */
@media (pointer: coarse) {
  #console { font-size: max(10px, 2.3vmin); max-width: 55vw; left: max(2.5vw, env(safe-area-inset-left)); }
  #scores { font-size: max(10px, 2.4vmin); padding: 0.4rem 0.7rem; top: 12%; }
  #scores td, #scores th { padding-right: 0.5rem; }
  #chat { font-size: max(12px, 2.5vmin); bottom: 36vh; }
  #menu button { font-size: max(16px, 5vmin); padding: 0.5vmin 1rem; }
  #menu h2 { font-size: max(20px, 6.5vmin); }
  #menu .help { font-size: 0.75rem; padding: 0 1rem; }
  .tag { font-size: max(10px, 3.3vmin); }
}

/* the original's bright background behind text too dark to read */
.dark-text { background: rgba(255, 255, 255, 0.7); border-radius: 2px; padding: 0 0.15em; }
