:root {
  --board: #242820;
  --board-deep: #1a1e18;
  --panel: #2e342c;
  --panel-2: #3a4136;
  --ink: #e8e4d8;
  --ink-soft: #a8a894;
  --copper: #d4894a;
  --copper-hot: #f0b060;
  --signal: #7ec27a;
  --signal-dim: #4a7a48;
  --wire-idle: #6a7164;
  --danger: #c45c4a;
  --line: rgba(200, 190, 160, 0.14);
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
  --font: "Outfit", "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --grid: rgba(180, 190, 150, 0.09);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  font-family: var(--font);
  background: var(--board-deep);
  color: var(--ink);
  user-select: none;
  -webkit-user-select: none;
}

body {
  overflow: hidden;
}

::selection {
  background: rgba(212, 137, 74, 0.35);
}

button {
  font: inherit;
}

#app {
  height: 100vh;
  width: 100vw;
}

.hidden {
  display: none !important;
}

/* —— Start screen —— */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}

.overlay.full-start-screen {
  flex-direction: column;
  align-items: stretch;
  padding: 48px clamp(20px, 5vw, 72px) 28px;
  background:
    radial-gradient(ellipse at 0% 0%, rgba(212, 137, 74, 0.12), transparent 42%),
    radial-gradient(ellipse at 100% 80%, rgba(90, 130, 80, 0.1), transparent 40%),
    linear-gradient(160deg, #1c211a, #242820 50%, #1a1e18);
  overflow-y: auto;
}

.welcome-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 24px;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto 28px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--line);
}

.welcome-header .eyebrow {
  margin: 0 0 4px;
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--copper);
}

.welcome-header h1 {
  margin: 0 0 8px;
  font-size: clamp(2.6rem, 7vw, 4.6rem);
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 0.95;
  color: var(--ink);
}

.welcome-header h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 400;
  color: var(--ink-soft);
}

.start-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.start-footer {
  max-width: 1100px;
  width: 100%;
  margin: 0 auto 20px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  color: var(--ink-soft);
  font-size: 0.88rem;
}

.ghost,
.text-button {
  background: transparent;
  border: 0;
  color: var(--ink-soft);
  cursor: pointer;
  padding: 10px 4px;
}

.ghost:hover,
.text-button:hover {
  color: var(--copper-hot);
}

.slot-grid.full-slot-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 16px;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  flex-grow: 1;
  align-content: start;
  padding-bottom: 32px;
}

.empty-projects {
  color: var(--ink-soft);
  padding: 40px;
  font-size: 0.95rem;
}

.slot.full-slot {
  flex: 0 1 260px;
  min-height: 132px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: rgba(46, 52, 44, 0.85);
  border: 1px solid var(--line);
  border-radius: 4px;
  cursor: pointer;
  transition: border-color 140ms ease, transform 140ms ease, background 140ms ease;
}

.slot.full-slot:hover {
  transform: translateY(-2px);
  border-color: rgba(212, 137, 74, 0.55);
  background: rgba(58, 65, 54, 0.95);
}

.slot .slot-main {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.slot .slot-main strong {
  font-size: 1.05rem;
}

.slot .slot-main span {
  color: var(--ink-soft);
  font-size: 0.78rem;
  font-family: var(--mono);
}

.slot-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
}

.slot-actions button {
  border: 1px solid var(--line);
  background: rgba(26, 30, 24, 0.7);
  color: var(--ink-soft);
  border-radius: 3px;
  padding: 6px 9px;
  font-size: 0.75rem;
  cursor: pointer;
}

.slot-actions button:hover {
  color: var(--ink);
  border-color: var(--copper);
}

button.tool-btn,
button.primary,
button.secondary,
.import-label,
.popup-btn {
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 600;
  letter-spacing: 0.02em;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}

button.primary,
.popup-btn.primary {
  background: var(--copper);
  border-color: #e09a58;
  color: #1a140e;
}

button.primary:hover,
.popup-btn.primary:hover {
  background: var(--copper-hot);
}

button.secondary,
.popup-btn.secondary,
button.tool-btn {
  background: rgba(46, 52, 44, 0.95);
  color: var(--ink);
}

button.tool-btn:hover,
button.secondary:hover,
.import-label:hover {
  border-color: rgba(212, 137, 74, 0.5);
}

button.tool-btn.active {
  background: rgba(126, 194, 122, 0.18);
  border-color: rgba(126, 194, 122, 0.55);
  color: #c8ecc4;
}

button.tool-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

/* —— Workspace —— */
.workspace {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.toolbar {
  height: 56px;
  padding: 8px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  background: rgba(26, 30, 24, 0.96);
  border-bottom: 1px solid var(--line);
}

.toolbar-group {
  display: flex;
  gap: 8px;
  align-items: center;
}

.project-title {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--ink-soft);
  margin-left: 6px;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.center-group .tool-btn {
  min-width: 56px;
  padding: 8px 10px;
  font-size: 0.82rem;
}

.layout {
  display: flex;
  flex: 1;
  min-height: 0;
  background: var(--board);
}

.viewport-container {
  flex: 1;
  overflow: hidden;
  position: relative;
  background:
    radial-gradient(ellipse at 50% 30%, rgba(70, 85, 55, 0.18), transparent 55%),
    var(--board);
}

.canvas-hint {
  position: absolute;
  left: 14px;
  bottom: 12px;
  z-index: 3;
  font-family: var(--mono);
  font-size: 0.68rem;
  color: rgba(168, 168, 148, 0.55);
  pointer-events: none;
}

.viewport {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  cursor: grab;
}

.viewport.dragging {
  cursor: grabbing;
}

.scene {
  position: absolute;
  left: 0;
  top: 0;
  width: 4000px;
  height: 3000px;
  transform-origin: 0 0;
}

.grid-layer {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 24px 24px;
}

.wires-layer,
.components-layer {
  position: absolute;
  inset: 0;
}

.components-layer {
  z-index: 2;
}

.wires-layer {
  overflow: visible;
  z-index: 1;
}

.wire-path {
  fill: none;
  stroke: var(--wire-idle);
  stroke-width: 2.4;
  stroke-linecap: round;
  transition: stroke 100ms ease, stroke-width 100ms ease;
}

.wire-path.active {
  stroke: var(--signal);
  stroke-width: 2.8;
}

.wire-path.byte-wire.active {
  stroke: var(--copper-hot);
}

.wire-path.selected {
  stroke: #f2d48a;
  stroke-width: 3.2;
}

.wire-path.draft {
  stroke: var(--copper);
  stroke-dasharray: 7 5;
  stroke-width: 2.2;
}

.wire-hit {
  fill: none;
  stroke: rgba(255, 255, 255, 0.01);
  stroke-width: 24;
  cursor: pointer;
  pointer-events: all;
}

.sidebar {
  width: 268px;
  padding: 14px 12px;
  background: rgba(30, 34, 28, 0.96);
  border-left: 1px solid var(--line);
  overflow-y: auto;
}

.sidebar-heading {
  margin: 0 4px 10px;
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.tool-groups {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tool-group {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: rgba(46, 52, 44, 0.55);
}

.tool-group h4 {
  margin: 0 0 8px;
  font-family: var(--mono);
  font-size: 0.65rem;
  letter-spacing: 0.14em;
  color: var(--ink-soft);
}

.tool-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.tool-item {
  border: 1px solid var(--line);
  border-left: 3px solid var(--tool-accent, var(--copper));
  border-radius: 3px;
  background: rgba(26, 30, 24, 0.75);
  color: var(--ink);
  min-height: 40px;
  padding: 6px 8px;
  font-size: 0.74rem;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
}

.tool-item:hover {
  border-color: rgba(212, 137, 74, 0.45);
  background: rgba(58, 65, 54, 0.9);
}

.tool-item.active {
  background: rgba(212, 137, 74, 0.22);
  border-color: var(--copper);
  color: #ffe6c8;
}

/* —— Components —— */
.component {
  position: absolute;
  min-width: 72px;
  min-height: 56px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 10px 12px;
  background: #30362c;
  border: 1px solid rgba(200, 190, 160, 0.22);
  border-left: 4px solid var(--block-color, var(--copper));
  border-radius: 3px;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.28);
  transition: border-color 100ms ease, box-shadow 100ms ease;
}

.component.selected {
  border-color: rgba(240, 176, 96, 0.85);
  box-shadow: 0 0 0 1px rgba(240, 176, 96, 0.45), 0 10px 22px rgba(0, 0, 0, 0.35);
}

.component-title {
  font-family: var(--mono);
  font-size: 0.62rem !important;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
  text-align: center;
  line-height: 1.2;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.import-label {
  display: inline-block;
}

.component-value {
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--copper-hot);
  text-align: center;
  white-space: pre-line;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.component-value.text-value {
  font-family: var(--font);
  font-size: 0.95rem;
  color: var(--ink);
  min-height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.component-meta {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  font-family: var(--mono);
  line-height: 1.15;
  max-width: 100%;
}

.component-meta .dec {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--copper-hot);
}

.component-meta .bin {
  font-size: 0.62rem;
  color: var(--ink-soft);
  letter-spacing: 0.06em;
}

.storage-meta { min-width: 104px; }
.decoder-meta { min-width: 96px; }
.decoder-state { display: flex; gap: 8px; font-family: var(--mono); font-size: 0.72rem; color: var(--ink-soft); }
.decoder-state .active { color: #d8f5d4; }
.type-mux .component-value { color: var(--copper-hot); }

.bit-strip {
  display: flex;
  gap: 2px;
  margin-top: 2px;
  max-width: 100%;
  flex-wrap: nowrap;
}

.bit-cell {
  width: 12px;
  height: 18px;
  padding: 0;
  border: 1px solid rgba(200, 190, 160, 0.28);
  border-radius: 2px;
  background: #1e221c;
  color: var(--ink-soft);
  font-family: var(--mono);
  font-size: 0.55rem;
  cursor: pointer;
}

.bit-cell.on {
  background: rgba(126, 194, 122, 0.28);
  border-color: var(--signal);
  color: #d8f5d4;
}

.bit-cell:disabled {
  cursor: default;
  opacity: 0.9;
}

.component.led-on {
  background: #2a4a32;
  border-color: var(--signal);
  box-shadow: 0 0 0 1px rgba(126, 194, 122, 0.4), 0 0 18px rgba(90, 160, 90, 0.35);
}

.component.led-on .component-title,
.component.led-on .component-value {
  color: #dff5dc;
}

.screen-component {
  padding: 0;
  min-width: 48px;
  min-height: 48px;
}

.screen-component .component-title {
  color: #f2f0e8;
}

.transparent-text-screen {
  background: transparent !important;
  border-color: transparent !important;
  box-shadow: none !important;
}

.transparent-text-screen .component-title {
  display: none;
}

.transparent-text-screen .component-value {
  color: #fff;
  font-size: 1.25rem;
  text-shadow: 0 2px 10px #000;
}

.pins {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.pin {
  position: absolute;
  width: 12px;
  height: 12px;
  margin-left: -6px;
  margin-top: -6px;
  border-radius: 50%;
  background: #1a1e18;
  border: 2px solid #8a907e;
  pointer-events: auto;
  cursor: crosshair;
  z-index: 4;
  transition: border-color 100ms ease, background 100ms ease, transform 100ms ease;
}

.pin:hover {
  transform: scale(1.2);
  border-color: var(--copper-hot);
}

.pin.hot {
  background: var(--signal-dim);
  border-color: var(--signal);
}

.pin.output.hot {
  background: var(--copper);
  border-color: var(--copper-hot);
}

.pin-label {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-family: var(--mono);
  font-size: 0.55rem;
  color: rgba(200, 190, 160, 0.7);
  pointer-events: none;
  white-space: nowrap;
}

.pin.output .pin-label {
  left: auto;
  right: 14px;
}

.type-byte-splitter .pin.output .pin-label,
.type-byte-merger .pin.input .pin-label {
  opacity: 0.85;
}

.selection-box {
  position: absolute;
  border: 1px dashed var(--copper);
  background: rgba(212, 137, 74, 0.08);
  pointer-events: none;
}

.context-menu {
  position: fixed;
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px;
  border-radius: 4px;
  background: #2e342c;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.context-menu button {
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  border-radius: 3px;
  padding: 8px 10px;
  text-align: left;
  cursor: pointer;
}

.context-menu button:hover {
  background: rgba(212, 137, 74, 0.15);
  border-color: var(--line);
}

/* —— Popups —— */
.popup-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(12, 14, 10, 0.72);
}

.popup-card {
  width: min(420px, 100%);
  padding: 22px;
  border-radius: 4px;
  background: #2e342c;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.popup-header h3 {
  margin: 0 0 6px;
  font-size: 1.2rem;
}

.popup-header p,
.popup-message {
  margin: 0;
  color: var(--ink-soft);
  line-height: 1.5;
}

.popup-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 14px;
}

.popup-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--ink-soft);
  font-size: 0.88rem;
}

.popup-field input {
  width: 100%;
  border-radius: 3px;
  border: 1px solid var(--line);
  background: #1a1e18;
  color: var(--ink);
  padding: 10px 12px;
  font-family: var(--mono);
}

.popup-field input[type='color'] {
  appearance: none;
  height: 48px;
  padding: 4px;
  cursor: pointer;
}

.popup-field input[type='color']::-webkit-color-swatch-wrapper {
  padding: 0;
}

.popup-field input[type='color']::-webkit-color-swatch {
  border: 0;
  border-radius: 2px;
}

.popup-checkbox {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.popup-checkbox input {
  accent-color: var(--copper);
  width: 16px;
  height: 16px;
}

.popup-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

.help-tips {
  margin-top: 16px;
  display: grid;
  gap: 8px;
  font-size: 0.88rem;
  color: var(--ink-soft);
}

.help-tips p {
  margin: 0;
}

.help-tips strong {
  color: var(--copper-hot);
  font-weight: 600;
}

.info-card {
  width: min(460px, 100%);
}

.info-links {
  display: grid;
  gap: 4px;
  margin-top: 18px;
}

.info-links a {
  display: flex;
  justify-content: space-between;
  padding: 12px 2px;
  color: var(--ink);
  text-decoration: none;
  border-bottom: 1px solid var(--line);
}

.info-links a:hover {
  color: var(--copper-hot);
}

/* —— Docs —— */
.document-page {
  min-height: 100vh;
  overflow: auto;
  user-select: text;
  -webkit-user-select: text;
  padding: 48px 20px;
  background:
    radial-gradient(ellipse at 10% 0%, rgba(212, 137, 74, 0.1), transparent 40%),
    var(--board-deep);
}

.document-shell {
  width: min(760px, 100%);
  margin: 0 auto;
  padding: clamp(26px, 5vw, 56px);
  background: rgba(46, 52, 44, 0.88);
  border: 1px solid var(--line);
  border-radius: 4px;
  box-shadow: var(--shadow);
}

.compact-document {
  max-width: 620px;
}

.back-link {
  color: var(--copper);
  text-decoration: none;
  font-weight: 600;
}

.document-shell .eyebrow {
  margin-top: 40px;
  color: var(--copper);
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.72rem;
  font-family: var(--mono);
}

.document-shell h1 {
  margin: 10px 0 14px;
  font-size: clamp(2.2rem, 6vw, 3.8rem);
  letter-spacing: -0.04em;
  line-height: 1;
}

.document-shell h2 {
  margin: 28px 0 8px;
  font-size: 1.05rem;
  color: #efe9d8;
}

.document-shell p,
.document-shell li {
  color: #b8b49e;
  line-height: 1.7;
}

.document-lead {
  font-size: 1.08rem;
  color: #d8d2c0 !important;
}

.draft-note {
  border-left: 3px solid var(--copper);
  padding-left: 14px;
}

.credit-name {
  font-size: 1.8rem;
  color: var(--ink) !important;
}

.release {
  margin-top: 36px;
  border-top: 1px solid var(--line);
  padding-top: 20px;
}

.release-version {
  color: var(--copper) !important;
  font-weight: 700;
}

.socials-shell {
  max-width: 820px;
}

.social-list {
  display: grid;
  gap: 12px;
  margin: 28px 0;
}

.social-card {
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 78px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--ink);
  text-decoration: none;
  background: rgba(36, 40, 32, 0.8);
}

.social-card:hover {
  border-color: rgba(212, 137, 74, 0.55);
}

.social-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  border-radius: 4px;
  color: #fff;
}

.social-icon svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.social-youtube .social-icon {
  background: #c43c32;
}

.social-tiktok .social-icon {
  background: #111;
}

.social-discord .social-icon {
  background: #5865f2;
}

.social-copy {
  display: grid;
  gap: 3px;
  flex: 1;
}

.social-copy strong {
  font-size: 1rem;
}

.social-copy small {
  color: var(--ink-soft);
  font-size: 0.82rem;
}

.social-arrow {
  color: var(--copper);
}

.mobile-sidebar-heading {
  display: none;
}

.mobile-app {
  overflow: auto;
  touch-action: manipulation;
}

.mobile-app .viewport,
.mobile-app .component,
.mobile-app .pin,
.mobile-app .tool-item,
.mobile-app button {
  touch-action: none;
}

@media (max-width: 900px) {
  .layout {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    height: 260px;
    border-left: none;
    border-top: 1px solid var(--line);
  }

  .toolbar {
    flex-wrap: wrap;
    height: auto;
  }

  .center-group {
    order: 3;
    width: 100%;
    justify-content: flex-start;
  }

  .start-footer {
    flex-direction: column;
  }
}

@media (max-width: 767px) {
  .mobile-app .overlay.full-start-screen {
    padding: 24px 14px 18px;
  }

  .mobile-app .welcome-header h1 {
    font-size: clamp(2rem, 11vw, 3rem);
  }

  .mobile-app .start-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
  }

  .mobile-app .start-actions .ghost {
    grid-column: 1 / -1;
  }

  .mobile-app .workspace {
    height: 100dvh;
  }

  .mobile-app .viewport-container {
    height: 56dvh;
  }

  .mobile-app .sidebar {
    height: 40dvh;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }

  .mobile-sidebar-heading {
    display: block;
    margin: 0 4px 8px;
    color: var(--ink-soft);
    font-size: 0.68rem;
    font-family: var(--mono);
    letter-spacing: 0.14em;
    text-transform: uppercase;
  }

  .mobile-app .tool-groups {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .mobile-app .tool-list {
    grid-template-columns: 1fr;
  }

  .mobile-app .pin {
    width: 15px;
    height: 15px;
    margin-left: -7px;
    margin-top: -7px;
  }

  .canvas-hint {
    display: none;
  }
}

@media (max-width: 560px) {
  .welcome-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .document-page {
    padding: 14px;
  }
}
