:root {
  color-scheme: light;
  --space-bg: #edf3fc;
  --space-surface: #ffffff;
  --space-surface-strong: #f8fbff;
  --space-ink: #071427;
  --space-muted: #627086;
  --space-line: #cdd9ea;
  --space-blue: #0967ff;
  --space-violet: #754ed5;
  --space-danger: #c83c55;
  --space-shadow: 0 18px 50px rgba(30, 62, 108, 0.14);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --space-bg: #080d15;
  --space-surface: #111a28;
  --space-surface-strong: #162131;
  --space-ink: #f3f7ff;
  --space-muted: #9eacc0;
  --space-line: #2d3c50;
  --space-blue: #6b9dff;
  --space-violet: #b397ff;
  --space-danger: #ff7086;
  --space-shadow: 0 22px 70px rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  min-width: 320px;
  color: var(--space-ink);
  background: var(--space-bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

.hidden {
  display: none !important;
}

.icon {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.avatar-space {
  position: relative;
  width: 100%;
  height: 100%;
  isolation: isolate;
  overflow: hidden;
}

#avatar-space-canvas {
  position: absolute;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}

#avatar-space-canvas:active {
  cursor: grabbing;
}

.space-header {
  position: absolute;
  z-index: 5;
  top: 18px;
  left: 22px;
  right: 22px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 18px;
  pointer-events: none;
}

.space-brand,
.space-header-actions,
.space-header-actions > * {
  pointer-events: auto;
}

.space-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  color: var(--space-ink);
  text-decoration: none;
}

.space-brand img {
  width: 108px;
  height: 44px;
  object-fit: contain;
  object-position: left center;
}

.space-brand span {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.space-brand b {
  color: var(--space-blue);
  font-size: 11px;
  letter-spacing: 0.08em;
}

.space-brand small {
  color: var(--space-muted);
  font-size: 12px;
  white-space: nowrap;
}

.space-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.archive-count,
.icon-button {
  min-height: 40px;
  border: 1px solid var(--space-line);
  border-radius: 8px;
  color: var(--space-ink);
  background: var(--space-surface);
  box-shadow: 0 8px 24px rgba(23, 49, 87, 0.08);
}

.archive-count {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 13px;
  font-size: 12px;
}

.archive-count .icon {
  color: var(--space-violet);
}

.archive-count b {
  font-size: 15px;
}

.archive-count span {
  color: var(--space-muted);
}

.icon-button {
  display: inline-grid;
  width: 40px;
  padding: 0;
  place-items: center;
  cursor: pointer;
  text-decoration: none;
  transition: border-color 160ms ease, color 160ms ease, transform 160ms ease;
}

.icon-button:hover,
.icon-button:focus-visible {
  color: var(--space-blue);
  border-color: var(--space-blue);
  transform: translateY(-1px);
  outline: none;
}

.back-icon {
  transform: rotate(180deg);
}

.space-intro {
  position: absolute;
  z-index: 4;
  top: clamp(94px, 14vh, 150px);
  left: clamp(22px, 5vw, 78px);
  width: min(440px, calc(100vw - 44px));
  padding: 24px;
  border: 1px solid var(--space-line);
  border-left: 4px solid var(--space-violet);
  border-radius: 8px;
  background: var(--space-surface);
  box-shadow: var(--space-shadow);
  transition: transform 320ms ease, opacity 240ms ease;
}

.space-intro.is-condensed {
  transform: translateX(calc(-100% - 100px));
  opacity: 0;
  pointer-events: none;
}

.space-kicker {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--space-violet);
  font-size: 11px;
  font-weight: 850;
  letter-spacing: 0.08em;
}

.space-kicker .icon {
  width: 18px;
  height: 18px;
}

.space-intro h1 {
  max-width: 400px;
  margin: 0 0 14px;
  color: var(--space-ink);
  font-size: clamp(38px, 4.2vw, 68px);
  line-height: 0.98;
  letter-spacing: 0;
}

.space-intro > p {
  margin: 0;
  color: var(--space-muted);
  font-size: 15px;
  line-height: 1.58;
}

.space-form {
  display: grid;
  gap: 8px;
  margin-top: 22px;
}

.space-form label {
  color: var(--space-muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.space-form > div {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.space-form input {
  width: 100%;
  min-width: 0;
  min-height: 46px;
  padding: 0 14px;
  border: 1px solid var(--space-line);
  border-radius: 7px;
  color: var(--space-ink);
  background: var(--space-surface-strong);
  outline: none;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.space-form input:focus {
  border-color: var(--space-blue);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--space-blue) 14%, transparent);
}

.space-form button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 0 17px;
  border: 1px solid var(--space-blue);
  border-radius: 7px;
  color: #fff;
  background: var(--space-blue);
  font-weight: 800;
  cursor: pointer;
  transition: filter 160ms ease, transform 160ms ease;
}

.space-form button:hover {
  filter: brightness(0.94);
  transform: translateY(-1px);
}

.space-form button:disabled {
  cursor: wait;
  opacity: 0.66;
}

.space-rule {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--space-line);
}

.space-rule > .icon {
  width: 34px;
  height: 34px;
  padding: 7px;
  border-radius: 7px;
  color: var(--space-violet);
  background: color-mix(in srgb, var(--space-violet) 10%, transparent);
}

.space-rule span {
  display: grid;
  gap: 3px;
}

.space-rule b {
  font-size: 13px;
}

.space-rule small {
  color: var(--space-muted);
  font-size: 12px;
  line-height: 1.35;
}

.artifact-inspector {
  position: absolute;
  z-index: 4;
  top: 92px;
  right: 22px;
  width: min(330px, calc(100vw - 44px));
  padding: 18px;
  border: 1px solid var(--space-line);
  border-top: 4px solid var(--artifact-accent, var(--space-violet));
  border-radius: 8px;
  background: var(--space-surface);
  box-shadow: var(--space-shadow);
}

.inspector-search {
  position: absolute;
  top: 12px;
  right: 12px;
  display: grid;
  width: 32px;
  height: 32px;
  padding: 0;
  place-items: center;
  border: 1px solid var(--space-line);
  border-radius: 7px;
  color: var(--space-muted);
  background: var(--space-surface-strong);
  cursor: pointer;
}

.inspector-search:hover,
.inspector-search:focus-visible {
  color: var(--space-blue);
  border-color: var(--space-blue);
  outline: none;
}

.inspector-search .icon {
  width: 16px;
  height: 16px;
}

.artifact-person {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  padding-right: 32px;
}

.artifact-person img {
  width: 54px;
  height: 54px;
  border: 1px solid var(--space-line);
  border-radius: 50%;
  object-fit: cover;
  background: var(--space-surface-strong);
}

.artifact-person span {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.artifact-person small {
  color: var(--artifact-accent, var(--space-violet));
  font-size: 10px;
  font-weight: 850;
  letter-spacing: 0.07em;
}

.artifact-person a {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.artifact-person strong {
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 16px;
  line-height: 1.15;
}

.artifact-person a {
  color: var(--space-blue);
  font-size: 12px;
  font-weight: 750;
  text-decoration: none;
}

.artifact-inspector dl {
  display: grid;
  gap: 0;
  margin: 16px 0 0;
  border-top: 1px solid var(--space-line);
}

.artifact-inspector dl > div {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr);
  gap: 12px;
  align-items: baseline;
  padding: 9px 0;
  border-bottom: 1px solid var(--space-line);
}

.artifact-inspector dt {
  color: var(--space-muted);
  font-size: 11px;
}

.artifact-inspector dd {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
  font-size: 12px;
  font-weight: 750;
  text-align: right;
}

.artifact-inspector > p {
  margin: 12px 0 0;
  color: var(--space-muted);
  font-size: 12px;
  line-height: 1.45;
}

.space-loading {
  position: absolute;
  z-index: 6;
  left: 50%;
  bottom: 86px;
  width: min(560px, calc(100vw - 44px));
  padding: 16px 18px;
  border: 1px solid var(--space-line);
  border-radius: 8px;
  background: var(--space-surface);
  box-shadow: var(--space-shadow);
  transform: translateX(-50%);
}

.space-loading-head {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  gap: 11px;
  align-items: center;
}

.space-loading-head > .icon {
  width: 34px;
  height: 34px;
  padding: 7px;
  border-radius: 7px;
  color: var(--space-violet);
  background: color-mix(in srgb, var(--space-violet) 10%, transparent);
  animation: space-spin 1.2s linear infinite;
}

.space-loading-head span {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.space-loading-head small {
  color: var(--space-violet);
  font-size: 10px;
  font-weight: 850;
  letter-spacing: 0.07em;
}

.space-loading-head strong {
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 13px;
  white-space: nowrap;
}

.space-loading-head > b {
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}

.space-loading-track {
  height: 4px;
  margin-top: 13px;
  overflow: hidden;
  border-radius: 99px;
  background: color-mix(in srgb, var(--space-line) 72%, transparent);
}

.space-loading-track span {
  display: block;
  width: 12%;
  height: 100%;
  border-radius: inherit;
  background: var(--space-violet);
  transition: width 460ms ease;
}

.space-message {
  position: absolute;
  z-index: 6;
  left: 50%;
  bottom: 88px;
  max-width: min(560px, calc(100vw - 44px));
  padding: 12px 16px;
  border: 1px solid var(--space-line);
  border-left: 4px solid var(--space-blue);
  border-radius: 7px;
  color: var(--space-ink);
  background: var(--space-surface);
  box-shadow: var(--space-shadow);
  font-size: 13px;
  line-height: 1.45;
  transform: translateX(-50%);
}

.space-message.is-error {
  border-left-color: var(--space-danger);
}

.space-controls {
  position: absolute;
  z-index: 4;
  left: 22px;
  right: 22px;
  bottom: 18px;
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.space-controls span,
.space-controls button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--space-line);
  border-radius: 7px;
  color: var(--space-muted);
  background: var(--space-surface);
  box-shadow: 0 7px 22px rgba(24, 49, 84, 0.08);
  font-size: 11px;
}

.space-controls .icon {
  width: 16px;
  height: 16px;
  color: var(--space-blue);
}

.space-controls button {
  margin-left: auto;
  color: var(--space-ink);
  font-weight: 750;
  cursor: pointer;
  pointer-events: auto;
}

.space-controls button:hover {
  color: var(--space-blue);
  border-color: var(--space-blue);
}

.artifact-tooltip {
  position: fixed;
  z-index: 8;
  max-width: 220px;
  padding: 8px 10px;
  border: 1px solid var(--space-line);
  border-radius: 6px;
  color: var(--space-ink);
  background: var(--space-surface);
  box-shadow: 0 8px 24px rgba(15, 34, 61, 0.16);
  font-size: 11px;
  font-weight: 750;
  pointer-events: none;
}

@keyframes space-spin {
  to { transform: rotate(360deg); }
}

@media (max-width: 760px) {
  .space-header {
    top: 10px;
    left: 12px;
    right: 12px;
  }

  .space-brand img {
    width: 82px;
    height: 36px;
  }

  .space-brand small,
  .archive-count span {
    display: none;
  }

  .archive-count {
    width: 40px;
    padding: 0;
    justify-content: center;
  }

  .archive-count .icon {
    display: none;
  }

  .space-intro {
    top: 72px;
    left: 12px;
    width: calc(100vw - 24px);
    padding: 18px;
  }

  .space-intro h1 {
    margin-top: 13px;
    font-size: clamp(36px, 12vw, 52px);
  }

  .space-intro > p {
    font-size: 14px;
  }

  .space-form > div {
    grid-template-columns: 1fr;
  }

  .space-form button {
    width: 100%;
  }

  .artifact-inspector {
    top: auto;
    right: 12px;
    bottom: 66px;
    left: 12px;
    width: auto;
    padding: 13px;
  }

  .artifact-inspector dl {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin-top: 11px;
  }

  .artifact-inspector dl > div {
    display: grid;
    grid-template-columns: 1fr;
    gap: 3px;
    padding: 8px;
    border: 0;
    border-left: 1px solid var(--space-line);
  }

  .artifact-inspector dl > div:first-child {
    border-left: 0;
  }

  .artifact-inspector dl > div:nth-child(4) {
    grid-column: 1 / -1;
    grid-template-columns: 72px minmax(0, 1fr);
    gap: 8px;
    align-items: start;
    border-top: 1px solid var(--space-line);
    border-left: 0;
  }

  .artifact-inspector dl > div:nth-child(4) dd {
    display: -webkit-box;
    overflow: hidden;
    line-height: 1.35;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  .artifact-inspector dd {
    font-size: 11px;
    text-align: left;
  }

  .artifact-inspector > p {
    display: none;
  }

  .space-loading {
    bottom: 68px;
    width: calc(100vw - 24px);
    max-width: none;
  }

  .space-message {
    top: 62px;
    bottom: auto;
    width: calc(100vw - 24px);
    max-width: none;
  }

  .space-loading-head strong {
    white-space: normal;
  }

  .space-controls {
    left: 12px;
    right: 12px;
    bottom: 10px;
  }

  .space-controls span {
    display: none;
  }

  .space-controls button {
    min-width: 100px;
  }
}

@media (max-height: 680px) and (min-width: 761px) {
  .space-intro {
    top: 80px;
    padding: 18px;
  }

  .space-intro h1 {
    margin: 12px 0 10px;
    font-size: 42px;
  }

  .space-rule {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
