:root {
  --bg: #050508;
  --panel-bg: #0d0e14;
  --border: #2a2d3d;
  --text: #e6e8f0;
  --muted: #8b92a8;
  --gold: #d9d014;
  --orange: #ff8c00;
  --purple: #8b1df3;
  --blue: #1d2cf3;
  --cyan: #00f0ff;
}

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

body {
  background-color: var(--bg);
  color: var(--text);
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  height: 100vh;
  height: 100dvh; /* Accounts for mobile browser URL bars */
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Top EDA Toolbar */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  background: var(--panel-bg);
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
  z-index: 10;
}

.status-badge {
  color: var(--cyan);
  border: 1px solid rgba(0, 240, 255, 0.3);
  padding: 3px 8px;
  border-radius: 3px;
  font-size: 0.75rem;
  white-space: nowrap;
}

/* Main Workspace */
main {
  flex: 1;
  display: flex;
  position: relative;
  overflow: hidden;
}

.chip-viewport {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: radial-gradient(circle at center, #0e101a 0%, #050508 100%);
  overflow: hidden;
}

svg#die {
  height: 100%;
  max-height: 86vh;
  width: auto;
  max-width: 100%;
  filter: drop-shadow(0 0 25px rgba(217, 208, 20, 0.08));
  touch-action: manipulation;
}

/* Interactive Macro Blocks */
.macro {
  cursor: pointer;
  outline: none;
  transition: transform 0.15s ease, filter 0.15s ease;
}

@media (hover: hover) {
  .macro:hover rect.macro-body {
    stroke: var(--cyan);
    stroke-width: 4;
    filter: brightness(1.15);
  }

  .io-pad:hover rect {
    fill: var(--cyan);
  }

  .io-pad:hover text {
    fill: #050508;
  }
}

.macro:focus-visible rect.macro-body {
  stroke: var(--cyan);
  stroke-width: 4;
  filter: brightness(1.15);
}

.macro.active rect.macro-body {
  stroke: #ffffff;
  stroke-width: 5;
}

.macro text,
.io-pad text {
  pointer-events: none;
  user-select: none;
}

/* Interactive I/O Pads */
.io-pad {
  cursor: pointer;
  outline: none;
}

.io-pad:focus-visible rect {
  fill: var(--cyan);
}

.io-pad:focus-visible text {
  fill: #050508;
}

/* Mobile Backdrop Dimmer */
.drawer-backdrop {
  display: none;
}

/* Slide-out Inspector Drawer */
aside#inspector {
  width: 450px;
  max-width: 100%;
  background: var(--panel-bg);
  border-left: 1px solid var(--border);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  z-index: 30;
}

aside#inspector.hidden {
  display: none;
}

.inspector-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px;
}

.inspector-meta {
  font-size: 0.75rem;
  color: var(--gold);
  margin-bottom: 4px;
}

.close-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 12px;
  min-width: 44px;
  min-height: 36px;
  cursor: pointer;
  font-family: inherit;
  border-radius: 3px;
}

.close-btn:hover,
.close-btn:focus-visible {
  border-color: var(--cyan);
  color: var(--cyan);
  outline: none;
}

.card {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  padding: 14px;
  border-radius: 4px;
  margin-bottom: 12px;
}

.card h3 {
  font-size: 0.95rem;
  color: var(--cyan);
  margin-bottom: 4px;
}

.card-meta {
  font-size: 0.75rem;
  color: var(--gold);
  margin-bottom: 8px;
}

.card ul {
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.card li,
.card p {
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--muted);
  overflow-wrap: break-word;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.tag {
  font-size: 0.7rem;
  background: rgba(139, 29, 243, 0.2);
  border: 1px solid var(--purple);
  color: #d8b4fe;
  padding: 2px 7px;
  border-radius: 2px;
}

/* Bottom Coordinate Bar */
footer {
  padding: 8px 20px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
  background: var(--panel-bg);
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  gap: 8px;
  z-index: 10;
}

/* Mobile & Tablet Responsive Overrides */
@media (max-width: 820px) {
  header {
    padding: 8px 12px;
    font-size: 0.75rem;
    flex-wrap: wrap;
  }

  .header-subtitle {
    display: block;
    font-size: 0.68rem;
    color: var(--muted);
  }

  .chip-viewport {
    padding: 8px;
  }

  svg#die {
    width: 100%;
    height: 100%;
    max-height: 100%;
    object-fit: contain;
  }

  .drawer-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(5, 5, 8, 0.72);
    backdrop-filter: blur(2px);
    z-index: 20;
  }

  .drawer-backdrop.hidden {
    display: none;
  }

  aside#inspector {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 72dvh;
    max-height: 82dvh;
    padding: 18px 16px calc(20px + env(safe-area-inset-bottom));
    border-left: none;
    border-top: 2px solid var(--cyan);
    border-radius: 12px 12px 0 0;
    box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.8);
  }

  footer {
    padding: 6px 12px calc(6px + env(safe-area-inset-bottom));
    font-size: 0.68rem;
  }
}