:root {
  --primary-color: #4d90fe;
  --modal-bg: #ffffff;

  --toolbar-width: 64px;
  --toolbar-inset: 12px;
  --toolbar-gap: 16px;
  --toolbar-radius: 16px;

  --toolbar-bg: rgba(255, 255, 255, 0.92);
  --toolbar-border: rgba(15, 23, 42, 0.10);
  --toolbar-shadow: 0 14px 40px rgba(15, 23, 42, 0.18);

  --btn-hover: rgba(15, 23, 42, 0.06);
  --btn-active: rgba(77, 144, 254, 0.16);
  --icon-color: rgba(15, 23, 42, 0.78);
  --icon-muted: rgba(15, 23, 42, 0.55);
}

html,
body {
  width: 100%;
  overflow-x: hidden;
}

body {
  font-family: 'Segoe UI', 'Roboto', sans-serif;
  margin: 0;
  padding: 0;
  height: 100vh;
  background-color: #f5f5f7;
  overflow: hidden;
}

#sidebar {
  width: var(--toolbar-width);
  position: fixed;
  left: var(--toolbar-inset);
  top: var(--toolbar-inset);
  bottom: var(--toolbar-inset);
  z-index: 100;

  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 0;

  background: var(--toolbar-bg);
  border: 1px solid var(--toolbar-border);
  border-radius: var(--toolbar-radius);
  box-shadow: var(--toolbar-shadow);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

#sidebar-scroll {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 2px 0;
  scrollbar-width: none;
}

#sidebar-scroll::-webkit-scrollbar {
  width: 0;
  height: 0;
}

#sidebar-header {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 10px;
  width: 100%;
}

#logo {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#logo img {
  display: block;
  object-fit: contain;
}

.tools-section {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(15, 23, 42, 0.08);
}

.tools-section:last-child {
  border-bottom: none;
  margin-bottom: 0;
}

.section-title {
  color: transparent;
  font-size: 0;
  height: 0;
  margin: 0;
}

.tool-button {
  background-color: transparent;
  border: none;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  margin: 4px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  color: var(--icon-color);
}

.tool-button:hover {
  background-color: var(--btn-hover);
}

.tool-button.active {
  background-color: var(--btn-active);
  color: var(--primary-color);
}

.tool-button svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

.tool-button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(77, 144, 254, 0.25);
}

.color-picker-wrapper {
  position: relative;
  margin: 4px 0;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  transition: all 0.2s ease;
}

.color-picker-wrapper:hover {
  background-color: var(--btn-hover);
}

#color-picker {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
}

#color-picker::-webkit-color-swatch-wrapper {
  padding: 0;
}

#color-picker::-webkit-color-swatch {
  border: none;
  border-radius: 8px;
}

.thickness-container,
.eraser-thickness-container,
.text-size-container {
  position: relative;
  margin: 4px 0;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  transition: all 0.2s ease;
}

.thickness-container:hover,
.eraser-thickness-container:hover,
.text-size-container:hover {
  background-color: var(--btn-hover);
}

.thickness-preview,
.eraser-thickness-preview,
.text-size-preview {
  width: 28px;
  height: 28px;
  border-radius: 10px;
  background-color: transparent;
  border: 1.5px solid rgba(15, 23, 42, 0.24);
  position: relative;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--icon-color);
}

.eraser-thickness-preview {
  border-style: dashed;
}

.thickness-dot,
.eraser-thickness-dot {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background-color: rgba(15, 23, 42, 0.65);
  border-radius: 50%;
  transition: all 0.2s ease;
}

.thickness-popup,
.eraser-thickness-popup,
.text-size-popup {
  position: fixed;
  left: 0;
  top: 0;
  background-color: rgba(15, 23, 42, 0.92);
  padding: 10px;
  border-radius: 8px;
  display: none;
  flex-direction: column;
  align-items: center;
  z-index: 101;
  box-shadow: 0 12px 34px rgba(15, 23, 42, 0.26);
  width: 140px;
  max-height: min(60vh, 360px);
  overflow: auto;
}

.thickness-popup.show,
.eraser-thickness-popup.show,
.text-size-popup.show {
  display: flex;
}

.shapes-popup {
  position: fixed;
  left: 0;
  top: 0;
  background-color: rgba(15, 23, 42, 0.92);
  padding: 10px;
  border-radius: 8px;
  display: none;
  flex-direction: column;
  align-items: center;
  z-index: 101;
  box-shadow: 0 12px 34px rgba(15, 23, 42, 0.26);
  width: 140px;
  max-height: min(60vh, 360px);
  overflow: auto;
}

.shapes-popup.show {
  display: flex;
}

.shapes-popup .tool-button {
  color: rgba(255, 255, 255, 0.92);
  width: 46px;
  height: 46px;
}

.layers-popup,
.pages-popup {
  position: fixed;
  left: 0;
  top: 0;
  background-color: rgba(15, 23, 42, 0.92);
  padding: 10px;
  border-radius: 8px;
  display: none;
  flex-direction: column;
  align-items: center;
  z-index: 101;
  box-shadow: 0 12px 34px rgba(15, 23, 42, 0.26);
  width: 240px;
  max-width: calc(100vw - 24px);
  box-sizing: border-box;
  max-height: min(70vh, 420px);
  overflow: auto;
}

.layers-popup.show,
.pages-popup.show {
  display: flex;
}

.popup-list {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 6px 0 10px;
  max-height: 220px;
  overflow: auto;
}

.popup-row {
  width: 100%;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
}

.popup-row.active {
  background: rgba(77, 144, 254, 0.28);
}

.popup-row-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.popup-row-title {
  color: rgba(255, 255, 255, 0.92);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.popup-row-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.mini-btn {
  border: none;
  background: rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.9);
  width: 24px;
  height: 24px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  line-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mini-btn svg {
  width: 16px;
  height: 16px;
  display: block;
  pointer-events: none;
}

.mini-btn:hover {
  background: rgba(255, 255, 255, 0.18);
}

.popup-action {
  width: 100%;
  border: none;
  background: rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.92);
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
  font-size: 12px;
}

.popup-action:hover {
  background: rgba(255, 255, 255, 0.18);
}

.popup-title {
  color: rgba(255, 255, 255, 0.85);
  font-size: 12px;
  font-weight: bold;
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  width: 100%;
  text-align: center;
}

.thickness-slider {
  width: 120px;
  margin: 10px 0;
  appearance: none;
  -webkit-appearance: none;
  height: 4px;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 2px;
}

.thickness-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--primary-color);
  cursor: pointer;
}

.thickness-value {
  color: rgba(255, 255, 255, 0.9);
  font-size: 12px;
  margin-top: 5px;
}

#whiteboard {
  position: fixed;
  top: 0;
  left: calc(var(--toolbar-inset) + var(--toolbar-width) + var(--toolbar-gap));
  width: calc(100vw - (var(--toolbar-inset) + var(--toolbar-width) + var(--toolbar-gap)));
  height: 100vh;
  background-color: #ffffff;
  cursor: crosshair;
  background-image: linear-gradient(#e5e5e5 1px, transparent 1px),
                    linear-gradient(90deg, #e5e5e5 1px, transparent 1px);
  background-size: 20px 20px;
  background-position: 0 0;
  display: block;
}

#zoom-controls {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 120;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--toolbar-bg);
  border: 1px solid var(--toolbar-border);
  box-shadow: var(--toolbar-shadow);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  user-select: none;
}

#zoom-value {
  font-size: 12px;
  font-weight: 600;
  color: rgba(15, 23, 42, 0.86);
  min-width: 56px;
  text-align: center;
}

.zoom-btn {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  border: none;
  background: rgba(15, 23, 42, 0.06);
  color: rgba(15, 23, 42, 0.82);
  font-size: 18px;
  line-height: 0;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}

.zoom-btn:hover {
  background: rgba(15, 23, 42, 0.10);
}

.zoom-btn:active {
  background: rgba(77, 144, 254, 0.16);
  color: var(--primary-color);
}

.zoom-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(77, 144, 254, 0.25);
}

.modal {
  display: none;
  position: fixed;
  z-index: 200;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  align-items: center;
  justify-content: center;
}

.modal-content {
  background-color: var(--modal-bg);
  padding: 20px 25px;
  border-radius: 10px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
  width: 400px;
  max-width: 90%;
  position: relative;
}

.modal h2 {
  margin-top: 0;
  color: #333;
}

.close-button {
  position: absolute;
  top: 15px;
  right: 20px;
  font-size: 24px;
  cursor: pointer;
  color: #777;
}

.modal ul {
  padding-left: 20px;
}

.modal p {
  margin: 10px 0;
}

.github-link {
  position: absolute;
  bottom: 15px;
  right: 15px;
  color: #333;
  transition: color 0.2s ease;
  line-height: 0;
}

.github-link:hover {
  color: var(--primary-color);
}