:root {
  color-scheme: light;
  --bg: #dcedfb;
  --panel: #f7fbff;
  --panel-2: #eaf6ff;
  --line: #b8d5e8;
  --text: #143040;
  --muted: #527083;
  --accent: #1686b8;
  --accent-2: #4c5961;
  --danger: #31383d;
  --blue: #2e78b7;
  --shadow: 0 18px 44px rgba(45, 96, 128, 0.2);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: #f6fbff;
  cursor: pointer;
  transition:
    background 140ms ease,
    border-color 140ms ease,
    transform 140ms ease;
}

button:hover {
  background: #e8f5ff;
  border-color: #7fb4d4;
}

button:active {
  transform: translateY(1px);
}

button svg {
  width: 17px;
  height: 17px;
  stroke-width: 2.2;
}

#app {
  display: grid;
  grid-template-rows: minmax(68px, auto) minmax(0, 1fr);
  width: 100%;
  height: 100%;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 68px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(247, 251, 255, 0.96);
  box-shadow: var(--shadow);
  z-index: 5;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 260px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background:
    radial-gradient(circle at 72% 28%, #ffffff 0 13%, transparent 14%),
    linear-gradient(135deg, #60c8f7, #1686b8 58%, #1c252b);
  box-shadow: 0 0 0 1px rgba(20, 48, 64, 0.12) inset;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 17px;
  font-weight: 760;
  letter-spacing: 0;
}

.brand p {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.transport {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.control-button,
.danger-button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  padding: 0 12px;
}

.danger-button {
  color: #11181c;
  background: rgba(49, 56, 61, 0.12);
  border-color: rgba(49, 56, 61, 0.38);
}

.danger-button:hover {
  background: rgba(49, 56, 61, 0.2);
}

.workspace {
  position: relative;
  display: grid;
  grid-template-columns: 136px minmax(0, 1fr) 286px;
  min-height: 0;
}

.toolbar {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-rows: minmax(54px, auto);
  align-content: start;
  gap: 6px;
  padding: 10px;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  background: #d7ecfb;
  z-index: 2;
}

.tool-button {
  display: grid;
  place-items: center;
  gap: 4px;
  min-width: 0;
  min-height: 54px;
  padding: 7px 4px;
  color: #496a7e;
  background: rgba(247, 251, 255, 0.72);
}

.tool-button span {
  font-size: 11px;
  line-height: 1.08;
  text-align: center;
}

.tool-button.active {
  color: #ffffff;
  background: #1686b8;
  border-color: #0b6f9f;
}

.viewport {
  position: relative;
  min-width: 0;
  min-height: 0;
  background: #d9f0ff;
}

.viewport canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.tool-status {
  position: absolute;
  left: 14px;
  top: 14px;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: min(360px, calc(100% - 28px - var(--panel-toggle-reserved-width, 0px)));
  min-height: 30px;
  padding: 6px 9px;
  border: 1px solid rgba(20, 48, 64, 0.13);
  border-radius: 8px;
  color: #143040;
  background: rgba(247, 251, 255, 0.88);
  box-shadow: 0 10px 24px rgba(45, 96, 128, 0.12);
  font-size: 12px;
  line-height: 1.25;
  pointer-events: none;
}

.tool-status strong {
  flex: 0 0 auto;
  font-size: 12px;
}

.tool-status span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #4d6472;
}

.tool-hint {
  position: absolute;
  left: 14px;
  bottom: 14px;
  z-index: 3;
  max-width: min(260px, calc(100% - 28px));
  padding: 7px 10px;
  border: 1px solid rgba(20, 48, 64, 0.12);
  border-radius: 8px;
  color: #143040;
  background: rgba(247, 251, 255, 0.9);
  box-shadow: 0 10px 24px rgba(45, 96, 128, 0.14);
  font-size: 12px;
  line-height: 1.3;
  opacity: 0;
  pointer-events: none;
  transform: translateY(4px);
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

.tool-hint.visible {
  opacity: 1;
  transform: translateY(0);
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
  overflow-x: hidden;
  overflow-y: auto;
  border-left: 1px solid var(--line);
  background: #d7ecfb;
  z-index: 2;
}

.panel-toggle {
  display: none;
  align-items: center;
  gap: 7px;
  position: absolute;
  top: 12px;
  right: 12px;
  min-height: 38px;
  padding: 0 12px;
  z-index: 5;
  box-shadow: 0 10px 28px rgba(45, 96, 128, 0.18);
}

.part-settings-panel {
  position: absolute;
  left: 112px;
  top: 90px;
  z-index: 6;
  display: grid;
  gap: 8px;
  width: 236px;
  padding: 10px;
  border: 1px solid rgba(20, 48, 64, 0.18);
  border-radius: 8px;
  background: rgba(247, 251, 255, 0.96);
  box-shadow: 0 16px 38px rgba(45, 96, 128, 0.22);
  backdrop-filter: blur(6px);
}

.part-settings-panel[hidden] {
  display: none;
}

.part-settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.part-settings-header h2 {
  color: #1d4356;
  font-size: 13px;
  letter-spacing: 0;
}

.part-settings-close {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  padding: 0;
  color: var(--muted);
  line-height: 1;
}

.part-field-row {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  align-items: center;
  gap: 9px;
  min-height: 34px;
  color: var(--muted);
  font-size: 12px;
}

.part-field-row select {
  width: 100%;
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  background: #f6fbff;
  font: inherit;
}

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

.panel-section h2 {
  margin-bottom: 10px;
  font-size: 13px;
  color: #1d4356;
  letter-spacing: 0;
}

.panel [data-tooltip],
.part-settings-panel [data-tooltip] {
  position: relative;
}

.panel [data-tooltip]::after,
.part-settings-panel [data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 30;
  width: max-content;
  max-width: min(220px, calc(100vw - 148px));
  padding: 7px 9px;
  border: 1px solid rgba(20, 48, 64, 0.16);
  border-radius: 6px;
  color: #f7fbff;
  background: rgba(20, 48, 64, 0.96);
  box-shadow: 0 12px 26px rgba(20, 48, 64, 0.18);
  font-size: 11px;
  font-weight: 560;
  line-height: 1.32;
  text-align: left;
  white-space: normal;
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
  transform: translateY(-2px);
  transition:
    opacity 120ms ease,
    transform 120ms ease,
    visibility 120ms ease;
  transition-delay: 0s;
}

.panel [data-tooltip]:hover::after,
.panel [data-tooltip]:focus-visible::after,
.panel [data-tooltip]:focus-within::after {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  transition-delay: 3s;
}

.part-settings-panel [data-tooltip].tooltip-ready:hover::after,
.part-settings-panel [data-tooltip].tooltip-ready:focus-visible::after,
.part-settings-panel [data-tooltip].tooltip-ready:focus-within::after {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  transition-delay: 0s;
}

.preset-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.preset-grid button {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 7px;
  min-height: 36px;
  padding: 0 9px;
}

.preset-grid button:nth-child(2n)::after {
  right: 0;
  left: auto;
}

.preset-grid span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}

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

.creator-actions button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 34px;
  padding: 0 8px;
  min-width: 0;
}

.creator-actions button span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}

.scene-name-row,
.scene-list-row {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  align-items: center;
  gap: 9px;
  min-height: 34px;
  color: var(--muted);
  font-size: 12px;
}

.scene-name-row input,
.scene-list-row select {
  width: 100%;
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  background: #f6fbff;
  font: inherit;
}

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

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

.physics-actions {
  grid-template-columns: minmax(0, 1fr);
  margin-bottom: 8px;
}

.scene-actions button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 34px;
  padding: 0 8px;
  min-width: 0;
}

.scene-actions button span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}

.scene-status {
  min-height: 18px;
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.scene-status.success {
  color: #187a46;
}

.scene-status.error {
  color: #b42318;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 34px;
  color: var(--muted);
  font-size: 13px;
}

.toggle-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.range-row {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) 42px;
  align-items: center;
  gap: 9px;
  min-height: 34px;
  color: var(--muted);
  font-size: 12px;
}

.range-row input {
  width: 100%;
  accent-color: var(--accent);
}

.range-row output {
  color: var(--text);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.stats-list,
.caliper-readout {
  display: grid;
  gap: 6px;
  margin: 0;
}

.stats-list div,
.caliper-readout div {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 5px;
  border-bottom: 1px solid rgba(20, 48, 64, 0.08);
  min-width: 0;
}

.stats-list div:last-child,
.caliper-readout div:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.stats-list dt,
.caliper-readout dt {
  color: var(--muted);
  font-size: 12px;
}

.stats-list dd,
.caliper-readout dd {
  margin: 0;
  color: var(--text);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.caliper-readout dd {
  min-width: 0;
  max-width: 132px;
  overflow: hidden;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.guide-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(20, 48, 64, 0.3);
  z-index: 22;
}

.guide-overlay[hidden] {
  display: none;
}

.guide-dialog {
  width: min(468px, 100%);
  max-height: min(620px, calc(100vh - 36px));
  padding: 18px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 24px 62px rgba(20, 48, 64, 0.28);
}

.guide-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.guide-mark {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  color: #ffffff;
  background: #1686b8;
}

.guide-header h2 {
  color: var(--text);
  font-size: 18px;
  letter-spacing: 0;
}

.guide-header p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.guide-steps {
  display: grid;
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.guide-step {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  gap: 10px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(20, 48, 64, 0.09);
}

.guide-step:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.guide-step-number {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 1px solid rgba(22, 134, 184, 0.28);
  border-radius: 8px;
  color: #0b6f9f;
  background: #eaf6ff;
  font-size: 13px;
  font-weight: 760;
  font-variant-numeric: tabular-nums;
}

.guide-step h3 {
  margin: 0 0 3px;
  color: var(--text);
  font-size: 13px;
  letter-spacing: 0;
}

.guide-step p {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.42;
}

.guide-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 16px;
}

.confirm-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(20, 48, 64, 0.28);
  z-index: 20;
}

.confirm-overlay[hidden] {
  display: none;
}

.confirm-dialog {
  width: min(360px, 100%);
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 22px 58px rgba(20, 48, 64, 0.26);
}

.confirm-dialog h2 {
  margin: 0 0 8px;
  color: var(--text);
  font-size: 18px;
  letter-spacing: 0;
}

.confirm-dialog p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

@media (max-width: 1180px) {
  .topbar {
    gap: 12px;
  }

  .brand {
    min-width: 210px;
  }

  .brand p {
    display: none;
  }

  .transport {
    gap: 6px;
  }

  .control-button,
  .danger-button {
    min-height: 34px;
    padding: 0 9px;
  }
}

@media (max-width: 980px) {
  #app {
    grid-template-rows: auto minmax(0, 1fr);
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  .workspace {
    grid-template-columns: 124px minmax(0, 1fr);
    --panel-toggle-reserved-width: 132px;
  }

  .panel {
    position: absolute;
    right: 10px;
    top: 58px;
    width: min(286px, calc(100vw - 146px));
    max-height: calc(100% - 70px);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    opacity: 0;
    pointer-events: none;
    transform: translateX(calc(100% + 18px));
    transition:
      opacity 160ms ease,
      transform 160ms ease;
    z-index: 4;
  }

  .workspace.panel-open .panel {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(0);
  }

  .panel-toggle {
    display: inline-flex;
  }

  .tool-button {
    min-height: 50px;
  }
}

@media (max-width: 620px) {
  .brand p {
    display: none;
  }

  .control-button span,
  .danger-button span {
    display: none;
  }

  .transport {
    width: 100%;
  }

  .control-button,
  .danger-button {
    flex: 1;
    justify-content: center;
    min-width: 0;
  }

  .guide-dialog {
    padding: 14px;
  }

  .guide-step {
    grid-template-columns: 26px minmax(0, 1fr);
    gap: 9px;
  }

  .guide-step-number {
    width: 24px;
    height: 24px;
  }
}
