/*
 * Takeover game page (takeover.php).
 * Dark, board-game feel: neutral slate chrome so the team colours on the map
 * are the only saturated colour on screen.
 */

.tk-page {
  --tk-bg:          #0b0e14;
  --tk-surface:     #11161f;
  --tk-surface-2:   #171d28;
  --tk-surface-3:   #1e2533;
  --tk-line:        #222a37;
  --tk-line-strong: #313b4b;
  --tk-text:        #e7eaf0;
  --tk-text-soft:   #c3c9d4;
  --tk-muted:       #8b94a5;
  --tk-faint:       #5c6576;
  --tk-focus:       #f4f6fa;
  --tk-danger:      #ff6b6b;
  --tk-radius-sm:   6px;
  --tk-radius:      10px;
  --tk-display:     'Barlow Condensed', 'Inter', system-ui, sans-serif;
  --tk-body:        'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --tk-label:       18px; /* map edge labels */
  --me:             var(--tk-focus); /* set to the player's team colour by takeover.js */

  margin: 0;
  padding: 0;
  background-color: var(--tk-bg);
  background-image:
    linear-gradient(rgba(255,255,255,0.018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.018) 1px, transparent 1px);
  background-size: 32px 32px;
  color: var(--tk-text);
  font-family: var(--tk-body);
  font-size: 14px;
  cursor: auto;
}

/* style.css draws two drifting white waves on body::before/::after for the rest of the site */
body.tk-page::before,
body.tk-page::after { content: none; }

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

.tk-page :focus-visible {
  outline: 2px solid var(--tk-focus);
  outline-offset: 2px;
}

.tk-page h1,
.tk-page h2,
.tk-page p { margin: 0; }

/* ─── Shell ─────────────────────────────────────────────────────────────── */

.tk-shell {
  width: min(1320px, 100%);
  margin: 0 auto;
  padding: 16px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.tk-bar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
}

.tk-eyebrow {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--tk-faint);
}

.tk-bar h1 {
  font-family: var(--tk-display);
  font-size: 30px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.01em;
  color: var(--tk-text);
  margin-top: 4px;
}

.tk-phase {
  display: flex;
  align-items: baseline;
  gap: 10px;
  text-align: right;
}

/* "N watching" (amber while the live connection is down) */
.tk-live {
  font-size: 11px;
  font-weight: 600;
  color: #ffb347;
}
.tk-live.is-up { color: var(--tk-faint); }
.tk-live:empty { display: none; }

/* Admins: hovering "N watching" lists everyone on the page, spectators (purple) first */
.tk-watch { position: relative; }
.tk-watch.has-list .tk-live { cursor: default; }
.tk-watchers {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  z-index: 50;
  min-width: 140px;
  max-height: 220px;
  overflow-y: auto;
  margin: 6px 0 0;
  padding: 4px 0;
  list-style: none;
  text-align: left;
  background: rgba(17, 22, 31, 0.88);
  border: 1px solid var(--tk-line-strong);
  border-radius: var(--tk-radius-sm);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  font-size: 12px;
  color: var(--tk-text-soft);
}
/* Bridges the gap under the count so the list stays open on the way down to it */
.tk-watch.has-list::after { content: ''; position: absolute; left: 0; right: 0; top: 100%; height: 7px; }
.tk-watch.has-list:hover .tk-watchers:not(:empty) { display: block; }
.tk-watchers li {
  padding: 3px 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tk-watchers li.is-spectator { color: #c9b3ff; }

.tk-phase-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--tk-muted);
}

.tk-clock {
  font-family: var(--tk-display);
  font-size: 40px;
  font-weight: 600;
  line-height: 0.9;
  font-variant-numeric: tabular-nums;
  color: var(--tk-text);
  min-width: 3.2ch;
}

.tk-clock.is-urgent { color: var(--tk-danger); }

/* ─── Scoreboard ────────────────────────────────────────────────────────── */

.tk-score { display: flex; flex-direction: column; gap: 8px; }

.tk-score-teams {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
}

.tk-score-team {
  display: flex;
  align-items: baseline;
  gap: 7px;
  color: var(--tk-muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.tk-score-team i {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: var(--team);
  align-self: center;
}

.tk-score-team b {
  font-family: var(--tk-display);
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
  color: var(--tk-text);
  font-variant-numeric: tabular-nums;
}

.tk-score-team.is-mine { color: var(--tk-text-soft); }
.tk-score-team.is-mine::after {
  content: 'You';
  font-size: 10px;
  color: var(--tk-faint);
}

.tk-score-team.is-out { opacity: 0.45; }
.tk-score-team.is-out b { font-size: 14px; color: var(--tk-muted); }

.tk-kill { margin: 0; font-size: 12px; color: var(--tk-muted); }
.tk-kill b { color: var(--tk-text); font-variant-numeric: tabular-nums; }

.tk-score-bar {
  display: flex;
  height: 6px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--tk-surface-3);
}

.tk-score-bar span {
  background: var(--team);
  transition: flex-basis 0.4s ease;
}

.tk-score-bar span + span { box-shadow: -2px 0 0 var(--tk-bg); }

/* ─── Body ──────────────────────────────────────────────────────────────── */

.tk-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 16px;
  align-items: start;
}

.tk-board {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.tk-map-area {
  container-type: inline-size;
  display: flex;
  justify-content: center;
}

/* ─── Map ───────────────────────────────────────────────────────────────── */

.tk-map {
  --map-w: min(100cqw, calc(78vh * var(--cols) / var(--rows)));
  --cell: calc((var(--map-w) - var(--tk-label)) / var(--cols));
  width: var(--map-w);
  display: grid;
  grid-template-columns: var(--tk-label) repeat(var(--cols), minmax(0, 1fr));
  grid-template-rows: var(--tk-label);
  gap: 3px;
  font-size: clamp(8px, calc(var(--cell) * 0.14), 13px);
}

.tk-axis {
  display: grid;
  place-items: center;
  font-size: 10px;
  font-weight: 600;
  color: var(--tk-faint);
  letter-spacing: 0.04em;
  user-select: none;
}

.tk-cell {
  position: relative;
  aspect-ratio: 1;
  min-width: 0;
  padding: 0.45em;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 0.2em;
  border: 1px solid var(--tk-line);
  border-radius: var(--tk-radius-sm);
  background: var(--tk-surface-2);
  color: var(--tk-muted);
  font: inherit;
  text-align: left;
  overflow: hidden;
  transition: background-color 0.25s ease, border-color 0.25s ease;
}

button.tk-cell { cursor: default; }

.tk-cell.is-owned {
  background: color-mix(in srgb, var(--team) 80%, var(--tk-bg));
  border-color: var(--team);
  color: var(--ink, #fff);
}

.tk-cell.is-void {
  border-color: transparent;
  background: repeating-linear-gradient(135deg, transparent 0 5px, rgba(255,255,255,0.03) 5px 6px);
}


.tk-cell.can-reach {
  cursor: pointer;
  outline: 2px dashed var(--me);
  outline-offset: -4px;
}

.tk-cell.can-reach:hover { background-color: var(--tk-surface-3); }
.tk-cell.can-reach.is-owned:hover { background-color: color-mix(in srgb, var(--team) 92%, #fff); }

.tk-cell.can-reach.is-waiting {
  cursor: not-allowed;
  outline-style: dotted;
  outline-color: color-mix(in srgb, var(--me) 45%, transparent);
}

.tk-cell.can-reach:focus-visible { outline: 2px solid var(--tk-focus); outline-offset: -4px; }

.cell-name {
  font-weight: 600;
  line-height: 1.15;
  color: inherit;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  hyphens: auto;
  overflow-wrap: break-word;
}

.tk-cell:not(.is-owned) .cell-name { color: var(--tk-text-soft); }
.cell-name.is-random { color: var(--tk-faint) !important; font-weight: 500; }
.cell-name.is-long { font-size: 0.8em; }

.cell-best {
  font-size: 0.9em;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  opacity: 0.85;
}

.cell-tokens {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2em;
  margin-top: auto;
}

.tok {
  width: 2.1em;
  height: 2.1em;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--c);
  color: var(--ink, #fff);
  font-size: 0.8em;
  font-weight: 700;
  letter-spacing: -0.02em;
  box-shadow: 0 0 0 1.5px var(--tk-bg);
}

.tok.is-me { box-shadow: 0 0 0 1.5px var(--tk-bg), 0 0 0 3px var(--tk-focus); }
.tok.is-more { background: var(--tk-surface-3); color: var(--tk-text-soft); }

/* Brawl / power markers and the player's power bonus, bottom-right of the square */
.cell-tags {
  position: absolute;
  right: 0.35em;
  bottom: 0.35em;
  display: flex;
  align-items: center;
  gap: 0.2em;
}

.cell-tag {
  width: 1.5em;
  height: 1.5em;
  display: grid;
  place-items: center;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.32);
  color: #fff;
}

.cell-tag svg { width: 1em; height: 1em; }
.cell-tag.is-power { color: #ffd166; }

.cell-bonus {
  padding: 0.1em 0.3em;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.45);
  color: var(--c, #ffd166); /* the boosted team's colour */
  font-size: 0.8em;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* Start squares: a corner flag in the team's colour */
.cell-start {
  position: absolute;
  top: 0;
  right: 0;
  width: 0;
  height: 0;
  border-top: 1.1em solid var(--c);
  border-left: 1.1em solid transparent;
  opacity: 0.9;
}

/* Small squares (phones, big maps): one-line names, no score (the inspector shows it), stacked tokens */
.tk-cell:not(.is-void) { container-type: inline-size; }

@container (max-width: 56px) {
  .cell-name {
    display: block;
    white-space: nowrap;
    text-overflow: ellipsis;
    hyphens: manual;
  }
  .cell-name.is-long { font-size: 1em; }
  .cell-best { display: none; }
  .cell-tokens { flex-wrap: nowrap; gap: 0; }
  .tok { width: 1.8em; height: 1.8em; font-size: 0.75em; }
  .tok + .tok { margin-left: -0.8em; }
  .cell-tags { right: 0.2em; bottom: 0.2em; }
  .cell-tag { width: 1.3em; height: 1.3em; }
  /* No room for text: a dot in the boosted team's colour; the inspector shows the figure */
  .cell-bonus {
    width: 0.7em;
    height: 0.7em;
    padding: 0;
    border-radius: 50%;
    font-size: 0;
    background: var(--c, #ffd166);
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5);
  }
}

.tk-inspect {
  min-height: 20px;
  font-size: 12px;
  color: var(--tk-muted);
  text-align: center;
}

.tk-inspect strong { color: var(--tk-text); font-weight: 600; }

/* ─── Side panels ───────────────────────────────────────────────────────── */

.tk-side {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.tk-panel {
  background: var(--tk-surface);
  border: 1px solid var(--tk-line);
  border-radius: var(--tk-radius);
  padding: 14px;
}

.tk-panel-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--tk-faint);
  margin-bottom: 10px;
}

/* Status */
.tk-status { display: flex; flex-direction: column; gap: 12px; }

.tk-status-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.tk-team-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: var(--tk-display);
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
  color: var(--tk-text);
}

.tk-team-chip i {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  background: var(--team);
}

.tk-status-sub { font-size: 12px; color: var(--tk-muted); }

.tk-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  margin: 0;
  border-radius: var(--tk-radius-sm);
  overflow: hidden;
  background: var(--tk-line);
}

.tk-stats div {
  background: var(--tk-surface-2);
  padding: 8px 10px;
  min-width: 0;
}

.tk-stats dt {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--tk-faint);
}

.tk-stats dd {
  margin: 3px 0 0;
  font-family: var(--tk-display);
  font-size: 20px;
  font-weight: 600;
  line-height: 1.05;
  color: var(--tk-text);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tk-cool {
  height: 4px;
  border-radius: 999px;
  background: var(--tk-surface-3);
  overflow: hidden;
}

.tk-cool i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--me);
}

.tk-square-info {
  font-size: 12.5px;
  color: var(--tk-muted);
  line-height: 1.5;
}

.tk-square-info strong { color: var(--tk-text); font-weight: 600; }

.tk-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: var(--tk-radius-sm);
  background: var(--me);
  color: var(--ink, #0b0e14);
  font: 600 14px/1 var(--tk-body);
  cursor: pointer;
  transition: filter 0.15s ease, background-color 0.15s ease;
}

.tk-btn:hover:not(:disabled) { filter: brightness(1.08); }
.tk-btn:disabled {
  background: var(--tk-surface-3);
  color: var(--tk-faint);
  cursor: not-allowed;
}

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

.tk-btn-ghost:hover:not(:disabled) { background: var(--tk-surface-2); filter: none; }

.tk-hint { font-size: 11.5px; color: var(--tk-faint); line-height: 1.45; }
.tk-hint kbd {
  font: 600 10px/1 var(--tk-body);
  padding: 2px 4px;
  border: 1px solid var(--tk-line-strong);
  border-radius: 3px;
  color: var(--tk-muted);
}

.tk-roster { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }

.tk-roster li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 12.5px;
  color: var(--tk-text-soft);
}

.tk-roster .tk-roster-meta { color: var(--tk-faint); font-variant-numeric: tabular-nums; }
.tk-roster .is-ready { color: var(--tk-text); }

.tk-standings { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }

.tk-standings li {
  display: grid;
  grid-template-columns: 22px 1fr auto;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--tk-text-soft);
}

.tk-standings .tk-rank { font-family: var(--tk-display); font-weight: 700; color: var(--tk-faint); }
.tk-standings b { font-family: var(--tk-display); font-size: 18px; color: var(--tk-text); font-variant-numeric: tabular-nums; }

.tk-result {
  font-family: var(--tk-display);
  font-size: 26px;
  font-weight: 700;
  line-height: 1.05;
  color: var(--tk-text);
}

.tk-flash:empty { display: none; }
.tk-flash { font-size: 12px; color: var(--tk-danger); }

/* Feed */
.tk-feed-panel { padding-bottom: 10px; }

.tk-feed {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 148px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.tk-feed li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  font-size: 12px;
  color: var(--tk-muted);
}

.tk-feed .who { font-weight: 600; }
.tk-feed .sq { color: var(--tk-text-soft); font-weight: 600; }
.tk-feed .pts { color: var(--tk-text-soft); font-variant-numeric: tabular-nums; }
.tk-feed-empty { font-size: 12px; color: var(--tk-faint); }

/* Chat: compact, no avatars, names in team colour */
.tk-chat {
  display: flex;
  flex-direction: column;
  min-height: 280px;
  padding-bottom: 10px;
}

.tk-chat-log {
  list-style: none;
  margin: 0 -4px;
  padding: 0 4px;
  flex: 1;
  min-height: 0;
  max-height: 340px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 12.5px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.msg { color: var(--tk-text-soft); }
.msg time {
  display: inline-block;
  min-width: 34px;
  font-size: 10.5px;
  color: var(--tk-faint);
  font-variant-numeric: tabular-nums;
}

.msg-user { font-weight: 600; text-decoration: none; }
.msg-user:hover { text-decoration: underline; }
.msg-tag { color: var(--tk-faint); font-size: 11px; }
.msg.is-system { color: var(--tk-muted); font-style: italic; }
.msg.is-system strong { color: var(--tk-text-soft); font-style: normal; }
.msg.is-private .msg-text { color: #c9b8ff; }
/* /team messages, in their team's colour behind the team icon (--team set on the line) */
.msg.is-team .msg-user, .msg.is-team .msg-text { color: var(--team, var(--tk-text)) !important; }
.msg-team { display: inline-block; vertical-align: -2px; margin-right: 3px; color: var(--team, var(--tk-muted)); }
.tk-chat-log.only-team .msg:not(.is-team) { display: none; }

/* Chat title, with the team icon at its right: shows only team messages while pressed */
.tk-chat-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.tk-chat-head .tk-panel-title { margin-bottom: 0; }
.tk-chat-team { display: inline-flex; padding: 3px; border: 0; border-radius: var(--tk-radius-sm); background: none;
  color: var(--team, var(--tk-muted)); cursor: pointer; line-height: 0; }
.tk-chat-team[hidden] { display: none; }
.tk-chat-team:hover { background: rgba(255, 255, 255, 0.08); }
.tk-chat-team[aria-pressed="true"] { background: color-mix(in srgb, var(--team, #fff) 22%, transparent); box-shadow: inset 0 0 0 1px var(--team, var(--tk-muted)); }
.msg img { max-width: 100%; border-radius: 4px; display: block; margin-top: 4px; }
.msg iframe { max-width: 100%; height: auto; aspect-ratio: 16 / 9; border: 0; }
.msg-loading { font-size: 11px; color: var(--tk-faint); text-align: center; padding: 4px 0; }

.tk-chat-form {
  display: flex;
  gap: 6px;
  margin-top: 10px;
}

.tk-chat-form input {
  flex: 1;
  min-width: 0;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--tk-line-strong);
  border-radius: var(--tk-radius-sm);
  background: var(--tk-surface-2);
  color: var(--tk-text);
  font: 400 13px var(--tk-body);
}

.tk-chat-form input::placeholder { color: var(--tk-faint); }
.tk-chat-form input:focus { outline: none; border-color: var(--tk-muted); }

.tk-chat-form button,
.tk-icon-btn {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  border: 1px solid var(--tk-line-strong);
  border-radius: var(--tk-radius-sm);
  background: var(--tk-surface-2);
  color: var(--tk-text-soft);
  cursor: pointer;
}

.tk-chat-form button:hover,
.tk-icon-btn:hover { background: var(--tk-surface-3); color: var(--tk-text); }

.tk-chat-note { margin-top: 10px; font-size: 12px; color: var(--tk-faint); }

/* ─── Minigame stage ───────────────────────────────────────────────────────
 * Takes the map's place while playing. Its header holds the title, a minimap and the
 * leave buttons; the minigame below is sized (takeover.js fitStage) to fit the screen.
 */

.tk-page.is-playing .tk-map-area,
.tk-page.is-playing .tk-inspect,
.tk-page.is-playing .tk-alert { display: none; }

.tk-stage {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}

.tk-stage[hidden] { display: none; }

.tk-stage-head {
  display: flex;
  align-items: center;
  gap: 14px;
}

.tk-stage-info { flex: 1; min-width: 0; }

.tk-stage-head h2 {
  font-family: var(--tk-display);
  font-size: 22px;
  font-weight: 700;
  line-height: 1.05;
}

.tk-stage-head p { font-size: 12.5px; color: var(--tk-muted); margin-top: 3px; line-height: 1.4; }
.tk-stage-head p strong { color: var(--tk-text); font-variant-numeric: tabular-nums; }

.tk-stage-actions { display: flex; gap: 6px; flex-shrink: 0; }

.tk-btn-danger { background: var(--tk-danger); color: #fff; border-color: var(--tk-danger); }
.tk-btn-danger[hidden] { display: none; }

.tk-stage-frame {
  display: flex;
  justify-content: center;
  min-width: 0;
}

.tk-stage-loading { padding: 80px 0; color: var(--tk-muted); font-size: 13px; }

/* Iframe minigames: an unscaled 500x500 viewport; the whole frame scales down when it doesn't fit */
.tk-frame-box {
  --frame-outer: 504px;
  width: calc(var(--frame-outer) * var(--frame-scale, 1));
  height: calc(var(--frame-outer) * var(--frame-scale, 1));
}

.tk-frame-box .minigame-frame {
  box-sizing: content-box;
  display: block;
  width: 500px;
  height: 500px;
  border: 2px solid var(--tk-line-strong);
  border-radius: 8px;
  background: #0f131b;
  transform-origin: 0 0;
}

.tk-frame-box.is-scaled .minigame-frame { transform: scale(var(--frame-scale)); }

/* Minigame server widget: fluid, its width set to fit */
.tk-pass-box { max-width: 100%; }

/* Minimap: colours, symbols and dots, in the stage header */
.tk-mini {
  --mini-h: 84px;
  height: var(--mini-h);
  aspect-ratio: var(--cols) / var(--rows);
  max-width: 34%;
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  grid-auto-rows: 1fr;
  gap: 1px;
  flex-shrink: 0;
  padding: 2px;
  border-radius: 6px;
  background: var(--tk-line);
}

.tk-mini .tk-cell {
  padding: 0;
  border: 0;
  border-radius: 1px;
  aspect-ratio: auto;
  display: block;
  font-size: 6px;
}

.tk-mini .tk-cell.is-owned { background: var(--team); }
.tk-mini .tk-cell.is-target { box-shadow: inset 0 0 0 1.5px #fff; }
.tk-mini .mini-syms { position: absolute; top: 0; left: 0; display: flex; }
.tk-mini .sym { width: 8px; height: 8px; background: none; padding: 0; }
.tk-mini .sym svg { width: 7px; height: 7px; }
.tk-mini .sym-points { font-size: 5px; width: auto; color: #fff; }
.tk-mini .cell-tokens { position: absolute; right: 1px; bottom: 1px; display: flex; margin: 0; }
.tk-mini .tok { width: 5px; height: 5px; border-radius: 50%; box-shadow: 0 0 0 1px rgba(0,0,0,0.6); animation: none; font-size: 0; }
.tk-mini .tok.is-me { width: 7px; height: 7px; box-shadow: 0 0 0 1px #fff; }
.tk-mini .tok + .tok { margin-left: -2px; }
.tk-mini .ov-attack { border-width: 1.5px; }

@media (max-width: 560px) {
  .tk-stage-head { flex-wrap: wrap; gap: 8px 10px; }
  .tk-stage-info { flex-basis: calc(100% - 110px); }
  .tk-mini { --mini-h: 64px; max-width: 96px; }
  .tk-stage-actions { width: 100%; }
  .tk-stage-actions .tk-btn { flex: 1; }
}

/* ─── Toast ─────────────────────────────────────────────────────────────── */

.tk-toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 2100;
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border: 1px solid var(--toast, var(--tk-line-strong));
  border-radius: var(--tk-radius-sm);
  background: var(--tk-surface-2);
  color: var(--tk-text);
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}

.tk-toast[hidden] { display: none; }

/* ─── Desktop: fill the viewport, panels scroll internally ─────────────── */

@media (min-width: 1024px) {
  html:has(.tk-page) { height: 100%; }

  .tk-page {
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .tk-page .modern-header { flex-shrink: 0; }

  .tk-shell { flex: 1; min-height: 0; }

  .tk-body {
    flex: 1;
    min-height: 0;
    align-items: stretch;
  }

  .tk-board { min-height: 0; }

  .tk-map-area {
    flex: 1;
    min-height: 0;
    container-type: size;
    align-items: center;
  }

  .tk-map {
    --map-w: min(100cqw, calc((100cqh - var(--tk-label)) * var(--cols) / var(--rows) + var(--tk-label)));
  }

  .tk-side {
    min-height: 0;
    overflow-y: auto;
    scrollbar-width: thin;
  }
  .tk-chat { flex: 1; min-height: 180px; }
  .tk-chat-log { max-height: none; }
}

/* Short desktop screens: give the chat the room */
@media (min-width: 1024px) and (max-height: 820px) {
  .tk-shell { gap: 10px; padding-top: 12px; }
  .tk-panel { padding: 12px; }
  .tk-status { gap: 10px; }
  .tk-status .tk-hint { display: none; }
  .tk-feed { max-height: 76px; }
}

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

@media (max-width: 1023px) {
  .tk-body { grid-template-columns: minmax(0, 1fr); }
  .tk-side { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
  .tk-chat { grid-column: 1 / -1; }
}

@media (max-width: 560px) {
  .tk-shell { padding: 12px 12px 20px; }
  .tk-bar h1 { font-size: 24px; }
  .tk-clock { font-size: 32px; }
  .tk-phase { flex-direction: column; align-items: flex-end; gap: 4px; }
  .tk-page { --tk-label: 14px; }
  .tk-map { gap: 3px; }
  .tk-side { display: flex; }
  .tk-chat-form input { font-size: 16px; } /* stops iOS zooming into the field */
}

/* Touch screens have no arrow keys */
@media (hover: none) {
  .tk-hint-keys { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .tk-page *, .tk-page *::before, .tk-page *::after { transition: none !important; }
}

/* ─── Map squares (both modes) ─────────────────────────────────────────────
 * Top: the minigame's name and your target mark. Middle: the defence. Bottom: players
 * (and teammates' aims) on the left, symbols on the right. Nothing is drawn over the text:
 * what a click does shows as a tint (attackable) or a hover (a step).
 */

.tk-cell { justify-content: space-between; gap: 0.15em; }
.tk-cell.is-owned { background: color-mix(in srgb, var(--team) 72%, var(--tk-bg)); }

.cell-top { display: flex; align-items: flex-start; gap: 0.3em; min-width: 0; }
.cell-name {
  flex: 1;
  min-width: 0;
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.82em;
  font-weight: 500;
  opacity: 0.75;
}
.tk-cell:not(.is-owned) .cell-name { color: var(--tk-muted); opacity: 1; }
.cell-name.is-long { font-size: 0.82em; }

.cell-def {
  font-family: var(--tk-display);
  font-size: 1.5em;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  min-height: 1em;
}
.tk-cell.is-fading .cell-def { opacity: 0.72; }
.tk-cell.is-fading .cell-def::after { content: ' ↓'; font-size: 0.6em; }

.cell-bottom { display: flex; align-items: flex-end; justify-content: space-between; gap: 0.2em; min-width: 0; }
.cell-bottom .cell-tokens { margin: 0; flex-wrap: nowrap; align-items: center; }
.cell-syms { display: flex; gap: 0.15em; flex-shrink: 0; }

.sym {
  width: 1.45em;
  height: 1.45em;
  display: grid;
  place-items: center;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.3);
  color: #fff;
}
.sym svg { width: 0.95em; height: 0.95em; }
.sym-power { color: #ffd166; }
.sym-hq { color: var(--c); background: rgba(0, 0, 0, 0.55); }
.sym-points { width: auto; padding: 0 0.3em; color: #9ad1ff; font-size: 0.85em; letter-spacing: -0.1em; }

.cell-aim { width: 1.1em; height: 1.1em; flex-shrink: 0; color: #fff; }
.cell-aim svg { width: 100%; height: 100%; }

/* Cut off from the HQ: lightly hatched */
.tk-cell.is-isolated::before {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(135deg, rgba(0,0,0,0.28) 0 3px, transparent 3px 9px);
  pointer-events: none;
}

/* Attackable: a tint of your colour; your target: stronger, with the mark at the top */
.tk-cell.can-aim {
  cursor: crosshair;
  background-image: linear-gradient(color-mix(in srgb, var(--me) 16%, transparent), color-mix(in srgb, var(--me) 16%, transparent));
}
.tk-cell.can-aim:hover { background-image: linear-gradient(color-mix(in srgb, var(--me) 30%, transparent), color-mix(in srgb, var(--me) 30%, transparent)); }
.tk-cell.is-target { background-image: linear-gradient(color-mix(in srgb, var(--me) 34%, transparent), color-mix(in srgb, var(--me) 34%, transparent)); }
.tk-cell.is-owned.can-aim,
.tk-cell.is-owned.is-target { background-image: linear-gradient(rgba(255,255,255,0.14), rgba(255,255,255,0.14)); }

/* A step onto your own land: shows on hover */
.tk-cell.can-step { cursor: pointer; }
.tk-cell.can-step:hover { filter: brightness(1.18); }
.tk-cell.can-step-wait { cursor: wait; }

/* Classic movement keeps its outline (it isn't over any text there either) */
.tk-cell.can-move { outline: 2px dashed var(--me); outline-offset: -4px; cursor: pointer; }
.tk-cell.can-wait { outline: 2px dotted color-mix(in srgb, var(--me) 45%, transparent); outline-offset: -4px; cursor: not-allowed; }

/* Someone is playing for this square right now: a pulsing glow inside its edge */
.ov-attack {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  box-shadow: inset 0 0 0 2px var(--c);
  animation: tk-attack 1.1s ease-in-out infinite;
}
@keyframes tk-attack { 50% { box-shadow: inset 0 0 14px 3px var(--c); } }

.ov-aim {
  width: 0.8em;
  height: 0.8em;
  border-radius: 50%;
  border: 2px solid var(--c);
  flex-shrink: 0;
  margin-left: 0.2em;
}

.ov-ping {
  flex-shrink: 0;
  width: 1.5em;
  height: 1.5em;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #fff;
  color: #0b0e14;
  font-size: 0.85em;
  font-weight: 800;
  line-height: 1;
  animation: tk-ping 1.4s ease-out infinite;
}
@keyframes tk-ping { 0% { box-shadow: 0 0 0 0 rgba(255,255,255,0.7); } 100% { box-shadow: 0 0 0 7px rgba(255,255,255,0); } }
.ov-ping svg { width: 0.9em; height: 0.9em; }
.tk-ping-btn svg { width: 13px; height: 13px; }
.tk-map.is-ping-mode .tk-cell[data-r] { cursor: copy; }

/* A square that just changed hands flashes */
.tk-cell.just-taken { animation: tk-taken 0.7s ease-out; }
@keyframes tk-taken {
  0% { filter: brightness(2) saturate(1.3); transform: scale(0.95); }
  100% { filter: none; transform: none; }
}

/* Tokens: avatars ringed in team colour; you are a little bigger */
.tok {
  background-color: var(--c);
  background-size: cover;
  background-position: center;
  box-shadow: 0 0 0 2px var(--c), 0 0 0 3px var(--tk-bg);
}
.tok.is-me { width: 2.4em; height: 2.4em; box-shadow: 0 0 0 2px var(--c), 0 0 0 4px #fff; }
.tok + .tok { margin-left: -0.5em; }

/* Scoreboard */
.tk-score-team small { font-size: 10px; font-weight: 600; letter-spacing: 0.02em; text-transform: none; color: var(--tk-faint); }
.is-frontier .tk-score-team b { font-size: 28px; }
.tk-score-unit { align-self: center; font-size: 10px; color: var(--tk-faint); text-transform: uppercase; letter-spacing: 0.08em; }
.tk-score-bar { height: 8px; }

/* Overtime */
.is-overtime .tk-phase-label { color: #ffb347; }
.is-overtime .tk-clock { color: #ffb347; }

/* Incoming attack banner */
.tk-alert { display: flex; flex-direction: column; gap: 6px; }
.tk-alert[hidden] { display: none; }
.tk-alert-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--team);
  border-radius: var(--tk-radius-sm);
  background: color-mix(in srgb, var(--team) 16%, var(--tk-surface));
  font-size: 13px;
}
.tk-alert-row > span:nth-child(2) { flex: 1; }
.tk-alert-icon { width: 20px; height: 20px; color: var(--team); flex-shrink: 0; }
.tk-alert-row .tk-btn { width: auto; flex-shrink: 0; }

.tk-btn-small { min-height: 32px; padding: 0 12px; font-size: 12.5px; width: auto; }

/* Pings and rules */
.tk-pings { display: flex; gap: 6px; flex-wrap: wrap; }
.tk-ping-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 30px;
  padding: 0 9px;
  border: 1px solid var(--tk-line-strong);
  border-radius: 999px;
  background: var(--tk-surface-2);
  color: var(--tk-text-soft);
  font: 600 11.5px var(--tk-body);
  cursor: pointer;
}
.tk-ping-btn:hover { background: var(--tk-surface-3); color: var(--tk-text); }
.tk-ping-btn.is-on { border-color: var(--me); color: var(--tk-text); background: color-mix(in srgb, var(--me) 20%, var(--tk-surface-2)); }

.tk-rules { font-size: 12px; color: var(--tk-muted); }
.tk-rules summary { cursor: pointer; font-weight: 600; color: var(--tk-text-soft); }
.tk-rules ul { margin: 8px 0 0; padding-left: 18px; display: flex; flex-direction: column; gap: 4px; line-height: 1.45; }
.tk-rules strong { color: var(--tk-text); }

.tk-feed li.is-took { font-weight: 600; }

@media (prefers-reduced-motion: reduce) {
  .tk-page *, .tk-page *::before, .tk-page *::after { animation: none !important; }
}
