/* one8d: plain CSS, colours are tokens that switch with the system theme */

:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --text: #1b1f24;
  --muted: #566170;
  --border: #d5dbe3;
  --accent: #2557d6;
  --accent-text: #ffffff;
  --danger: #b3261e;
  --danger-bg: #fdecea;
  --winner: #1a7f37;
  --winner-bg: #e5f4ea;
  --draw: #9a5200;
  --draw-bg: #fff3df;
  --shared: #6b3fc4;
  --shared-bg: #f1ebfc;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%);
  --radius: 10px;
  --gutter: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --surface: #171b22;
    --text: #e6e9ee;
    --muted: #9aa5b4;
    --border: #2a313b;
    --accent: #7aa2ff;
    --accent-text: #0b1020;
    --danger: #ff9b92;
    --danger-bg: #3a1a18;
    --winner: #66d68f;
    --winner-bg: #12301d;
    --draw: #ffb454;
    --draw-bg: #3a290d;
    --shared: #c7a8ff;
    --shared-bg: #2a1d45;
    --shadow: none;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: rgb(37 87 214 / 15%);
}

a,
button,
input,
select,
[role='combobox'] {
  touch-action: manipulation; /* no delay for a double-tap zoom */
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

h1 {
  margin: 0 0 12px;
  font-size: 1.5rem;
  line-height: 1.25;
}

p {
  margin: 0 0 12px;
}

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

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

main:focus {
  outline: none;
}

.container {
  width: 100%;
  max-width: 52rem;
  margin: 0 auto;
  /* a notch in landscape must not cover the content */
  padding-inline: max(var(--gutter), env(safe-area-inset-left)) max(var(--gutter), env(safe-area-inset-right));
}

main.container {
  flex: 1;
  /* a closed tooltip that sticks out over the edge must not make the page scroll sideways (a shown one is placed) */
  overflow-x: clip;
  padding-block: 20px 32px;
}

.narrow {
  max-width: 28rem;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 8px;
  padding: 8px 12px;
  background: var(--surface);
  border-radius: 6px;
  z-index: 10;
}

.skip-link:focus {
  left: 8px;
}

/* header */

.site-header {
  background: var(--surface);
  border-bottom: 3px solid var(--accent);
}

.bar {
  display: flex;
  align-items: center;
  gap: 8px 24px;
  min-height: 68px;
  flex-wrap: wrap;
  padding-block: 10px;
}

/* the name of the app: big, heavy and in the accent colour, with a bullseye */
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 1.9rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.03em;
  color: var(--accent);
  text-decoration: none;
}

.brand::before {
  content: '';
  flex: none;
  width: 0.95em;
  height: 0.95em;
  border-radius: 50%;
  background: radial-gradient(
    circle,
    var(--accent) 0 17%,
    transparent 18% 34%,
    var(--accent) 35% 51%,
    transparent 52% 67%,
    var(--accent) 68% 100%
  );
}

.brand:hover {
  filter: brightness(1.1);
}

#nav {
  display: flex;
  align-items: center;
  gap: 4px 16px;
  flex: 1;
  flex-wrap: wrap;
}

#nav > a {
  color: var(--muted);
  text-decoration: none;
  padding: 6px 2px;
  border-bottom: 2px solid transparent;
}

#nav > a:hover {
  color: var(--text);
}

#nav > a.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

#nav .spacer {
  flex: 1;
}

/* the logged-in user: the name opens a small menu */
.user-menu {
  position: relative;
}

.user-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 14rem;
  min-height: 40px;
  padding: 6px 12px;
  font: inherit;
  font-weight: 600;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-button::after {
  content: '';
  flex: none;
  width: 0.4em;
  height: 0.4em;
  margin-top: -0.2em;
  border-right: 2px solid currentcolor;
  border-bottom: 2px solid currentcolor;
  transform: rotate(45deg);
}

.user-button[aria-expanded='true'] {
  border-color: var(--accent);
}

.user-menu-list {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 20;
  min-width: 11rem;
  margin: 0;
  padding: 6px;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgb(16 24 40 / 18%);
}

.user-menu-list[hidden] {
  display: none;
}

.user-menu-list [role='menuitem'] {
  display: block;
  width: 100%;
  min-height: 40px;
  padding: 8px 12px;
  font: inherit;
  text-align: left;
  color: var(--text);
  background: none;
  border: 0;
  border-radius: 6px;
  text-decoration: none;
  cursor: pointer;
}

.user-menu-list [role='menuitem']:hover,
.user-menu-list [role='menuitem']:focus-visible {
  background: var(--bg);
}

/* cards and lists */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.match-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 12px;
}

.match-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 8px;
  font-size: 0.875rem;
}

.match-type {
  color: var(--muted);
}

.results {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
}

.result-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid transparent;
}

.result-row.is-winner {
  background: var(--winner-bg);
  border-color: var(--winner);
}

/* a draw is neither a win nor a loss: amber */
.result-row.is-draw {
  background: var(--draw-bg);
  border-color: var(--draw);
}

.result-row .player {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
  font-weight: 600;
}

.result-row .player a {
  color: var(--text);
}

.result-row .total {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.badge {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--winner);
  color: var(--surface);
}

.badge.badge-draw {
  background: var(--draw);
}

/* profile: what is known about the user, in a card of its own */

.profile-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px 24px;
  padding: 20px;
}

.profile-main {
  min-width: 0;
}

.profile-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
}

.profile-head h1 {
  margin: 0;
  overflow-wrap: anywhere;
}

.profile-facts {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 24px;
  margin: 10px 0 0;
}

.profile-facts div {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.profile-facts dt {
  font-size: 0.85rem;
  color: var(--muted);
}

.profile-facts dd {
  margin: 0;
  font-weight: 600;
}

.profile-actions {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  flex: none;
}

.pill {
  padding: 2px 10px;
  font-size: 0.8rem;
  font-weight: 700;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
}

.pill-user {
  color: var(--accent);
  border-color: var(--accent);
}

/* the guest badge is a button, so that it can be reached with the keyboard and tapped */
button.pill {
  font-family: inherit;
  line-height: inherit;
  background: var(--bg);
  cursor: help;
}

.pill-guest {
  border-style: dashed;
}

/* the account that is used in common is a special case: its own colour */
.pill-shared {
  color: var(--shared);
  background: var(--shared-bg);
  border-color: var(--shared);
}

button.pill.pill-shared {
  background: var(--shared-bg);
}

/* only shown if the login link cannot be copied: it is offered to copy by hand */
.login-link-field {
  width: min(100%, 22rem);
  margin-top: 10px;
  min-height: 36px;
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-size: 0.85rem;
}

/* tooltip: hover, keyboard focus or a tap shows it, Escape dismisses it */

.tip-wrap {
  position: relative;
  display: inline-flex;
}

.tooltip {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 25;
  width: 18rem;
  max-width: calc(100vw - 2 * var(--gutter));
  padding-top: 8px; /* no gap between the badge and the text, the pointer can move onto it */
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.12s;
}

.tooltip-body {
  display: block;
  padding: 10px 12px;
  font-size: 0.85rem;
  font-weight: 400;
  line-height: 1.4;
  color: var(--bg);
  background: var(--text);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgb(16 24 40 / 22%);
}

.tip-wrap:not([data-dismissed]):hover .tooltip,
.tip-wrap:not([data-dismissed]):focus-within .tooltip,
.tip-wrap[data-open] .tooltip {
  visibility: visible;
  opacity: 1;
}

@media (max-width: 560px) {
  .profile-actions {
    width: 100%;
  }

  .profile-actions .button {
    width: 100%;
  }
}

h2 {
  margin: 24px 0 12px;
  font-size: 1.15rem;
}

.more {
  margin-top: 16px;
}

/* guest hint behind a name */

.guest-hint {
  font-size: 0.8em;
  font-weight: 400;
  color: var(--muted);
}

/* users */

.user-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
}

.user-name {
  min-width: 0;
  overflow-wrap: anywhere;
  font-weight: 600;
}

.user-name a {
  color: var(--text);
}

.small {
  font-size: 0.85rem;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin: 24px 0 12px;
}

.section-head h2 {
  margin: 0;
}

.inline-field {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
}

.inline-field select {
  width: auto;
  min-height: 36px;
}

/* select: the look of the menu of the user, but attached to its button: the open box extends downwards */

.select {
  position: relative;
}

/* the native select stays for the value and for the width: its widest option makes the control as wide as needed */
.select .select-native {
  display: block;
  width: 100%;
  height: 0;
  min-height: 0;
  margin: 0;
  /* room for what the options need: their padding, and the check mark of the chosen one */
  padding: 0 64px 0 12px;
  border: 0;
  overflow: hidden;
  visibility: hidden;
  pointer-events: none;
  appearance: none;
}

.select-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  font: inherit;
  text-align: left;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}

.select-button::after {
  content: '';
  flex: none;
  width: 0.4em;
  height: 0.4em;
  margin-top: -0.2em;
  border-right: 2px solid currentcolor;
  border-bottom: 2px solid currentcolor;
  transform: rotate(45deg);
}

/* open: one box, the button and the list below it, no round corners where they meet */
.select[data-open] .select-button {
  background: var(--surface);
  border-color: var(--accent);
  border-bottom-color: var(--surface);
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}

/* the accent border of the open box says where the focus is, a ring around it would cut the box into two */
.select[data-open] .select-button:focus-visible {
  outline: none;
}

.select[data-open] .select-button::after {
  margin-top: 0.2em;
  transform: rotate(-135deg);
}

.select-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 30;
  max-height: 16rem;
  margin: -1px 0 0;
  padding: 6px;
  overflow-y: auto;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--accent);
  border-top: 0;
  border-radius: 0 0 8px 8px;
  box-shadow: 0 8px 24px rgb(16 24 40 / 18%);
}

.select-list[hidden] {
  display: none;
}

.select-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 40px;
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  overflow-wrap: anywhere;
}

.select-option.is-active {
  background: var(--bg);
}

.select-option[aria-selected='true'] {
  font-weight: 600;
}

.select-option span {
  white-space: nowrap;
}

.select-option[aria-selected='true']::after {
  content: '✓';
  flex: none;
  color: var(--accent);
}

.select-option[aria-disabled='true'] {
  color: var(--muted);
  cursor: not-allowed;
}

.inline-field .select-button {
  min-height: 36px;
  padding-block: 4px;
}

/* username autocomplete */

.ac-wrap {
  position: relative;
}

.ac-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 30;
  max-height: 18rem;
  margin: 0;
  padding: 4px;
  overflow-y: auto;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgb(16 24 40 / 18%);
}

.ac-list[hidden] {
  display: none;
}

.ac-option,
.ac-message {
  padding: 10px 12px;
  border-radius: 6px;
  overflow-wrap: anywhere;
}

.ac-option {
  cursor: pointer;
}

.ac-option[aria-selected='true'],
.ac-option:hover {
  background: var(--bg);
  outline: 1px solid var(--accent);
  outline-offset: -1px;
}

.ac-message {
  color: var(--muted);
}

.ac-match {
  color: var(--accent);
}

/* "guest" / "new guest" inside of a username field */

.has-badge input {
  padding-right: 6.5rem;
}

.status-badge {
  position: absolute;
  top: 50%;
  right: 10px;
  transform: translateY(-50%);
  padding: 2px 10px;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  pointer-events: none;
  white-space: nowrap;
}

.status-badge[hidden] {
  display: none;
}

.status-badge.is-new {
  color: var(--accent);
  border-color: var(--accent);
}

.status-badge.is-shared {
  color: var(--shared);
  background: var(--shared-bg);
  border-color: var(--shared);
}

/* what is wrong with the typed username */

.feedback {
  font-size: 0.85rem;
  color: var(--danger);
}

/* a message that is not in use takes no space at all, there are two of them under every username field */
.feedback:empty {
  display: none;
}

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

/* a notice: something the person should read before going on, amber like a draw */

.notice {
  padding: 14px 16px;
  background: var(--draw-bg);
  border: 1px solid var(--draw);
  border-radius: var(--radius);
}

.notice[hidden] {
  display: none;
}

.notice-title {
  display: block;
  margin-bottom: 4px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.notice p {
  margin: 0 0 12px;
}

.notice-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
}

/* forms */

.form {
  display: grid;
  gap: 16px;
}

.field {
  display: grid;
  gap: 4px;
}

.field label {
  font-weight: 600;
  font-size: 0.9rem;
}

input,
select {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}

input:focus,
select:focus {
  border-color: var(--accent);
}

/* a field that is fixed, like the name of the profile that is claimed: readable, but clearly not for typing */
input:disabled {
  cursor: default;
  color: var(--text);
  -webkit-text-fill-color: var(--text);
  opacity: 1;
  background: var(--surface);
  border-style: dashed;
}

fieldset.player-row {
  display: grid;
  gap: 12px;
  margin: 0 0 12px;
  padding: 12px 14px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

fieldset.player-row legend {
  padding-inline: 6px;
  font-weight: 600;
}

.hint,
.muted {
  color: var(--muted);
}

.hint {
  font-size: 0.85rem;
}

.alert {
  margin: 0;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--danger);
  background: var(--danger-bg);
  border: 1px solid var(--danger);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 8px 16px;
  font: inherit;
  font-weight: 600;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  text-decoration: none;
  cursor: pointer;
}

.button:hover {
  border-color: var(--accent);
}

.button.primary {
  color: var(--accent-text);
  background: var(--accent);
  border-color: var(--accent);
}

.button.small {
  min-height: 34px;
  padding: 4px 12px;
}

.button:disabled,
.button.disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* list toolbar, filter and pages */

.toolbar {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.toolbar .field.grow {
  flex: 1 1 14rem;
}

/* the users of the filter, each in a tile of its own */

.tiles {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 12px;
  padding: 0;
  list-style: none;
}

.tiles[hidden] {
  display: none;
}

.tile {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
  padding: 4px 4px 4px 14px;
  font-weight: 600;
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: 999px;
}

.tile-name {
  min-width: 0;
  overflow-wrap: anywhere;
}

.tile-remove {
  flex: none;
  width: 28px;
  height: 28px;
  padding: 0;
  font: inherit;
  line-height: 1;
  color: var(--muted);
  background: none;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
}

.tile-remove:hover,
.tile-remove:focus-visible {
  color: var(--text);
  background: var(--bg);
}

/* a short answer to what was just done, e.g. that a user does not exist */
.field-message {
  margin: 0 0 12px;
  color: var(--danger);
  font-size: 0.9rem;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 16px;
}

@media (max-width: 560px) {
  .toolbar .button {
    width: 100%;
  }

  /* brand on top, navigation and the user menu in a row below it */
  .bar {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  /* Matches, Users, New match and Log in / Register have to fit in one row */
  #nav {
    width: 100%;
    gap: 4px 8px;
    font-size: 0.95rem;
  }

  #nav > a {
    padding-inline: 0;
  }

  .user-button {
    max-width: 9rem;
  }
}

/* phones and other small screens */

@media (max-width: 560px) {
  :root {
    --gutter: 14px;
  }

  h1 {
    font-size: 1.35rem;
  }

  main.container {
    padding-block: 16px 28px;
  }

  .brand {
    font-size: 1.6rem;
  }

  .bar {
    min-height: 0;
    padding-block: 8px;
  }

  /* the menu of the user sits at the right end of the row of the navigation, wraps below it if it must */
  #nav .spacer {
    display: none;
  }

  #nav .user-menu {
    margin-left: auto;
  }

  .user-button {
    max-width: 7.5rem;
    padding-inline: 10px;
  }

  .user-menu-list {
    max-width: calc(100vw - 2 * var(--gutter));
  }

  /* filter and sorting: two columns, the field with the username and the buttons take the whole width */
  .toolbar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: end;
  }

  .toolbar > .field,
  .toolbar > .button {
    min-width: 0;
  }

  .toolbar > .field.grow,
  .toolbar > .button,
  .toolbar > :only-child {
    grid-column: 1 / -1;
  }

  .card {
    padding: 12px;
  }

  /* the name gets the room, the badge and the total wrap below it when there is none */
  .result-row {
    flex-wrap: wrap;
    gap: 4px 10px;
    padding: 8px;
  }

  .result-row .player {
    flex: 1 1 9rem;
    overflow-wrap: break-word;
  }

  .profile-card {
    padding: 16px;
  }

  .profile-facts {
    flex-direction: column;
  }

  .profile-actions,
  .login-link-field {
    width: 100%;
  }

  fieldset.player-row {
    padding: 10px 12px 12px;
  }

  .has-badge input {
    padding-right: 5.5rem;
  }

  .form .button.primary {
    width: 100%;
  }

  .select-list,
  .ac-list {
    max-height: min(16rem, 40dvh);
  }

  .pagination {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .pagination > :not(.button) {
    grid-column: 1 / -1;
    grid-row: 1;
    text-align: center;
  }

  .pagination .button {
    width: 100%;
  }

  input,
  select {
    scroll-margin-top: 16px;
  }
}

/* a finger is the pointer: bigger targets, the look on a desktop stays */
@media (pointer: coarse) {
  #nav > a {
    padding-block: 10px;
  }

  .button.small,
  .inline-field .select-button {
    min-height: 44px;
  }

  button.pill {
    min-height: 32px;
    padding-block: 5px;
  }

  .tile {
    padding-block: 2px;
  }

  .tile-remove {
    width: 40px;
    height: 40px;
  }

  .select-option,
  .ac-option {
    min-height: 44px;
  }

  /* the names in lists are links: the area to tap reaches above and below the text */
  .result-row .player a,
  .user-name a {
    display: inline-block;
    padding-block: 8px;
  }
}

/* a phone held sideways: little height, so the header gets slim */
@media (max-height: 480px) and (orientation: landscape) {
  .bar {
    min-height: 0;
    padding-block: 4px;
  }

  main.container {
    padding-block: 12px 20px;
  }
}


@media (prefers-reduced-motion: reduce) {
  .tooltip {
    transition: none;
  }
}
