.identity-pilot {
  box-sizing: border-box;
  width: min(100%, 46rem);
  margin: -.4rem auto 1rem;
  padding: 0 1rem;
}

.identity-pill {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  min-height: 2.5rem;
  padding: .55rem .95rem;
  border: 1px solid rgba(21, 59, 53, .25);
  border-radius: 999px;
  background: #fff;
  color: #153b35;
  font-weight: 750;
  box-shadow: 0 3px 12px rgba(21, 59, 53, .09);
}

.identity-pill-gear {
  flex: none;
  opacity: .62;
}

.identity-session-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .75rem;
}

.identity-status {
  display: inline;
  margin-left: .65rem;
  color: #53635f;
  font-size: .84rem;
}

.identity-status:empty { display: none; }

.home-admin-link {
  display: block;
  width: fit-content;
  margin: 1rem auto 0;
  padding: .45rem;
  color: #53635f;
  font-size: .82rem;
}

.home-admin-link.hidden { display: none; }

.identity-account {
  margin: 0;
  padding: 1rem;
  border: 1px solid rgba(21, 59, 53, .16);
  border-radius: 1rem;
  background: rgba(255, 255, 255, .82);
}

.identity-account-heading,
.identity-history-item > div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
}

.identity-account-heading h2 { margin: 0; }

.identity-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: .5rem;
  margin: .9rem 0;
}

.identity-stats > div {
  padding: .65rem .5rem;
  border-radius: .75rem;
  background: #eef4f1;
  text-align: center;
}

.identity-stats strong,
.identity-stats span { display: block; }
.identity-stats strong { font-size: 1.25rem; }
.identity-stats strong { overflow-wrap: anywhere; }
.identity-stats span { font-size: .72rem; color: #53635f; }
.identity-stats-note { grid-column: 1 / -1; margin: 0; color: #53635f; font-size: .78rem; }

.identity-history {
  width: fit-content;
  max-width: 100%;
  margin-top: .35rem;
}

.identity-history > summary {
  display: list-item;
  width: fit-content;
  padding: .25rem .2rem;
  cursor: pointer;
  font-weight: 750;
  line-height: 1.5;
}

.identity-history > summary::marker { color: #53635f; }
.identity-history[open] { width: 100%; }
.identity-history-count { margin-left: .3rem; color: #53635f; font-size: .82rem; font-weight: 700; }
.identity-history-list { display: grid; gap: .55rem; margin-top: .55rem; }
.identity-history-more { justify-self: center; }

.identity-history-item {
  box-sizing: border-box;
  width: 100%;
  padding: .75rem;
  border: 1px solid rgba(21, 59, 53, .12);
  border-radius: .75rem;
  background: #fff;
  color: inherit;
  font: inherit;
  text-align: left;
}

.identity-history-item:is(button) { cursor: pointer; }
.identity-history-item:is(button):hover { border-color: rgba(21, 59, 53, .32); }
.identity-history-item:is(button):focus-visible {
  outline: 3px solid rgba(201, 163, 72, .55);
  outline-offset: 2px;
}
.identity-history-item p { margin: .25rem 0; color: #53635f; font-size: .82rem; }
.identity-coverage-label { padding: .2rem .45rem; border-radius: 999px; background: #e7f2ec; color: #153b35; font-size: .72rem; font-weight: 750; }
.identity-coverage-label[data-result="loss"] { background: #f7dfdc; color: #7f2a24; }
.identity-coverage-label[data-result="tie"] { background: #e3ebf5; color: #2b4a6e; }
.identity-coverage-label:is([data-result="incomplete"], [data-result="pending"]) { background: #f3ead9; color: #6b5324; }

.identity-history-dialog {
  box-sizing: border-box;
  width: min(44rem, calc(100% - 1.5rem));
  max-height: calc(100dvh - 1.5rem);
  margin: auto;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 1rem;
  background: #f8f3e8;
  color: #153b35;
  box-shadow: 0 24px 70px rgba(14, 44, 38, .28);
}

.identity-history-dialog::backdrop { background: rgba(7, 26, 22, .56); }

.identity-history-detail-shell {
  position: relative;
  box-sizing: border-box;
  max-height: calc(100dvh - 1.5rem);
  padding: 1.1rem;
  overflow-y: auto;
}

.identity-history-detail-shell > .eyebrow,
.identity-history-detail-shell > h2 { margin-right: 2.5rem; }
.identity-history-detail-shell > h2 { margin-top: .25rem; }
.identity-history-detail-body { display: grid; gap: 1rem; }
.identity-history-detail-body[aria-busy="true"] { min-height: 8rem; place-items: center; }
.identity-history-detail-body > section > h3,
.identity-history-round > h3 { margin: 0 0 .55rem; font-size: .95rem; }
.identity-history-rounds { display: grid; gap: 1rem; }
.identity-history-rounds > h3 { margin-bottom: 0; }
.identity-history-round .round-result-list { margin: 0; }
.identity-history-team {
  padding: .7rem .8rem;
  border: 1px solid rgba(21, 59, 53, .12);
  border-radius: .75rem;
  background: #fff;
}
.identity-history-team + .identity-history-team { margin-top: .5rem; }
.identity-history-team > div { display: flex; justify-content: space-between; gap: .75rem; }
.identity-history-team p,
.identity-history-players,
.identity-history-available-total,
.identity-history-unavailable,
.identity-history-loading { margin: .3rem 0 0; color: #53635f; }
.identity-history-detail-shell > .wide-button { margin-top: 1rem; }

@media (max-width: 480px) {
  .identity-history-dialog {
    width: 100%;
    max-width: none;
    max-height: 100dvh;
    border-radius: 0;
  }
  .identity-history-detail-shell {
    min-height: 100dvh;
    max-height: 100dvh;
    padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right))
      max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
  }
  /* Full screen on a phone, the top of the dialog sits under the status bar,
     where the close button can't be tapped. Keep it below and in view. */
  .identity-history-detail-shell > .identity-dialog-close {
    position: fixed;
    z-index: 1;
    top: calc(env(safe-area-inset-top) + .5rem);
    right: max(.5rem, env(safe-area-inset-right));
    background: var(--paper);
    box-shadow: 0 2px 10px rgba(12, 28, 24, .18);
  }
  .identity-history-detail-shell > .eyebrow { margin-top: 2.75rem; }
}

.identity-dialog {
  width: min(calc(100% - 2rem), 28rem);
  padding: 0;
  border: 0;
  border-radius: 1.25rem;
  box-shadow: 0 24px 70px rgba(20, 35, 31, .3);
}

.identity-dialog::backdrop { background: rgba(12, 28, 24, .55); }
.identity-dialog form { padding: 1.35rem; }
.identity-dialog h2 { margin: .2rem 0 .5rem; }
.identity-dialog p { color: #53635f; }
.identity-dialog-actions { display: flex; flex-wrap: wrap; gap: .65rem; margin-top: 1rem; }

.identity-settings-dialog form { position: relative; }

.identity-dialog-close {
  position: absolute;
  top: .65rem;
  right: .65rem;
  width: 44px;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: #53635f;
  font-size: 1.6rem;
  line-height: 1;
}

.identity-settings-dialog label,
.identity-notification-default span { display: block; font-weight: 750; }

.identity-settings-dialog input {
  box-sizing: border-box;
  width: 100%;
  min-height: 44px;
  margin-top: .35rem;
}

.identity-settings-status,
.identity-notification-state {
  min-height: 1.25rem;
  margin: .45rem 0 0;
  color: #53635f;
  font-size: .84rem;
}

.identity-settings-status:empty,
.identity-notification-state:empty { display: none; }

.identity-settings-status[data-state="error"],
.identity-notification-state[data-state="error"] { color: #8a2e26; }

.identity-notification-settings {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid rgba(21, 59, 53, .14);
}

.identity-notification-default {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: .85rem;
  margin: 0 0 .45rem;
}

.identity-notification-default > div { min-width: 0; }

.identity-notification-settings > button {
  min-height: 44px;
  margin-top: .55rem;
}

.identity-settings-sign-out {
  min-height: 44px;
  margin-top: 1rem;
  padding: .5rem .9rem;
  border: 1px solid rgba(138, 46, 38, .32);
  border-radius: 999px;
  background: #fff7f5;
  color: #8a2e26;
  font-weight: 750;
}

.identity-sign-ins { margin-top: 1rem; }
.identity-sign-ins h3 { margin: 0 0 .4rem; font-size: 1rem; }
.identity-sign-in-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .25rem 0; font-weight: 750; }
.identity-sign-in-row button { min-height: 44px; min-width: 6rem; }
.identity-sign-in-row button:disabled { opacity: .5; }
.identity-sign-ins-note { margin: .35rem 0 0; font-size: .9rem; color: var(--muted); }

.identity-theme-setting { margin-top: 1rem; }
.identity-theme-setting > span { display: block; font-weight: 750; }

.identity-theme-options {
  display: flex;
  gap: .4rem;
  margin-top: .35rem;
}

.identity-theme-option {
  flex: 1 1 0;
  min-width: 0;
  min-height: 44px;
  padding: .5rem .55rem;
  border: 1px solid #cad9ce;
  border-radius: 999px;
  background: #e8efe9;
  color: #153b35;
  font-weight: 750;
}

.identity-theme-option[aria-checked="true"] {
  border-color: #153b35;
  background: #153b35;
  color: #fff;
}

/* The dark palette lives with the control because the dialog opens from Home
   and from the lobby; home-dark.css only reaches one phase at a time. */
html[data-scheme="dark"] .identity-theme-options .identity-theme-option {
  border-color: #3a5048;
  background: #24352f;
  color: #cfe3da;
}

html[data-scheme="dark"] .identity-theme-options .identity-theme-option[aria-checked="true"] {
  border-color: #2f7a68;
  background: #2f7a68;
  color: #fff;
}

.identity-callback-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 1rem;
  background: #edf3f0;
  color: #153b35;
  font: 16px/1.5 system-ui, sans-serif;
}

.identity-callback-card {
  width: min(100%, 30rem);
  padding: 1.5rem;
  border-radius: 1rem;
  background: #fff;
  box-shadow: 0 12px 45px rgba(21, 59, 53, .18);
}

@media (max-width: 480px) {
  .identity-pilot { padding: 0 .75rem; }
  .identity-status { display: block; margin: .4rem 0 0; }
  .identity-account-heading { align-items: flex-start; }
  .identity-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .identity-settings-dialog {
    width: min(calc(100% - 1rem), 28rem);
    max-height: calc(100dvh - 1rem);
  }
  .identity-settings-dialog form { overflow-y: auto; max-height: calc(100dvh - 1rem); }
}

@media (max-height: 480px) and (orientation: landscape) {
  .identity-dialog form { padding: .9rem 1rem; }
  .identity-dialog h2 { font-size: 1.25rem; }
  .identity-dialog p { margin: .4rem 0; }
  .identity-settings-dialog { max-height: calc(100dvh - .5rem); }
  .identity-settings-dialog form { max-height: calc(100dvh - .5rem); overflow-y: auto; }
}

button.identity-history-item {
  position: relative;
  padding-right: 2rem;
}
button.identity-history-item::after {
  content: "";
  position: absolute;
  right: .85rem;
  top: calc(50% - 4px);
  width: 7px;
  height: 7px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
}
button.identity-history-item:focus-visible {
  outline-color: #153b35;
}

#player-table-style { margin: 1rem 0; }
#interface-toggle { color: inherit; }
#interface-setting-label { color: inherit; }
