:root {
  --bg-dark: #0a0c10;
  --bg-viewport: #12151e;
  --panel-bg: rgba(18, 22, 32, 0.78);
  --panel-border: rgba(255, 255, 255, 0.12);
  --panel-border-hover: rgba(255, 255, 255, 0.25);
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --accent-primary: #3b82f6;
  --accent-glow: rgba(59, 130, 246, 0.35);
  --accent-success: #10b981;
  --accent-warning: #f59e0b;
  --accent-danger: #ef4444;
  --font-sans: 'Silkscreen', monospace, sans-serif;
  --font-mono: 'Silkscreen', monospace;
}

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

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-dark);
  color: var(--text-main);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
}

/* Header Navbar */
.app-header {
  position: absolute;
  top: 16px;
  left: 16px;
  right: 16px;
  height: 56px;
  width: fit-content;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--panel-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.header-left,
.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-box {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-box h1 {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #ffffff;
}

.logo-box h1 span {
  color: var(--accent-primary);
  font-weight: 500;
  font-size: 0.9rem;
  margin-left: 4px;
}

/* Status Pill */
.status-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 500;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--panel-border);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--text-muted);
}

.status-connecting .status-dot {
  background-color: var(--accent-warning);
  box-shadow: 0 0 8px var(--accent-warning);
  animation: pulse 1.5s infinite;
}

.status-connected .status-dot {
  background-color: var(--accent-success);
  box-shadow: 0 0 8px var(--accent-success);
}

.status-offline .status-dot {
  background-color: var(--accent-danger);
}

.stat-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.05);
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid var(--panel-border);
  font-family: var(--font-mono);
}

.stat-pill span {
  color: var(--text-main);
  font-weight: 600;
}

/* Buttons */
.btn-action {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--accent-primary);
  background: var(--accent-primary);
  color: #ffffff;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px var(--accent-glow);
}

.btn-action:hover {
  background: #2563eb;
  border-color: #2563eb;
  transform: translateY(-1px);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--panel-border);
  color: var(--text-main);
  box-shadow: none;
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: var(--panel-border-hover);
}

/* Viewport Area */
.viewport-container {
  width: 100vw;
  height: 100vh;
  position: relative;
  background-color: #05070a;
  background-image:
    linear-gradient(to right, rgba(255, 255, 255, 0.07) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 255, 255, 0.07) 1px, transparent 1px);
  background-size: 32px 32px;
  overflow: hidden;
  cursor: crosshair;
}

.viewport-container.panning {
  cursor: grab;
}

.viewport-container.panning:active {
  cursor: grabbing;
}

.canvas-wrapper {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 250px;
  height: 250px;
  margin-top: -125px;
  margin-left: -125px;
  transform-origin: center center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.8), 0 0 0 1px rgba(255, 255, 255, 0.25);
  background: #000000;
}

#pixelCanvas,
#gridCanvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 250px;
  height: 250px;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
}

#gridCanvas {
  pointer-events: none;
  background-image:
    linear-gradient(to right, rgba(255, 255, 255, 0.45) 0.025px, transparent 0.025px),
    linear-gradient(to bottom, rgba(255, 255, 255, 0.45) 0.025px, transparent 0.025px);
  background-size: 1px 1px;
}

/* Floating Toolbar */
.floating-toolbar {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  background: var(--panel-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
}

.toolbar-divider {
  height: 1px;
  background: var(--panel-border);
  margin: 4px 0;
}

.tool-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  border-radius: 10px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s ease;
}

.tool-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
}

.tool-btn.active {
  background: rgba(59, 130, 246, 0.18);
  border-color: var(--accent-primary);
  color: #60a5fa;
  box-shadow: 0 0 12px var(--accent-glow);
}

.color-swatch {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  margin-bottom: 2px;
}

.color-swatch.black {
  background: #000000;
  border: 1px solid rgba(255, 255, 255, 0.4);
}

.color-swatch.white {
  background: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.3);
}

.tool-label {
  font-size: 0.65rem;
  font-weight: 500;
  margin-top: 2px;
}

.text-btn {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-main);
}

/* Footer Info Bar */
.app-footer {
  position: absolute;
  bottom: 16px;
  left: 16px;
  right: 16px;
  height: 40px;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--panel-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.footer-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
}

.footer-label {
  color: var(--text-muted);
}

.mono-val {
  font-family: var(--font-mono);
  color: var(--text-main);
  font-weight: 500;
}

.cooldown-gauge {
  width: 80px;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  overflow: hidden;
  display: inline-block;
  vertical-align: middle;
}

.cooldown-fill {
  width: 100%;
  height: 100%;
  background: var(--accent-success);
}

@keyframes cooldownShake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-3px); }
  40%, 80% { transform: translateX(3px); }
}

.cooldown-gauge.shake {
  animation: cooldownShake 0.3s ease;
}

.cooldown-timer-text {
  display: inline-block;
  width: 48px;
  min-width: 48px;
  margin-left: 6px;
  font-size: 11px;
  text-align: left;
}

@keyframes pulse {
  0% {
    opacity: 0.5;
  }

  50% {
    opacity: 1;
  }

  100% {
    opacity: 0.5;
  }
}

@media (max-width: 640px) {
  .logo-box h1 span {
    display: none;
  }

  .tech-badge {
    display: none;
  }

  .floating-toolbar {
    left: 50%;
    top: auto;
    bottom: 68px;
    transform: translateX(-50%);
    flex-direction: row;
  }

  .toolbar-divider {
    width: 1px;
    height: 32px;
    margin: 0 4px;
  }

  .help-tooltip-box {
    top: 80px;
    right: 16px;
    max-width: calc(100vw - 32px);
  }
}

/* Top Right Help Tooltip Box */
.help-tooltip-box {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 50;
  width: 320px;
  background: var(--panel-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  padding: 12px 14px;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  font-family: var(--font-sans);
}

.help-tooltip-box:hover {
  border-color: var(--panel-border-hover);
}

.tooltip-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
}

.tooltip-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: 0.02em;
}

.tooltip-title svg {
  color: var(--accent-primary);
  flex-shrink: 0;
}

.tooltip-toggle-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--panel-border);
  color: var(--text-muted);
  border-radius: 6px;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.tooltip-toggle-btn:hover {
  background: rgba(255, 255, 255, 0.18);
  color: var(--text-main);
}

.tooltip-content {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.help-tooltip-box.collapsed {
  width: auto;
  padding: 8px 12px;
}

.help-tooltip-box.collapsed .tooltip-content {
  display: none;
}

.tooltip-desc {
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.45;
  border-bottom: 1px solid var(--panel-border);
  padding-bottom: 8px;
}

.tooltip-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tooltip-list li {
  font-size: 0.7rem;
  color: var(--text-main);
  line-height: 1.4;
  /* display: flex; */
  /* align-items: flex-start; */
  gap: 6px;
}

.tooltip-list li::before {
  /* content: "•"; */
  color: var(--accent-primary);
  font-size: 0.85rem;
  line-height: 1;
  margin-top: 1px;
}

.control-key {
  color: #60a5fa;
  font-weight: 600;
}