/* ==========================================================================
   TANGENT - the one-button party game (tangent.html)

   The stage fills the space between the site's header and footer, and on a
   touch screen or a phone the whole screen; during a match it covers the
   whole window. The arena is drawn on a canvas under everything; the
   waiting room, the pause and the match's end are cards over it. Nothing
   scrolls but a card that is taller than its room.
   ========================================================================== */

.tg-body {
  /* the canvas reads these (tangent.js readColours) */
  --tg-star: #d9a300;
  --tg-ball: #ffffff;
  --tg-ballink: #161b22;
  --tg-bg: #e6eaef;
  --tg-arena: #fbfcfd;
  --tg-dot: #d2d8df;
  --tg-wall: #98a2ae;
  --tg-warn: #c4501f;
  --tg-ink: #161b22;
  --tg-muted: #5d6773;
  --tg-card: rgba(255, 255, 255, 0.9);
}
[data-theme="dark"] .tg-body {
  --tg-star: #ffd23a;
  --tg-ball: #eef1f4;
  --tg-ballink: #1b2129;
  --tg-bg: #07090c;
  --tg-arena: #10141a;
  --tg-dot: #242b34;
  --tg-wall: #3d4856;
  --tg-warn: #ff8a5c;
  --tg-ink: #e9ecef;
  --tg-muted: #9aa4b0;
  --tg-card: rgba(21, 26, 33, 0.9);
}

/* The page never scrolls as a whole, and a double tap does not zoom it.
   A pinned body leaves <html> zero high, so <html> paints the background. */
html { overflow: hidden; overscroll-behavior: none; touch-action: manipulation; background: var(--bg-primary); }
body.tg-body { position: fixed; inset: 0; overflow: hidden; overscroll-behavior: none; }

.tg-content { overflow: hidden; }

.tg {
  position: relative;
  height: 100%;
  font-family: var(--font-sans);
  color: var(--text-primary);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
.tg [hidden] { display: none !important; }

.tg-stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: var(--tg-bg);
  /* every finger is a player's: no scrolling, no zooming, no menus */
  touch-action: none;
}
.tg-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* During a match the stage covers the window, the site's chrome too. */
:root.tg-playing .tg-stage { position: fixed; inset: 0; z-index: 3000; }
:root.tg-playing body.tg-body > header,
:root.tg-playing body.tg-body > footer,
:root.tg-playing body.tg-body > .nav-toggle,
:root.tg-playing body.tg-body > #menu,
:root.tg-playing body.tg-body > #kvotmap { display: none; }

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

/* ── The card's own bar ───────────────────────────────────────────────── */

.tg-head { display: flex; align-items: center; gap: 10px; min-width: 0; }
.tg-homelink { display: none; border-radius: 6px; flex: none; }
.tg-homelink:focus-visible { outline: 2px solid var(--accent-line); outline-offset: 3px; }
.tg-homelink img { display: block; width: 26px; height: 26px; }
.tg-title {
  margin: 0;
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 1.5rem;
  line-height: 1.1;
  letter-spacing: 0.01em;
  white-space: nowrap;
}
.tg-head-end { display: flex; gap: 6px; margin-left: auto; }

.tg-iconbtn, .tg-head-end > .theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 15px;
  cursor: pointer;
  flex: none;
}
.tg-head-end > .theme-toggle { display: none; font-size: 17px; line-height: 1; }
.tg-iconbtn:focus-visible, .tg-head-end > .theme-toggle:focus-visible { outline: 2px solid var(--accent-line); outline-offset: 2px; }

/* The browser's full screen: arrows out, or in again while it is on. */
#tg-fsbtn .tg-fs-in, #tg-fsbtn[aria-pressed="true"] .tg-fs-out { display: none; }
#tg-fsbtn[aria-pressed="true"] .tg-fs-in { display: inline; }

/* The full window (the four corners, kvot-fullwin.js): the page without the
   site's header and footer, the kvot mark and the theme switch in the card. */
.tg-head-end > .kvot-fullwin > button[type] {
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: transparent;
}
:root.kvot-full .tg-homelink { display: flex; }
:root.kvot-full .tg-head-end > .theme-toggle { display: inline-flex; }

/* A touch screen or a phone never shows the site's header and footer: the
   card has the kvot mark and the theme switch instead, and no button for a
   full window it always has. On a computer a match covers the window anyway,
   and the full-screen button hides the browser's own bars too. */
@media (max-width: 680px), (pointer: coarse) {
  :root { --header-height: 0px; --footer-height: 0px; }
  body.tg-body > header, body.tg-body > footer, body.tg-body > .nav-toggle,
  body.tg-body > #menu, body.tg-body > #kvotmap { display: none; }
  .tg-homelink { display: flex; }
  .tg-head-end > .theme-toggle { display: inline-flex; }
  .tg-head-end > .kvot-fullwin { display: none; }
}

/* ── The cards ────────────────────────────────────────────────────────── */

/* The cards sit in the middle, clear of the edges where the players tap
   (--tg-edge, from the seats' size). */
.tg-center {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-items: center;
  padding: var(--tg-edge, 24px);
  pointer-events: none;
}

.tg-card {
  box-sizing: border-box;
  width: min(460px, 100%);
  max-height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  padding: 16px 18px 14px;
  border: 1px solid var(--border-color);
  border-radius: 14px;
  background: var(--tg-card);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  box-shadow: 0 12px 34px var(--shadow-color);
  pointer-events: auto;
}
.tg-card h2 { margin: 0 0 10px; font-size: 1.2rem; font-weight: 600; }

.tg-lobby { display: grid; gap: 12px; }
.tg-lead { margin: 0 0 6px; font-size: 0.98rem; line-height: 1.42; color: var(--text-secondary); }
.tg-lead + .tg-lead { margin-top: 2px; }

.tg-players { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 6px; }
.tg-none { color: var(--text-muted); font-size: 0.95rem; padding: 6px 0; }
.tg-player {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 2px 3px 2px 10px;
  border-radius: 10px;
  border: 1px solid color-mix(in srgb, var(--tg-c) 40%, transparent);
  background: color-mix(in srgb, var(--tg-c) 9%, transparent);
}
.tg-shape { width: 20px; height: 20px; flex: none; display: block; }
.tg-pl-name { font-weight: 600; white-space: nowrap; }
.tg-pl-how {
  flex: 1;
  min-width: 0;
  color: var(--text-secondary);
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tg-pl-level {
  margin-right: auto;
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid var(--border-color);
  border-radius: 16px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}
.tg-pl-x {
  flex: none;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}
.tg-pl-x:focus-visible, .tg-pl-level:focus-visible { outline: 2px solid var(--accent-line); outline-offset: 1px; }

.tg-lobby-side { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }

.tg-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  box-sizing: border-box;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font: inherit;
  font-size: 1rem;
  cursor: pointer;
}
.tg-btn:focus-visible { outline: 2px solid var(--accent-line); outline-offset: 2px; }
.tg-btn:disabled { opacity: 0.5; cursor: default; }
.tg-btn-go { background: var(--accent-fill); border-color: var(--accent-fill); color: #fff; font-weight: 600; }
.tg-btn-go[aria-disabled="true"] { opacity: 0.6; }
#tg-start { flex: 1 0 100%; min-height: 50px; font-size: 1.12rem; letter-spacing: 0.02em; }

.tg-seg { display: inline-flex; align-items: center; gap: 4px; margin-left: auto; }
.tg-seg-label { margin-right: 4px; font-size: 0.92rem; color: var(--text-secondary); white-space: nowrap; }
.tg-seg button {
  min-width: 40px;
  min-height: 40px;
  padding: 0 6px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font: inherit;
  font-size: 1rem;
  cursor: pointer;
}
.tg-seg button[aria-pressed="true"] { background: var(--text-primary); border-color: var(--text-primary); color: var(--bg-primary); font-weight: 600; }
.tg-seg button:focus-visible { outline: 2px solid var(--accent-line); outline-offset: 2px; }

/* The game: a button with its name, opening the list of games. */
.tg-moderow { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
.tg-modebtn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font: inherit;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}
.tg-modebtn:focus-visible { outline: 2px solid var(--accent-line); outline-offset: 2px; }
.tg-modedesc { flex: 1 0 100%; font-size: 0.88rem; line-height: 1.35; color: var(--text-secondary); }
.tg-balls, .tg-teams { margin-left: 0; }

.tg-modelist { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); padding-top: 8px; }
.tg-modeitem {
  display: grid;
  gap: 2px;
  align-content: start;
  padding: 10px 12px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.tg-modeitem[aria-pressed="true"] { border-color: var(--accent-line); box-shadow: inset 0 0 0 1px var(--accent-line); }
.tg-modeitem:focus-visible { outline: 2px solid var(--accent-line); outline-offset: 2px; }
.tg-modeitem-name { font-weight: 600; font-size: 1rem; }
.tg-modeitem-desc { font-size: 0.86rem; line-height: 1.35; color: var(--text-secondary); }

/* Football: a player's team, a button that moves them to the other. */
.tg-pl-team {
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid var(--tg-c);
  border-radius: 16px;
  background: var(--tg-c);
  color: #fff;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.tg-pl-team:focus-visible { outline: 2px solid var(--accent-line); outline-offset: 2px; }
[data-theme="dark"] .tg-pl-team { color: #0d1015; }
.tg-player .tg-pl-team + .tg-pl-level { margin-left: 2px; }

.tg-enter { flex: 1 0 100%; margin: -4px 0 0; text-align: center; font-size: 0.8rem; color: var(--text-muted); }
.tg-note { margin: 0; min-height: 0; font-size: 0.92rem; color: var(--accent-text); }
.tg-note:empty { display: none; }

.tg-stack { display: grid; gap: 8px; }
.tg-stack-row { grid-template-columns: 1fr 1fr; margin-top: 12px; }
.tg-pause, .tg-over { width: min(380px, 100%); text-align: center; }

.tg-standings { list-style: none; margin: 4px 0 0; padding: 0; display: grid; gap: 4px; text-align: left; }
.tg-standings li { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px; }
.tg-standings li:first-child { background: var(--bg-secondary); }
.tg-st-name { font-weight: 600; }
.tg-st-how { flex: 1; min-width: 0; color: var(--text-secondary); font-size: 0.88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tg-st-score { font-variant-numeric: tabular-nums; white-space: nowrap; }
.tg-st-badge { width: 14px; height: 14px; border-radius: 50%; flex: none; }
.tg-st-team { display: flex; gap: 4px; }
.tg-st-team .tg-shape { width: 16px; height: 16px; }
.tg-standings li.tg-st-coop { justify-content: center; font-weight: 600; }

/* The pause button, placed by tangent.js in the widest gap between seats. */
.tg-pausebtn {
  position: absolute;
  z-index: 4;
  width: 40px;
  height: 40px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-color);
  border-radius: 50%;
  background: var(--tg-card);
  color: var(--text-secondary);
  cursor: pointer;
}
.tg-pausebtn:focus-visible { outline: 2px solid var(--accent-line); outline-offset: 2px; }

/* ── Dialogs ──────────────────────────────────────────────────────────── */

.tg-dialog {
  width: min(560px, calc(100vw - 24px));
  max-height: min(86vh, 760px);
  max-height: min(86dvh, 760px);
  box-sizing: border-box;
  padding: 0;
  border: 1px solid var(--border-color);
  border-radius: 14px;
  background: var(--modal-bg);
  color: var(--text-primary);
  box-shadow: 0 18px 50px var(--shadow-color);
  font-family: var(--font-sans);
  overflow: hidden;
}
.tg-dialog[open] { display: flex; flex-direction: column; }
.tg-dialog::backdrop { background: var(--overlay-bg); }
.tg-dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px 10px 20px; border-bottom: 1px solid var(--border-color); }
.tg-dialog-head h2 { margin: 0; font-family: var(--font-sans); font-weight: normal; font-size: 1.4rem; }
.tg-dialog-head .tg-iconbtn { background: transparent; }
.tg-dialog-body { padding: 8px 20px 20px; overflow-y: auto; overscroll-behavior: contain; font-size: 0.95rem; line-height: 1.55; }
.tg-dialog-body h3 { margin: 16px 0 6px; font-size: 1rem; }
.tg-dialog-body ul { margin: 6px 0; padding-left: 22px; }
.tg-dialog-body li + li { margin-top: 6px; }
.tg-check { display: flex; gap: 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--border-color); cursor: pointer; font-size: 1rem; }
.tg-check input { flex: none; width: 18px; height: 18px; margin: 0; }
.tg-setrow { padding: 12px 0; border-bottom: 1px solid var(--border-color); }
.tg-setrow:has(> [hidden]) { display: none; }
.tg-langs { margin: 8px 0 0; padding: 0; border: 0; }
.tg-langs legend { padding: 8px 0 0; font-size: 0.85rem; color: var(--text-secondary); }
.tg-dialog-foot { display: flex; justify-content: flex-end; margin-top: 16px; }

.tg-noscript { position: fixed; inset: 40% 16px auto; text-align: center; font-family: var(--font-sans); }

/* ── Small screens ────────────────────────────────────────────────────── */

@media (max-width: 420px) {
  .tg-title { font-size: 1.3rem; }
  .tg-head { gap: 8px; }
  /* room for the name and three buttons: full screen is in the settings */
  #tg-fsbtn { display: none; }
  .tg-card { padding: 12px 12px 12px; }
  .tg-lead { font-size: 0.93rem; }
  .tg-seg { margin-left: 0; }
}

/* A phone on its side: the waiting room in two columns. */
@media (max-height: 500px) and (orientation: landscape) {
  .tg-iconbtn, .tg-head-end > .theme-toggle { width: 36px; height: 36px; }
  .tg-title { font-size: 1.25rem; }
  .tg-center { padding: 10px var(--tg-edge, 24px); }
  .tg-lobby {
    width: min(720px, 100%);
    grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
    column-gap: 16px;
    row-gap: 6px;
    padding: 10px 14px;
  }
  .tg-head, .tg-moderow, .tg-note { grid-column: 1 / -1; }
  .tg-modedesc { flex: 1 1 200px; }
  .tg-lead { font-size: 0.88rem; line-height: 1.3; margin-bottom: 2px; }
  .tg-players { margin-top: 6px; gap: 4px; }
  .tg-player { min-height: 34px; }
  .tg-pl-x { width: 32px; height: 32px; }
  .tg-lobby-side { align-content: start; gap: 8px; }
  .tg-seg { margin-left: 0; }
  .tg-seg button { min-width: 36px; min-height: 36px; }
  #tg-start { min-height: 44px; }
  .tg-btn { min-height: 40px; }
}

/* Hover only where there is hovering: a touch screen keeps a tapped
   button looking hovered until the next tap elsewhere. */
@media (hover: hover) {
  .tg-iconbtn:hover, .tg-head-end > .theme-toggle:hover, .tg-head-end > .kvot-fullwin > button[type]:hover {
    color: var(--text-primary); border-color: var(--accent-line); background: transparent; transform: none;
  }
  .tg-pl-x:hover, .tg-pl-level:hover { color: var(--text-primary); background: var(--bg-secondary); }
  .tg-btn:hover:not(:disabled) { border-color: var(--accent-line); }
  .tg-btn-go:hover:not(:disabled) { background: var(--accent-fill-hover); border-color: var(--accent-fill-hover); }
  .tg-pausebtn:hover { color: var(--text-primary); border-color: var(--accent-line); }
  .tg-modebtn:hover, .tg-modeitem:hover { border-color: var(--accent-line); }
}

@media (prefers-reduced-motion: reduce) {
  .tg-card { -webkit-backdrop-filter: none; backdrop-filter: none; }
}
