/*
 * Hello Board Games Mini App and web app.
 *
 * The palette, the type scale, the spacing grid, the radii, the shadows and the motion curves are
 * not here: they are in design-system.css, which is the group's design system copied in by
 * scripts/sync-design-system.sh rather than transcribed. This file is only what the app adds on top
 * of it — the screens and the tab bar.
 *
 * Where this file departs from the system it says so on the line, with the reason. The only place
 * is the fields: they are 16px because anything smaller makes iOS zoom the page when the field is
 * focused.
 *
 * What moves is in motion.css; the hover and press states of the controls are here, with the
 * controls, as the system's own components have them.
 */

:root {
  --tabbar-height: 64px;
  --column-max: 560px;

  /* what sits over what: the bar, then the sheets, then the notice, which has to be readable over
     a sheet (it used to be under it) */
  --z-tabs: 10;
  --z-sheet: 20;
  --z-notice: 40;

  /* Telegram writes the height of the visible part of the window here, on the root element, as it
     changes; this is its value outside Telegram */
  --tg-viewport-stable-height: 100vh;

  /* the dimmed part behind a sheet */
  --scrim: rgba(2, 6, 23, 0.55);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
}

[hidden] { display: none !important; }

.eyebrow {
  font-family: var(--font-mono);
  font-size: var(--fs-mono-label);
  letter-spacing: var(--ls-label);
  text-transform: uppercase;
  color: var(--text-muted);
}

/* ------------------------------------------------------------------------ the notice line */

/* centred with auto margins and not with a translate, so that its entrance can use the transform */
.notice {
  position: fixed;
  top: var(--space-3);
  left: var(--space-4);
  right: var(--space-4);
  margin-inline: auto;
  max-width: calc(var(--column-max) - 2 * var(--space-4));
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--surface);
  border: var(--border-hairline) solid var(--border);
  border-left: 3px solid var(--accent);
  box-shadow: var(--shadow-md);
  color: var(--text);
  z-index: var(--z-notice);
}

.notice--error { border-left-color: var(--danger); }

/* ------------------------------------------------------------- landing, login and expired */

.landing {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
}

.landing__card {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-6);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.landing__title {
  margin: 0;
  font-size: var(--fs-h2);
  line-height: var(--lh-heading);
}

.landing__text {
  margin: 0;
  color: var(--text-muted);
}

.login__error {
  padding: var(--space-3);
  border-radius: var(--radius-md);
  background: var(--danger-soft);
  color: var(--danger);
}

.login__divider {
  text-align: center;
  color: var(--text-subtle);
  font-size: var(--fs-body-sm);
}

/* -------------------------------------------------------------------------------- controls */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 44px;
  padding: 0 var(--space-4);
  border: 1px solid var(--accent);
  border-radius: var(--radius-md);
  background: var(--accent);
  color: var(--text-on-accent);
  font: inherit;
  font-weight: var(--fw-medium);
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition:
    background var(--dur) var(--ease-out),
    border-color var(--dur) var(--ease-out),
    color var(--dur) var(--ease-out),
    opacity var(--dur) var(--ease-out),
    transform var(--dur-fast) var(--ease-out);
}

/* hover is for a pointer: on a touch screen it would stay on the button after the finger has gone */
@media (hover: hover) {
  .button:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
}

/* a press, which a touch screen has instead of a hover: the system's own */
.button:active:not(:disabled) {
  transform: translateY(0.5px) scale(0.992);
  background: var(--accent-press);
  border-color: var(--accent-press);
}

.button:disabled { opacity: 0.45; cursor: default; }

.button--ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border-strong);
}

@media (hover: hover) {
  .button--ghost:hover { background: var(--surface-2); border-color: var(--border-strong); }
}

.button--ghost:active:not(:disabled) { background: var(--surface-2); border-color: var(--border-strong); }
.button--small { min-height: 36px; font-size: var(--fs-body-sm); }
.button--selected, .button--selected:active:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); }

/* a chip, the system's: a pill 34px high, in a row that scrolls sideways when it is longer than
   the screen. It is a small ghost button that has been given the shape */
.chip {
  flex: none;
  min-height: 34px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-pill);
  font-size: var(--fs-caption);
}

.chips {
  display: flex;
  gap: var(--space-2);
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  /* the row runs to the edges of the screen while its first chip lines up with the title */
  margin-inline: calc(-1 * var(--space-4));
  padding-inline: var(--space-4);
}

.chips::-webkit-scrollbar { display: none; }

.field { display: flex; flex-direction: column; gap: var(--space-1); margin-bottom: var(--space-3); }

.field__label {
  font-size: var(--fs-body-sm);
  font-weight: var(--fw-medium);
  color: var(--text-muted);
}

.input {
  min-height: 44px;
  padding: 0 var(--space-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text);
  /* 16px and not the system's body size: below it iOS zooms the page when a field is focused */
  font: inherit;
  font-size: 16px;
}

.input:focus-visible, .button:focus-visible, .tab:focus-visible, .button:focus-within, .chip:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
}

.choice { display: flex; gap: var(--space-2); flex-wrap: wrap; }

/* ------------------------------------------------------------------------- app and screens */

#app {
  max-width: var(--column-max);
  margin: 0 auto;
  min-height: 100vh;
}

.screens {
  padding: var(--space-4);
  padding-bottom: calc(var(--tabbar-height) + var(--space-6) + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.screen { display: flex; flex-direction: column; gap: var(--space-4); }

.screen__title {
  margin: 0;
  font-size: var(--fs-h2);
  line-height: var(--lh-heading);
}

.screen__text { margin: 0; color: var(--text-muted); }

.card {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

/* ---------------------------------------------------------------------------- the tab bar */

/* the system's bottom navigation: an icon for each tab, and the one on show is a pill that also
   carries its name. The others are the icon alone, with the name kept for a screen reader; four
   names side by side do not fit a small phone ("Impostazioni" was cut), four icons and one name do */
.tabs {
  position: fixed;
  left: 0;
  right: 0;
  margin-inline: auto;
  bottom: 0;
  max-width: var(--column-max);
  height: calc(var(--tabbar-height) + env(safe-area-inset-bottom));
  padding: 0 var(--space-1) env(safe-area-inset-bottom);
  display: flex;
  align-items: center;
  justify-content: space-around;
  background: var(--surface);
  border-top: var(--border-hairline) solid var(--border);
  z-index: var(--z-tabs);
}

.tab {
  position: relative;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-width: 44px;
  height: 44px;
  padding: 0;
  border: var(--border-hairline) solid transparent;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: var(--fs-caption);
  font-weight: var(--fw-medium);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition:
    color var(--dur-fast) var(--ease-out),
    background var(--dur) var(--ease-out),
    border-color var(--dur) var(--ease-out);
}

.tab__icon {
  flex: none;
  width: 22px;
  height: 22px;
  transition: transform var(--dur-fast) var(--ease-out);
}

.tab:active .tab__icon { transform: scale(0.88); }

/* a label that does not fit is shortened rather than pushing the other tabs off the screen */
.tab__label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tab[aria-current="page"] {
  flex: 0 1 auto;
  min-width: 0;
  padding: 0 var(--space-3);
  background: var(--accent-soft);
  border-color: var(--accent-soft-border);
  color: var(--accent);
}

.tab:not([aria-current="page"]) .tab__label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

/* ------------------------------------------------------------------------ lists and groups */

.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;
}

.list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.group { display: flex; flex-direction: column; gap: var(--space-2); }

.group__title {
  margin: 0;
  font-family: var(--font-mono);
  font-size: var(--fs-mono-label);
  font-weight: var(--fw-medium);
  letter-spacing: var(--ls-label);
  text-transform: uppercase;
  color: var(--text-muted);
}

/* an inline SVG icon has no size of its own: inside a button it would shrink to nothing */
.icon { flex: none; width: 1.25em; height: 1.25em; }
/* ---------------------------------------------------------------------------------- sheets */

/* a sheet is dimmed and below the screen until motion.js opens it (is-open, in motion.css), and
   it is that state it goes back to, over the quicker of the two curves, when it closes */
.sheet {
  position: fixed;
  inset: 0;
  z-index: var(--z-sheet);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: var(--scrim);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur) var(--ease-in-out);
}

.sheet__card {
  width: 100%;
  max-width: var(--column-max);
  /* the part of the window Telegram says is visible, not the one the keyboard or the client's own
     bar is covering */
  max-height: calc(var(--tg-viewport-stable-height) * 0.92);
  overflow-y: auto;
  /* dragging the end of a sheet must not drag the page behind it */
  overscroll-behavior: contain;
  padding: var(--space-3) var(--space-5) calc(var(--space-6) + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  background: var(--surface);
  border-top: var(--border-hairline) solid var(--border);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  box-shadow: var(--shadow-xl);
  transform: translateY(100%);
  transition: transform var(--dur) var(--ease-in-out);
}

/* the grab handle, the system's: 36 by 4 */
.sheet__card::before {
  content: "";
  flex: none;
  align-self: center;
  width: 36px;
  height: 4px;
  border-radius: var(--radius-pill);
  background: var(--border-strong);
}

.sheet__head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.sheet__title { margin: 0; font-size: var(--fs-h3); line-height: var(--lh-heading); }

/* ------------------------------------------------------------------------ the settings */

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

@media (hover: hover) {
  .button--danger:hover { background: var(--danger); border-color: var(--danger); opacity: 0.9; }
}

.button--danger:active:not(:disabled) { background: var(--danger); border-color: var(--danger); opacity: 0.85; }

.card--danger { border-color: var(--danger); }

/* a confirm step: the destructive button and the way out each on their own row */
.danger { display: flex; flex-direction: column; gap: var(--space-2); }
