.lobby {
  --bottom-nav-height: 73px;
  min-height: 100dvh;
}

.lobby .site-header {
  max-width: 680px;
  height: 78px;
  padding: 0 24px;
  margin: 0 auto;
  border-bottom: 1px solid var(--control-border);
}

.wordmark {
  color: var(--ink);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.7px;
  text-decoration: none;
}

.wordmark span {
  color: var(--muted);
  font-weight: 400;
}

.account-label {
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 12px;
  text-decoration: none;
}

.app-main {
  width: calc(100% - 48px);
  max-width: 632px;
  margin: 0 auto;
  padding: 34px 0 calc(110px + env(safe-area-inset-bottom));
}

.page h1 {
  color: var(--ink);
  font:
    600 25px/1.3 Arial,
    sans-serif;
  letter-spacing: -0.7px;
  margin: 0 0 24px;
}

.page-description {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
  margin: -8px 0 26px;
}

.play-page {
  min-height: calc(100dvh - 330px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.matchmaking {
  width: 100%;
  max-width: 320px;
}

.matchmaking h1 {
  font-size: 25px;
  margin-bottom: 10px;
}

.match-format {
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 32px;
}

.button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-height: 44px;
  padding: 12px 20px;
  border: 1px solid var(--accent);
  border-radius: 7px;
  background: var(--accent);
  color: #ffffff;
  font:
    500 13px Arial,
    sans-serif;
  line-height: 1.3;
  text-decoration: none;
  cursor: pointer;
}

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

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

.button.secondary {
  color: var(--ink);
  background: transparent;
  border-color: var(--control-border);
}

.button.secondary:hover {
  background: var(--surface-hover);
}

.button.small {
  padding: 10px 14px;
  font-size: 12px;
}

.match-button {
  min-width: 140px;
  min-height: 44px;
  font-size: 16px;
  font-weight: 600;
}

.play-actions {
  margin-top: 20px;
}

.offline-play {
  width: 100%;
  max-width: 320px;
  margin-top: 40px;
  padding-top: 24px;
  border-top: 1px solid var(--control-border);
}
.offline-play h2 { font-size: 16px; margin: 0 0 8px; }
.team-play { width: 100%; max-width: 360px; margin-top: 36px; padding-top: 24px; border-top: 1px solid var(--control-border); }
.team-play h2 { margin: 0 0 8px; font-size: 18px; }
.team-play p { font-size: 12px; line-height: 1.6; color: var(--muted); }
.team-friend-invite { display: flex; gap: 8px; margin-top: 12px; }
.team-friend-invite select { min-width: 0; flex: 1; padding: 8px; border: 1px solid var(--control-border); border-radius: 6px; color: var(--ink); background: var(--surface); font: inherit; font-size: 12px; }
#team-dialog label { display: block; font-size: 12px; margin-top: 24px; }
#team-dialog .team-friend-invite { margin-top: 8px; }
#team-dialog > p:not(.form-error) { color: var(--muted); font-size: 13px; line-height: 1.6; }
#team-dialog #fill-teammate { width: 100%; }
#team-invites .person-row { text-align: left; flex-wrap: wrap; gap: 10px; }
.offline-play p { color: var(--muted); font-size: 12px; line-height: 1.6; margin: 0 0 16px; }

.queue-message {
  min-height: 20px;
  margin: 17px 0 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.7;
}

.search-spinner {
  width: 32px;
  height: 32px;
  margin: 0 auto 20px;
  border: 3px solid var(--control-border);
  border-top-color: var(--accent);
  border-right-color: transparent;
  border-radius: 50%;
  animation: searching 1s linear infinite;
}

@keyframes searching {
  to {
    transform: rotate(360deg);
  }
}

.text-button {
  min-height: 44px;
  border: 0;
  background: none;
  padding: 10px 0;
  color: var(--muted);
  font:
    12px Arial,
    sans-serif;
  cursor: pointer;
}

.text-button:hover {
  color: var(--ink);
}

.bottom-nav {
  position: fixed;
  z-index: 5;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  width: 100%;
  max-width: 680px;
  padding: 9px 12px calc(9px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--control-border);
  background: var(--surface);
}

.bottom-nav a {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 54px;
  border-radius: 7px;
  color: var(--muted);
  text-decoration: none;
  font-size: 10px;
}

.bottom-nav a[aria-current="page"] {
  color: var(--accent);
  background: var(--surface-hover);
}

.bottom-nav a:hover {
  color: var(--ink);
}

.bottom-nav svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.page-heading {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 24px;
}

.page-heading h1 {
  margin-bottom: 0;
}

.count {
  color: var(--muted);
  font-size: 12px;
}

.inline-form {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
}

input {
  min-height: 44px;
  width: 100%;
  min-width: 0;
  border: 1px solid var(--control-border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  padding: 12px;
  font:
    13px Arial,
    sans-serif;
}

input::placeholder {
  color: var(--muted);
}

.inline-form input {
  flex: 1;
}

.inline-form button {
  flex-shrink: 0;
}

.empty-state {
  padding: 45px 0;
}

.empty-state h2 {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 500;
}

.empty-state p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.7;
}

.person-row,
.history-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 17px 0;
  border-bottom: 1px solid var(--control-border);
}

.person-info {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.avatar {
  flex-shrink: 0;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--surface-hover);
  color: var(--ink);
  font-size: 13px;
  text-transform: uppercase;
  overflow: hidden;
}

.avatar img { display: block; width: 100%; height: 100%; object-fit: cover; }
.avatar-large { width: 72px; height: 72px; font-size: 28px; }
.avatar-button { border: 0; padding: 0; cursor: pointer; }
.avatar-button:hover { box-shadow: 0 0 0 3px var(--control-border); }
.avatar-button:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
.own-profile-heading { display: flex; align-items: center; gap: 16px; margin-bottom: 30px; }
.own-profile-heading .profile-name { margin: 0; overflow-wrap: anywhere; }
#picture-dialog { max-width: 420px; }
.picture-expanded { width: min(256px, 100%); height: auto; aspect-ratio: 1; margin: 24px auto; border-radius: 12px; font-size: 80px; }
.picture-controls { min-width: 0; flex: 1; }
.picture-controls .profile-actions { margin-top: 16px; align-items: center; justify-content: center; }
.picture-controls > .form-hint { text-align: center; line-height: 1.6; }
.picture-controls [role="status"] { margin-top: 10px; line-height: 1.6; }
.player-profile-heading { display: flex; align-items: center; gap: 16px; margin-bottom: 16px; }
.player-profile-heading #friend-profile-title { margin: 0; }

.person-row strong,
.history-row strong {
  font-size: 12px;
  font-weight: 500;
  overflow-wrap: anywhere;
}

.person-row small,
.history-row small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.6;
}

.row-actions {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  gap: 12px;
}


:is(#history-list, #friend-history-list) .history-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
}

:is(#history-list, #friend-history-list) .history-row > div:first-child {
  min-width: 0;
}

#history-list .row-actions {
  justify-content: flex-end;
  flex-wrap: nowrap;
}

#history-list .result {
  min-width: 48px;
  text-align: center;
  white-space: nowrap;
}

.result {
  padding: 5px 9px;
  border-radius: 4px;
  background: #e8f0ec;
  color: var(--player-one);
  font-size: 11px;
}

.result.loss {
  background: var(--player-two-goal);
  color: #97513d;
}

.result.local {
  background: var(--surface-hover);
  color: var(--muted);
}


.profile-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.profile-name {
  font-size: 16px;
  margin: 0 0 30px;
}

.profile-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  padding: 22px 0;
  border-top: 1px solid var(--control-border);
  border-bottom: 1px solid var(--control-border);
  margin: 0;
}

.profile-stats dt {
  font-size: 12px;
  color: var(--muted);
}

.profile-stats dd {
  font-size: 25px;
  margin: 10px 0 0;
}

.stat-note {
  color: var(--muted);
  font-size: 11px;
  margin: 12px 0 24px;
}

.notice {
  border: 1px solid var(--control-border);
  border-radius: 6px;
  padding: 12px 14px;
  background: var(--surface);
  font-size: 12px;
  line-height: 1.7;
}

.notice.error {
  border-color: #ebc9c9;
  background: #fff1f1;
  color: var(--danger);
}

dialog {
  width: calc(100% - 32px);
  max-width: 400px;
  padding: 35px 28px 25px;
  border: 1px solid var(--control-border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
}

dialog::backdrop {
  background: #14202b80;
}

#search-dialog {
  max-width: 340px;
  max-height: calc(100dvh - 32px);
  padding: 32px 24px 24px;
  text-align: center;
  overflow: auto;
}
#search-dialog h2 { font-size: 22px; margin-bottom: 8px; }
#search-mode { margin: 0; color: var(--muted); font-size: 13px; }
#search-elapsed { margin: 20px 0 24px; font-size: 16px; font-variant-numeric: tabular-nums; }
#search-error:empty { display: none; }
#search-error { margin: 0 0 16px; }
#cancel-matchmaking { width: 100%; min-height: 48px; touch-action: manipulation; }
.lobby:has(#search-dialog[open]) { overflow: hidden; }

.dialog-close {
  width: 44px;
  height: 44px;
  position: absolute;
  top: 10px;
  right: 15px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 24px;
  cursor: pointer;
}

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

#auth-description {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.7;
  margin-bottom: 24px;
}

#auth-form,
#username-form {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

#auth-form label,
#username-form label {
  font-size: 12px;
  margin-top: 5px;
}

#auth-submit {
  margin-top: 4px;
}

.form-hint {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
}

.form-error {
  min-height: 14px;
  margin: 0;
  color: var(--danger);
  font-size: 12px;
  line-height: 1.7;
}

.switch-auth {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  margin: 22px 0 0;
}

.switch-auth button {
  color: var(--accent);
}

.google-button {
  width: 100%;
  background: var(--surface);
  color: var(--ink);
  border-color: var(--control-border);
}

.google-button:hover {
  background: var(--surface-hover);
  color: var(--ink);
  border-color: var(--control-border);
}

.auth-divider {
  margin: 18px 0;
  text-align: center;
  color: var(--muted);
  font-size: 11px;
}

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

[hidden] {
  display: none !important;
}

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

@media (max-width: 480px) {
  .lobby input, .lobby select { font-size: 16px !important; min-height: 44px; }
  .lobby .site-header {
    height: 68px;
    padding: 0 20px;
  }

  .wordmark {
    font-size: 18px;
  }

  .account-label {
    max-width: 110px;
    font-size: 11px;
  }

  .app-main {
    width: calc(100% - 40px);
    padding-top: 28px;
  }

  .person-row,
  .history-row {
    flex-wrap: wrap;
    gap: 10px;
  }

  .row-actions {
    flex-wrap: wrap;
  }
}

@media (prefers-reduced-motion: reduce) {
  .search-spinner {
    animation: none;
  }
}

.mode-profile { margin-bottom: 28px; }
.mode-profile-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin-bottom: 12px; }
.mode-profile-heading h2 { margin: 0; font-size: 16px; font-weight: 500; }
.profile-rating { font-size: 28px; font-variant-numeric: tabular-nums; }
.mode-profile .profile-stats { padding: 16px 0; }
.unrated-label { color: var(--muted); font-size: 12px; }
.history-rating { font-variant-numeric: tabular-nums; }
.rating-gain { color: var(--player-one); font-weight: 600; }
.rating-loss { color: var(--danger); font-weight: 600; }

.bottom-nav a { position: relative; }
.invite-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: #d4343b; flex-shrink: 0; }
#friend-invite-badge { position: absolute; top: 7px; left: calc(50% + 9px); border: 2px solid var(--surface, #fff); width: 11px; height: 11px; }
.invite-dot[hidden] { display: none; }
.friend-row-dot { margin-right: 7px; }
.invite-options { display: flex; gap: 12px; margin-top: 20px; }
.invite-options > button { flex: 1; }

.mode-profile:has(.rating-distribution) .profile-stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.rating-distribution { margin: 0 0 26px; }
.distribution-summary { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 16px; font-size: 11px; color: var(--muted); }
.distribution-summary strong { color: var(--ink); font-weight: 500; }
.rating-distribution svg { display: block; width: 100%; height: auto; margin-top: 12px; overflow: visible; }
.rating-density-area { fill: var(--accent); opacity: 0.14; }
.rating-density-curve { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.rating-marker { stroke: var(--ink); stroke-width: 1.5; stroke-dasharray: 3 3; }
.rating-axis { fill: var(--muted); font-size: 17px; }
.rating-you { fill: var(--ink); font-size: 18px; font-weight: 500; }
.distribution-empty { font-size: 12px; color: var(--muted); margin: 14px 0; }

.distribution-title { margin: 16px 0 10px; font-size: 13px; font-weight: 500; }
.rating-grid { stroke: var(--control-border); stroke-width: 1; }

.unrated-play { border-top: 1px solid var(--control-border); padding: 24px 0; }
.unrated-play h2 { font-size: 16px; font-weight: 500; margin: 0 0 10px; }
.unrated-play > p:not(.queue-message) { color: var(--muted); font-size: 12px; margin-bottom: 16px; }
.unrated-play .queue-message:empty { display: none; }

/* Compact Home: rated and unrated choices align by mode, with offline below. */
.play-page { min-height: 0; justify-content: flex-start; padding-top: 16px; }
.online-modes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; width: 100%; max-width: 480px; }
.online-modes .matchmaking, .online-modes .team-play { min-width: 0; max-width: none; width: 100%; margin: 0; padding: 0; border: 0; }
.online-modes h1, .online-modes h2 { font-size: 22px; font-weight: 600; line-height: 1.3; margin: 0; letter-spacing: -.5px; }
.online-modes .match-format { font-size: 12px; line-height: 1.6; margin: 8px 0 20px; }
.online-modes .play-actions { display: grid; gap: 10px; margin: 0; }
.online-modes .button { min-width: 0; width: 100%; min-height: 56px; padding: 8px 12px; touch-action: manipulation; }
.online-modes .queue-message, #team-status { min-height: 0; margin: 10px 0 0; }
.online-modes .queue-message:empty, #team-status:empty { display: none; }
.play-page .offline-play { display: flex; align-items: center; justify-content: space-between; gap: 16px; width: 100%; max-width: 480px; margin-top: 28px; padding-top: 22px; text-align: left; }
.play-page .offline-play h2 { margin: 0 0 6px; }
.play-page .offline-play p { margin: 0; }
.play-page .offline-play .button { flex-shrink: 0; }
.play-page #team-invites { width: 100%; max-width: 480px; }
.ai-play { width: 100%; max-width: 480px; margin-top: 28px; padding-top: 22px; border-top: 1px solid var(--control-border); text-align: left; }
.ai-play h2 { margin: 0; font-size: 20px; }
.ai-play .page-heading { margin-bottom: 12px; }
.ai-play .match-format { margin: 6px 0 0; font-size: 12px; }
.ai-play > .button { width: 100%; }
#ai-setup { display: grid; grid-template-columns: 1fr; gap: 8px; }
#ai-setup label { font-size: 12px; color: var(--muted); }
#ai-setup label[for="ai-setup-side"] { margin-top: 12px; }
#ai-setup select { min-width: 0; width: 100%; padding: 10px; border: 1px solid var(--control-border); border-radius: 6px; background: var(--surface); color: var(--ink); font: inherit; font-size: 13px; }
#ai-setup button { margin-top: 16px; }
#resume-ai { display: inline-block; margin-top: 12px; }
@media (max-width: 480px) { .online-modes { gap: 18px; } .play-page { padding-top: 8px; } }

.friend-profile-link { color: inherit; text-decoration: none; min-width: 0; }
.friend-profile-link:hover strong { text-decoration: underline; }
.friend-profile-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 4px; }
.friend-presence { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.person-row small.friend-presence { display: flex; }
.presence-dot { display: inline-block; flex-shrink: 0; width: 7px; height: 7px; border-radius: 50%; background: #99a1a8; }
.friend-presence.online .presence-dot { background: var(--accent); }
#friend-profile-title { margin-bottom: 10px; overflow-wrap: anywhere; }
#friend-profile-presence { margin: 0 0 28px; }
#friend-history { border-top: 1px solid var(--control-border); padding-top: 24px; }
#friend-history h2 { font-size: 18px; margin: 0 0 12px; }

.profile-history { margin-top: 32px; }
.profile-history h2 { font-size: 18px; margin: 0 0 12px; }
.profile-history h3 { font-size: 14px; font-weight: 500; }
.pagination { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 24px; }
.pagination span, .list-status { color: var(--muted); font-size: 12px; line-height: 1.7; }
.mode-switch { display: flex; gap: 4px; padding: 4px; margin-bottom: 24px; border: 1px solid var(--control-border); border-radius: 8px; background: var(--surface); }
.mode-switch button { flex: 1; min-height: 42px; border: 0; border-radius: 5px; background: transparent; color: var(--muted); font: 500 13px Arial, sans-serif; cursor: pointer; }
.mode-switch button[aria-pressed="true"] { background: var(--accent); color: #fff; }
.leaderboard-list { list-style: none; padding: 0; margin: 16px 0 0; }
.leaderboard-row { display: flex; align-items: center; gap: 12px; padding: 18px 0; border-bottom: 1px solid var(--control-border); color: var(--ink); text-decoration: none; }
.leaderboard-row:hover { background: var(--surface-hover); }
.leaderboard-rank { width: 28px; flex-shrink: 0; color: var(--muted); font-size: 12px; text-align: center; }
.leaderboard-player { flex: 1; min-width: 0; }
.leaderboard-player strong { font-size: 13px; overflow-wrap: anywhere; }
.leaderboard-rating { flex-shrink: 0; color: var(--accent); font-size: 18px; font-variant-numeric: tabular-nums; }
