:root {
  color-scheme: dark;
  --bg: #07110d;
  --surface: #0d1915;
  --surface-2: #12241e;
  --surface-3: #172a24;
  --text: #edf7f1;
  --muted: #9fb5aa;
  --line: rgba(179, 255, 208, 0.14);
  --accent: #58ff57;
  --accent-2: #5ee7ff;
  --warn: #ffc857;
  --danger: #ff6b6b;
  --ok: #63f3a0;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  --radius: 8px;
  --sidebar: 260px;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f7faf7;
  --surface: #ffffff;
  --surface-2: #eef5f1;
  --surface-3: #e5efe9;
  --text: #102019;
  --muted: #557064;
  --line: rgba(16, 32, 25, 0.14);
  --accent: #0bb247;
  --accent-2: #006f91;
  --warn: #9b6500;
  --danger: #bf2d2d;
  --ok: #0a8a48;
  --shadow: 0 20px 60px rgba(21, 46, 34, 0.14);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 14% 0%, rgba(88, 255, 87, 0.12), transparent 32rem),
    linear-gradient(135deg, rgba(94, 231, 255, 0.06), transparent 36rem),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

.ambient-canvas {
  position: fixed;
  inset: 0;
  z-index: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  opacity: 0.28;
  transition: opacity 360ms ease;
}

.ambient-canvas[data-mode="auth"] {
  opacity: 0.82;
}

.ambient-canvas[data-mode="workspace"] {
  opacity: 0.24;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  color: inherit;
}

.app-shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
  min-height: 100vh;
}

.app-shell.auth-mode {
  grid-template-columns: minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 20px 14px;
  border-right: 1px solid var(--line);
  background: rgba(7, 17, 13, 0.82);
  backdrop-filter: blur(16px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  padding: 8px 10px;
  color: var(--text);
  text-decoration: none;
  font-weight: 800;
}

.trixma-logo {
  position: relative;
  display: inline-grid;
  place-items: center;
  isolation: isolate;
}

.trixma-logo img {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: var(--radius);
  object-fit: cover;
  filter: drop-shadow(0 0 14px rgba(88, 255, 87, 0.36));
  animation: trixmaLogoEnergy 6.8s ease-in-out infinite;
}

.trixma-logo::before,
.trixma-logo::after,
.trixma-logo__scan,
.trixma-logo__spark {
  position: absolute;
  inset: -7%;
  z-index: 1;
  border-radius: inherit;
  content: "";
  pointer-events: none;
}

.trixma-logo::before {
  border: 1px solid rgba(88, 255, 87, 0.22);
  box-shadow:
    0 0 22px rgba(88, 255, 87, 0.26),
    inset 0 0 18px rgba(88, 255, 87, 0.1);
  animation: trixmaLogoGlow 8.5s ease-in-out infinite;
}

.trixma-logo::after {
  background:
    linear-gradient(90deg, transparent 0 36%, rgba(94, 231, 255, 0.3) 38% 40%, transparent 42% 100%),
    linear-gradient(0deg, transparent 0 68%, rgba(88, 255, 87, 0.2) 70% 72%, transparent 74% 100%);
  mix-blend-mode: screen;
  opacity: 0;
  transform: translateX(0);
  animation: trixmaLogoGlitch 11s steps(1, end) infinite;
}

.trixma-logo__scan {
  inset: 0;
  overflow: hidden;
  background: linear-gradient(180deg, transparent 0 42%, rgba(88, 255, 87, 0.24) 48%, transparent 56% 100%);
  opacity: 0;
  animation: trixmaLogoScan 9s ease-in-out infinite;
}

.trixma-logo__spark {
  inset: -14%;
  background: radial-gradient(circle at 80% 18%, rgba(255, 255, 255, 0.72), rgba(88, 255, 87, 0.28) 9%, transparent 18%);
  opacity: 0;
  animation: trixmaLogoSpark 13s ease-in-out infinite;
}

.brand-logo {
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
}

.nav-list {
  display: grid;
  gap: 6px;
  margin-top: 18px;
}

.nav-item,
.mobile-nav button {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  border-radius: var(--radius);
  text-align: left;
}

.nav-item[aria-current="page"],
.nav-item:hover,
.mobile-nav button[aria-current="page"] {
  background: var(--surface-2);
  color: var(--text);
}

.nav-icon {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  color: var(--accent);
  font-weight: 700;
}

.workspace {
  min-width: 0;
  padding: 22px clamp(16px, 2.4vw, 34px) 34px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  min-height: 68px;
  margin-bottom: 16px;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(1.55rem, 2vw, 2.35rem);
  line-height: 1.08;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.topbar-actions {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.icon-button,
.button,
.danger-button,
.ghost-button,
.chip-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
}

.icon-button {
  width: 42px;
  font-weight: 800;
}

.account-menu {
  position: relative;
}

.account-toggle {
  background: linear-gradient(135deg, rgba(88, 255, 87, 0.16), rgba(94, 231, 255, 0.08));
}

.account-avatar {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1px solid rgba(88, 255, 87, 0.36);
  color: var(--accent);
  font-size: 0.82rem;
  line-height: 1;
}

.account-popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 18;
  display: grid;
  gap: 8px;
  width: min(280px, calc(100vw - 32px));
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(13, 25, 21, 0.96);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

:root[data-theme="light"] .account-popover {
  background: rgba(255, 255, 255, 0.96);
}

.account-summary {
  display: grid;
  gap: 3px;
  padding: 4px 2px 8px;
  border-bottom: 1px solid var(--line);
}

.account-summary strong,
.account-summary span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.account-summary span {
  color: var(--muted);
  font-size: 0.78rem;
}

.button {
  gap: 8px;
  padding: 0 14px;
  background: linear-gradient(135deg, rgba(88, 255, 87, 0.22), rgba(94, 231, 255, 0.12));
}

.danger-button {
  gap: 8px;
  padding: 0 14px;
  border-color: rgba(255, 107, 107, 0.45);
  background: rgba(255, 107, 107, 0.12);
}

.ghost-button,
.chip-button {
  padding: 0 12px;
  background: transparent;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.view {
  outline: none;
}

.grid {
  display: grid;
  gap: 14px;
}

.grid.cols-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid.cols-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.grid.cols-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.panel,
.item-card,
.danger-zone {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(13, 25, 21, 0.82);
  box-shadow: var(--shadow);
}

:root[data-theme="light"] .panel,
:root[data-theme="light"] .item-card,
:root[data-theme="light"] .danger-zone,
:root[data-theme="light"] .sidebar {
  background: rgba(255, 255, 255, 0.86);
}

.panel {
  padding: 16px;
}

.item-card {
  padding: 14px;
}

.danger-zone {
  padding: 16px;
  border-color: rgba(255, 107, 107, 0.38);
}

.panel-header,
.item-row,
.form-row,
.split-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-header {
  margin-bottom: 12px;
}

.panel h2,
.panel h3,
.item-card h3,
.danger-zone h3 {
  margin: 0;
  font-size: 1rem;
  line-height: 1.2;
}

.metric {
  display: grid;
  gap: 8px;
  min-height: 116px;
}

.metric strong {
  font-size: clamp(1.45rem, 3vw, 2.4rem);
  line-height: 1;
}

.metric span,
.muted,
.helper {
  color: var(--muted);
}

.helper {
  font-size: 0.88rem;
  line-height: 1.45;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.78rem;
  white-space: nowrap;
}

.badge.ok {
  color: var(--ok);
  border-color: rgba(99, 243, 160, 0.35);
}

.badge.warn {
  color: var(--warn);
  border-color: rgba(255, 200, 87, 0.35);
}

.badge.danger {
  color: var(--danger);
  border-color: rgba(255, 107, 107, 0.35);
}

.progress {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-3);
}

.progress > span {
  display: block;
  height: 100%;
  width: var(--value, 0%);
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

.form {
  display: grid;
  gap: 12px;
}

.field {
  display: grid;
  gap: 6px;
}

.field label,
.toggle label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.field input,
.field textarea,
.field select {
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}

.field textarea {
  min-height: 160px;
  resize: vertical;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.segmented button {
  min-height: 42px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
}

.segmented button[aria-pressed="true"] {
  background: var(--surface-2);
  color: var(--text);
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

th,
td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 0.8rem;
}

.result-box,
.code-box {
  max-height: 320px;
  overflow: auto;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.22);
  white-space: pre-wrap;
}

.code-box.compact {
  max-height: 150px;
  margin-top: 10px;
  font-size: 0.78rem;
}

.choice-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.choice-card {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 44px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}

.choice-card span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.api-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr));
  gap: 12px;
}

.api-card {
  display: grid;
  gap: 12px;
}

.api-card strong {
  display: block;
  margin-top: 4px;
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

.syntax-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.syntax-suggestions[hidden] {
  display: none;
}

.language-picker {
  max-width: 220px;
  margin: 0 auto 14px;
}

.qr-preview {
  display: block;
  width: min(220px, 100%);
  height: auto;
  margin: 0 auto 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 10px;
}

.file-drop {
  display: grid;
  place-items: center;
  min-height: 150px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: center;
}

.file-drop input {
  max-width: 100%;
}

.modal {
  width: min(720px, calc(100vw - 28px));
  max-height: min(86vh, 780px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  padding: 0;
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.68);
}

.modal-content {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.toast-region {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 20;
  display: grid;
  gap: 8px;
  width: min(360px, calc(100vw - 32px));
}

.toast {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.mobile-nav {
  display: none;
}

.empty {
  display: grid;
  place-items: center;
  min-height: 160px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
  padding: 20px;
}

.auth-wrap {
  display: grid;
  place-items: center;
  min-height: calc(100vh - 118px);
  padding: clamp(18px, 4vw, 44px) 0;
}

.auth-card {
  width: min(720px, 100%);
  border-color: rgba(88, 255, 87, 0.28);
  background:
    linear-gradient(145deg, rgba(13, 25, 21, 0.78), rgba(7, 17, 13, 0.66)),
    rgba(13, 25, 21, 0.82);
  box-shadow:
    0 28px 90px rgba(0, 0, 0, 0.52),
    0 0 42px rgba(88, 255, 87, 0.14);
  backdrop-filter: blur(20px);
}

.auth-logo {
  width: 92px;
  height: 92px;
  margin: 0 auto 16px;
  border-radius: var(--radius);
}

.auth-logo img {
  animation-duration: 5.8s;
}

.space-map {
  position: relative;
  height: 180px;
  margin: 10px 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(90deg, transparent 24%, rgba(255,255,255,0.05) 25%, transparent 26%, transparent 49%, rgba(255,255,255,0.05) 50%, transparent 51%, transparent 74%, rgba(255,255,255,0.05) 75%, transparent 76%),
    linear-gradient(0deg, transparent 24%, rgba(255,255,255,0.05) 25%, transparent 26%, transparent 49%, rgba(255,255,255,0.05) 50%, transparent 51%, transparent 74%, rgba(255,255,255,0.05) 75%, transparent 76%),
    var(--surface);
}

.space-map span {
  position: absolute;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: 1px solid rgba(88, 255, 87, 0.5);
  background: var(--surface-2);
  color: var(--accent);
  font-weight: 800;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

@media (max-width: 1080px) {
  .grid.cols-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .grid.cols-3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .app-shell {
    display: block;
    padding-bottom: 74px;
  }

  .sidebar {
    display: none;
  }

  .workspace {
    padding: 16px 14px 24px;
  }

  .topbar {
    align-items: center;
    min-height: 56px;
  }

  .topbar-actions {
    gap: 6px;
  }

  .icon-button {
    width: 40px;
    min-height: 40px;
  }

  .account-popover {
    position: fixed;
    top: 64px;
    right: 14px;
    left: 14px;
    width: auto;
  }

  .grid.cols-2,
  .grid.cols-3,
  .grid.cols-4 {
    grid-template-columns: 1fr;
  }

  .choice-grid {
    grid-template-columns: 1fr;
  }

  .panel-header,
  .form-row,
  .split-row {
    align-items: stretch;
    flex-direction: column;
  }

  .item-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .mobile-nav {
    position: fixed;
    right: 10px;
    bottom: 10px;
    left: 10px;
    z-index: 12;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(70px, 1fr);
    overflow-x: auto;
    gap: 4px;
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: rgba(13, 25, 21, 0.94);
    backdrop-filter: blur(18px);
    box-shadow: var(--shadow);
  }

  :root[data-theme="light"] .mobile-nav {
    background: rgba(255, 255, 255, 0.94);
  }

  .mobile-nav button {
    display: grid;
    place-items: center;
    gap: 2px;
    min-height: 48px;
    border-radius: 6px;
    font-size: 0.68rem;
  }

  .mobile-nav .nav-icon {
    width: auto;
    height: auto;
  }

  .toast-region {
    bottom: 84px;
  }
}

@keyframes trixmaLogoEnergy {
  0%,
  100% {
    filter: drop-shadow(0 0 12px rgba(88, 255, 87, 0.32)) brightness(1);
    transform: translate3d(0, 0, 0);
  }
  18% {
    filter: drop-shadow(0 0 20px rgba(88, 255, 87, 0.44)) brightness(1.05);
  }
  43% {
    filter: drop-shadow(0 0 15px rgba(88, 255, 87, 0.35)) brightness(0.98);
  }
  68% {
    filter: drop-shadow(0 0 24px rgba(94, 231, 255, 0.24)) brightness(1.06);
  }
  73% {
    transform: translate3d(0.5px, -0.5px, 0);
  }
  74% {
    transform: translate3d(-0.5px, 0.5px, 0);
  }
  75% {
    transform: translate3d(0, 0, 0);
  }
}

@keyframes trixmaLogoGlow {
  0%,
  100% {
    opacity: 0.64;
  }
  33% {
    opacity: 0.94;
  }
  47% {
    opacity: 0.58;
  }
  72% {
    opacity: 0.82;
  }
}

@keyframes trixmaLogoGlitch {
  0%,
  88%,
  91%,
  100% {
    opacity: 0;
    transform: translateX(0);
  }
  89% {
    opacity: 0.44;
    transform: translateX(1.5px);
  }
  90% {
    opacity: 0.26;
    transform: translateX(-1px);
  }
}

@keyframes trixmaLogoScan {
  0%,
  72%,
  100% {
    opacity: 0;
    transform: translateY(-55%);
  }
  78% {
    opacity: 0.5;
  }
  86% {
    opacity: 0;
    transform: translateY(55%);
  }
}

@keyframes trixmaLogoSpark {
  0%,
  80%,
  100% {
    opacity: 0;
  }
  83% {
    opacity: 0.78;
  }
  86% {
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    scroll-behavior: auto !important;
    transition: none !important;
  }

  .ambient-canvas[data-mode="auth"],
  .ambient-canvas[data-mode="workspace"] {
    opacity: 0.18;
  }

  .trixma-logo img {
    filter: drop-shadow(0 0 13px rgba(88, 255, 87, 0.24));
  }
}
