:root {
  --bg: #f4f6f7;
  --panel: #ffffff;
  --border: #e4e8ea;
  --icon: #3c474d;
  --icon-dim: #8a959b;
  --accent: #43a047;
  --shadow: 0 1px 3px rgba(20, 30, 35, .06);
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--icon);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

#wrapper {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 8px 10px 10px;
  gap: 10px;
}

/* ---------- toolbars ---------- */

#toolbarHolder,
#altToolbarTop {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 34px;
  flex: 0 0 auto;
}

.tb-group { display: flex; align-items: center; gap: 6px; }
.tb-right { margin-left: auto; }

.tb-sep {
  width: 1px;
  height: 22px;
  background: var(--border);
  margin: 0 8px;
}

.tb-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--icon);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background .12s ease, color .12s ease;
}

.tb-btn:hover { background: rgba(0, 0, 0, .055); }
.tb-btn:active { background: rgba(0, 0, 0, .1); }
.tb-btn:focus-visible { outline: 2px solid #90a4ae; outline-offset: 1px; }

.tb-btn svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tb-btn svg.fill-icon path { fill: currentColor; stroke: none; }

.tb-btn.active {
  color: var(--accent);
  background: rgba(67, 160, 71, .1);
}

.color-btn #colorSwatch {
  display: block;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: #e53935;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .18);
}

/* ---------- viewport ---------- */

#application {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
}

#renderHolder {
  position: relative;
  flex: 1 1 auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

#view {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

#view.mode-pointer { cursor: default; }
#view.mode-camera { cursor: grab; }
#view.mode-camera.dragging { cursor: grabbing; }

#coordReadout {
  position: absolute;
  right: 10px;
  bottom: 8px;
  font-size: 12.5px;
  color: #46545c;
  pointer-events: none;
  letter-spacing: .1px;
}

#coordReadout #coordReadoutCoords { color: #8a959b; }

#selectionBox {
  position: absolute;
  border: 1px solid #3d8bfd;
  background: rgba(61, 139, 253, .13);
  pointer-events: none;
}

/* ---------- popovers / menus ---------- */

.popover {
  position: absolute;
  z-index: 40;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 9px;
  box-shadow: 0 8px 26px rgba(20, 30, 35, .16);
  padding: 8px;
}

.hidden { display: none !important; }

.menu {
  position: absolute;
  z-index: 50;
  min-width: 218px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 9px;
  box-shadow: 0 10px 30px rgba(20, 30, 35, .18);
  padding: 5px;
}

.menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 13.5px;
  cursor: pointer;
  white-space: nowrap;
}

.menu-item:hover { background: #f1f4f5; }
.menu-item.disabled { color: var(--icon-dim); pointer-events: none; }
.menu-item .hint { color: #a5b0b6; font-size: 11.5px; }
.menu-sep { height: 1px; background: var(--border); margin: 5px 6px; }

/* ---------- palette ---------- */

.palette {
  display: grid;
  grid-template-columns: repeat(8, 22px);
  gap: 5px;
}

.swatch {
  width: 22px;
  height: 22px;
  border-radius: 5px;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .16);
}

.swatch:hover { transform: scale(1.1); }
.swatch.sel { box-shadow: 0 0 0 2px #fff, 0 0 0 3.5px var(--accent); }

.palette-custom {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 9px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-size: 12.5px;
}

.palette-custom input[type=color] {
  width: 34px;
  height: 24px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: none;
  cursor: pointer;
}

/* ---------- modal ---------- */

#modalLayer {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(25, 34, 39, .38);
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal {
  width: min(430px, calc(100vw - 40px));
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 18px 50px rgba(10, 20, 25, .3);
  padding: 18px 20px 16px;
  animation: pop .13s ease-out;
}

@keyframes pop {
  from { transform: scale(.97); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal h3 {
  margin: 0 0 8px;
  font-size: 16px;
  font-weight: 600;
  color: #26333a;
}

.modal p { margin: 0 0 14px; font-size: 13.5px; line-height: 1.5; color: #55636b; }

.modal .field { margin-bottom: 13px; }
.modal label { display: block; font-size: 12.5px; color: #6b777d; margin-bottom: 5px; }

.modal input[type=text],
.modal input[type=number],
.modal select {
  width: 100%;
  padding: 8px 10px;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #fbfcfc;
  color: var(--icon);
}

.modal input:focus, .modal select:focus { outline: none; border-color: #9fb6c0; }

.modal .row { display: flex; gap: 8px; flex-wrap: wrap; }
.modal .row > * { flex: 1 1 auto; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.btn {
  padding: 8px 15px;
  font-size: 13.5px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: #fff;
  color: #44535b;
  cursor: pointer;
}

.btn:hover { background: #f3f6f7; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #38833b; }
.btn.danger { background: #e53935; border-color: #e53935; color: #fff; }
.btn.danger:hover { background: #d32f2f; }

.list {
  max-height: 230px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 11px;
  font-size: 13.5px;
  cursor: pointer;
  border-bottom: 1px solid #eef1f2;
}

.list-item:last-child { border-bottom: 0; }
.list-item:hover { background: #f3f6f7; }
.list-item.sel { background: #e8f3e9; }
.list-item .meta { color: #9aa5ab; font-size: 11.5px; }

.check { display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: #4c5a62; }

.keys { display: grid; grid-template-columns: 1fr auto; gap: 7px 14px; font-size: 13px; color: #55636b; }
.keys kbd {
  justify-self: end;
  background: #f2f5f6;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 2px 7px;
  font-family: inherit;
  font-size: 11.5px;
  color: #46545c;
}

/* ---------- toast ---------- */

#toastLayer {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: 7px;
  align-items: center;
  pointer-events: none;
}

.toast {
  background: rgba(30, 40, 46, .93);
  color: #fff;
  padding: 8px 15px;
  border-radius: 20px;
  font-size: 13px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .2);
  animation: toastIn .16s ease-out;
}

@keyframes toastIn {
  from { transform: translateY(8px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
