* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body, html {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: #dcdfdc;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

#whiteboard {
  position: absolute;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
}

/* Menu Popup Sidebar */
.menu-popup {
  position: absolute;
  bottom: 96px;
  left: 0;
  background: #f1f3f0;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  display: none;
  flex-direction: column;
  padding: 12px 0;
  min-width: 220px;
  z-index: 20;
  border: 1px solid #d1d5db;
}

.menu-popup.open {
  display: flex;
}

.menu-item-group {
  position: relative;
  width: 100%;
}

.menu-item {
  background: transparent;
  border: none;
  display: flex;
  align-items: center;
  padding: 10px 20px;
  width: 100%;
  cursor: pointer;
  color: #4b5563;
  font-size: 15px;
  gap: 16px;
  transition: background 0.15s ease;
}

.menu-item i {
  font-size: 22px;
  color: #2c698d;
}

.menu-item span {
  flex-grow: 1;
  text-align: left;
}

.menu-item .arrow {
  font-size: 12px;
  color: #3f4cb0;
}

.menu-item:hover {
  background-color: #e4e8e1;
}

/* Submenu for Import */
.submenu {
  position: absolute;
  left: 100%;
  top: 0;
  background: #ffffff;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
  display: none;
  flex-direction: column;
  padding: 8px 0;
  min-width: 140px;
  border: 1px solid #e2e8f0;
}

.menu-item-group:hover .submenu {
  display: flex;
}

.submenu-item {
  background: transparent;
  border: none;
  display: flex;
  align-items: center;
  padding: 10px 16px;
  cursor: pointer;
  gap: 12px;
  color: #3b4cca;
  font-weight: 600;
  font-size: 14px;
}

.submenu-item:hover {
  background-color: #f1f5f9;
}

/* Object Action Toolbar */
.object-toolbar {
  position: absolute;
  display: none;
  background: #ffffff;
  border-radius: 10px;
  padding: 6px 12px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.15);
  gap: 12px;
  z-index: 30;
  border: 1px solid #e2e8f0;
  transform: translateX(-50%);
}

.object-toolbar.open {
  display: flex;
}

.obj-btn {
  background: transparent;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
  color: #3b4cca;
  font-size: 11px;
}

.obj-btn i {
  font-size: 18px;
}

.obj-btn:hover {
  color: #1d2780;
}

/* Theme Modal */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; width: 100vw; height: 100vh;
  background: rgba(0, 0, 0, 0.35);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-overlay.open {
  display: flex;
}

.theme-card {
  background: #f3f3f3;
  border-radius: 16px;
  width: 520px;
  padding: 24px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.theme-card h2 {
  text-align: center;
  color: #374151;
  font-size: 20px;
}

.theme-tabs {
  display: flex;
  justify-content: center;
  gap: 0;
  background: #e2e8f0;
  border-radius: 8px;
  padding: 3px;
  width: fit-content;
  margin: 0 auto;
}

.theme-tab-btn {
  background: transparent;
  border: none;
  padding: 6px 20px;
  font-size: 14px;
  font-weight: 500;
  color: #475569;
  cursor: pointer;
  border-radius: 6px;
}

.theme-tab-btn.active {
  background: #3b4cca;
  color: #ffffff;
}

.tab-content {
  display: none;
  min-height: 220px;
}

.tab-content.active {
  display: block;
}

.template-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

.template-item {
  height: 90px;
  background: #ffffff;
  border: 2px solid #e2e8f0;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.template-item.active {
  border-color: #3b4cca;
}

.tpl-preview {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 8px;
}

.empty-tpl { font-size: 24px; color: #94a3b8; }
.ruled-lines div { width: 80%; height: 2px; background: #cbd5e1; }
.stave-lines div { width: 80%; height: 1px; background: #94a3b8; }

.grid-box {
  background-size: 12px 12px;
  background-image: linear-gradient(to right, #e2e8f0 1px, transparent 1px),
                    linear-gradient(to bottom, #e2e8f0 1px, transparent 1px);
}

.dots-box {
  background-image: radial-gradient(#94a3b8 1px, transparent 1px);
  background-size: 10px 10px;
}

.section-title {
  font-size: 13px;
  color: #64748b;
  margin-bottom: 8px;
}

.bg-color-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.bg-swatch {
  height: 36px;
  border-radius: 6px;
  border: 1px solid #cbd5e1;
  cursor: pointer;
  position: relative;
}

.bg-swatch.active::after {
  content: "✓";
  color: #3b4cca;
  font-weight: bold;
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
}

.bg-image-row {
  display: flex;
  gap: 12px;
  align-items: center;
}

.upload-btn-box {
  width: 60px;
  height: 60px;
  background: #e2e8f0;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.upload-label {
  cursor: pointer;
  font-size: 24px;
  color: #3b4cca;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.uploaded-images {
  display: flex;
  gap: 10px;
  overflow-x: auto;
}

.uploaded-thumb {
  width: 60px;
  height: 60px;
  border-radius: 8px;
  object-fit: cover;
  cursor: pointer;
  border: 2px solid transparent;
}

.uploaded-thumb.active {
  border-color: #3b4cca;
}

.theme-footer {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-top: 10px;
}

.btn-cancel, .btn-ok {
  border-radius: 20px;
  padding: 8px 32px;
  font-size: 14px;
  cursor: pointer;
  border: 1px solid #cbd5e1;
}

.btn-cancel {
  background: #ffffff;
  color: #475569;
}

.btn-ok {
  background: #ffffff;
  color: #3b4cca;
  border-color: #3b4cca;
  font-weight: bold;
}

/* Pen Settings Popup */
.pen-popup {
  position: absolute;
  bottom: 96px;
  left: 0;
  background: #f1f3f0;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  display: none;
  flex-direction: row;
  z-index: 20;
  border: 1px solid #d1d5db;
  overflow: hidden;
  width: 440px;
}

.pen-popup.open {
  display: flex;
}

.pen-sidebar {
  background: #e2e5e1;
  display: flex;
  flex-direction: column;
  width: 60px;
}

.pen-tab {
  background: transparent;
  border: none;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #4b5563;
  font-size: 22px;
}

.pen-tab.active {
  background: #7cb342;
  color: #ffffff;
}

.pen-content {
  flex-grow: 1;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.pen-toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: #4b5563;
}

.switch {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
}

.switch input { opacity: 0; width: 0; height: 0; }

.slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: #ccc;
  transition: .2s;
  border-radius: 20px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 14px; width: 14px;
  left: 3px; bottom: 3px;
  background-color: white;
  transition: .2s;
  border-radius: 50%;
}

input:checked + .slider { background-color: #7cb342; }
input:checked + .slider:before { transform: translateX(16px); }

.pen-types {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.pen-type-btn {
  background: transparent;
  border: none;
  font-size: 26px;
  color: #3f4cb0;
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
}

.pen-type-btn.active {
  color: #7cb342;
}

.ab-icon {
  font-weight: bold;
  font-size: 18px;
}

.pen-size-row input[type=range] {
  width: 100%;
  accent-color: #3f4cb0;
}

.color-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 10px;
}

.color-swatch {
  width: 44px;
  height: 32px;
  border-radius: 4px;
  border: none;
  cursor: pointer;
  position: relative;
}

.color-swatch.active::after {
  content: "✓";
  color: white;
  font-size: 14px;
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
}

.rainbow-swatch {
  background: linear-gradient(135deg, red, orange, yellow, green, blue, indigo, violet);
}

/* Main Toolbar Wrapper */
.toolbar-wrapper {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: stretch;
  gap: 12px;
  height: 68px;
  max-width: 98vw;
  width: max-content;
  z-index: 10;
}

.tool-card {
  background: #f3f3f3;
  border-radius: 8px;
  display: flex;
  align-items: center;
  padding: 0 6px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.12);
  overflow: hidden;
}

.section-blue .tool-item i { color: #2c698d; }
.section-indigo .tool-item i { color: #3f4cb0; }
.tool-item.muted i { color: #b0b4be; }

.tool-item {
  background: transparent;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  height: 100%;
  cursor: pointer;
  min-width: 58px;
  color: #616161;
  transition: background-color 0.15s ease;
  position: relative;
}

.tool-item i {
  font-size: 24px;
  margin-bottom: 2px;
}

.tool-item span {
  font-size: 11px;
  white-space: nowrap;
}

.tool-item:hover {
  background-color: #e4e6ea;
}

.tool-arrow {
  display: none;
  position: absolute;
  right: 2px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 10px !important;
}

.tool-item.active {
  background-color: #3b4cca !important;
  color: #ffffff !important;
  border-radius: 4px;
}

.tool-item.active i {
  color: #ffffff !important;
}

.tool-item.active .tool-arrow {
  display: block;
}

.tool-item.menu-active {
  border: 2px solid #374151;
  border-radius: 6px;
  background-color: #e5e7eb;
}

.page-indicator {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #ffffff;
  border: 1px solid #d1d5db;
  border-radius: 16px;
  padding: 2px 18px;
  margin: 0 4px;
}

.page-indicator span {
  font-size: 12px;
  font-weight: bold;
  color: #3f4cb0;
}

.page-indicator .sub-label {
  font-size: 9px;
  color: #888888;
  font-weight: normal;
}

.guru-icon {
  width: 24px;
  height: 24px;
  margin-bottom: 2px;
  object-fit: contain;
}