/*
 * EXPERIENCE — XP login screen.
 *
 * An on-demand authentication surface, not the front door. It is raised over a
 * live desktop when a protected feature asks for an account, and removed again
 * when the user signs in or chooses Guest. The XP visual language below is
 * unchanged from Build 02A; only the lifecycle around it changed.
 *
 * Adapted from the Windows XP Welcome screen layout in the reference project
 * at docs/reference/login/xp-main (header/main/footer bands, the radial blue
 * field, the vertical white gradient rule, the beveled square user tile).
 * Colours, gradients and band proportions come from that reference's
 * styles/style.scss; the tile plate, focus/hover/loading states, the error
 * dialog and every responsive rule are new.
 *
 * Everything here is scoped under #xp-login. This file must never restyle the
 * desktop, taskbar, Start menu or windows — only the shell surface that sits
 * in front of them while signed out.
 */

/* ---------------------------------------------------------------- palette */

#xp-login {
  /* From the reference SCSS: $blackBlue and the main radial field stops. */
  --xp-login-band: #084da3;
  --xp-login-field-inner: #9cc0e9;
  --xp-login-field-outer: #508fd9;
  --xp-login-rule: #ffffff;
  --xp-login-tile-from: #084da3;
  --xp-login-tile-to: #5490d9;
  --xp-login-tile-border: #ffcc00;
}

/* ------------------------------------------------------------ the surface */

/*
 * Above the desktop (windows top out at 3000, notifications at 2000) but below
 * the full-screen effect overlays at 20000+, which only ever run once the user
 * is already signed in and past this screen.
 */
#xp-login {
  position: fixed;
  inset: 0;
  z-index: 15000;

  display: flex;
  flex-direction: column;

  font-family: Tahoma, "Franklin Gothic Medium", sans-serif;
  color: #fff;
  user-select: none;
  overflow: hidden;

  opacity: 1;
  transition: opacity 320ms ease;
}

/* The exit transition. Removal happens on transitionend in loginScreen.js. */
#xp-login.xp-login--leaving {
  opacity: 0;
  pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
  #xp-login { transition: none; }
}

/* ------------------------------------------------------ bands and hairlines */

.xp-login__header,
.xp-login__footer {
  flex: 0 0 auto;
  background: var(--xp-login-band);
  position: relative;
}

.xp-login__header {
  min-height: 112px;
}

/*
 * The two horizontal hairlines are the reference's ::before gradients: a white
 * one under the header, an orange one over the footer, each fading out toward
 * the edges.
 */
.xp-login__header::after,
.xp-login__footer::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 6px;
  pointer-events: none;
}

.xp-login__header::after {
  bottom: 0;
  background: linear-gradient(
    270deg,
    #084da3 -33.4%, #084da3 6.07%,
    #ffffff 49.56%,
    #084da3 82.59%, #084da3 121.25%
  );
}

.xp-login__footer::before {
  top: 0;
  background: linear-gradient(
    270deg,
    #084da3 -33.4%, #084da3 6.07%,
    #ff9933 49.56%,
    #084da3 82.59%, #084da3 121.25%
  );
}

/* ------------------------------------------------------------- centre field */

.xp-login__main {
  flex: 1 1 auto;
  min-height: 0;

  background: radial-gradient(
    19.48% 42.48% at 10% 22.48%,
    var(--xp-login-field-inner) 0%,
    var(--xp-login-field-outer) 100%
  );

  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  overflow: auto;
}

/* Left half: EXPERIENCE branding, right-aligned against the rule. */
.xp-login__brand {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  padding: 0 40px 0 24px;
  text-align: right;
}

.xp-login__brand-logo {
  width: 150px;
  max-width: 100%;
  height: auto;
  margin-bottom: 16px;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.25);
  display: block;
}

.xp-login__brand-mark {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.xp-login__brand-name {
  margin: 0;
  font-size: 46px;
  line-height: 1;
  font-weight: 400;
  letter-spacing: 0.5px;
  text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.35);
}

.xp-login__brand-suffix {
  font-size: 24px;
  font-weight: 700;
  color: #f2a33c;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
}

.xp-login__brand-hint {
  margin: 26px 0 0;
  font-size: 17px;
  font-weight: 400;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
}

/* The vertical rule: bright in the middle, dissolving into the field. */
.xp-login__rule {
  width: 2px;
  height: 78%;
  margin: 0 42px;
  background: linear-gradient(
    180deg,
    var(--xp-login-field-outer) 0%,
    var(--xp-login-rule) 47.4%,
    var(--xp-login-field-outer) 98.96%
  );
}

/* Right half: the account list. Two tiles — EXPERIENCE, then Guest. */
.xp-login__accounts {
  display: flex;
  flex-direction: column;
  justify-content: center;
  /* The reference separates its two account tiles by 40px (style.scss .crystal),
     which is what makes the second read as a separate account rather than a
     second row of the first. */
  gap: 40px;
  padding: 0 24px 0 0;
}

/* --------------------------------------------------------------- user tile */

/*
 * A real <button>: keyboard focus, Enter/Space activation and disabled
 * semantics come from the element rather than being re-implemented.
 */
.xp-login__tile {
  -webkit-appearance: none;
  appearance: none;
  display: flex;
  align-items: center;
  gap: 18px;

  width: 445px;
  max-width: 100%;
  padding: 15px 20px;
  border: 0;
  border-radius: 4px 0 0 4px;
  /* The reference ships this plate as a PNG; a gradient reproduces it exactly
     and costs no request. */
  background: linear-gradient(90deg, var(--xp-login-tile-from) 0%, var(--xp-login-tile-to) 100%);

  font-family: inherit;
  color: #fff;
  text-align: left;
  cursor: pointer;
  transition: filter 120ms ease, box-shadow 120ms ease;

  /* xp.css also styles bare <button>, and its bevel happens to suit the tile.
     Declaring the highlight explicitly means the look does not depend on a
     remote stylesheet that could change. */
  box-shadow:
    inset 1px 1px 0 rgba(255, 255, 255, 0.28),
    inset -1px -1px 0 rgba(0, 0, 0, 0.18);
}

.xp-login__tile:hover:not(:disabled) {
  filter: brightness(1.14);
}

/*
 * The tile is focused on mount so a keyboard user lands on it without hunting
 * for it. Chrome counts that programmatic focus as :focus-visible, which would
 * paint a ring at a mouse user who never asked for one — so the ring is gated
 * on .xp-login--kbd, which loginScreen.js sets on the first real key press.
 */
.xp-login__tile:focus { outline: none; }

/* Repeats the bevel so focusing does not flatten the tile. */
#xp-login.xp-login--kbd .xp-login__tile:focus {
  box-shadow:
    inset 1px 1px 0 rgba(255, 255, 255, 0.28),
    inset -1px -1px 0 rgba(0, 0, 0, 0.18),
    0 0 0 2px #fff,
    0 0 0 4px rgba(8, 77, 163, 0.9);
}

.xp-login__tile:active:not(:disabled) {
  filter: brightness(0.94);
}

/* Selected/loading: stays lit rather than dimming, as XP does mid-logon. */
.xp-login__tile[aria-busy="true"] {
  filter: brightness(1.14);
}

.xp-login__tile:disabled {
  cursor: default;
}

/*
 * Wallet login unavailable (the wallet layer's chunk did not load). Greyed like an XP disabled account so it does not read as a
 * live tile that ignores clicks; the status line underneath says why.
 */
.xp-login__tile[data-unavailable] {
  cursor: not-allowed;
  filter: grayscale(0.85);
  opacity: 0.6;
}

.xp-login__tile[data-unavailable] .xp-login__tile-status {
  color: #fff;
  font-style: italic;
}

.xp-login__tile-image {
  flex: 0 0 auto;
  width: 81px;
  height: 81px;
  border: 2px solid var(--xp-login-tile-border);
  border-radius: 4px;
  object-fit: cover;
  background: #1c4f95;
}

.xp-login__tile-text {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.xp-login__tile-name {
  font-size: 22px;
  font-weight: 400;
  line-height: 1.2;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
}

.xp-login__tile-status {
  margin-top: 10px;
  font-size: 12px;
  font-family: Verdana, Tahoma, sans-serif;
  color: #dbe8fa;
  min-height: 15px;
}


/* ------------------------------------------------------------- guest tile */

/*
 * Guest is a first-class EXPERIENCE state, so it gets a real user tile rather
 * than a Cancel link.
 *
 * Its treatment is the reference's own secondary-account tile (style.scss
 * `.crystal`): the same plate at `opacity: 0.6`, its avatar bordered in white
 * instead of the active tile's #FFCC00, and the name alone with no status line
 * under it. That is how XP itself distinguished the inactive account, so the
 * pattern is period-correct rather than invented — and it reads as secondary
 * without ever reading as disabled.
 */
.xp-login__tile--guest {
  opacity: 0.6;
  transition: opacity 120ms ease, filter 120ms ease, box-shadow 120ms ease;
}

/* Hover/focus lifts it to full strength, so it never feels unavailable. */
.xp-login__tile--guest:hover:not(:disabled),
.xp-login__tile--guest:focus:not(:disabled) {
  opacity: 1;
}

/* White border, per the reference's .iconB. */
.xp-login__tile-image--guest {
  display: flex;
  align-items: center;
  justify-content: center;
  border-color: #fff;
  color: #dbe8fa;
  background: #1c4f95;
}

/*
 * The reference's secondary tile carries a name and nothing else, centred
 * against its avatar rather than top-aligned like the active account.
 */
.xp-login__tile--guest .xp-login__tile-text {
  justify-content: center;
}

.xp-login__tile--guest .xp-login__tile-status {
  margin-top: 4px;
}

/* --------------------------------------------------------------- the footer */

.xp-login__footer {
  min-height: 84px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 12px 50px;
}

.xp-login__shutdown {
  display: flex;
  align-items: center;
  gap: 18px;
  font-size: 15px;
}

/* The red power glyph, reproduced from the reference's myBtn mixin. */
.xp-login__power {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;

  background-color: #e55022;
  border: 1px solid #fff;
  border-radius: 4px;
  box-shadow:
    inset 4px 2px 8px rgba(255, 255, 255, 0.6),
    inset -2px -3px 5px #aa2300;

  color: #fff;
  font-size: 18px;
  line-height: 1;
}

.xp-login__footer-note {
  font-size: 12px;
  line-height: 1.5;
  text-align: right;
  color: #cfe0f6;
}

.xp-login__footer-note p {
  margin: 0;
}

/* --------------------------------------------------------- the error dialog */

/*
 * Sits inside #xp-login rather than using windowManager: the Welcome screen is
 * part of the shell, not an application, so it must not create desktop windows.
 * The visual language is the same classic dialog the desktop uses.
 */
.xp-login__dialog-layer {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.35);
}

.xp-login__dialog-layer[hidden] {
  display: none;
}

.xp-login__dialog {
  width: 400px;
  max-width: 100%;
  background: #ece9d8;
  color: #000;
  border: 1px solid #0831d9;
  border-radius: 6px 6px 3px 3px;
  box-shadow: 3px 3px 12px rgba(0, 0, 0, 0.45);
  overflow: hidden;
}

.xp-login__dialog-title {
  display: flex;
  align-items: center;
  height: 26px;
  padding: 0 8px;
  background: linear-gradient(180deg, #0058e6 0%, #3a93ff 8%, #288cff 40%, #127aff 88%, #036ffc 100%);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
}

.xp-login__dialog-body {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 16px 18px 10px;
  font-size: 12px;
  line-height: 1.5;
}

.xp-login__dialog-body img {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
}

.xp-login__dialog-body p {
  margin: 0 0 8px;
}

.xp-login__dialog-body p:last-child {
  margin-bottom: 0;
}

.xp-login__dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 6px 18px 16px;
}

.xp-login__dialog-actions button {
  min-width: 78px;
  padding: 4px 12px;
  font-family: Tahoma, sans-serif;
  font-size: 12px;
  cursor: pointer;
}

/* ------------------------------------------------------ responsive behaviour */

/*
 * The composition is preserved at every size — bands, rule, tile — and only
 * spacing and type scale down. The rule turns horizontal once the two halves
 * can no longer sit side by side, which keeps the same reading order stacked.
 */

@media (max-width: 900px) {
  .xp-login__brand-name { font-size: 38px; }
  .xp-login__brand-hint { font-size: 15px; margin-top: 20px; }
  .xp-login__rule { margin: 0 24px; }
  .xp-login__tile { width: 380px; gap: 14px; }
  .xp-login__accounts { gap: 28px; }
  .xp-login__footer { padding: 12px 24px; }
}

@media (max-width: 720px), (max-height: 520px) {
  .xp-login__header { min-height: 60px; }

  .xp-login__main {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
    justify-items: center;
    align-content: center;
    gap: 18px;
    padding: 24px 16px;
  }

  .xp-login__brand {
    align-items: center;
    text-align: center;
    padding: 0;
  }

  .xp-login__brand-logo {
    width: 110px;
    margin-bottom: 10px;
  }

  .xp-login__brand-hint { margin-top: 14px; }

  /* Horizontal when stacked, mirroring the vertical rule's fade. */
  .xp-login__rule {
    width: min(320px, 80vw);
    height: 2px;
    margin: 0;
    background: linear-gradient(
      90deg,
      var(--xp-login-field-outer) 0%,
      var(--xp-login-rule) 47.4%,
      var(--xp-login-field-outer) 98.96%
    );
  }

  .xp-login__accounts { padding: 0; width: 100%; align-items: center; }

  .xp-login__tile {
    width: min(445px, 100%);
    border-radius: 4px;
  }

  .xp-login__footer {
    min-height: 0;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    padding: 16px 20px;
  }

  .xp-login__footer-note { text-align: left; }
}

/*
 * Short viewports (phone landscape). The whole composition has to fit between
 * two bands in ~375px of height, so the bands shrink and the stack tightens —
 * otherwise .xp-login__main scrolls and the brand name clips under the header.
 */
@media (max-height: 520px) {
  .xp-login__header { min-height: 28px; }
  .xp-login__header::after,
  .xp-login__footer::before { height: 4px; }

  .xp-login__main {
    gap: 10px;
    padding: 12px 16px;
  }

  .xp-login__brand-logo { width: 70px; margin-bottom: 4px; }
  .xp-login__brand-name { font-size: 26px; }
  .xp-login__brand-suffix { font-size: 15px; }
  .xp-login__brand-hint { font-size: 13px; margin-top: 8px; }

  .xp-login__rule { width: min(260px, 60vw); }

  .xp-login__tile { padding: 10px 14px; gap: 12px; }
  .xp-login__tile-image { width: 56px; height: 56px; }
  .xp-login__tile-image--guest svg { width: 32px; height: 32px; }
  .xp-login__accounts { gap: 14px; }
  .xp-login__tile-name { font-size: 17px; }
  .xp-login__tile-status { font-size: 11px; margin-top: 5px; }

  .xp-login__footer {
    flex-direction: row;
    align-items: center;
    padding: 8px 20px;
  }

  .xp-login__shutdown { font-size: 12px; gap: 10px; }
  .xp-login__power { width: 28px; height: 28px; font-size: 14px; }
  .xp-login__footer-note { font-size: 10px; text-align: right; }
}

@media (max-width: 420px) {
  .xp-login__brand-name { font-size: 30px; }
  .xp-login__brand-suffix { font-size: 17px; }
  .xp-login__brand-hint { font-size: 13px; }

  .xp-login__tile { padding: 12px 14px; gap: 12px; }
  .xp-login__tile-image { width: 60px; height: 60px; }
  .xp-login__tile-image--guest svg { width: 34px; height: 34px; }
  .xp-login__accounts { gap: 20px; }
  .xp-login__tile-name { font-size: 18px; }
  .xp-login__tile-status { font-size: 11px; margin-top: 7px; }

  .xp-login__footer { padding: 14px 16px; }
  .xp-login__shutdown { font-size: 13px; gap: 12px; }
  .xp-login__power { width: 32px; height: 32px; font-size: 15px; }
  .xp-login__footer-note { font-size: 11px; }
}

/* ------------------------------------------------------------------------
 * Wallet picker (src/auth/solana/walletPicker.ts)
 *
 * An xp.css window over the login screen. Its own layer sits above
 * #xp-login (z-index 15000). Sized to fit a phone with a 16px gutter; the
 * mobile title-bar rules in css/mobile.css apply to it like any window.
 * ---------------------------------------------------------------------- */
.xp-wallet-picker {
  position: fixed;
  inset: 0;
  z-index: 15100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.35);
}

.xp-wallet-picker__window {
  width: min(380px, 100%);
  max-height: calc(100% - 32px);
  display: flex;
  flex-direction: column;
}

.xp-wallet-picker__body {
  overflow: auto;
  font-size: 12px;
}

.xp-wallet-picker__lead,
.xp-wallet-picker__note {
  margin: 4px 2px 10px;
  line-height: 1.4;
}

.xp-wallet-picker__note {
  color: #555;
  font-size: 11px;
}

.xp-wallet-picker__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.xp-wallet-picker__list li::before {
  content: none;
}

.xp-wallet-picker__option {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 48px;
  padding: 6px 10px;
  box-sizing: border-box;
  text-align: left;
  text-decoration: none;
  color: inherit;
  background: #fff;
  border: 1px solid #7f9db9;
  border-radius: 3px;
  cursor: pointer;
}

.xp-wallet-picker__option:hover,
.xp-wallet-picker__option:focus-visible {
  background: #e8f0fd;
  border-color: #316ac5;
  outline: none;
}

.xp-wallet-picker__icon {
  flex: 0 0 32px;
  width: 32px;
  height: 32px;
  border-radius: 6px;
}

.xp-wallet-picker__icon--letter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #316ac5;
  color: #fff;
  font-weight: bold;
  font-size: 16px;
}

.xp-wallet-picker__text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.xp-wallet-picker__name {
  font-weight: bold;
  font-size: 13px;
}

.xp-wallet-picker__status {
  font-size: 11px;
  color: #444;
}

.xp-wallet-picker__actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 4px;
}
