* {
  box-sizing: border-box;
}

:root {
  color-scheme: light;
  --bg: #f7f4ef;
  --ink: #1a1a1a;
  --ink-soft: #3f3f3f;
  --accent: #0f766e;
  --accent-soft: #14b8a6;
  --panel: rgba(255, 255, 255, 0.78);
  --panel-border: rgba(15, 23, 42, 0.08);
}

html,
body {
  margin: 0;
  padding: 0;
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
  color: var(--ink);
  height: 100%;
  background: var(--bg);
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow: hidden;
}

body.pseudo-fullscreen {
  overflow: hidden;
}

body.pseudo-fullscreen .topbar,
body.pseudo-fullscreen .footer {
  display: none;
}

body.pseudo-fullscreen .stage {
  position: fixed;
  inset: 0;
  margin: 0;
  border-radius: 0;
  height: 100vh;
  width: 100vw;
}

body.pseudo-fullscreen .toolbox {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: 12px;
  z-index: 5;
}

.background {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
}

.glow {
  position: absolute;
  width: 40vw;
  height: 40vw;
  border-radius: 50%;
  filter: blur(60px);
  opacity: 0.55;
}

.glow-a {
  background: #fde68a;
  top: -10vh;
  left: -10vw;
}

.glow-b {
  background: #99f6e4;
  bottom: -15vh;
  right: -10vw;
}

.grid {
  position: absolute;
  inset: 0;
  background-image: linear-gradient(
      rgba(15, 23, 42, 0.04) 1px,
      transparent 1px
    ),
    linear-gradient(90deg, rgba(15, 23, 42, 0.04) 1px, transparent 1px);
  background-size: 64px 64px;
  mask-image: radial-gradient(circle at 50% 30%, black, transparent 70%);
}

.topbar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 28px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  font-weight: 700;
  font-size: 20px;
  letter-spacing: 0.2em;
  padding: 10px 14px;
  border-radius: 16px;
  background: white;
  border: 1px solid var(--panel-border);
  box-shadow: 0 16px 30px rgba(15, 23, 42, 0.1);
}

.brand-title {
  font-weight: 600;
  font-size: 18px;
}

.brand-subtitle {
  font-size: 13px;
  color: var(--ink-soft);
}


.stage {
  position: relative;
  z-index: 1;
  flex: 1;
  margin: 0 20px 16px;
  border-radius: 24px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.5);
  border: 1px solid var(--panel-border);
  box-shadow: 0 30px 60px rgba(15, 23, 42, 0.18);
}

.stage.dragging {
  border-color: rgba(15, 118, 110, 0.45);
  box-shadow: 0 34px 70px rgba(15, 118, 110, 0.22);
}

#viewer {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

#viewer:focus {
  outline: none;
}

.distance-label {
  position: absolute;
  top: 0;
  left: 0;
  transform: translate(-50%, -50%);
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.9);
  color: white;
  font-size: 12px;
  font-weight: 600;
  pointer-events: none;
  display: none;
  z-index: 3;
}

.bond-rotate-angle {
  position: absolute;
  top: 0;
  left: 0;
  transform: translate(-50%, -50%);
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.9);
  color: white;
  font-size: 12px;
  font-weight: 600;
  pointer-events: none;
  display: none;
  z-index: 3;
}

.selection-box {
  position: absolute;
  border: 1px dashed rgba(15, 118, 110, 0.8);
  background: rgba(45, 212, 191, 0.12);
  border-radius: 8px;
  pointer-events: none;
  display: none;
  z-index: 3;
}

.hud {
  position: absolute;
  top: 24px;
  left: 24px;
  max-width: 320px;
  padding: 18px 20px;
  border-radius: 18px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  box-shadow: 0 18px 30px rgba(15, 23, 42, 0.12);
  backdrop-filter: blur(12px);
}

.hud.dragging {
  border-color: rgba(15, 118, 110, 0.4);
  box-shadow: 0 22px 36px rgba(15, 118, 110, 0.2);
}

.hud-title {
  font-weight: 600;
  margin-bottom: 8px;
}

.hud-text {
  font-size: 14px;
  color: var(--ink-soft);
  line-height: 1.4;
}

.hud-tip {
  margin-top: 12px;
  font-size: 12px;
  color: #0f172a;
  background: rgba(255, 255, 255, 0.7);
  padding: 8px 10px;
  border-radius: 10px;
}

.toolbox {
  position: absolute;
  right: 24px;
  bottom: 24px;
  padding: 16px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid var(--panel-border);
  box-shadow: 0 18px 30px rgba(15, 23, 42, 0.12);
  backdrop-filter: blur(12px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 200px;
  max-width: 240px;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.toolbox-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.toolbox-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.file-input-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.toolbox-title {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.tool-button {
  border: 1px solid rgba(15, 23, 42, 0.12);
  background: white;
  color: #0f172a;
  padding: 8px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 12px 20px rgba(15, 23, 42, 0.08);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.tool-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 16px 24px rgba(15, 23, 42, 0.12);
}

.tool-button.active {
  border-color: rgba(15, 118, 110, 0.5);
  box-shadow: 0 14px 24px rgba(15, 118, 110, 0.2);
}

.toolbox-toggle {
  border: 1px solid rgba(15, 23, 42, 0.12);
  background: white;
  color: #0f172a;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}

.toolbox-action {
  border: 1px solid rgba(15, 23, 42, 0.12);
  background: white;
  color: #0f172a;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}


.tool-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
  color: #0f172a;
}

.tool-toggle input {
  accent-color: var(--accent);
}

.toolbox-hint {
  font-size: 11px;
  color: var(--ink-soft);
  line-height: 1.4;
}

.toolbox-actions-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.toolbox-actions-row .tool-button {
  flex: 1;
}


.group-adder {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.group-adder + .tool-button {
  margin-top: 6px;
}

.group-adder-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-soft);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.group-adder-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.group-select {
  flex: 1;
  border-radius: 10px;
  border: 1px solid rgba(15, 23, 42, 0.12);
  padding: 6px 8px;
  font-size: 12px;
  font-weight: 600;
  color: #0f172a;
  background: white;
}

.group-drawer {
  display: none;
}

.group-drawer-toggle {
  width: 100%;
  border: 1px solid rgba(15, 23, 42, 0.12);
  background: white;
  color: #0f172a;
  padding: 12px 14px;
  border-radius: 16px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 12px 20px rgba(15, 23, 42, 0.08);
}

.group-drawer-panel {
  margin-top: 10px;
  padding: 12px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid var(--panel-border);
  box-shadow: 0 18px 30px rgba(15, 23, 42, 0.12);
  display: none;
}

.group-drawer.active .group-drawer-panel {
  display: grid;
  gap: 10px;
}

.group-drawer-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}


.toolbox.collapsed {
  opacity: 0.7;
  padding: 10px 12px;
  min-width: 0;
  max-width: 140px;
}

.toolbox.collapsed .tool-toggle,
.toolbox.collapsed .toolbox-hint {
  display: none;
}

.toolbox.collapsed .toolbox-action {
  display: none;
}



.footer {
  position: relative;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 28px 18px;
  font-size: 12px;
  color: var(--ink-soft);
}

.status {
  font-weight: 600;
}

.legend {
  text-align: right;
  max-width: 50%;
}

@media (max-width: 900px) {
  .topbar {
    flex-direction: column;
    gap: 16px;
    padding: 14px 16px;
  }

  .brand-subtitle {
    display: none;
  }

  .stage {
    margin: 0 8px 88px;
    height: 70vh;
    min-height: 280px;
  }

  .hud {
    position: static;
    margin: 12px;
    max-width: none;
    max-height: 50vh;
    overflow-y: auto;
  }

  .toolbox {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: 12px;
    margin: 0;
    width: auto;
    z-index: 4;
  }

  .group-adder {
    display: none;
  }



  .group-drawer {
    position: fixed;
    left: auto;
    right: 12px;
    bottom: 24px;
    display: block;
    z-index: 4;
    width: min(110px, calc(100vw - 24px));
  }


  .footer {
    flex-direction: column;
    gap: 8px;
    text-align: center;
    padding: 8px 16px 12px;
  }

  .legend {
    display: none;
  }
}
