:root {
  color-scheme: dark;
  --app-radius: 0.45rem;
  --app-shell-canvas: #131313;
  --app-shell-context: #0d0d0d;
  --app-shell-surface: #191919;
  --app-shell-surface-soft: #222222;
  --app-shell-border: transparent;
  --app-shell-divider: transparent;
  --app-shell-text: #f4f4f4;
  --app-shell-muted: #a9a9a9;
  --tensor-card-bg: #191919;
  --tensor-card-preview-bg: #191919;
  --tensor-card-body-bg: #191919;
  --tensor-card-border: transparent;
  --tensor-card-text: #f4f4f4;
  --tensor-card-muted: #b9b9b9;
  --tensor-cube-color: #ffffff;
  --tensor-button-icon-color: #ffffff;
  --app-shell-sidebar: #191919;
  --app-shell-sidebar-raised: #222222;
  --app-shell-sidebar-hover: #252525;
  --app-shell-sidebar-text: #f4f4f4;
  --app-shell-sidebar-muted: rgba(244, 244, 244, 0.62);
  --app-shell-sidebar-border: transparent;
  --app-shell-cyan: #ffffff;
  --app-shell-danger: #d84d57;
}

body.logged-in-body {
  min-height: 100vh;
  display: block;
  background: var(--app-shell-canvas);
  color: var(--app-shell-text);
  transition: background-color 0.2s ease, color 0.2s ease;
}

body.logged-in-body :where(.btn, button, input, select, textarea, summary, .tensor-card, .settings-section, .dashboard-section, .logged-in-context-menu, .logged-in-mobile-context-menu, .app-flash, .tensor-color-popup, .tensor-color-swatch-color) {
  border: 0;
  border-radius: var(--app-radius);
  box-shadow: none;
}

.app-context-menu {
  padding: 0.35rem;
  border: 0;
  border-radius: var(--app-radius);
  background: var(--app-shell-context);
  color: var(--app-shell-text);
  box-shadow: none;
}

.app-context-menu-item {
  width: 100%;
  display: block;
  padding: 0.65rem 0.7rem;
  border: 0;
  border-radius: var(--app-radius);
  background: transparent;
  color: var(--app-shell-text);
  font: inherit;
  font-size: 0.9rem;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.app-context-menu-item:hover {
  background: var(--app-shell-canvas);
}

.app-context-menu form {
  margin: 0;
}

.logged-in-shell {
  --logged-in-sidebar-width: 248px;
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--logged-in-sidebar-width) minmax(0, 1fr);
}

.logged-in-mobile-topbar {
  display: none;
}

.logged-in-sidebar {
  box-sizing: border-box;
  z-index: 40;
  background: var(--app-shell-sidebar);
  color: var(--app-shell-sidebar-text);
  min-height: 100vh;
  height: 100vh;
  margin: 0;
  padding: 0 0 0.75rem 0;
  border-right: 0;
  border-radius: 0;
  position: sticky;
  top: 0;
  overflow: visible;
  transition: border-color 0.2s ease;
}

.logged-in-sidebar-inner {
  position: relative;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: visible;
}

.logged-in-brand {
  height: 4rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1.25rem;
  border-bottom: 0;
  color: var(--app-shell-sidebar-text);
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.logged-in-brand-mark {
  width: 1.75rem;
  height: 1.75rem;
  display: inline-flex;
  color: var(--app-shell-sidebar-text);
}

.logged-in-brand-mark svg {
  width: 100%;
  height: 100%;
}

.logged-in-sidebar-nav,
.logged-in-sidebar-footer {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.logged-in-sidebar-nav {
  padding: 1rem 0 0 0;
}

.logged-in-nav-label {
  padding: 0 1.25rem 0.65rem;
  color: var(--app-shell-sidebar-muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: lowercase;
}

.logged-in-sidebar-link {
  width: auto;
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 0.85rem;
  margin: 0 0.75rem;
  padding: 0.82rem 0.9rem;
  border: 0;
  border-radius: var(--app-radius);
  background: transparent;
  color: var(--app-shell-sidebar-muted);
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 600;
  transition: background-color 0.18s ease, color 0.18s ease;
  cursor: pointer;
}

.logged-in-sidebar-link:hover {
  background: var(--app-shell-sidebar-hover);
  color: var(--app-shell-sidebar-text);
}

.logged-in-sidebar-link.active {
  color: var(--app-shell-sidebar-text);
}

.logged-in-sidebar-link.active:hover {
  background: var(--app-shell-sidebar-hover);
  color: var(--app-shell-sidebar-text);
}

.logged-in-sidebar-button {
  font: inherit;
  text-align: left;
}

.logged-in-sidebar-icon {
  width: 1.25rem;
  height: 1.25rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.logged-in-sidebar-icon svg {
  width: 100%;
  height: 100%;
}

.logged-in-sidebar-footer {
  position: relative;
  padding: 0 0 0.75rem 0;
}

.logged-in-profile-menu {
  position: relative;
  margin-top: 0.75rem;
  z-index: 2;
}

.logged-in-profile-summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.9rem;
  min-height: 4rem;
  padding: 0.75rem 1rem;
  border-top: 0;
  border-bottom: 0;
  color: var(--app-shell-sidebar-text);
  cursor: pointer;
}

.logged-in-profile-summary::-webkit-details-marker {
  display: none;
}

.logged-in-profile-summary:hover {
  background: var(--app-shell-sidebar-hover);
}

.logged-in-profile-avatar {
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: var(--app-shell-sidebar-text);
  color: var(--app-shell-sidebar);
  font-size: 0.9rem;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.logged-in-profile-copy {
  min-width: 0;
}

.logged-in-profile-name {
  color: var(--app-shell-sidebar-text);
  font-weight: 700;
}

.logged-in-profile-email {
  margin-top: 0.18rem;
  color: var(--app-shell-sidebar-muted);
  font-size: 0.82rem;
  overflow: hidden;
  text-overflow: ellipsis;
}

.logged-in-context-menu {
  position: absolute;
  left: calc(100% + 0.9rem);
  bottom: 0.15rem;
  z-index: 120;
  width: 13rem;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.logged-in-context-menu::before {
  content: none;
  position: absolute;
  left: -0.45rem;
  bottom: 1.35rem;
  width: 0.8rem;
  height: 0.8rem;
  background: var(--app-shell-surface);
  border-left: 0;
  border-bottom: 0;
  rotate: 45deg;
}

.logged-in-mobile-menu {
  position: relative;
}

.logged-in-mobile-icon-button,
.logged-in-mobile-profile-summary {
  list-style: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--app-shell-text);
  cursor: pointer;
}

.logged-in-mobile-icon-button::-webkit-details-marker,
.logged-in-mobile-profile-summary::-webkit-details-marker {
  display: none;
}

.logged-in-mobile-icon-button {
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 999px;
}

.logged-in-mobile-hamburger {
  width: 1.2rem;
  display: grid;
  gap: 0.22rem;
}

.logged-in-mobile-hamburger span {
  height: 2px;
  border-radius: 999px;
  background: currentColor;
}

.logged-in-mobile-context-menu {
  position: absolute;
  top: calc(100% + 0.8rem);
  z-index: 20;
  width: min(18rem, calc(100vw - 2rem));
}

.logged-in-mobile-context-menu::before {
  content: none;
  position: absolute;
  top: -0.45rem;
  width: 0.8rem;
  height: 0.8rem;
  background: var(--app-shell-surface);
  border-top: 0;
  border-left: 0;
  rotate: 45deg;
}

.logged-in-mobile-nav-panel {
  left: 0;
}

.logged-in-mobile-nav-panel::before {
  left: 1.2rem;
}

.logged-in-mobile-profile-panel {
  right: 0;
}

.logged-in-mobile-profile-panel::before {
  right: 1.2rem;
}

.logged-in-mobile-nav {
  display: grid;
  gap: 0.2rem;
}

.logged-in-mobile-nav .logged-in-sidebar-link {
  margin: 0;
  color: var(--app-shell-text);
}

.logged-in-mobile-nav .logged-in-sidebar-link:hover,
.logged-in-mobile-nav .logged-in-sidebar-link.active {
  background: var(--app-shell-canvas);
  color: var(--app-shell-text);
}

.logged-in-mobile-profile-card {
  padding: 0.75rem 0.8rem 0.9rem;
  margin-bottom: 0.2rem;
  border-bottom: 0;
}

.logged-in-mobile-profile-name {
  color: var(--app-shell-text);
  font-weight: 700;
}

.logged-in-mobile-profile-email {
  margin-top: 0.2rem;
  color: var(--app-shell-muted);
  font-size: 0.84rem;
  overflow-wrap: anywhere;
}

.app-flash-stack {
  position: fixed;
  top: 1.25rem;
  left: 50%;
  z-index: 100;
  display: grid;
  gap: 0.75rem;
  width: min(28rem, calc(100vw - 2rem));
  transform: translateX(-50%);
}

.app-flash {
  padding: 0.85rem 1rem;
  border: 0;
  border-radius: var(--app-radius);
  font-size: 0.95rem;
  font-weight: 600;
  box-shadow: none;
  animation: app-flash-enter 0.22s ease-out, app-flash-exit 0.24s ease-in 4.6s forwards;
}

.app-flash-success {
  background: #193321;
  color: #9be7ad;
}

.app-flash-error {
  background: #351c1f;
  color: #ffb0b8;
}

.app-flash-warning {
  background: #332c17;
  color: #f0d083;
}

.app-flash-info {
  background: #1b2538;
  color: #adc8ff;
}

@keyframes app-flash-enter {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes app-flash-exit {
  from {
    opacity: 1;
    transform: translateY(0);
  }

  to {
    opacity: 0;
    transform: translateY(-6px);
  }
}

.logged-in-main {
  position: relative;
  z-index: 0;
  min-width: 0;
  background: var(--app-shell-canvas);
  padding: 2.5rem;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.logged-in-main .btn-primary,
.logged-in-main .btn-login {
  background: var(--app-shell-surface);
  color: var(--app-shell-sidebar-text);
  border: 1px solid var(--app-shell-sidebar-hover) !important;
}

.logged-in-main .btn:hover {
  transform: none;
}

.logged-in-main .btn-primary:hover,
.logged-in-main .btn-login:hover {
  background: var(--app-shell-sidebar-hover);
}

.logged-in-main .btn-secondary {
  background: var(--app-shell-surface);
  color: var(--app-shell-text);
  border: 1px solid var(--app-shell-surface-soft) !important;
}

.logged-in-main .btn-secondary:hover {
  background: var(--app-shell-surface-soft);
}

.logged-in-main .btn-danger {
  background: var(--app-shell-danger);
  color: #ffffff;
  border: 1px solid #c73f49 !important;
}

.logged-in-main .btn-danger:hover {
  background: #c73f49;
}

.logged-in-main .badge-viewer {
  background: var(--app-shell-surface-soft);
  color: var(--app-shell-text);
}

.logged-in-main .badge-editor {
  background: var(--app-shell-surface-soft);
  color: var(--app-shell-text);
}

.logged-in-main .badge-admin {
  background: var(--app-shell-text);
  color: var(--app-shell-surface);
}

.logged-in-main .badge-owner {
  background: var(--app-shell-surface-soft);
  color: var(--app-shell-text);
}

.logged-in-main .badge-success {
  background: var(--app-shell-surface-soft);
  color: var(--app-shell-text);
}

.logged-in-main .badge-warning {
  background: var(--app-shell-surface-soft);
  color: var(--app-shell-text);
}

.logged-in-main .form-group input,
.logged-in-main .form-group select,
.logged-in-main .form-group textarea,
.logged-in-main .form-select {
  color-scheme: dark;
  background: var(--app-shell-canvas);
  color: var(--app-shell-text);
  border: 0;
}

.logged-in-main .form-group select,
.logged-in-main .form-select {
  accent-color: var(--app-shell-text);
}

.logged-in-main .form-group input:focus,
.logged-in-main .form-group select:focus,
.logged-in-main .form-group textarea:focus,
.logged-in-main .form-select:focus {
  outline: none;
  box-shadow: none;
}

.logged-in-main .form-group input:disabled,
.logged-in-main .form-group select:disabled,
.logged-in-main .form-group textarea:disabled,
.logged-in-main .form-select:disabled {
  background: var(--app-shell-surface-soft);
  color: var(--app-shell-muted);
  opacity: 1;
  cursor: not-allowed;
}

.logged-in-main select option,
.logged-in-main select optgroup {
  background: var(--app-shell-canvas);
  color: var(--app-shell-text);
}

.logged-in-main select option {
  padding: 0.55rem 0.65rem;
}

.logged-in-main select[multiple] {
  padding: 0.35rem;
}

.logged-in-main select[multiple] option {
  margin: 0.15rem 0;
  border-radius: var(--app-radius);
}

.logged-in-main select option:checked,
.logged-in-main select option:hover,
.logged-in-main select option:focus {
  background: var(--app-shell-surface-soft);
  box-shadow: 0 0 0 999px var(--app-shell-surface-soft) inset;
  color: var(--app-shell-text);
}

.logged-in-main .settings-header h1 {
  color: var(--app-shell-text);
}

.logged-in-main .settings-back-link {
  color: var(--app-shell-muted);
}

.logged-in-main .settings-back-link:hover {
  color: var(--app-shell-cyan);
}

.logged-in-main .settings-section {
  background: var(--app-shell-surface);
  border: 0;
  border-radius: var(--app-radius);
  box-shadow: none;
  padding: 1.5rem;
}

.logged-in-main .settings-form-card {
  max-width: 37rem;
}

.logged-in-main .settings-form {
  max-width: none;
}

.logged-in-main .tensor-form-page {
  max-width: 1180px;
}

.logged-in-main .tensor-form {
  max-width: none;
}

.logged-in-main .settings-section h2 {
  color: var(--app-shell-text);
}

.logged-in-main .settings-section + .settings-section {
  margin-top: 2.5rem;
}

.logged-in-main .settings-table th,
.logged-in-main .settings-table td {
  border-bottom: 0;
}

.logged-in-main .settings-table th {
  color: var(--app-shell-muted);
}

.logged-in-main .settings-form .form-group input.disabled,
.logged-in-main .settings-form .form-group input:disabled {
  background: var(--app-shell-canvas);
  color: var(--app-shell-muted);
  cursor: not-allowed;
}

@media (prefers-reduced-motion: reduce) {
  .app-flash {
    animation: app-flash-exit 0.18s linear 4.6s forwards;
  }

  body.logged-in-body,
  .logged-in-sidebar,
  .logged-in-context-menu,
  .logged-in-mobile-context-menu,
  .logged-in-main,
  .logged-in-main .btn {
    transition: none;
  }
}

@media (max-width: 720px) {
  .app-flash-stack {
    top: 1rem;
  }
}

.logged-in-main .empty-state {
  color: var(--app-shell-muted);
}

.settings-subnav {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0;
  margin-bottom: 1.5rem;
  border-radius: 0;
  background: transparent;
  border: 0;
}

.settings-subnav-link {
  padding: 0.45rem 0;
  border-radius: 0;
  margin-right: 1rem;
  color: var(--app-shell-muted);
  font-size: 0.95rem;
  font-weight: 600;
  text-decoration: none;
  transition: background-color 0.18s ease, color 0.18s ease;
}

.settings-subnav-link:hover {
  background: transparent;
  color: var(--app-shell-text);
}

.settings-subnav-link.active {
  background: transparent;
  color: var(--app-shell-text);
  box-shadow: none;
  border-bottom: 0;
}

.dashboard-page {
  max-width: 1160px;
}

.dashboard-page-header {
  margin-bottom: 2rem;
}

.dashboard-page-kicker {
  margin-bottom: 0.75rem;
  color: var(--app-shell-cyan);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.dashboard-page-header h1 {
  font-size: clamp(2rem, 4vw, 3rem);
  line-height: 1.05;
  color: var(--app-shell-text);
}

.dashboard-page-copy {
  max-width: 52rem;
  margin-top: 1rem;
  color: var(--app-shell-muted);
  font-size: 1rem;
  line-height: 1.7;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 2rem;
}

.dashboard-section {
  padding: 0;
  border-radius: 0;
  background: transparent;
  border: 0;
  box-shadow: none;
}

.dashboard-section.is-accent {
  background: transparent;
}

.dashboard-section h2 {
  margin-bottom: 1.1rem;
  color: var(--app-shell-text);
  font-size: 1.1rem;
}

.dashboard-section p {
  color: var(--app-shell-muted);
  line-height: 1.7;
}

.dashboard-details {
  display: grid;
  gap: 1rem;
}

.dashboard-details dt {
  margin-bottom: 0.25rem;
  color: var(--app-shell-muted);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.dashboard-details dd {
  color: var(--app-shell-text);
  font-size: 1rem;
}

.dashboard-cube-page {
  min-height: calc(100vh - 8rem);
  display: grid;
  place-items: center;
}

.tensor-show-page {
  display: block;
  width: 100%;
  max-width: 1180px;
}

.tensor-show-header {
  margin-bottom: 1.8rem;
}

.tensor-show-center-anchor {
  width: min(42rem, calc(100vw - var(--logged-in-sidebar-width, 248px) - 5rem));
  min-height: min(42rem, calc(100vh - 12rem));
  aspect-ratio: 1;
  pointer-events: none;
}

.dashboard-cube-stage {
  position: relative;
  width: min(42rem, 100%);
  aspect-ratio: 1;
  cursor: grab;
  touch-action: none;
}

.dashboard-cube-stage.is-dragging {
  cursor: grabbing;
}

.dashboard-cube-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.tensor-view-reset-button {
  position: absolute;
  top: var(--tensor-reset-top, 0.75rem);
  left: var(--tensor-reset-left, 0.75rem);
  z-index: 10;
  cursor: pointer;
}

.tensor-view-reset-button[hidden] {
  display: none;
}

.tensor-view-reset-icon {
  position: relative;
  width: 1.05rem;
  height: 1.05rem;
  border: 2px solid currentColor;
  border-radius: 999px;
}

.tensor-view-reset-icon::before,
.tensor-view-reset-icon::after {
  content: "";
  position: absolute;
  background: currentColor;
}

.tensor-view-reset-icon::before {
  left: 50%;
  top: -0.35rem;
  bottom: -0.35rem;
  width: 2px;
  transform: translateX(-50%);
}

.tensor-view-reset-icon::after {
  top: 50%;
  left: -0.35rem;
  right: -0.35rem;
  height: 2px;
  transform: translateY(-50%);
}

.tensors-page,
.tensor-form-page {
  max-width: 1180px;
}

.tensor-form-page {
  position: relative;
}

.tensors-page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  margin-bottom: 1.8rem;
}

.tensor-form-header {
  position: relative;
  z-index: 1;
  margin-bottom: 1.8rem;
}

.tensors-page-title {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.tensors-page-header h1,
.tensor-form-header h1 {
  color: var(--app-shell-text);
  font-size: clamp(1.35rem, 2.4vw, 1.85rem);
  line-height: 1;
}

.tensors-count-badge {
  min-width: 1.75rem;
  height: 1.75rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: var(--app-radius);
  background: var(--app-shell-surface);
  color: var(--app-shell-text);
  font-size: 0.95rem;
  font-weight: 800;
  line-height: 1;
}

.logged-in-main .tensors-create-button {
  padding: 0.7rem 1.45rem;
  border: 1px solid var(--app-shell-surface-soft) !important;
  border-radius: var(--app-radius);
  background: var(--app-shell-surface);
  color: var(--app-shell-text);
  font-weight: 800;
  text-decoration: none;
  box-shadow: none;
}

.logged-in-main .tensors-create-button:hover {
  background: var(--app-shell-surface-soft);
}

.tensors-page-menu {
  position: relative;
  display: none;
}

.tensors-page-menu-button {
  list-style: none;
  width: 2.5rem;
  height: 2.5rem;
  display: grid;
  place-items: center;
  gap: 0.22rem;
  padding: 0.68rem;
  border-radius: var(--app-radius);
  background: var(--app-shell-surface);
  color: var(--app-shell-text);
  cursor: pointer;
}

.tensors-page-menu-button::-webkit-details-marker {
  display: none;
}

.tensors-page-menu-button span {
  width: 100%;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
}

.tensors-page-menu-panel {
  position: absolute;
  top: calc(100% + 0.45rem);
  right: 0;
  z-index: 35;
  width: 11rem;
}

.tensor-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(15.5rem, 15.5rem));
  gap: 1.6rem;
  align-items: start;
}

.tensor-card {
  position: relative;
  min-height: 15.8rem;
  border: 0;
  border-radius: var(--app-radius);
  background: var(--tensor-card-bg);
  color: var(--tensor-card-text);
  overflow: visible;
}

.tensor-card-link {
  min-height: 15.8rem;
  display: grid;
  grid-template-rows: 10.5rem minmax(0, 1fr);
  color: inherit;
  text-decoration: none;
}

.tensor-card-preview {
  min-height: 0;
  padding: 0.95rem 1rem 0;
  border: 0;
  border-radius: var(--app-radius) var(--app-radius) 0 0;
  background: var(--tensor-card-preview-bg);
}

.tensor-card-preview canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.tensor-card-preview-stage {
  width: 100%;
  height: 100%;
  aspect-ratio: auto;
  cursor: pointer;
  touch-action: auto;
}

.tensor-card-body {
  min-height: 0;
  padding: 0.55rem 1rem 1.1rem;
  border: 0;
  border-radius: 0 0 var(--app-radius) var(--app-radius);
  background: var(--tensor-card-body-bg);
}

.tensor-card-body h2 {
  margin: 0;
  color: var(--tensor-card-text);
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.25;
}

.tensor-card-body p {
  margin-top: 0.5rem;
  color: var(--tensor-card-muted);
  font-weight: 800;
  letter-spacing: 0.02em;
}

.decomposition-card-link {
  min-height: 15.8rem;
  display: grid;
  grid-template-rows: 10.5rem minmax(0, 1fr);
}

.decomposition-card-body {
  min-height: 0;
  display: grid;
  align-content: start;
  gap: 0.5rem;
  padding: 1.25rem 1rem 1rem;
}

.decomposition-card-body p {
  margin: 0;
}

.decomposition-status {
  width: fit-content;
  margin-top: 0.35rem;
  padding: 0.35rem 0.5rem;
  border-radius: var(--app-radius);
  background: var(--app-shell-surface-soft);
  color: var(--app-shell-muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.decomposition-status.is-solved {
  color: var(--app-shell-text);
}

.decomposition-card {
  min-height: 0;
}

.tensor-card-menu {
  position: absolute;
  top: 0.85rem;
  right: 0.2rem;
  z-index: 20;
}

.tensor-card-menu-button {
  list-style: none;
  width: 3rem;
  height: 3rem;
  display: grid;
  place-items: center;
  grid-template-rows: repeat(3, 0.22rem);
  gap: 0.16rem;
  border-radius: 999px;
  color: var(--tensor-card-text);
  cursor: pointer;
}

.tensor-card-menu-button::-webkit-details-marker {
  display: none;
}

.tensor-card-menu-button span {
  width: 0.22rem;
  height: 0.22rem;
  border-radius: 50%;
  background: currentColor;
}

.tensor-card-menu-panel {
  position: absolute;
  top: calc(100% + 0.4rem);
  right: 0;
  z-index: 30;
  width: 8.5rem;
}

.tensor-form-grid {
  display: grid;
  grid-template-columns: minmax(18rem, 26rem) minmax(18rem, 1fr);
  gap: 2rem;
  align-items: start;
  pointer-events: none;
}

.tensor-form {
  display: block;
}

.tensor-form-fields {
  display: grid;
  gap: 1.2rem;
}

.tensor-form-card,
.tensor-show-card {
  position: relative;
  z-index: 1;
  pointer-events: auto;
  background: var(--app-shell-surface);
  border: 0;
  border-radius: var(--app-radius);
  box-shadow: none;
  padding: 1.5rem;
}

.tensor-form-preview-card {
  display: grid;
  place-items: center;
}

.tensor-form-preview-background,
.tensor-show-background {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: var(--logged-in-sidebar-width, 248px);
  z-index: 0;
  width: auto;
  min-height: 100vh;
  aspect-ratio: auto;
  pointer-events: auto;
}

.tensor-form-preview-anchor {
  min-height: min(40rem, calc(100vh - 12rem));
  aspect-ratio: 1;
  pointer-events: none;
}

.decomposition-form-card {
  max-width: 28rem;
}

.decomposition-page {
  width: 100%;
}

.decomposition-workspace {
  position: relative;
  display: grid;
  grid-template-columns: minmax(18rem, 24rem) minmax(18rem, 1fr);
  gap: 2rem;
  align-items: start;
  min-height: calc(100vh - 5rem);
  pointer-events: none;
}

.decomposition-rank-panel {
  position: relative;
  z-index: 2;
  width: min(24rem, 100%);
  pointer-events: auto;
}

.decomposition-view-anchor {
  position: relative;
  z-index: 2;
  min-height: min(42rem, calc(100vh - 8rem));
  aspect-ratio: 1;
  padding-top: 3.4rem;
  pointer-events: none;
}

.decomposition-vector-viewer {
  --tensor-reset-control-offset: 6.65rem;
}

.decomposition-rank-panel-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.decomposition-view-controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.45rem;
  width: clamp(15rem, 32vw, 22rem);
  margin-bottom: 0.5rem;
  pointer-events: auto;
}

.decomposition-view-controls .btn {
  padding-inline: 0.5rem;
}

.decomposition-view-controls .btn.active {
  background: var(--app-shell-sidebar-hover);
  color: var(--app-shell-sidebar-text);
}

.decomposition-rank-panel-header p {
  margin: 0;
  color: var(--app-shell-muted);
}

.decomposition-naive-badge {
  margin-left: auto;
  padding: 0.55rem 0.75rem;
  border-radius: var(--app-radius);
  background: var(--app-shell-canvas);
  color: var(--app-shell-muted);
  font-size: 0.85rem;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
}

.decomposition-rank-form,
.decomposition-rank-list {
  display: grid;
  gap: 0.5rem;
}

.decomposition-rank-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem;
  border: 1px solid transparent;
  border-radius: var(--app-radius);
  background: var(--app-shell-canvas);
  cursor: pointer;
  transition: background 0.16s ease, border-color 0.16s ease, transform 0.16s ease;
}

.decomposition-rank-base-item {
  width: 100%;
  color: var(--app-shell-text);
  font: inherit;
  font-weight: 800;
  text-align: left;
}

.decomposition-rank-item.active {
  background: var(--app-shell-surface-soft);
  border-color: var(--app-shell-text);
}

.decomposition-rank-item.is-dragging {
  opacity: 0.55;
}

.decomposition-rank-handle {
  cursor: grab;
  flex: 0 0 auto;
  min-width: 0;
  padding-inline: 0.55rem;
}

.decomposition-rank-label-input {
  min-width: 0;
  flex: 1 1 auto;
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 0;
  border-radius: 6px;
  background: var(--app-shell-surface);
  color: var(--app-shell-text);
  font-size: 1rem;
}

.decomposition-rank-label-input:focus {
  outline: none;
  box-shadow: none;
}

.decomposition-rank-remove {
  flex: 0 0 auto;
}

.decomposition-rank-remove-icon {
  width: 1rem;
  height: 1rem;
  display: block;
  filter: invert(1);
}

.decomposition-rank-add {
  width: 100%;
  min-height: 3.25rem;
  justify-content: center;
}

.decomposition-rank-footer {
  justify-content: space-between;
  margin-top: 0.25rem;
}

.decomposition-solved-badge {
  width: fit-content;
  padding: 0.55rem 0.75rem;
  border: 1px solid currentColor;
  border-radius: var(--app-radius);
  font-size: 0.85rem;
  font-weight: 800;
  line-height: 1;
}

.decomposition-card-badge {
  margin-top: 0.25rem;
}

.decomposition-solved-badge.is-unsolved {
  background: color-mix(in srgb, #ff9500 18%, transparent);
  color: #ff9500;
}

.decomposition-solved-badge.is-solved {
  background: color-mix(in srgb, #2dff72 18%, transparent);
  color: #2dff72;
}

.tensor-dimension-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.9rem;
}

.tensor-dimension-grid[hidden] {
  display: none;
}

.tensor-template-fields {
  display: grid;
  gap: 1rem;
}

.tensor-template-fields[hidden] {
  display: none;
}

.tensor-template-message {
  margin: -0.35rem 0 0.2rem;
  color: var(--app-shell-danger);
  font-size: 0.9rem;
  line-height: 1.45;
}

.tensor-template-factor h2 {
  margin: 0 0 0.55rem;
  color: var(--app-shell-text);
  font-size: 1rem;
}

.tensor-form-actions {
  display: flex;
  gap: 0.8rem;
  align-items: center;
}

.tensor-form-preview {
  width: min(40rem, 100%);
  aspect-ratio: 1;
}

.tensor-show-card {
  width: min(44rem, 100%);
}

.tensor-show-card .dashboard-cube-stage {
  width: 100%;
}

.tensor-form-preview canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.tensor-color-popup {
  position: absolute;
  z-index: 25;
  display: flex;
  gap: 0.35rem;
  padding: 0.4rem;
  border: 0;
  border-radius: var(--app-radius);
  background: var(--app-shell-context);
  transform: translate(0.65rem, -50%);
}

.tensor-color-swatch {
  display: grid;
  gap: 0.2rem;
  justify-items: center;
  border: 0;
  background: transparent;
  color: var(--app-shell-text);
  font: inherit;
  cursor: pointer;
}

.tensor-color-swatch-color {
  width: 1.7rem;
  height: 1.7rem;
  border: 0;
  border-radius: var(--app-radius);
}

.tensor-color-swatch-label {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.72rem;
  line-height: 1;
}

.form-errors {
  margin-bottom: 1rem;
  color: var(--app-shell-danger);
  font-weight: 700;
}

.form-errors ul {
  margin: 0.5rem 0 0;
  padding-left: 1.2rem;
  font-weight: 600;
  line-height: 1.45;
}

@media (max-width: 960px) {
  .logged-in-shell {
    --logged-in-sidebar-width: 0px;
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    align-content: start;
  }

  .logged-in-mobile-topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: grid;
    grid-template-columns: 2.25rem minmax(0, 1fr) 2.25rem;
    align-items: center;
    gap: 0.55rem;
    min-height: 3.25rem;
    height: 3.25rem;
    box-sizing: border-box;
    padding: 0.45rem 0.75rem;
    border-bottom: 1px solid var(--app-shell-surface-soft);
    background: color-mix(in srgb, var(--app-shell-surface) 92%, transparent);
    backdrop-filter: blur(16px);
  }

  .logged-in-mobile-icon-button,
  .logged-in-mobile-profile-summary {
    width: 2.25rem;
    height: 2.25rem;
  }

  .logged-in-mobile-icon-button {
    border-radius: var(--app-radius);
  }

  .logged-in-mobile-hamburger {
    width: 1rem;
    gap: 0.18rem;
  }

  .logged-in-mobile-profile-summary .logged-in-profile-avatar {
    width: 2.1rem;
    height: 2.1rem;
    font-size: 0.72rem;
  }

  .logged-in-mobile-brand {
    text-align: center;
    color: var(--app-shell-text);
    font-size: 0.95rem;
    font-weight: 800;
    letter-spacing: -0.02em;
  }

  .logged-in-sidebar {
    display: none;
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .tensor-form-grid {
    grid-template-columns: 1fr;
  }

  .decomposition-workspace {
    grid-template-columns: 1fr;
  }

  .decomposition-rank-panel {
    width: 100%;
  }

  .decomposition-view-anchor {
    min-height: min(32rem, 80vw);
  }

  .decomposition-view-controls {
    width: min(22rem, calc(100vw - 3rem));
    margin-left: 0;
    padding-top: 3.25rem;
  }

  .tensor-form-preview-background,
  .tensor-show-background {
    top: 3.25rem;
    left: var(--logged-in-sidebar-width);
    min-height: calc(100vh - 3.25rem);
  }

  .tensor-form-preview-anchor {
    min-height: min(32rem, 80vw);
  }

  .logged-in-main {
    padding: 1.5rem;
  }
}

@media (max-width: 640px) {
  .logged-in-main {
    padding: 1rem;
  }

  .logged-in-main .settings-section,
  .dashboard-section {
    padding: 0;
  }

  .logged-in-main .settings-table {
    display: block;
    overflow-x: auto;
  }

  .logged-in-main .form-row {
    flex-direction: column;
    align-items: stretch;
  }

  .settings-subnav {
    width: 100%;
    justify-content: space-between;
  }

  .dashboard-page-header h1 {
    font-size: clamp(1.7rem, 9vw, 2.4rem);
  }

  .tensors-page-header {
    align-items: center;
    flex-direction: row;
    gap: 0.85rem;
  }

  .logged-in-main .tensors-create-button {
    display: none;
  }

  .tensors-page-menu {
    display: block;
  }

  .tensors-page-title {
    min-width: 0;
  }

  .tensor-card-grid {
    grid-template-columns: 1fr;
  }

  .tensor-card {
    min-height: 16rem;
  }

  .decomposition-card {
    min-height: 0;
  }
}
