/*
 * Polarnatt, StormTrack's look on the web: violet structure and mint for anything live, on a deep indigo
 * night (spec section 9, after the OPV bridge screens). Why one file: both pages share the colours, the
 * fonts and the card shape, and the content security policy allows styles from files on this site only.
 * Every card has one cut corner with a violet line along it and a violet strip down its left side; nothing
 * is fully rounded. Silkscreen is for short labels and headings, Chakra Petch for body text and numbers.
 */

@font-face {
  font-family: 'Silkscreen';
  src: url('../fonts/silkscreen/Silkscreen-Regular.ttf') format('truetype');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'Chakra Petch';
  src: url('../fonts/chakrapetch/ChakraPetch-Regular.ttf') format('truetype');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'Chakra Petch';
  src: url('../fonts/chakrapetch/ChakraPetch-SemiBold.ttf') format('truetype');
  font-weight: 600;
  font-display: swap;
}

:root {
  color-scheme: dark;
  --night: #0A081A;
  --card: #181438;
  --off: #262054;
  --violet: #8C64FF;
  --dim-violet: #42348C;
  --text: #ECECFF;
  --dim: #968CCD;
  --mint: #46EBB4;
  --amber: #FFBE46;
  --red: #FF466E;
  --glass: rgba(24, 20, 56, 0.93); /* card colour, a touch see-through over the map */
  --plate: rgba(10, 8, 26, 0.67); /* night at alpha 170: backing for text laid over the map */
  --cut: 12px;
  --label: 'Silkscreen', 'Chakra Petch', monospace;
  --body: 'Chakra Petch', system-ui, sans-serif;
}

* { box-sizing: border-box; min-width: 0; }
html, body { margin: 0; }
body {
  background: var(--night);
  color: var(--text);
  font: 400 15px/1.45 var(--body);
  -webkit-text-size-adjust: 100%;
}
a { color: var(--mint); }
:focus-visible { outline: 2px solid var(--mint); outline-offset: 2px; }
[hidden] { display: none !important; }

/* The card: the cut corner is drawn by the background itself (transparent past the cut, then a 1.5 px
   violet line), so it needs no clip-path and no extra element. 0.7071 turns the cut's leg into the
   distance along the 45 degree gradient. */
.card {
  position: relative;
  border-left: 3px solid var(--violet);
  background: linear-gradient(225deg,
    transparent calc(var(--cut) * 0.7071),
    var(--violet) calc(var(--cut) * 0.7071),
    var(--violet) calc(var(--cut) * 0.7071 + 1.5px),
    var(--glass) calc(var(--cut) * 0.7071 + 1.5px));
}

.label {
  font: 400 12px/1.2 var(--label);
  color: var(--dim);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin: 0;
}

.wordmark {
  font: 400 24px/1 var(--label);
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
  letter-spacing: 0.02em;
}
.wordmark em { font-style: normal; color: var(--mint); }

.pill {
  display: inline-block;
  font: 600 12px/1 var(--body);
  padding: 4px 7px;
  border-radius: 2px;
  background: var(--off);
  color: var(--dim);
  white-space: nowrap;
}
.pill.on { background: var(--mint); color: var(--night); }
.pill.warn { background: var(--amber); color: var(--night); }

.btn {
  font: 400 12px/1 var(--label);
  letter-spacing: 0.04em;
  color: var(--text);
  background: var(--off);
  border: 0;
  border-radius: 2px;
  min-height: 36px;
  padding: 0 12px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--dim-violet); }
.btn[aria-pressed="true"], .btn[aria-expanded="true"] { background: var(--mint); color: var(--night); }

.foot {
  margin: 0;
  font-size: 12px;
  line-height: 1.4;
  color: var(--dim);
}

/* ---------- The map page ---------- */

.map-page { height: 100%; overflow: hidden; }
html:has(.map-page) { height: 100%; }

.view { position: fixed; inset: 0; touch-action: none; }
.view canvas { display: block; width: 100%; height: 100%; }

/* Name tags sit over the canvas; the layer lets the pointer through, the tags themselves are buttons. */
.tags { position: fixed; inset: 0; overflow: hidden; pointer-events: none; }
.tag {
  position: absolute;
  left: 0;
  top: 0;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font: 400 10px/1 var(--label);
  letter-spacing: 0.03em;
  padding: 3px 5px;
  border: 0;
  border-radius: 2px;
  background: var(--mint);
  color: var(--night);
  cursor: pointer;
  pointer-events: auto;
  will-change: transform;
}
.tag:hover { box-shadow: 0 0 0 2px var(--night), 0 0 0 3px var(--mint); }
.tag-character { background: var(--amber); }
.tag.dim { opacity: 0.55; }

.hud {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-columns: minmax(0, 290px) 1fr auto;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  grid-template-areas:
    "bar bar bar"
    "list . ."
    "delays delays tools"
    "foot foot foot";
  gap: 10px;
  padding: 10px;
  pointer-events: none;
}
.hud > * { pointer-events: auto; }

.bar {
  grid-area: bar;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 9px 22px 9px 12px;
  box-shadow: 0 1px 0 var(--off);
}
.world {
  display: flex;
  align-items: center;
  gap: 4px 12px;
  flex-wrap: wrap;
  flex: 1;
  padding-left: 14px;
  border-left: 1px solid var(--violet);
}
.world-name {
  margin: 0;
  font: 600 18px/1.25 var(--body);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  /* The title's mint underline; the padding keeps it inside the box that clips the ellipsis. */
  text-decoration: underline 1px var(--mint);
  text-underline-offset: 4px;
  padding-bottom: 6px;
  margin-bottom: -6px;
}
.status-line { margin: 0; line-height: 1; }
.list-toggle { display: none; }

.list {
  grid-area: list;
  align-self: start;
  max-height: 100%;
  overflow: auto;
  padding: 12px 14px 6px 12px;
}
.list > .label { margin-bottom: 8px; }
.group-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin: 10px 0 4px;
  font: 400 12px/1.2 var(--label);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--dim);
}
.count { font: 600 14px/1 var(--body); color: var(--mint); }
.rows { list-style: none; margin: 0 0 4px; padding: 0; }
.rows .none { font-size: 13px; color: var(--dim); padding: 4px 0 6px; }
.row {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr) auto;
  gap: 9px;
  align-items: center;
  width: 100%;
  min-height: 36px;
  padding: 6px 4px;
  border: 0;
  border-top: 1px solid var(--off);
  background: none;
  color: var(--text);
  font: 400 14px/1.2 var(--body);
  text-align: left;
  cursor: pointer;
}
.row:hover { background: var(--off); }
.row-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-note { font-size: 12px; color: var(--dim); white-space: nowrap; }
.row.dim .row-name { color: var(--dim); }
.ico { width: 12px; height: 12px; }
.ico-player { background: var(--mint); border-radius: 50%; }
.ico-vehicle { background: var(--text); clip-path: polygon(50% 0, 100% 100%, 50% 72%, 0 100%); }
.ico-character { border: 2px solid var(--amber); border-radius: 50%; }
.row.dim .ico-vehicle { opacity: 0.4; }

.tools {
  grid-area: tools;
  align-self: end;
  justify-self: end;
  display: flex;
  gap: 6px;
  align-items: center;
}
.seg {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 0 0 0 10px;
  background: var(--glass);
  border-left: 3px solid var(--violet);
}

.delays {
  grid-area: delays;
  justify-self: start;
  align-self: end;
  margin: 0;
  padding: 7px 20px 7px 10px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--dim);
}
.delays .part { white-space: nowrap; }
.delays b { font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }

.map-page .foot {
  grid-area: foot;
  justify-self: start;
  padding: 3px 8px;
  background: var(--plate);
}

.notice {
  position: fixed;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%);
  width: max-content;
  max-width: min(90vw, 420px);
  padding: 18px 26px 18px 18px;
  text-align: left;
}
.notice p { margin: 0 0 8px; font: 600 17px/1.35 var(--body); }

@media (max-width: 640px) {
  .wordmark { font-size: 16px; }
  .hud {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto minmax(0, 1fr) auto auto auto;
    grid-template-areas:
      "bar bar"
      ". ."
      ". tools"
      "delays delays"
      "foot foot";
    gap: 8px;
    padding: 8px;
  }
  .bar { gap: 10px; padding: 7px 16px 7px 9px; }
  .world { padding-left: 10px; gap: 3px 8px; }
  .world-name { font-size: 16px; flex-basis: 100%; }
  .list-toggle { display: inline-block; }
  /* The list becomes a sheet over the bottom of the map, opened with the List button. */
  .list {
    display: none;
    position: fixed;
    left: 8px;
    right: 8px;
    bottom: 8px;
    max-height: 60vh;
    z-index: 5;
    background: linear-gradient(225deg,
      transparent calc(var(--cut) * 0.7071),
      var(--violet) calc(var(--cut) * 0.7071),
      var(--violet) calc(var(--cut) * 0.7071 + 1.5px),
      var(--card) calc(var(--cut) * 0.7071 + 1.5px));
  }
  .list.open { display: block; }
  .delays { justify-self: stretch; font-size: 12px; }
  .map-page .foot { font-size: 11px; }
}

/* ---------- The home page ---------- */

/* The header, the list and the footer share one column, at most 1040 px wide and centred. */
.home {
  --gutter: calc(max(0px, (100% - 1040px) / 2) + max(4vw, 16px));
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.home-bar {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 6px 18px;
  padding: 22px var(--gutter) 20px;
  box-shadow: 0 1px 0 var(--off);
}
.home-bar .wordmark { font-size: 40px; }
.tagline { margin: 0; color: var(--dim); }
.home-main {
  flex: 1;
  padding: 28px var(--gutter) 36px;
}
.home-main h1 { font-size: 16px; margin-bottom: 14px; }
.note { margin: 0 0 12px; color: var(--dim); }
.worlds {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 290px), 1fr));
  gap: 12px;
}
.world-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px 12px;
  align-items: center;
  padding: 14px 18px 14px 14px;
  color: var(--text);
  text-decoration: none;
}
.world-card:hover { --glass: #201a4a; }
.world-card h2 {
  margin: 0;
  font: 600 18px/1.25 var(--body);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.world-card .pill { justify-self: end; }
.world-card .counts { margin: 0; color: var(--dim); font-size: 14px; }
.world-card .counts b { color: var(--text); font-weight: 600; }
.world-card .open { font: 400 12px/1 var(--label); color: var(--mint); letter-spacing: 0.04em; white-space: nowrap; }
.home > .foot { padding: 14px var(--gutter) 18px; box-shadow: 0 -1px 0 var(--off); }

@media (max-width: 640px) {
  .home-bar .wordmark { font-size: 32px; }
  .home-main { padding-top: 22px; }
}
