:root {
  --bg: #0f1115;
  --surface: #171a21;
  --toolbar: rgba(23, 26, 33, 0.92);
  --border: rgba(255, 255, 255, 0.08);
  --icon: rgba(255, 255, 255, 0.22);
  --icon-hover: rgba(255, 255, 255, 0.35);
  --text-muted: rgba(255, 255, 255, 0.45);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --toolbar-h: 52px;
  --icon-size: 36px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: #fff;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Noto Sans SC", sans-serif;
}

body {
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
}

.toolbar {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: var(--toolbar-h);
  padding: 8px 10px;
  padding-left: calc(10px + var(--safe-left));
  padding-right: calc(10px + var(--safe-right));
  background: var(--toolbar);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
}

.toolbar::-webkit-scrollbar {
  display: none;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.tool-btn {
  width: var(--icon-size);
  height: var(--icon-size);
  min-width: var(--icon-size);
  min-height: var(--icon-size);
  padding: 0;
  margin: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}

.tool-btn:hover,
.tool-btn:focus-visible {
  outline: none;
  border-color: rgba(255, 255, 255, 0.18);
  background: #1d2230;
}

.tool-btn:active {
  transform: scale(0.96);
}

.icon-placeholder {
  width: 16px;
  height: 16px;
  border-radius: 3px;
  background: var(--icon);
  display: block;
}

.tool-btn:hover .icon-placeholder,
.tool-btn:focus-visible .icon-placeholder {
  background: var(--icon-hover);
}

.canvas-shell {
  position: relative;
  flex: 1;
  min-height: 0;
  width: 100%;
  background:
    radial-gradient(circle at 1px 1px, rgba(255, 255, 255, 0.06) 1px, transparent 0) 0 0 / 24px 24px,
    var(--bg);
  touch-action: none;
  overflow: hidden;
}

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

.canvas-hint {
  position: absolute;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 12px;
  pointer-events: none;
  white-space: nowrap;
  opacity: 1;
  transition: opacity 0.4s ease;
}

.canvas-hint.hide {
  opacity: 0;
}

@media (max-width: 640px) {
  :root {
    --toolbar-h: 48px;
    --icon-size: 34px;
  }

  .toolbar-center {
    display: none;
  }

  .canvas-hint {
    font-size: 11px;
    max-width: calc(100vw - 32px);
    overflow: hidden;
    text-overflow: ellipsis;
  }
}
