:root {
  color-scheme: light;
  --bg: #edf2f4;
  --surface: #ffffff;
  --canvas: #fbfcfd;
  --grid: #e4ebef;
  --grid-major: #b9c7cf;
  --line: #d4dde3;
  --ink: #17212b;
  --muted: #66727d;
  --accent: #0d7f73;
  --accent-strong: #075e56;
  --warn: #c47a12;
  --danger: #c23b32;
  --blue: #245f9f;
  --select: #177ddc;
  --ui-font-size: 14px;
}

body.dark-theme {
  color-scheme: dark;
  --bg: #020304;
  --surface: #090c0e;
  --canvas: #000000;
  --grid: #12181c;
  --grid-major: #2a343a;
  --line: #252d32;
  --ink: #f1f6f7;
  --muted: #9aa8ae;
  --accent: #21a899;
  --accent-strong: #2bbbad;
  --warn: #e1a13a;
  --danger: #ef6a5e;
  --blue: #6aa7e8;
  --select: #7bbcff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", Arial, sans-serif;
  font-size: var(--ui-font-size);
}

body.dynamics-active {
  overflow: hidden;
}

.hidden,
.app-hidden {
  display: none !important;
}

.welcome-screen {
  position: relative;
  min-height: 100vh;
  display: grid;
  place-items: center;
  overflow-x: hidden;
  padding: 42px 18px;
  background: url("/static/welcome-bg.jpg") center / cover no-repeat fixed;
}

.welcome-content {
  width: min(1100px, 100%);
  min-height: min(760px, calc(100vh - 84px));
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 18px;
  padding: clamp(24px, 5vw, 58px);
  color: #050505;
  text-align: center;
}

.welcome-title {
  margin: 0;
  max-width: 980px;
  font-size: clamp(32px, 5.2vw, 64px);
  line-height: 1.08;
  font-weight: 900;
  letter-spacing: 0;
}

.welcome-title span {
  display: block;
}

.welcome-subtitle,
.welcome-contact {
  margin: 0;
  font-size: clamp(15px, 1.75vw, 20px);
  line-height: 1.5;
}

.welcome-subtitle {
  font-weight: 800;
}

.welcome-version {
  margin: -2px 0 0;
  font-size: clamp(22px, 3vw, 34px);
  line-height: 1;
  font-weight: 900;
}

.studio-credit {
  color: rgba(224, 230, 236, 0.92);
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.46);
  font-weight: 800;
}

.welcome-contact {
  max-width: 900px;
  color: rgba(234, 238, 242, 0.9);
  font-weight: 650;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.68);
}

.local-profile-note {
  max-width: 760px;
  margin: 0;
  color: rgba(224, 232, 238, 0.78);
  font-size: 12px;
  line-height: 1.5;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.72);
}

.rainbow-animated {
  background: linear-gradient(90deg, #d71920, #f47b20, #f4d03f, #27ae60, #1489d8, #6c5ce7, #c039b7, #d71920);
  background-size: 260% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: rainbowFlow 7s linear infinite;
}

@keyframes rainbowFlow {
  from {
    background-position: 0% 50%;
  }
  to {
    background-position: 260% 50%;
  }
}

.announcement-trigger {
  position: absolute;
  top: clamp(16px, 3vw, 34px);
  left: clamp(14px, 3vw, 38px);
  z-index: 2;
  width: 94px;
  height: 108px;
  min-width: 0;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 5px;
  border: 1px solid rgba(191, 226, 245, 0.5);
  border-radius: 8px;
  background: rgba(5, 18, 29, 0.64);
  color: #e9f6ff;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.24);
  backdrop-filter: blur(7px);
}

.announcement-trigger:hover,
.announcement-trigger:focus-visible {
  border-color: rgba(255, 255, 255, 0.86);
  background: rgba(14, 55, 78, 0.82);
  color: #ffffff;
}

.li-atom {
  position: relative;
  width: 66px;
  height: 66px;
  display: block;
}

.li-nucleus {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 2;
  width: 27px;
  height: 27px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: 50%;
  background: #143e55;
  color: #f4fbff;
  font-size: 12px;
  font-weight: 900;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 14px rgba(56, 189, 248, 0.34);
}

.li-ion {
  position: relative;
  display: inline-block;
  padding-right: 0.34em;
  line-height: 1;
  white-space: nowrap;
}

.li-ion sup {
  position: absolute;
  top: -0.34em;
  right: 0;
  line-height: 1;
  vertical-align: baseline;
  font-size: 0.48em;
}

.li-nucleus sup {
  position: absolute;
  top: 2px;
  right: 3px;
  line-height: 1;
  vertical-align: baseline;
  font-size: 0.48em;
}

.announcement-kicker sup {
  position: static;
  line-height: 0;
  vertical-align: super;
  font-size: 0.62em;
}

.atom-orbit {
  --orbit-angle: 0deg;
  position: absolute;
  inset: 10px 1px;
  border: 1px solid rgba(149, 219, 250, 0.78);
  border-radius: 50%;
  animation: atomOrbit 4.8s linear infinite;
}

.atom-orbit-two {
  --orbit-angle: 60deg;
  animation-duration: 4.2s;
}

.atom-orbit-three {
  --orbit-angle: -60deg;
  animation-duration: 5.4s;
}

.atom-electron {
  position: absolute;
  top: -3px;
  left: 50%;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 0 8px rgba(125, 211, 252, 0.95);
  transform: translateX(-50%);
}

.announcement-label {
  font-size: 13px;
  font-weight: 800;
}

@keyframes atomOrbit {
  from {
    transform: rotate(var(--orbit-angle));
  }
  to {
    transform: rotate(calc(var(--orbit-angle) + 360deg));
  }
}

.auth-choice-panel {
  display: flex;
  justify-content: center;
  gap: 18px;
  margin-top: 26px;
  width: min(420px, 100%);
}

.auth-choice-button {
  width: 164px;
  height: 54px;
  border: 1px solid rgba(255, 255, 255, 0.56);
  border-radius: 8px;
  background: rgba(7, 14, 18, 0.78);
  color: #edf8fb;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.22);
  font-size: 20px;
  font-weight: 850;
  backdrop-filter: blur(5px);
}

.auth-choice-button:hover,
.auth-choice-button.active {
  background: rgba(36, 151, 139, 0.86);
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.72);
}

.auth-panel {
  width: min(430px, 100%);
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  margin-top: 8px;
}

.auth-card {
  display: grid;
  gap: 10px;
  padding: 18px;
  border: 1px solid rgba(179, 221, 232, 0.3);
  border-radius: 8px;
  background: rgba(3, 8, 11, 0.88);
  color: #eef7f9;
  box-shadow: 0 20px 56px rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(12px);
  text-align: left;
}

.auth-card h2 {
  margin: 0 0 4px;
  color: #f4fbfc;
  font-size: 20px;
}

.auth-field {
  display: grid;
  gap: 5px;
  color: #d9e7ea;
  font-weight: 650;
}

.auth-field input {
  background: rgba(0, 0, 0, 0.72);
  color: #f4fbfc;
  border-color: rgba(177, 209, 218, 0.36);
}

.auth-field input:focus-visible {
  border-color: #65d7c9;
  outline: 2px solid rgba(101, 215, 201, 0.25);
  outline-offset: 1px;
}

.auth-action,
.start-app-button {
  border-color: rgba(0, 0, 0, 0.16);
  background: #0f766e;
  color: #ffffff;
  font-weight: 800;
}

.auth-action {
  width: 100%;
  height: 38px;
  margin-top: 4px;
}

.auth-secondary {
  width: 100%;
  height: 36px;
  border-color: rgba(150, 194, 207, 0.34);
  background: rgba(10, 22, 28, 0.84);
  color: #b8d9e3;
  font-weight: 750;
}

.auth-secondary:hover,
.auth-secondary:focus-visible {
  border-color: rgba(112, 210, 226, 0.75);
  color: #edfaff;
}

.auth-agreement {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  gap: 8px;
  color: #bdd0d5;
  font-size: 12px;
  line-height: 1.5;
}

.auth-agreement input {
  margin-top: 3px;
}

.auth-agreement a {
  margin-left: 3px;
  color: #7ad9cf;
  font-weight: 800;
}

.migration-notice {
  max-width: 680px;
  margin: 0;
  border-left: 3px solid #e2a83f;
  background: rgba(8, 12, 15, 0.76);
  color: #f0d9a9;
  padding: 8px 12px;
  font-size: 12px;
  line-height: 1.55;
  text-align: left;
}

.auth-action:hover,
.start-app-button:hover {
  background: #0b5f58;
}

.avatar-upload-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: center;
}

.default-avatar {
  width: 42px;
  height: 42px;
  display: inline-grid;
  place-items: center;
  overflow: hidden;
  border-radius: 8px;
  background: #000000;
  color: #ffffff;
  font-weight: 900;
  letter-spacing: 0;
}

.default-avatar img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.avatar-upload {
  height: 34px;
  display: inline-grid;
  place-items: center;
  border: 1px solid rgba(183, 211, 219, 0.34);
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.68);
  color: #e8f3f5;
  cursor: pointer;
  font-weight: 700;
}

.avatar-upload input {
  display: none;
}

.start-panel {
  display: grid;
  justify-items: center;
  gap: 10px;
  margin-top: 20px;
}

.start-app-button {
  width: min(360px, 76vw);
  height: 58px;
  border-radius: 8px;
  font-size: 22px;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.22);
}

.welcome-logout-button {
  width: min(220px, 58vw);
  height: 40px;
  border-color: rgba(255, 255, 255, 0.42);
  background: rgba(246, 252, 255, 0.72);
  color: #07131e;
  font-weight: 800;
  backdrop-filter: blur(5px);
}

.welcome-logout-button:hover {
  background: rgba(232, 239, 243, 0.9);
}

.module-choice-panel {
  width: min(520px, 92vw);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 10px;
  animation: moduleChoiceIn 220ms ease-out both;
}

.module-choice-button {
  height: 62px;
  border: 1px solid rgba(255, 255, 255, 0.58);
  border-radius: 999px;
  background: linear-gradient(135deg, rgba(245, 251, 255, 0.84), rgba(201, 234, 229, 0.78));
  color: #07131e;
  box-shadow: 0 16px 34px rgba(0, 0, 0, 0.24);
  font-size: 22px;
  font-weight: 900;
  backdrop-filter: blur(5px);
  transition: transform 140ms ease, background 140ms ease, color 140ms ease, box-shadow 140ms ease;
}

.module-choice-button:hover {
  background: rgba(18, 126, 119, 0.88);
  color: #ffffff;
  box-shadow: 0 18px 38px rgba(5, 45, 43, 0.3);
  transform: translateY(-2px);
}

@keyframes moduleChoiceIn {
  from {
    opacity: 0;
    transform: translateX(-18px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.auth-message {
  min-height: 22px;
  margin: 0;
  color: #e6eff2;
  font-weight: 700;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.84);
}

button,
input,
select {
  font: inherit;
}

button {
  min-width: 56px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: color-mix(in srgb, var(--surface) 90%, var(--bg));
  color: var(--ink);
  cursor: pointer;
}

button:hover {
  border-color: var(--muted);
}

button.active,
button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

button.primary:hover {
  background: var(--accent-strong);
}

button:disabled {
  cursor: default;
  opacity: 0.45;
}

input,
select {
  height: 32px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  padding: 0 8px;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  padding: 8px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.brand-mark,
.brand-avatar {
  width: 34px;
  height: 34px;
  border-radius: 6px;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  background: var(--ink);
  color: var(--surface);
  font-weight: 800;
  letter-spacing: 0;
}

.brand-avatar {
  display: block;
  object-fit: cover;
  border: 1px solid var(--line);
  background: var(--ink);
}

.main-avatar {
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  position: relative;
  overflow: hidden;
  border-radius: 6px;
  flex: 0 0 auto;
}

.main-avatar > img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.main-user-name {
  max-width: 128px;
  overflow: hidden;
  color: var(--ink);
  font-weight: 800;
  text-overflow: ellipsis;
}

.user-tier {
  min-height: 22px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 2px 6px;
  color: var(--muted);
  font-size: 9px;
  font-weight: 900;
  white-space: nowrap;
}

.user-tier[data-role="admin"] {
  border-color: #df6e68;
  color: #ff9e99;
}

.user-settings {
  display: flex;
  align-items: center;
  justify-self: end;
  gap: 8px;
  min-width: 0;
}

.manual-download-card {
  width: 98px;
  min-height: 58px;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 1px;
  flex: 0 0 auto;
  border: 1px solid transparent;
  border-radius: 6px;
  background:
    linear-gradient(rgba(2, 5, 7, 0.94), rgba(2, 5, 7, 0.94)) padding-box,
    linear-gradient(120deg, #ef5350, #f6b73c, #57c785, #4db6e8, #8c6ee8) border-box;
  color: var(--ink);
  text-decoration: none;
  line-height: 1.05;
  box-shadow: 0 7px 24px rgba(0, 0, 0, 0.25);
  transition: transform 150ms ease, box-shadow 150ms ease, color 150ms ease;
}

.manual-download-card:hover,
.manual-download-card:focus-visible {
  color: #ffffff;
  box-shadow: 0 10px 30px rgba(38, 184, 174, 0.2);
  transform: translateY(-1px);
  outline: none;
}

.manual-cube-icon {
  position: relative;
  width: 30px;
  height: 22px;
  display: block;
  filter: drop-shadow(0 0 4px rgba(77, 182, 232, 0.32));
}

.manual-cube-icon .cube-edge {
  position: absolute;
  left: var(--edge-x);
  top: var(--edge-y);
  width: var(--edge-length);
  height: 2px;
  border-radius: 999px;
  background: var(--edge-color);
  transform: rotate(var(--edge-angle));
  transform-origin: left center;
  box-shadow: 0 0 4px color-mix(in srgb, var(--edge-color) 58%, transparent);
}

.manual-cube-icon .edge-1 { --edge-x: 15px; --edge-y: 1px; --edge-length: 12px; --edge-angle: 156deg; --edge-color: #ff5d5d; }
.manual-cube-icon .edge-2 { --edge-x: 15px; --edge-y: 1px; --edge-length: 12px; --edge-angle: 24deg; --edge-color: #ffb44a; }
.manual-cube-icon .edge-3 { --edge-x: 4px; --edge-y: 6px; --edge-length: 12px; --edge-angle: 24deg; --edge-color: #ffe05c; }
.manual-cube-icon .edge-4 { --edge-x: 26px; --edge-y: 6px; --edge-length: 12px; --edge-angle: 156deg; --edge-color: #56d47c; }
.manual-cube-icon .edge-5 { --edge-x: 4px; --edge-y: 6px; --edge-length: 10px; --edge-angle: 90deg; --edge-color: #42c8e8; }
.manual-cube-icon .edge-6 { --edge-x: 26px; --edge-y: 6px; --edge-length: 10px; --edge-angle: 90deg; --edge-color: #8b6cf6; }
.manual-cube-icon .edge-7 { --edge-x: 15px; --edge-y: 11px; --edge-length: 10px; --edge-angle: 90deg; --edge-color: #ff5d5d; }
.manual-cube-icon .edge-8 { --edge-x: 4px; --edge-y: 16px; --edge-length: 12px; --edge-angle: 24deg; --edge-color: #42c8e8; }
.manual-cube-icon .edge-9 { --edge-x: 26px; --edge-y: 16px; --edge-length: 12px; --edge-angle: 156deg; --edge-color: #8b6cf6; }

.manual-download-title {
  font-size: 9.5px;
  font-weight: 800;
  white-space: nowrap;
}

.manual-download-card small {
  color: var(--muted);
  font-size: 8px;
}

.settings-button {
  height: 34px;
  min-width: 62px;
  font-weight: 800;
}

.brand-copy {
  display: grid;
  gap: 1px;
}

.brand-title {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0;
}

.rainbow-title {
  background: linear-gradient(90deg, #e53935, #fb8c00, #fdd835, #43a047, #1e88e5, #6d4c41, #8e24aa);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.brand-subtitle {
  font-size: 11px;
  line-height: 1.1;
}

.rainbow-subtitle {
  width: max-content;
  background: linear-gradient(90deg, #e53935, #fb8c00, #43a047, #1e88e5, #8e24aa);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  font-weight: 700;
}

.tool-strip,
.action-strip,
.toolbar-controls,
.module-switch,
.dynamics-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.toolbar-controls,
.dynamics-controls {
  grid-column: 1 / -1;
  justify-content: flex-start;
  min-width: 0;
  flex-wrap: wrap;
}

.module-switch button {
  height: 34px;
  min-width: 82px;
  font-weight: 850;
}

.static-module-switch {
  margin-left: 10px;
}

.action-strip {
  grid-column: 1 / -1;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.compact-field,
.wide-field {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
}

.compact-field {
  grid-template-columns: auto minmax(76px, 112px);
  align-items: center;
}

.inline-toggle {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  white-space: nowrap;
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(560px, 1fr) 340px;
  grid-template-rows: minmax(420px, 1fr) 360px;
  gap: 10px;
  padding: 10px;
}

.canvas-panel {
  position: relative;
  overflow: hidden;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--canvas);
}

.diagram-panel {
  grid-column: 1;
  grid-row: 2;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

#canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
}

body.freeform-drawing #canvas {
  cursor: crosshair;
}

#canvas:active {
  cursor: grabbing;
}

#diagramCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

.toast {
  position: absolute;
  left: 12px;
  bottom: 12px;
  max-width: min(560px, calc(100% - 24px));
  min-height: 32px;
  display: none;
  align-items: center;
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--ink);
  color: var(--surface);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.2);
}

.toast.visible {
  display: flex;
}

.side-panel {
  grid-column: 2;
  grid-row: 1 / span 2;
  display: grid;
  align-content: start;
  gap: 10px;
  min-width: 0;
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 12px;
}

.panel h2 {
  margin: 0 0 10px;
  font-size: 14px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 0 0 12px;
}

.metric-grid div {
  min-height: 52px;
  display: grid;
  align-content: center;
  justify-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: color-mix(in srgb, var(--surface) 85%, var(--bg));
}

.metric-grid dt {
  color: var(--muted);
  font-size: 12px;
}

.metric-grid dd {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
}

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

.toggle-grid label,
.scope-row label,
.solve-grid label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
}

.solve-grid label:has(input:disabled) {
  opacity: 0.55;
  cursor: not-allowed;
}

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

.element-release-grid label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
}

.capability-note {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
}

.wide-field {
  margin-bottom: 10px;
}

.wide-field input,
.wide-field select {
  width: 100%;
}

.field-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: end;
}

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

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

.field-row .wide-field {
  margin-bottom: 10px;
}

.selection-info {
  min-height: 56px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  background: color-mix(in srgb, var(--surface) 85%, var(--bg));
  color: var(--muted);
  line-height: 1.5;
}

.result-panel pre {
  min-height: 220px;
  max-height: 38vh;
  margin: 0;
  overflow: auto;
  white-space: pre-wrap;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.55;
}

.modal {
  width: min(560px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 0;
  box-shadow: 0 20px 70px rgba(0, 0, 0, 0.25);
}

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

.modal form {
  padding: 14px;
}

.modal-header,
.modal-actions,
.scope-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.modal-header h2 {
  margin: 0;
  font-size: 16px;
}

.modal-copy {
  margin: 14px 0;
  color: var(--muted);
  line-height: 1.55;
}

.icon-button {
  min-width: 32px;
  width: 32px;
  font-size: 20px;
  line-height: 1;
}

.segmented,
.button-grid,
.solve-grid {
  display: grid;
  gap: 8px;
}

.segmented {
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  margin: 14px 0;
}

.segmented label,
.button-grid button {
  min-height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.button-grid {
  grid-template-columns: repeat(4, 1fr);
  margin-bottom: 12px;
}

.modal-section.hidden {
  display: none;
}

.solve-modal {
  width: min(680px, calc(100vw - 32px));
}

.element-modal {
  width: min(720px, calc(100vw - 32px));
}

.settings-modal {
  width: min(520px, calc(100vw - 32px));
}

.announcement-modal {
  width: min(760px, calc(100vw - 32px));
  max-height: min(84dvh, 760px);
}

.announcement-modal form {
  max-height: min(84dvh, 760px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
}

.announcement-modal .modal-header {
  align-items: flex-start;
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
}

.announcement-modal .modal-header h2 {
  margin-top: 2px;
  font-size: 18px;
}

.announcement-kicker {
  margin: 0;
  color: var(--accent-strong);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.announcement-body {
  min-height: 0;
  display: grid;
  gap: 12px;
  overflow-y: auto;
  padding: 14px 3px 14px 0;
  line-height: 1.6;
}

.announcement-body section {
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.announcement-body h3 {
  margin: 0 0 5px;
  color: var(--ink);
  font-size: 14px;
}

.announcement-body p,
.announcement-body ul {
  margin: 4px 0 0;
}

.announcement-body ul {
  padding-left: 22px;
}

.announcement-limitations {
  border-left: 3px solid var(--danger);
  border-radius: 4px;
  background: color-mix(in srgb, var(--danger) 8%, var(--surface));
  padding: 10px 12px;
}

.announcement-limitations strong {
  color: var(--danger);
}

.announcement-actions {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.announcement-manual-link {
  color: var(--accent-strong);
  font-weight: 800;
}

.settings-section {
  display: grid;
  gap: 8px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.settings-section h3 {
  margin: 0;
  color: var(--ink);
  font-size: 13px;
}

.settings-avatar-preview {
  width: 52px;
  height: 52px;
}

.settings-message {
  min-height: 20px;
  margin: 0;
  color: var(--muted);
  font-weight: 700;
}

.danger-button {
  border-color: color-mix(in srgb, var(--danger) 70%, var(--line));
  color: var(--danger);
}

.danger-button:hover {
  background: color-mix(in srgb, var(--danger) 12%, var(--surface));
}

.solve-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: 14px 0;
}

.dynamics-shell {
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  grid-template-rows: auto minmax(0, 1fr);
  --bg: #edf8fd;
  --surface: #ffffff;
  --canvas: #f8fcff;
  --grid: #dceef7;
  --grid-major: #9fc9df;
  --line: #c7dfeb;
  --ink: #102b3a;
  --muted: #567487;
  --accent: #1688c5;
  --accent-strong: #0b6f9f;
  --blue: #1688c5;
  --select: #0ea5e9;
  background: var(--bg);
}

body.dark-theme .dynamics-shell {
  --bg: #020405;
  --surface: #080d10;
  --canvas: #000000;
  --grid: #0c1a22;
  --grid-major: #263f4c;
  --line: #1f3540;
  --ink: #eff9fd;
  --muted: #a2becd;
  --accent: #35a9e6;
  --accent-strong: #5abcf0;
  --blue: #5abcf0;
  --select: #38bdf8;
}

.dynamics-shell .topbar {
  background: var(--surface);
  border-bottom-color: var(--line);
}

.dynamics-topbar {
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-areas:
    "brand actions user"
    "modules controls controls";
  align-content: start;
}

.dynamics-topbar > .brand {
  grid-area: brand;
}

.dynamics-topbar > .module-switch {
  grid-area: modules;
}

.dynamics-topbar > .user-settings {
  grid-area: user;
}

.dynamics-topbar > .dynamics-controls {
  grid-area: controls;
  grid-column: auto;
}

.dynamics-topbar > .dynamics-action-strip {
  grid-area: actions;
  grid-column: auto;
  justify-content: flex-end;
  flex-wrap: nowrap;
}

.dynamics-shell button.active,
.dynamics-shell button.primary,
.dynamics-field-modal button.primary {
  border-color: #1688c5;
  background: #1688c5;
  color: #ffffff;
}

.dynamics-shell button.primary:hover,
.dynamics-field-modal button.primary:hover {
  background: #0b6f9f;
}

.dynamics-command {
  border-color: color-mix(in srgb, #1688c5 55%, var(--line));
  color: #0b6f9f;
  font-weight: 800;
}

body.dark-theme .dynamics-command {
  color: #8bd5f8;
}

.dynamics-command.active {
  background: #1688c5;
  color: #ffffff;
}

.dynamics-field-status {
  min-width: 76px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.dynamics-placement-cancel {
  color: var(--danger);
}

.dynamics-scene-panel h3 {
  margin: 12px 0 6px;
  color: var(--muted);
  font-size: 12px;
}

.dynamics-scene-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.dynamics-scene-metrics span {
  display: grid;
  place-items: center;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  font-size: 11px;
}

.dynamics-scene-metrics strong {
  color: var(--ink);
  font-size: 16px;
}

.dynamics-scene-list {
  display: grid;
  gap: 4px;
}

.dynamics-scene-row {
  min-height: 34px;
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr) auto;
  align-items: center;
  gap: 7px;
  padding: 4px 5px 4px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: color-mix(in srgb, var(--surface) 90%, var(--bg));
}

.dynamics-scene-row.selected {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
}

.dynamics-scene-row-main {
  min-width: 0;
  overflow: hidden;
  color: var(--ink);
  font-size: 12px;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}

.dynamics-scene-swatch {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
}

.dynamics-scene-row button {
  width: 26px;
  min-width: 26px;
  height: 26px;
  padding: 0;
  color: var(--danger);
  font-size: 17px;
  line-height: 1;
}

.dynamics-scene-empty {
  min-height: 28px;
  display: grid;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
}

.dynamics-workspace {
  min-height: 0;
  height: 100%;
  overflow: hidden;
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(300px, 24vw, 360px);
  gap: 10px;
  padding: 10px;
}

.dynamics-canvas-panel {
  height: 100%;
  min-height: 0;
}

#dynamicsCanvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
  touch-action: none;
}

#dynamicsCanvas:active {
  cursor: grabbing;
}

#dynamicsCanvas.placing,
#dynamicsCanvas.drawing-range,
#dynamicsCanvas.drawing-object {
  cursor: crosshair;
}

.dynamics-side-panel {
  grid-column: 2;
  grid-row: 1;
  min-height: 0;
  max-height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
}

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

.dynamics-result-line {
  color: var(--muted);
}

.dynamics-field-modal {
  --accent: #1688c5;
  --accent-strong: #0b6f9f;
  width: min(640px, calc(100vw - 32px));
}

.dynamics-field-message {
  min-height: 22px;
  margin: 2px 0 12px;
}

.dynamics-field-modal .wide-field:last-of-type {
  margin-bottom: 10px;
}

@media (max-width: 1180px) {
  .topbar:not(.dynamics-topbar) {
    grid-template-columns: 1fr;
  }

  .toolbar-controls,
  .tool-strip,
  .action-strip,
  .module-switch,
  .dynamics-controls,
  .user-settings {
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(420px, 62vh) 360px auto;
  }

  .workspace > .canvas-panel {
    height: 62vh;
  }

  .diagram-panel,
  .workspace > .side-panel {
    grid-column: 1;
    grid-row: auto;
  }
}

@media (max-width: 899px) {
  body.dynamics-active {
    overflow: auto;
  }

  .dynamics-shell {
    height: auto;
    min-height: 100dvh;
    overflow: visible;
  }

  .dynamics-topbar {
    grid-template-columns: 1fr;
    grid-template-areas:
      "brand"
      "modules"
      "controls"
      "actions"
      "user";
  }

  .dynamics-topbar > .user-settings {
    justify-self: start;
  }

  .dynamics-topbar > .dynamics-action-strip {
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .dynamics-workspace {
    height: auto;
    overflow: visible;
    grid-template-columns: 1fr;
  }

  .dynamics-canvas-panel {
    height: 62dvh;
    min-height: 420px;
  }

  .dynamics-side-panel {
    grid-column: 1;
    grid-row: auto;
    max-height: none;
    overflow: visible;
  }
}

@media (max-width: 760px) {
  .auth-panel {
    grid-template-columns: 1fr;
  }

  .welcome-content {
    min-height: calc(100vh - 36px);
    padding: 112px 22px 22px;
  }

  .announcement-trigger {
    top: 12px;
    left: 12px;
    width: 78px;
    height: 91px;
  }

  .li-atom {
    width: 56px;
    height: 56px;
  }

  .announcement-modal {
    max-height: calc(100dvh - 24px);
  }

  .announcement-modal form {
    max-height: calc(100dvh - 24px);
  }

  .announcement-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .module-choice-panel,
  .field-row.two,
  .field-row.three,
  .dynamics-option-grid {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  .rainbow-animated,
  .atom-orbit,
  .module-choice-panel {
    animation: none !important;
  }

  .module-choice-button,
  .announcement-trigger,
  .manual-download-card {
    transition: none !important;
  }
}
