:root {
  --toolbar-bg: rgba(10, 14, 20, 0.86);
  --toolbar-border: rgba(255, 255, 255, 0.18);
  --text: #eaf2f6;
  --accent: #ff7a59;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #000;
  color: var(--text);
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
}

#appRoot {
  position: fixed;
  inset: 0;
}

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

.toolbar {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  padding: 8px 10px;
  max-width: calc(100vw - 18px);
  border: 1px solid var(--toolbar-border);
  border-radius: 14px;
  background: var(--toolbar-bg);
  backdrop-filter: blur(8px);
  user-select: none;
  touch-action: manipulation;
}

.toolbar-row {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 8px;
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
}

.toolbar-row::-webkit-scrollbar {
  display: none;
}

.toolbar-tools {
  justify-content: space-between;
}

.toolbar-tools > * {
  flex: 0 0 auto;
}

.toolbar-sliders {
  justify-content: space-between;
}

.toolbar label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  white-space: nowrap;
}

.toolbar select,
.toolbar input[type="color"],
.toolbar button,
.toolbar input[type="range"] {
  border-radius: 9px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  padding: 6px 8px;
}

.toolbar input[type="color"] {
  width: 46px;
  height: 34px;
  padding: 3px;
}

.toolbar button {
  cursor: pointer;
  touch-action: manipulation;
}

.toolbar button.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(255, 122, 89, 0.4) inset;
}

.icon-tool {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  min-width: 34px;
  height: 34px;
  padding: 0;
}

.tool-icon {
  position: relative;
  display: inline-block;
  color: #d7e2e8;
}

.tool-icon[hidden] {
  display: none !important;
}

.icon-bomb {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: currentColor;
}

.icon-bomb::before {
  content: "";
  position: absolute;
  right: -7px;
  top: -8px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  border: 1px solid currentColor;
}

.icon-bomb::after {
  content: "";
  position: absolute;
  right: -5px;
  top: -4px;
  width: 8px;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
  transform: rotate(-35deg);
}

.icon-delete {
  width: 12px;
  height: 11px;
  border: 2px solid currentColor;
  border-top: 0;
  border-radius: 0 0 2px 2px;
}

.icon-delete::before {
  content: "";
  position: absolute;
  left: -4px;
  top: -4px;
  width: 16px;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
}

.icon-delete::after {
  content: "";
  position: absolute;
  left: 2px;
  top: -7px;
  width: 6px;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
}

.icon-pause {
  width: 14px;
  height: 14px;
}

.icon-pause::before,
.icon-pause::after {
  content: "";
  position: absolute;
  top: 0;
  width: 3px;
  height: 14px;
  border-radius: 1px;
  background: currentColor;
}

.icon-pause::before {
  left: 2px;
}

.icon-pause::after {
  right: 2px;
}

.icon-play {
  width: 0;
  height: 0;
  margin-left: 2px;
  border-top: 7px solid transparent;
  border-bottom: 7px solid transparent;
  border-left: 12px solid currentColor;
}

.icon-lock {
  width: 12px;
  height: 10px;
  border: 2px solid currentColor;
  border-radius: 2px;
}

.icon-lock::before {
  content: "";
  position: absolute;
  left: 1px;
  top: -8px;
  width: 8px;
  height: 7px;
  border: 2px solid currentColor;
  border-bottom: 0;
  border-radius: 6px 6px 0 0;
}

.icon-lock::after {
  content: "";
  position: absolute;
  left: 4px;
  top: 2px;
  width: 2px;
  height: 4px;
  border-radius: 2px;
  background: currentColor;
}

.icon-help {
  width: 100%;
  text-align: center;
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
}

#unbreakableBtn.active {
  border-color: #6ee0ab;
  box-shadow: 0 0 0 1px rgba(110, 224, 171, 0.42) inset;
}

#clearBtn:not(.active),
#unbreakableBtn:not(.active) {
  border-color: rgba(255, 255, 255, 0.18);
  box-shadow: none;
}

/* keep color picker compact in tools row */
.color-control input[type="color"] {
  width: 34px;
  min-width: 34px;
}

.toolbar-tools .shape-strip {
  margin-right: 2px;
}

.toolbar-tools .icon-tool + .icon-tool {
  margin-left: 2px;
}

.toolbar-tools .color-control {
  margin-left: 2px;
}

.toolbar-tools #pauseBtn {
  margin-left: 2px;
}

.color-control {
  min-width: 0;
}

.shape-strip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.04);
}

.shape-btn {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  height: 34px;
  width: 34px;
  padding: 0;
  min-width: 34px;
  justify-content: center;
}

.shape-icon {
  display: inline-block;
  color: #d7e2e8;
  flex: 0 0 auto;
}

.icon-rectangle {
  width: 16px;
  height: 12px;
  border: 2px solid currentColor;
  border-radius: 2px;
}

.icon-circle {
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-radius: 50%;
}

.icon-triangle {
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-bottom: 14px solid currentColor;
}

.icon-pentagon {
  width: 14px;
  height: 14px;
  background: currentColor;
  clip-path: polygon(50% 0, 100% 38%, 82% 100%, 18% 100%, 0 38%);
}

.icon-hexagon {
  width: 16px;
  height: 14px;
  background: currentColor;
  clip-path: polygon(25% 0, 75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%);
}

.icon-bar {
  width: 18px;
  height: 4px;
  border-radius: 2px;
  background: currentColor;
}

.range-control {
  min-width: 228px;
  display: grid;
  grid-template-columns: auto minmax(92px, 1fr) auto;
  align-items: center;
  column-gap: 8px;
  padding-right: 4px;
}

.range-control input[type="range"] {
  width: 100%;
  margin: 0;
}

.range-value {
  width: 45px;
  text-align: right;
  display: inline-block;
  font-variant-numeric: tabular-nums;
}

.help-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.58);
  padding: 16px;
}

.help-modal[hidden] {
  display: none !important;
}

.help-panel {
  width: min(760px, 100%);
  max-height: min(86vh, 780px);
  overflow-y: auto;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(8, 12, 18, 0.95);
  box-shadow: 0 16px 34px rgba(0, 0, 0, 0.4);
  color: var(--text);
}

.help-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
}

.help-header h2 {
  margin: 0;
  font-size: 18px;
}

.help-close {
  width: 28px;
  min-width: 28px;
  height: 28px;
  padding: 0;
  font-size: 16px;
}

.help-content {
  padding: 12px 14px 14px;
}

.help-content h3 {
  margin: 10px 0 6px;
  font-size: 15px;
}

.help-content ul {
  margin: 0;
  padding-left: 18px;
}

.help-content li {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 0 0 6px;
  line-height: 1.3;
}

.help-icon-cell {
  width: 22px;
  min-width: 22px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 1px;
}

.help-icon-pack {
  min-width: 22px;
  min-height: 18px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 1px;
}

.help-icon-pack .shape-icon {
  transform: scale(0.7);
  transform-origin: center;
}

.help-icon-pack .tool-icon {
  transform: scale(0.8);
  transform-origin: center;
}

.icon-color-chip {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: linear-gradient(135deg, #6ee0ab 0%, #3bc7ff 100%);
}

.icon-slider-glyph {
  position: relative;
  width: 16px;
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.35);
}

.icon-slider-glyph::after {
  content: "";
  position: absolute;
  top: -2px;
  left: 7px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #06d27f;
}

@media (max-width: 720px) {
  .toolbar {
    top: max(8px, env(safe-area-inset-top));
    width: calc(100% - 12px);
    max-width: calc(100vw - 12px);
    left: 6px;
    transform: none;
    border-radius: 12px;
    padding: 10px 8px;
  }

  .toolbar-tools,
  .toolbar-sliders {
    justify-content: flex-start;
    overflow-x: visible;
    white-space: normal;
  }

  .icon-tool,
  .shape-btn {
    height: 38px;
    width: 38px;
    min-width: 38px;
  }

  .color-control input[type="color"] {
    width: 38px;
    min-width: 38px;
    height: 38px;
  }

  .toolbar-tools {
    flex-wrap: wrap;
    gap: 6px;
  }

  .toolbar-tools .shape-strip {
    order: 0;
    width: 100%;
    justify-content: space-between;
    margin-right: 0;
  }

  .toolbar-tools > :not(.shape-strip) {
    order: 1;
  }

  .toolbar-tools .shape-btn {
    flex: 1 1 auto;
  }

  .toolbar-tools .icon-tool + .icon-tool,
  .toolbar-tools .color-control,
  .toolbar-tools #pauseBtn {
    margin-left: 0;
  }

  .toolbar-sliders {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }

  .range-control {
    min-width: 0;
    width: 100%;
    padding-right: 0;
  }

  .range-control input[type="range"] {
    width: 100%;
  }
}
