:root {
  --xs-red: #ec1230;
  --xs-red-text: #ff5b72;
  --xs-black: #0d0d0f;
  --xs-panel: #111114;
  --xs-line: #35353c;
  --xs-white: #f5f5f7;
  --xs-dim: #9999a3;
  --xs-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --xs-sans: "Noto Sans SC", -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
}

body.xs-modal-open {
  overflow: hidden !important;
}

.xs-overlay,
.xs-overlay * {
  box-sizing: border-box;
}

.xs-sync-chip {
  position: fixed;
  z-index: 48;
  left: max(14px, env(safe-area-inset-left));
  bottom: max(14px, env(safe-area-inset-bottom));
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  max-width: min(310px, calc(100vw - 28px));
  padding: 8px 13px;
  border: 2px solid #fff;
  border-radius: 0;
  background: #111;
  box-shadow: 4px 4px 0 var(--xs-red);
  color: #fff;
  font-family: var(--xs-mono);
  font-size: 11px;
  font-weight: 800;
  line-height: 1.3;
  letter-spacing: .04em;
  cursor: pointer;
  touch-action: manipulation;
}

.xs-sync-chip:focus-visible {
  outline: 3px solid var(--xs-red);
  outline-offset: 3px;
}

.xs-sync-dot {
  flex: 0 0 auto;
  width: 9px;
  height: 9px;
  background: var(--xs-dim);
  border-radius: 50%;
}

.xs-sync-chip[data-state="synced"] .xs-sync-dot { background: #54d88b; }
.xs-sync-chip[data-state="syncing"] .xs-sync-dot { background: #fff; animation: xs-pulse .8s ease-in-out infinite alternate; }
.xs-sync-chip[data-state="offline"] .xs-sync-dot,
.xs-sync-chip[data-state="error"] .xs-sync-dot,
.xs-sync-chip[data-state="migration"] .xs-sync-dot { background: var(--xs-red); }

.xs-overlay {
  position: fixed;
  z-index: 10000;
  inset: 0;
  display: grid;
  place-items: center;
  padding:
    max(16px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
  background: rgba(0, 0, 0, .86);
  font-family: var(--xs-sans);
  overscroll-behavior: contain;
}

.xs-dialog {
  position: relative;
  width: min(540px, 100%);
  min-width: 0;
  max-width: 100%;
  max-height: min(760px, calc(100dvh - 32px - env(safe-area-inset-top) - env(safe-area-inset-bottom)));
  overflow: auto;
  border: 3px solid #fff;
  border-left: 8px solid var(--xs-red);
  border-radius: 0;
  background: var(--xs-black);
  box-shadow: 10px 10px 0 var(--xs-red);
  color: var(--xs-white);
  animation: xs-enter 180ms ease-out both;
  overscroll-behavior: contain;
}

.xs-dialog-head {
  position: sticky;
  z-index: 2;
  top: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 20px 14px;
  background: var(--xs-black);
  border-bottom: 2px solid var(--xs-line);
}

.xs-dialog-title {
  margin: 0;
  color: #fff;
  font-family: var(--xs-sans);
  font-size: clamp(23px, 6vw, 32px);
  font-style: italic;
  font-weight: 950;
  line-height: 1.15;
}

.xs-dialog-subtitle {
  display: block;
  margin-top: 4px;
  color: var(--xs-red-text);
  font-family: var(--xs-mono);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .16em;
}

.xs-close {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border: 2px solid var(--xs-line);
  border-radius: 0;
  background: #111;
  color: #fff;
  font: 800 22px/1 var(--xs-sans);
  cursor: pointer;
}

.xs-close:hover { border-color: var(--xs-red); background: var(--xs-red); }
.xs-close:focus-visible,
.xs-button:focus-visible,
.xs-tab:focus-visible,
.xs-code-input:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 3px;
}

.xs-dialog-body {
  width: 100%;
  min-width: 0;
  overflow-x: hidden;
  padding: 18px 20px 22px;
}

.xs-notice {
  margin: 0 0 18px;
  padding: 12px 14px;
  border-left: 3px solid var(--xs-red);
  background: #18181c;
  color: #d6d6dd;
  font-size: 14px;
  line-height: 1.65;
}

.xs-notice strong { color: #fff; }

.xs-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: 100%;
  min-width: 0;
  gap: 8px;
  margin-bottom: 18px;
}

.xs-tab {
  min-width: 0;
  min-height: 48px;
  border: 2px solid var(--xs-line);
  border-radius: 0;
  background: #111;
  color: var(--xs-dim);
  font-family: var(--xs-sans);
  font-size: 15px;
  font-weight: 900;
  cursor: pointer;
}

.xs-tab[aria-selected="true"] {
  border-color: #fff;
  background: #fff;
  color: #111;
  box-shadow: 3px 3px 0 var(--xs-red);
}

.xs-label {
  display: block;
  margin-bottom: 8px;
  color: #fff;
  font-size: 14px;
  font-weight: 900;
}

.xs-code-input {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  height: 64px;
  padding: 8px 12px 8px 19px;
  border: 3px solid #fff;
  border-radius: 0;
  background: #fff;
  color: #111;
  font-family: var(--xs-mono);
  font-size: clamp(28px, 9vw, 38px);
  font-weight: 900;
  line-height: 1;
  letter-spacing: .3em;
  text-align: center;
  caret-color: var(--xs-red);
}

.xs-field-hint {
  min-height: 22px;
  margin: 7px 0 0;
  color: var(--xs-dim);
  font-family: var(--xs-mono);
  font-size: 11px;
  line-height: 1.5;
}

.xs-field-hint.is-error { color: var(--xs-red-text); font-weight: 800; }

.xs-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

.xs-button {
  min-height: 48px;
  padding: 10px 18px;
  border: 2px solid #fff;
  border-radius: 0;
  background: #111;
  color: #fff;
  font-family: var(--xs-sans);
  font-size: 14px;
  font-weight: 900;
  cursor: pointer;
  touch-action: manipulation;
}

.xs-button:hover:not(:disabled) { background: #25252b; }
.xs-button:disabled { cursor: wait; opacity: .55; }
.xs-button-primary {
  flex: 1 1 190px;
  border-color: var(--xs-red);
  background: var(--xs-red);
  box-shadow: 4px 4px 0 #fff;
}
.xs-button-primary:hover:not(:disabled) { background: #c90d27; }
.xs-button-danger { border-color: var(--xs-red); color: var(--xs-red-text); }
.xs-button-quiet { border-color: var(--xs-line); color: #c7c7ce; }

.xs-security-note {
  margin-top: 18px;
  color: #777781;
  font-family: var(--xs-mono);
  font-size: 10.5px;
  line-height: 1.6;
}

.xs-code-reveal {
  margin: 18px 0;
  padding: 14px 14px 14px 22px;
  border: 3px solid #111;
  background: #fff;
  box-shadow: 5px 5px 0 var(--xs-red);
  color: #111;
  font-family: var(--xs-mono);
  font-size: clamp(30px, 11vw, 46px);
  font-weight: 950;
  line-height: 1;
  letter-spacing: .24em;
  text-align: center;
}

.xs-summary-grid {
  display: grid;
  gap: 8px;
  margin: 14px 0;
}

.xs-summary-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 12px;
  align-items: center;
  min-height: 52px;
  padding: 9px 12px;
  border: 2px solid var(--xs-line);
  background: #141418;
}

.xs-summary-row strong { font-size: 14px; }
.xs-summary-row span {
  color: var(--xs-dim);
  font-family: var(--xs-mono);
  font-size: 10.5px;
  text-align: right;
}

.xs-account-list {
  display: grid;
  gap: 10px;
}

.xs-account-status {
  margin-bottom: 16px;
  padding: 13px 14px;
  border-left: 3px solid var(--xs-red);
  background: #18181c;
}

.xs-account-status strong { display: block; color: #fff; }
.xs-account-status span { color: var(--xs-dim); font-family: var(--xs-mono); font-size: 11px; }

.xs-live {
  min-height: 20px;
  margin-top: 12px;
  color: var(--xs-red-text);
  font-family: var(--xs-mono);
  font-size: 11px;
  font-weight: 800;
}

@keyframes xs-enter {
  from { opacity: 0; transform: translateY(18px) skewX(-1deg); }
  to { opacity: 1; transform: none; }
}

@keyframes xs-pulse {
  from { opacity: .45; transform: scale(.8); }
  to { opacity: 1; transform: scale(1.15); }
}

@media (max-width: 599px) {
  html { scroll-padding-bottom: calc(76px + env(safe-area-inset-bottom)); }

  .xs-sync-chip {
    right: max(14px, env(safe-area-inset-right));
    left: auto;
  }

  .xs-sync-chip.is-compact {
    width: 44px;
    min-width: 44px;
    max-width: 44px;
    padding: 0;
    justify-content: center;
  }

  .xs-sync-chip.is-compact .xs-sync-text {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  .xs-overlay {
    align-items: end;
    padding: 0;
  }

  .xs-dialog {
    width: 100vw;
    min-width: 0;
    max-width: 100vw;
    max-height: calc(100dvh - max(8px, env(safe-area-inset-top)));
    border-right: 0;
    border-bottom: 0;
    border-left-width: 6px;
    box-shadow: none;
  }

  .xs-dialog-head {
    width: 100%;
    min-width: 0;
    padding: 16px 16px 12px;
  }

  .xs-dialog-body {
    padding: 15px 16px calc(20px + env(safe-area-inset-bottom));
  }

  .xs-code-input { height: 60px; }
  .xs-tab { padding-inline: 8px; font-size: 14px; }
  .xs-actions { display: grid; grid-template-columns: 1fr; }
  .xs-button { width: 100%; }
  .xs-summary-row { grid-template-columns: minmax(0, 1fr) auto; }
  .xs-summary-row span:first-of-type { display: none; }
}

@media (max-height: 500px) and (orientation: landscape) {
  .xs-overlay { align-items: start; }
  .xs-dialog { max-height: 100dvh; }
  .xs-dialog-head { padding-block: 10px; }
  .xs-dialog-body { padding-block: 12px; }
  .xs-notice { margin-bottom: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .xs-dialog,
  .xs-sync-dot { animation: none !important; }
}
