:root {
  color-scheme: dark;
  --ink: #f7f8ff;
  --muted: #9ba6bd;
  --muted-strong: #bdc5d6;
  --surface: rgba(18, 31, 57, 0.82);
  --surface-strong: #172641;
  --line: rgba(155, 166, 189, 0.16);
  --violet: #7867f2;
  --violet-bright: #9487ff;
  --green: #57d5a1;
  --red: #ff7d86;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.32);
  font-family:
    Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: #091327;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 70% -20%, rgba(89, 65, 185, 0.32), transparent 38rem),
    linear-gradient(155deg, #0d1a34 0%, #091327 58%, #08101f 100%);
}

button,
input {
  font: inherit;
}

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

button:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(148, 135, 255, 0.52);
  outline-offset: 3px;
}

[hidden] {
  display: none !important;
}

.ambient {
  position: fixed;
  z-index: 0;
  border-radius: 999px;
  pointer-events: none;
  filter: blur(2px);
}

.ambient-one {
  top: 7rem;
  right: -8rem;
  width: 19rem;
  height: 19rem;
  background: rgba(91, 70, 202, 0.09);
  border: 1px solid rgba(135, 115, 255, 0.12);
}

.ambient-two {
  bottom: 7rem;
  left: -5rem;
  width: 12rem;
  height: 12rem;
  background: rgba(59, 212, 166, 0.04);
  border: 1px solid rgba(87, 213, 161, 0.08);
}

.app-shell {
  position: relative;
  z-index: 1;
  width: min(100%, 47rem);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(1.1rem, env(safe-area-inset-top)) 1.1rem max(2rem, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 3rem;
}

.brand {
  display: inline-flex;
  gap: 0.72rem;
  align-items: center;
  color: var(--ink);
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 2.35rem;
  height: 2.35rem;
  place-items: center;
  border: 1px solid rgba(148, 135, 255, 0.35);
  border-radius: 0.82rem;
  color: white;
  background: linear-gradient(145deg, #6d5ae9, #4537a9);
  box-shadow: 0 9px 24px rgba(79, 63, 187, 0.3);
  font-family: Georgia, serif;
  font-size: 1.1rem;
}

.brand strong,
.brand small {
  display: block;
  letter-spacing: 0.14em;
}

.brand strong {
  font-size: 0.72rem;
}

.brand small {
  margin-top: 0.14rem;
  color: var(--muted);
  font-size: 0.56rem;
}

.mode-badge {
  padding: 0.38rem 0.64rem;
  border: 1px solid rgba(255, 194, 99, 0.2);
  border-radius: 999px;
  color: #ffd69a;
  background: rgba(255, 176, 60, 0.08);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.state-view {
  display: grid;
  min-height: 65vh;
  place-content: center;
  justify-items: center;
  text-align: center;
  color: var(--muted);
}

.state-view h1 {
  margin: 1.25rem 0 0.6rem;
  color: var(--ink);
  font-size: 1.45rem;
}

.state-view p {
  max-width: 22rem;
  margin: 0 0 1.4rem;
  line-height: 1.5;
}

.spinner {
  width: 2.1rem;
  height: 2.1rem;
  border: 3px solid rgba(148, 135, 255, 0.15);
  border-top-color: var(--violet-bright);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.error-icon {
  display: grid;
  width: 3.3rem;
  height: 3.3rem;
  place-items: center;
  border: 1px solid rgba(255, 125, 134, 0.3);
  border-radius: 1.1rem;
  color: var(--red);
  background: rgba(255, 125, 134, 0.08);
  font-size: 1.4rem;
  font-weight: 800;
}

.hero {
  display: block;
  padding: 4rem 0 1.7rem;
}

.eyebrow {
  margin: 0 0 0.55rem;
  color: var(--violet-bright);
  font-size: 0.71rem;
  font-weight: 750;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.hero h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2.35rem, 10vw, 4.1rem);
  font-weight: 500;
  letter-spacing: -0.045em;
  line-height: 0.95;
}

.profile-line {
  margin: 0.78rem 0 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.demo-switch {
  margin-top: 0.7rem;
  padding: 0.55rem 0;
  border: 0;
  color: var(--muted-strong);
  background: transparent;
  cursor: pointer;
  font-size: 0.74rem;
  text-decoration: underline;
  text-underline-offset: 0.25rem;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.65rem;
}

.stat-card {
  min-width: 0;
  padding: 1rem 0.95rem;
  border: 1px solid var(--line);
  border-radius: 1.1rem;
  background: rgba(18, 31, 57, 0.67);
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.02);
}

.stat-card span,
.stat-card strong {
  display: block;
}

.stat-card span {
  overflow: hidden;
  color: var(--muted);
  font-size: 0.68rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stat-card strong {
  margin-top: 0.45rem;
  font-size: 1.65rem;
  font-weight: 650;
  letter-spacing: -0.04em;
}

.stat-ready {
  border-color: rgba(87, 213, 161, 0.18);
  background: linear-gradient(145deg, rgba(24, 67, 64, 0.64), rgba(17, 43, 52, 0.58));
}

.stat-ready strong {
  color: var(--green);
}

.list-section {
  padding-top: 2.1rem;
}

.section-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.85rem;
}

.section-heading h2 {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 650;
}

.section-heading span {
  color: var(--muted);
  font-size: 0.72rem;
}

.unit-list {
  display: grid;
  gap: 0.65rem;
}

.unit-card {
  display: grid;
  width: 100%;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 0.9rem;
  align-items: center;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 1.15rem;
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 12px 38px rgba(0, 0, 0, 0.12);
  cursor: pointer;
  text-align: left;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.unit-card:hover {
  transform: translateY(-1px);
  border-color: rgba(148, 135, 255, 0.3);
  background: rgba(24, 39, 70, 0.92);
}

.unit-number {
  display: grid;
  width: 2.65rem;
  height: 2.65rem;
  place-items: center;
  border: 1px solid rgba(148, 135, 255, 0.18);
  border-radius: 0.85rem;
  color: var(--violet-bright);
  background: rgba(120, 103, 242, 0.08);
  font-size: 0.76rem;
  font-weight: 750;
}

.unit-copy {
  min-width: 0;
}

.unit-copy strong,
.unit-copy span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.unit-copy strong {
  font-size: 0.9rem;
  font-weight: 630;
}

.unit-copy span {
  margin-top: 0.3rem;
  color: var(--muted);
  font-size: 0.7rem;
}

.status-pill {
  padding: 0.38rem 0.52rem;
  border: 1px solid rgba(148, 135, 255, 0.15);
  border-radius: 999px;
  color: #c7c0ff;
  background: rgba(120, 103, 242, 0.08);
  font-size: 0.65rem;
  font-weight: 700;
  white-space: nowrap;
}

.status-pill.ready {
  border-color: rgba(87, 213, 161, 0.17);
  color: var(--green);
  background: rgba(87, 213, 161, 0.07);
}

.unit-dialog {
  width: min(calc(100% - 1.4rem), 36rem);
  max-height: min(90vh, 46rem);
  margin: auto auto max(0.7rem, env(safe-area-inset-bottom));
  padding: 1.1rem;
  border: 1px solid rgba(148, 135, 255, 0.18);
  border-radius: 1.5rem;
  color: var(--ink);
  background: #111f38;
  box-shadow: var(--shadow);
}

.unit-dialog::backdrop {
  background: rgba(3, 8, 18, 0.76);
  backdrop-filter: blur(6px);
}

.dialog-handle {
  width: 2.8rem;
  height: 0.23rem;
  margin: -0.2rem auto 1.2rem;
  border-radius: 999px;
  background: rgba(155, 166, 189, 0.28);
}

.dialog-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 1rem;
}

.dialog-header h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.75rem;
  font-weight: 500;
  letter-spacing: -0.025em;
}

.icon-button {
  display: grid;
  flex: 0 0 auto;
  width: 2.5rem;
  height: 2.5rem;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 0.85rem;
  color: var(--muted-strong);
  background: rgba(255, 255, 255, 0.025);
  cursor: pointer;
  font-size: 1.45rem;
  line-height: 1;
}

.unit-meta {
  margin: 1.3rem 0 1.5rem;
  padding: 0.85rem 0.95rem;
  border: 1px solid var(--line);
  border-radius: 0.9rem;
  background: rgba(7, 15, 30, 0.34);
}

.unit-meta span,
.unit-meta code {
  display: block;
}

.unit-meta span {
  margin-bottom: 0.35rem;
  color: var(--muted);
  font-size: 0.67rem;
}

.unit-meta code {
  color: var(--muted-strong);
  font-size: 0.76rem;
}

form label {
  display: block;
  font-size: 0.87rem;
  font-weight: 650;
}

.field-hint {
  margin: 0.35rem 0 0.75rem;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.45;
}

input {
  width: 100%;
  min-height: 3.25rem;
  padding: 0.8rem 0.9rem;
  border: 1px solid rgba(155, 166, 189, 0.25);
  border-radius: 0.9rem;
  color: var(--ink);
  background: rgba(7, 15, 30, 0.58);
}

input::placeholder {
  color: #69758d;
}

.button {
  min-height: 3rem;
  padding: 0.75rem 1rem;
  border: 0;
  border-radius: 0.92rem;
  cursor: pointer;
  font-weight: 720;
}

.button-primary {
  color: white;
  background: linear-gradient(135deg, #7563ec, #5d4bd1);
  box-shadow: 0 12px 26px rgba(82, 65, 190, 0.28);
}

.button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.button-wide {
  width: 100%;
  margin-top: 1rem;
}

.form-error {
  margin: 0.7rem 0 0;
  color: #ff9ca3;
  font-size: 0.73rem;
}

.ready-result {
  display: flex;
  gap: 0.9rem;
  align-items: start;
  padding: 1rem;
  border: 1px solid rgba(87, 213, 161, 0.18);
  border-radius: 1rem;
  background: rgba(87, 213, 161, 0.06);
}

.ready-check {
  display: grid;
  flex: 0 0 auto;
  width: 2.15rem;
  height: 2.15rem;
  place-items: center;
  border-radius: 50%;
  color: #071b16;
  background: var(--green);
  font-weight: 900;
}

.ready-result strong {
  font-size: 0.88rem;
}

.ready-result p {
  margin: 0.28rem 0 0.65rem;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.45;
}

.ready-result a {
  color: var(--green);
  font-size: 0.73rem;
  font-weight: 650;
}

.toast {
  position: fixed;
  z-index: 20;
  right: 1rem;
  bottom: max(1rem, env(safe-area-inset-bottom));
  left: 1rem;
  width: fit-content;
  max-width: calc(100% - 2rem);
  margin: 0 auto;
  padding: 0.8rem 1rem;
  border: 1px solid rgba(87, 213, 161, 0.2);
  border-radius: 0.9rem;
  color: #d8ffef;
  background: rgba(15, 51, 46, 0.96);
  box-shadow: var(--shadow);
  font-size: 0.78rem;
}

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

@media (min-width: 640px) {
  .app-shell {
    padding-right: 1.8rem;
    padding-left: 1.8rem;
  }

  .hero {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 1rem;
  }

  .demo-switch {
    margin-top: 0;
  }

  .unit-dialog {
    margin: auto;
    padding: 1.4rem;
  }

  .dialog-handle {
    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;
  }
}
