:root {
  color-scheme: dark;
  --bg: #050505;
  --panel: rgba(18, 18, 20, 0.86);
  --panel-strong: rgba(22, 22, 25, 0.96);
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.15);
  --text: #f3f3f5;
  --muted: #96969f;
  --accent: #f5f5f5;
  --danger: #ff6565;
  --shadow: 0 14px 44px rgba(0, 0, 0, 0.35);
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; background: var(--bg); }
body {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  user-select: none;
  -webkit-user-select: none;
}
button, input, textarea { font: inherit; }
button { color: inherit; }

.app-shell { position: relative; width: 100%; height: 100%; background: #000; }
#canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: default; }

.glass {
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px) saturate(120%);
  -webkit-backdrop-filter: blur(18px) saturate(120%);
}

.topbar {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  height: 48px;
  min-width: min(760px, calc(100vw - 150px));
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 7px;
  border-radius: 15px;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 8px; padding: 0 8px 0 5px; white-space: nowrap; }
.brand-mark {
  width: 28px; height: 28px; display: grid; place-items: center;
  border-radius: 9px; background: #f5f5f5; color: #050505; font-weight: 800; font-size: 19px;
}
.brand-name { font-size: 13px; font-weight: 650; letter-spacing: .01em; }
.topbar-divider, .rail-divider, .property-separator, .menu-sep { background: var(--border); }
.topbar-divider { width: 1px; height: 22px; margin: 0 3px; }
.topbar-spacer, .status-spacer { flex: 1; }
.icon-btn, .text-btn, .format-btn, .minimap-head button {
  border: 0; background: transparent; cursor: pointer; transition: background .15s ease, color .15s ease, transform .1s ease;
}
.icon-btn:hover, .text-btn:hover, .format-btn:hover, .minimap-head button:hover { background: rgba(255,255,255,.08); }
.icon-btn:active, .text-btn:active, .format-btn:active { transform: translateY(1px); }
.icon-btn { width: 34px; height: 34px; border-radius: 9px; font-size: 18px; }
.text-btn { min-height: 34px; padding: 0 11px; border-radius: 9px; font-size: 12px; font-weight: 600; color: #d9d9de; }
.text-btn.compact { min-width: 54px; }

.toolrail {
  position: absolute;
  left: max(14px, env(safe-area-inset-left));
  top: 50%; transform: translateY(-50%);
  display: flex; flex-direction: column; gap: 5px;
  width: 54px; padding: 6px;
  border-radius: 16px; z-index: 20;
}
.tool-btn {
  position: relative; width: 40px; height: 40px;
  display: grid; place-items: center;
  border: 0; border-radius: 11px; background: transparent; cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.tool-btn:hover { background: rgba(255,255,255,.07); }
.tool-btn.active { background: #f4f4f4; color: #070707; }
.tool-icon { font-size: 19px; line-height: 1; }
.keycap {
  position: absolute; right: 4px; bottom: 2px; font-size: 7px; font-weight: 800;
  opacity: .52; letter-spacing: -.02em;
}
.rail-divider { height: 1px; width: 30px; align-self: center; margin: 2px 0; }

.properties {
  position: absolute;
  left: max(82px, calc(env(safe-area-inset-left) + 82px));
  bottom: max(18px, calc(env(safe-area-inset-bottom) + 18px));
  display: flex; align-items: center; gap: 12px;
  min-height: 54px; padding: 8px 11px;
  border-radius: 15px; z-index: 19;
  max-width: calc(100vw - 360px);
}
.property-row { display: flex; align-items: center; gap: 8px; }
.palette-row { gap: 7px; }
.color-control { width: 34px; height: 34px; display: grid; place-items: center; position: relative; cursor: pointer; }
.color-control input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.color-chip { width: 27px; height: 27px; border-radius: 8px; background: #fff; border: 2px solid rgba(255,255,255,.22); box-shadow: inset 0 0 0 1px rgba(0,0,0,.25); }
.swatches { display: flex; gap: 5px; }
.swatches button { width: 17px; height: 17px; border-radius: 50%; border: 1px solid rgba(255,255,255,.20); background: var(--swatch); cursor: pointer; padding: 0; }
.swatches button:hover { transform: scale(1.13); }
.property-separator { width: 1px; height: 30px; flex: 0 0 1px; }
.property-block { display: flex; flex-direction: column; gap: 3px; min-width: 110px; }
.property-label { font-size: 9px; line-height: 1; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; }
.property-label b { color: #e5e5e8; margin-left: 3px; font-weight: 650; }
.property-block input[type="range"] { width: 112px; accent-color: #f0f0f0; }
.toggle-cluster { display: flex; flex-direction: column; gap: 4px; }
.toggle-line { display: flex; align-items: center; gap: 8px; font-size: 10px; color: #c2c2c7; cursor: pointer; white-space: nowrap; }
.toggle-line input { position: absolute; opacity: 0; pointer-events: none; }
.switch { width: 26px; height: 14px; border-radius: 999px; background: #34343a; position: relative; transition: .18s ease; }
.switch::after { content: ""; position: absolute; width: 10px; height: 10px; border-radius: 50%; left: 2px; top: 2px; background: #92929a; transition: .18s ease; }
.toggle-line input:checked + .switch { background: #e8e8eb; }
.toggle-line input:checked + .switch::after { left: 14px; background: #0e0e10; }
.text-controls { display: flex; align-items: center; gap: 8px; }
.text-controls.hidden { display: none; }
.inline-control { min-width: 78px; }
.inline-control input { width: 72px; height: 27px; border-radius: 7px; border: 1px solid var(--border); background: rgba(255,255,255,.05); color: #fff; padding: 0 7px; outline: none; }
.format-buttons { display: flex; gap: 4px; }
.format-btn { width: 30px; height: 30px; border-radius: 8px; color: #c7c7cc; }
.format-btn.active { background: #f0f0f0; color: #050505; }

.minimap-panel {
  position: absolute; right: max(14px, env(safe-area-inset-right)); bottom: max(18px, calc(env(safe-area-inset-bottom) + 18px));
  width: 210px; height: 154px; padding: 8px; border-radius: 14px; z-index: 18;
}
.minimap-head { height: 22px; display: flex; align-items: center; justify-content: space-between; padding: 0 2px 5px 4px; }
.minimap-head span { font-size: 8px; letter-spacing: .14em; color: #8b8b93; font-weight: 800; }
.minimap-head button { border-radius: 6px; font-size: 9px; color: #bdbdc4; padding: 3px 6px; }
#minimap { width: 100%; height: calc(100% - 22px); display: block; border-radius: 8px; background: #08080a; cursor: crosshair; }

.statusbar {
  position: absolute; left: 50%; bottom: max(18px, calc(env(safe-area-inset-bottom) + 18px)); transform: translateX(-50%);
  min-width: 260px; height: 32px; display: flex; align-items: center; gap: 7px; padding: 0 10px;
  border-radius: 11px; z-index: 15; font-size: 9px; color: #9898a0; pointer-events: none;
}
.statusbar .dot { opacity: .35; }
#statusTool { color: #d7d7dc; font-weight: 650; }
#coords { font-variant-numeric: tabular-nums; }

.context-menu, .board-menu {
  position: absolute; min-width: 220px; padding: 6px; border-radius: 12px; z-index: 50;
  background: var(--panel-strong); border: 1px solid var(--border-strong); box-shadow: 0 18px 60px rgba(0,0,0,.55);
}
.context-menu { display: none; }
.context-menu.open { display: block; }
.context-menu button, .board-menu button, .menu-toggle {
  width: 100%; min-height: 34px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 9px; border: 0; border-radius: 8px; background: transparent; color: #dedee2; font-size: 11px; cursor: pointer;
}
.context-menu button:hover, .board-menu button:hover, .menu-toggle:hover { background: rgba(255,255,255,.07); }
.context-menu button span { color: #72727b; font-size: 9px; margin-left: 20px; }
.context-menu .danger, .board-menu .danger { color: var(--danger); }
.menu-sep { height: 1px; margin: 5px 4px; }
.board-menu { top: 70px; right: 14px; width: 190px; }
.board-menu.hidden { display: none; }
.menu-toggle { cursor: default; }
.menu-toggle input { accent-color: #fff; }

.canvas-text-editor {
  position: absolute; z-index: 70; min-width: 140px; min-height: 46px; padding: 3px 5px;
  resize: both; overflow: hidden; background: rgba(12,12,14,.86); color: #fff;
  border: 1px solid rgba(255,255,255,.32); outline: 0; border-radius: 7px; box-shadow: 0 10px 30px rgba(0,0,0,.45);
  transform-origin: top left; user-select: text; -webkit-user-select: text;
}

.toast {
  position: absolute; left: 50%; top: 78px; transform: translateX(-50%) translateY(-8px);
  padding: 8px 12px; border-radius: 9px; background: rgba(28,28,31,.95); border: 1px solid var(--border);
  color: #e8e8ea; font-size: 11px; opacity: 0; pointer-events: none; z-index: 80;
  transition: opacity .18s ease, transform .18s ease;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 900px) {
  .topbar { left: 76px; right: 14px; transform: none; min-width: 0; width: auto; }
  .brand-name, .text-btn:not(.compact) { display: none; }
  .properties { right: 14px; max-width: none; overflow-x: auto; scrollbar-width: none; }
  .properties::-webkit-scrollbar { display: none; }
  .minimap-panel { display: none; }
  .statusbar { display: none; }
}

@media (max-width: 560px) {
  .topbar { top: 10px; left: 68px; right: 10px; height: 44px; }
  .toolrail { left: 10px; width: 48px; }
  .tool-btn { width: 34px; height: 36px; }
  .properties { left: 68px; right: 10px; bottom: 10px; padding: 7px 8px; gap: 9px; }
  .swatches { display: none; }
  .property-block { min-width: 94px; }
  .property-block input[type="range"] { width: 94px; }
  .toggle-cluster { display: none; }
}
