:root {
  --colorPrimary: #242424;
  --colorSecondary: rgba(0, 0, 0, 0.1);
  --colorHover: rgba(255, 255, 255, 0.01);
}

::selection {
  background: rgba(255, 255, 255, 0.3);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  scrollbar-width: thin;
}

html,
body {
  overflow: hidden;
  touch-action: none;
  overscroll-behavior: contain;
  -webkit-user-select: none;
  user-select: none;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  background: var(--colorPrimary);
  color: #fff;
  padding: 10px;
  gap: 5px;
}

.workspace {
  flex: 1;
  display: flex;
  overflow: hidden;
  border-radius: 5px;
}

.resizer {
  width: 5px;
  min-width: 5px;
  cursor: ew-resize;
  z-index: 10;
}

.editor-wrapper,
.canvas-wrapper {
  flex: 1;
  background: var(--colorSecondary);
  position: relative;
  border: 1px solid rgba(0, 0, 0, 0.1);
  transition: background 0.2s;
}

.editor-wrapper:hover,
.canvas-wrapper:hover {
  background: var(--colorHover);
}

.editor-wrapper {
  width: 100%;
  height: 100%;
  overflow: auto;
  padding: 20px;
  font-family: monospace;
}

.editor {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: transparent;
  color: transparent;
  padding: 10px;
  resize: none;
  overflow: auto;
  border: none;
  line-height: 1.4;
  font-size: 12px;
  caret-color: #fff;
  outline: none;
  white-space: pre;
  word-break: normal;
}

pre,
code {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: transparent;
  color: #ffffff;
  padding: 10px;
  padding-bottom: 100px;
  border: none;
  line-height: 1.4;
  font-size: 12px;
  pointer-events: none;
  overflow: hidden;
  white-space: pre;
  word-break: normal;
  overflow-x: auto;
}

.canvas-wrapper {
  overflow: hidden;
  touch-action: none;
  cursor: grab;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
}

.main {
  position: absolute;
  top: 0;
  left: 0;
  user-select: none;
  touch-action: none;
}

.grid {
  position: absolute;
  bottom: 50%;
  right: 50%;
  width: 10000px;
  height: 10000px;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 1px), linear-gradient(90deg, rgba(255, 255, 255, 0.05) 1px, transparent 1px);
  background-size: 50px 50px;
  pointer-events: none;
  transform: translate(50%, 50%);
}

canvas.canvas {
  position: relative;
  display: block;
  z-index: 2;
}

/* Top bar container */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  gap: 10px;
  flex-wrap: wrap;
  background: var(--colorSecondary);
  padding: 5px;
  border-radius: 5px;
}

/* Left side: main controls */
.topbar-left {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  align-items: center;
}

/* Right side: settings button */
.topbar-right {
  display: flex;
  align-items: center;
}

/* Buttons in top bar */
.topbar .button {
  flex: initial;
  background: var(--colorSecondary);
  color: #fff;
  border: 1px solid rgba(0, 0, 0, 0.1);
  width: 80px;
  border-radius: 5px;
  padding: 5px 14px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.2s;
}

.topbar .button:hover,
.topbar .button:active {
  background: var(--colorHover);
}

/* Scale display text */
.topbar .scale-display {
  font-size: 10px;
  opacity: 0.8;
  margin-left: 4px;
}

/* Modal overlay and container */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.modal.active {
  opacity: 1;
  pointer-events: all;
}

.modal-content {
  display: flex;
  flex-direction: row;
  background: #2b2520;
  width: 90%;
  max-width: 700px;
  height: 500px;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.25);
  color: #fff;
}

/* Sidebar on the left */
.modal-sidebar {
  flex: 0 0 150px;
  background: #3b322b;
  overflow-y: auto;
  border-right: 1px solid rgba(255, 255, 255, 0.1);
}

.modal-sidebar ul {
  list-style: none;
  padding: 10px 0;
}

.modal-sidebar li {
  padding: 12px 16px;
  cursor: pointer;
  transition: background 0.2s;
}

.modal-sidebar li:hover {
  background: rgba(255, 255, 255, 0.08);
}

.modal-sidebar li.active {
  background: rgba(255, 255, 255, 0.15);
  font-weight: 500;
}

/* Right side: content area */
.modal-body {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
}

.modal-page h2 {
  font-size: 20px;
  margin-bottom: 10px;
}

/* Close button at bottom-right inside modal content */
.modal .close-modal {
  margin: 10px 20px 10px auto;
  background: var(--colorSecondary);
  border-radius: 10px;
  border: 1px solid rgba(0, 0, 0, 0.1);
  cursor: pointer;
  color: #fff;
  padding: 10px 16px;
  transition: background 0.2s;
}

.modal .close-modal:hover {
  background: var(--colorHover);
}

/* Responsive for smaller screens */
@media (max-width: 700px) {
  body {
    padding: 8px;
  }

  .workspace {
    flex-direction: column;
    gap: 8px;
  }
  .resizer {
    display: none;
  }
  .button {
    flex: 1 1 48%;
    font-size: 17px;
    padding: 10px;
  }

  .modal-content {
    flex-direction: column;
    height: auto;
  }

  .modal-sidebar {
    flex: 0 0 auto;
    width: 100%;
    display: flex;
    overflow-x: auto;
    border-right: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  }

  .modal-sidebar li {
    flex: 0 0 auto;
    padding: 10px 14px;
  }

  .modal-body {
    padding: 15px;
  }
}

@keyframes loading {
  0%,
  100% {
    opacity: 0.2;
  }
  50% {
    opacity: 1;
  }
}

.loading {
  animation: loading 1s infinite ease-in-out;
}
