/* WORLD RANKINGS: the public page. Look taken from the approved sketch.
   The Orm Quest font is drawn on a 25 px grid, so every text size here is 25 px or 50 px:
   one font pixel is then a whole number of screen pixels and nothing blurs. */

@font-face {
  font-family: "Orm Quest";
  src: url("fonts/OrmQuest-Regular.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Orm Quest";
  src: url("fonts/OrmQuest-Bold.ttf") format("truetype");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #0b0905;
  --ink: #fff0bd;
  --gold: #ffde44;
  --line: #b8962e;
  --mute: #dacf98;
  --soft: #b1a87b;
  --dim: #8a7f5a;
  --panel: #0d0a06;
  --panel2: #15100a;
  --tab: #241a0b;
  --tab-hover: #2f2310;
  --lit: #40301a;
  --btn: #332510;
  --btn-hover: #40301a;
  --up: #a4e247;
  --down: #ff8069;
  --new: #6ee7ee;
  --focus: #6ee7ee;
  --off: #958c66;
  --off-bg: #1a130a;
  --off-line: #6f5c22;
  --gap: var(--bg);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  background: var(--bg);
  color-scheme: dark;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body {
  margin: 0;
  padding: 14px;
  background: var(--bg);
  color: var(--ink);
  font-family: "Orm Quest", ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", "DejaVu Sans Mono", monospace;
  font-size: 25px;
  line-height: 36px;
  font-weight: 400;
  font-synthesis: none;
  -webkit-font-smoothing: none;
  font-smooth: never;
}
img, svg { image-rendering: pixelated; }
svg { shape-rendering: crispEdges; fill: currentColor; }
h1, h2, h3, p, ul { margin: 0; padding: 0; }
ul { list-style: none; }
button, select { font: inherit; letter-spacing: inherit; border-radius: 0; }

.defs { position: absolute; width: 0; height: 0; overflow: hidden; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Keyboard focus: a bright ring, never hidden. */
:focus { outline: 3px solid var(--focus); outline-offset: 2px; }
:focus:not(:focus-visible) { outline: none; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.skip {
  position: absolute;
  left: 14px;
  top: -200px;
  z-index: 5;
  padding: 6px 14px;
  color: var(--bg);
  background: var(--focus);
  border: 0;
  font-weight: 700;
  cursor: pointer;
}
.skip:focus { top: 14px; }

/* ---------- frame and title ---------- */

.frame {
  max-width: 1040px;
  margin: 0 auto;
  border: 2px solid var(--line);
  padding: 4px;
}
.in {
  border: 2px solid var(--line);
  padding: 22px 18px 18px;
}
h1 {
  font-size: 50px;
  line-height: 56px;
  font-weight: 700;
  color: var(--gold);
}
.sub { margin-top: 4px; color: var(--mute); }
.tag { float: right; margin-left: 14px; color: var(--new); }

/* ---------- the two-line gold border used on tabs, boxes and buttons ---------- */

.tab, .box, .btn, .pickbox select {
  border: 2px solid var(--line);
  box-shadow: 0 0 0 2px var(--gap), 0 0 0 4px var(--line);
  margin: 4px;
}

/* ---------- TODAY / THIS WEEK / ALL TIME ---------- */

.tabs { display: flex; gap: 12px; margin-top: 20px; }
.tab {
  flex: 1 1 0;
  min-width: 0;
  padding: 8px 4px;
  font-weight: 700;
  text-align: center;
  white-space: normal;
  color: var(--mute);
  background: var(--tab);
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}
.tab:hover { background: var(--tab-hover); }
.tab[aria-current="true"] {
  color: var(--gold);
  background: var(--lit);
  /* a bar under the chosen tab, so it is not told by colour alone */
  box-shadow: inset 0 -4px 0 var(--gold), 0 0 0 2px var(--gap), 0 0 0 4px var(--line);
}
/* a tab or button that cannot be pressed: dimmer, but its words still pass 4.5:1 */
.tab:disabled, .btn[aria-disabled="true"] {
  color: var(--off);
  background: var(--off-bg);
  border-color: var(--off-line);
  box-shadow: 0 0 0 2px var(--gap), 0 0 0 4px var(--off-line);
  cursor: default;
}
.tab:focus-visible, .btn:focus-visible, .pickbox select:focus-visible { outline-offset: 6px; }

/* the line under the tabs, with the countdown at its right end */
.rule { display: flex; align-items: center; gap: 14px; min-height: 36px; margin-top: 10px; }
.rule .line { flex: 1 1 auto; border-top: 2px solid var(--line); }
.ends { white-space: nowrap; color: var(--mute); }
.ends:empty { display: none; }

/* ---------- board list (wide) and board picker (phones) ---------- */

.pick { display: none; margin-top: 10px; }   /* shown on phones, as a flow-root so the picker's margin stays inside */
.pickbox { position: relative; display: block; }
.pickbox select {
  display: block;
  width: calc(100% - 8px);
  min-height: 56px;
  padding: 8px 34px 8px 10px;
  font-weight: 700;
  color: var(--gold);
  background: var(--lit);
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}
.pickbox select option, .pickbox select optgroup {
  color: var(--ink);
  background: var(--panel2);
  font-style: normal;
}
.pickbox .tri {
  position: absolute;
  right: 18px;
  top: 50%;
  margin-top: -6px;
  color: var(--gold);
  pointer-events: none;
}

.cols { display: flex; gap: 14px; margin-top: 10px; }
.box { background: var(--panel); }
.left { flex: 0 0 auto; padding: 10px 10px 12px; }
.left .g { margin-top: 6px; font-size: 25px; font-weight: 400; color: var(--soft); }
.it {
  display: block;
  padding: 0 10px;
  font-weight: 700;
  white-space: nowrap;
  color: var(--ink);
  text-decoration: none;
}
.it:hover { background: var(--tab); }
.it[aria-current] {
  color: var(--gold);
  background: var(--lit);
  /* a bar beside the chosen board, so it is not told by colour alone */
  box-shadow: inset 4px 0 0 var(--gold);
}
.it:focus-visible { outline-offset: 0; }

/* ---------- the board ---------- */

.right {
  --gap: var(--panel2);
  flex: 1 1 0;
  min-width: 0;
  padding: 14px 16px 16px;
  background: var(--panel2);
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--line);
  container-type: inline-size;
  container-name: board;
  scroll-margin-top: 14px;
}
.right:focus-visible { outline-offset: 6px; }
.bt { font-size: 25px; font-weight: 700; color: var(--gold); }
.bd { color: var(--mute); }

.note { margin-top: 10px; overflow-wrap: anywhere; }
.note:empty { margin-top: 0; }
.note.is-empty { color: var(--mute); }
.note.is-reading { color: var(--new); }
.note.is-error { color: var(--down); }
#retry { margin-top: 14px; }

/* The ranked table. By default every player takes two lines (rank and name, then badge,
   value and movement): that fits any width. A board with room becomes one line per player
   further down, in the container rule. */
.rows { display: block; margin-top: 10px; }
.rows tbody { display: block; }
.rows thead {
  /* the column heads stay for screen readers when the two-line rows have no room for them */
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  white-space: nowrap;
}
.rows th, .rows td { display: block; min-width: 0; padding: 0; font-weight: 400; text-align: left; }
.rows thead th { font-weight: 700; color: var(--gold); white-space: nowrap; }
.rows tbody tr {
  display: grid;
  grid-template-columns: var(--rankw, 38px) minmax(0, 1fr) auto;
  column-gap: 10px;
  align-items: center;
  padding: 5px 0 7px;
  border-top: 2px solid var(--tab);
}
.rows .c-rank { grid-area: 1 / 1 / 2 / 2; white-space: nowrap; }
.rows .c-name { grid-area: 1 / 2 / 2 / 4; overflow-wrap: anywhere; }
.rows .c-badge { grid-area: 2 / 1 / 3 / 2; }
.rows .c-val { grid-area: 2 / 1 / 3 / 3; padding-left: 48px; text-align: right; white-space: nowrap; }   /* 48 = badge + gap */
.rows .c-move { grid-area: 2 / 3 / 3 / 4; min-width: 62px; text-align: right; white-space: nowrap; }
.rows.no-marks .c-val { grid-column: 1 / 4; }
.rows .c-badge img, .rows .c-badge .none { display: block; width: 38px; height: 42px; }
.rows tr.top td, .rows tr.top th { color: var(--gold); }
.rows tr.top .c-name { font-weight: 700; }
.rows.is-busy tbody { opacity: .5; }

.crown { width: 27px; height: 21px; margin-left: 10px; vertical-align: -2px; }
.tri { width: 12px; height: 12px; vertical-align: 3px; }
.mv-up { color: var(--up); }
.mv-down { color: var(--down); }
.mv-new { color: var(--new); }
.mv-same { color: var(--dim); }
.rows tr.top .mv-up { color: var(--up); }
.rows tr.top .mv-down { color: var(--down); }
.rows tr.top .mv-new { color: var(--new); }
.rows tr.top .mv-same { color: var(--dim); }
.mv-up .tri, .mv-down .tri { margin-right: 6px; }

/* ---------- paging and buttons ---------- */

.btn {
  display: inline-block;
  padding: 6px 14px;
  font-weight: 700;
  text-align: center;
  text-decoration: none;
  color: var(--ink);
  background: var(--btn);
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}
.btn:hover { background: var(--btn-hover); }
.btn[aria-disabled="true"]:hover { background: var(--off-bg); }
.btn .tri { vertical-align: 3px; }
.btn .tri.before { margin-right: 10px; }
.btn .tri.after { margin-left: 10px; }

.pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 8px;
  margin-top: 16px;
}
.pageof { order: -1; flex: 1 1 100%; text-align: center; white-space: nowrap; color: var(--mute); }
.pager .btn { flex: 1 1 auto; padding-left: 6px; padding-right: 6px; }

/* ---------- under the board ---------- */

.foot { margin-top: 14px; }
.cta { display: block; padding: 10px 12px; }
.fresh { min-height: 36px; margin: 10px 4px 0; text-align: center; color: var(--mute); }
.nojs { margin: 14px; text-align: center; }

/* ---------- a board with room: one line per player, as in the game ---------- */

@container board (min-width: 500px) {
  .rows { display: table; width: 100%; border-collapse: collapse; border-spacing: 0; }
  .rows thead {
    display: table-header-group;
    position: static;
    width: auto;
    height: auto;
    margin: 0;
    overflow: visible;
    clip: auto;
    clip-path: none;
  }
  .rows tbody { display: table-row-group; }
  .rows thead tr, .rows tbody tr { display: table-row; padding: 0; border: 0; }
  .rows th, .rows td { display: table-cell; padding: 2px 0; vertical-align: middle; }
  .rows thead th { padding: 0; }
  .rows .c-rank { width: 1%; padding-right: 12px; }
  .rows .c-badge { width: 1%; padding-right: 10px; }
  .rows .c-val { width: 1%; padding-left: 16px; }
  .rows .c-move { width: 1%; min-width: 76px; padding-left: 14px; }
  .pageof { order: 0; flex: 1 1 auto; }
  .pager .btn { flex: 0 0 auto; padding-left: 14px; padding-right: 14px; }
}

/* ---------- phones: the board list becomes a picker above the board ---------- */

@media (max-width: 699.98px) {
  .left { display: none; }
  .pick { display: flow-root; }
  .cols { flex-direction: column; }
  /* the picker just above already shows the board's name */
  .bt {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    clip-path: inset(50%);
    white-space: nowrap;
  }
}

@media (max-width: 519.98px) {
  body { padding: 6px; }
  .frame { padding: 3px; }
  .in { padding: 14px 8px 10px; }
  h1 { line-height: 48px; }
  .tabs { gap: 4px; margin-top: 14px; }
  .tab { padding: 6px 2px; }
  .right { padding: 10px 10px 12px; }
  .skip { left: 6px; }
  .skip:focus { top: 6px; }
}

@media (max-width: 349.98px) {
  .in { padding: 12px 4px 8px; }
  .right { padding: 8px 6px 10px; }
  .pickbox select { padding-left: 6px; padding-right: 30px; font-weight: 400; }
  .pickbox .tri { right: 14px; }
}

/* ---------- people who ask for less motion, and high-contrast modes ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}

@media (forced-colors: active) {
  .tab[aria-current="true"], .it[aria-current] { text-decoration: underline; }
  .tab:disabled, .btn[aria-disabled="true"] { color: GrayText; border-color: GrayText; }
  .rows tbody tr { border-color: CanvasText; }
}
