/* Look & feel borrowed from eniarof.com: flat yellow/cyan/magenta, Futura caps titles, Fira Sans text */
:root {
  --clr-main: 255, 238, 0;      /* yellow */
  --clr-contrast: 0, 232, 255;  /* cyan */
  --clr-pink: 255, 181, 232;
  --clr-magenta: #f0f;
  --font-title: futura-pt, Futura, Jost, sans-serif;
  --font-text: 'Fira Sans', sans-serif;
}
* { box-sizing: border-box; text-decoration: none; }
html, body { margin: 0; height: 100%; height: 100dvh; overscroll-behavior: none; font: 15px/1.4 var(--font-text); color: #000; }
body { display: grid; grid-template-columns: 300px 1fr; grid-template-rows: 56px 1fr; background: rgb(var(--clr-main)); }
button, select, input { font: inherit; color: #000; }

header {
  grid-column: 1 / 3; display: flex; align-items: center; gap: 10px; padding: 0 16px;
  background: linear-gradient(rgb(var(--clr-contrast)) 0, rgba(var(--clr-contrast), 0) 100%);
  z-index: 2;
}
header .logo {
  font: 800 26px var(--font-title); text-transform: uppercase; margin-right: 12px;
  text-shadow: 2px 1px 0 rgba(var(--clr-contrast), 1), 4px 2px 0 rgba(var(--clr-contrast), .7), 6px 3px 0 rgba(var(--clr-contrast), .4);
}
header label { display: flex; align-items: center; gap: 4px; }
header label::after { content: none; }
header .sep { width: 2px; height: 22px; background: #000; opacity: .25; }
#status { margin-left: auto; font-weight: 700; }

button, select, input:not([type=color]):not([type=checkbox]) {
  border: 0; border-radius: 1em; padding: 4px 14px; height: 30px; background: #fff; outline: none;
}
input[type=color] { border: 0; padding: 0; width: 30px; height: 30px; border-radius: 50%; background: none; cursor: pointer; }
button { font-family: var(--font-title); font-weight: 700; text-transform: uppercase; cursor: pointer; transition: background .2s, transform .2s; }
button:hover { background: rgb(var(--clr-pink)); transform: translateY(-1px); }
select { cursor: pointer; }
input:focus { box-shadow: 0 0 0 2px #000; }
header input#name { width: 150px; }

aside { display: flex; flex-direction: column; min-height: 0; }
#search { margin: 4px 16px 12px; width: calc(100% - 32px); }
#palette { overflow: auto; flex: 1; padding: 0 16px 16px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; align-content: start; }
.card {
  background: #fff; border: .3rem solid #fff; border-radius: .75em; padding: 2px; cursor: grab; text-align: center;
  font: 700 11px/1.2 var(--font-title); text-transform: uppercase; transition: transform .2s, box-shadow .2s;
}
.card:hover { transform: translateY(-2px); box-shadow: 4px 4px 0 rgb(var(--clr-contrast)); }
.card img { width: 100%; height: 70px; object-fit: contain; pointer-events: none; }
.card span { display: block; height: 26px; overflow: hidden; }

main { position: relative; min-width: 0; min-height: 0; margin: 0 16px 16px 0; border-radius: 1em; overflow: hidden; background: rgba(255, 255, 255, .55); }
#canvas { width: 100%; height: 100%; display: block; cursor: default; touch-action: none; user-select: none; -webkit-user-select: none; }
#canvas.panning { cursor: grabbing; }
.part { cursor: move; }
.part.selected > .outline { stroke: var(--clr-magenta); stroke-width: 2; stroke-dasharray: 5 3; fill: rgba(255, 0, 255, .07); }
.part .outline { fill: transparent; stroke: none; }
.pin { fill: transparent; stroke: none; cursor: crosshair; }
.pin:hover, .pin.target { fill: rgba(var(--clr-contrast), .6); stroke: #000; stroke-width: .6; }
.wire { pointer-events: none; fill: none; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.wire-shadow { fill: none; stroke: rgba(0, 0, 0, .28); stroke-width: 3.8; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
.wire-hit { fill: none; stroke: transparent; stroke-width: 8; cursor: pointer; }
.wire-end { stroke: rgba(0, 0, 0, .35); stroke-width: .8; pointer-events: none; }
.wire-sel { fill: none; stroke: var(--clr-magenta); stroke-width: 7; opacity: .35; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
.handle { fill: #fff; stroke: var(--clr-magenta); stroke-width: 1.6; }
.handle.ns { cursor: ns-resize; }
.handle.ew { cursor: ew-resize; }
#wire-preview { fill: none; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; opacity: .85; pointer-events: none; }

/* ---------- sticky notes ---------- */
.note-body {
  box-sizing: border-box; width: 100%; height: 100%; display: flex; flex-direction: column; gap: 4px;
  padding: 8px; border-radius: 2px 16px 2px 2px; box-shadow: 2px 4px 10px rgba(0, 0, 0, .28);
  font: 13px/1.35 var(--font-text); cursor: move; overflow: hidden;
}
.note.selected .note-body { box-shadow: 2px 4px 10px rgba(0, 0, 0, .28), 0 0 0 2px var(--clr-magenta); }
.note.editing .note-body { cursor: text; }
.note-text {
  flex: 1; width: 100%; resize: none; border: 0; outline: none; background: transparent; font: inherit; color: #000;
  pointer-events: none; padding: 0; overflow: auto;
}
.note.editing .note-text { pointer-events: auto; }
.note-resize-hit { fill: transparent; cursor: nwse-resize; opacity: 0; pointer-events: none; }
.note-resize { fill: #fff; stroke: var(--clr-magenta); stroke-width: 1.6; opacity: 0; pointer-events: none; }
.note.selected .note-resize-hit { pointer-events: auto; }
.note.selected .note-resize { opacity: 1; }
#tip { position: absolute; pointer-events: none; background: #000; color: rgb(var(--clr-main)); padding: 3px 10px; border-radius: 1em; font-size: 12px; white-space: nowrap; }
#swatches { display: flex; gap: 4px; }
button.sw { width: 18px; height: 18px; padding: 0; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.35); }
button.sw:hover { transform: scale(1.2); background-blend-mode: normal; }
button.sw.on { box-shadow: 0 0 0 2px #000; }

.only-narrow, #scrim { display: none; }
header { overflow-x: auto; scrollbar-width: none; white-space: nowrap; }
header::-webkit-scrollbar { display: none; }
header > * { flex: none; }

/* touch screens: fatter pin targets (the pitch is only 9 px, the extra stroke stays under half of it) */
@media (pointer: coarse) {
  .pin { stroke: rgba(0, 0, 0, .001); stroke-width: 5; }
  .handle { r: 8; }
  .wire-hit { stroke-width: 16; }
  button, select, input:not([type=color]):not([type=checkbox]) { height: 38px; }
  button.sw { width: 26px; height: 26px; }
}

/* tablets and phones: the parts list becomes a slide-in drawer */
@media (max-width: 860px) {
  body { grid-template-columns: 1fr; grid-template-rows: 56px 1fr; }
  .only-narrow { display: inline-block; }
  header { padding: 0 10px; gap: 8px; }
  header .logo { display: none; }
  header input#name { width: 120px; }
  #status { display: none; }
  aside {
    position: fixed; z-index: 20; top: 56px; bottom: 0; left: 0; width: min(340px, 88vw);
    background: rgb(var(--clr-main)); box-shadow: 4px 0 24px rgba(0, 0, 0, .3);
    transform: translateX(-105%); transition: transform .2s ease-out;
    padding-bottom: env(safe-area-inset-bottom);
  }
  body.parts-open aside { transform: none; }
  body.parts-open #scrim { display: block; position: fixed; z-index: 10; inset: 56px 0 0 0; background: rgba(0, 0, 0, .25); }
  main { margin: 0; border-radius: 0; grid-column: 1; }
  #palette { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  #tip { display: none; }
}
@media (max-width: 480px) {
  #palette { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  header { gap: 6px; }
  button { padding: 4px 10px; }
}
@media (max-height: 480px) and (orientation: landscape) {
  body { grid-template-rows: 46px 1fr; }
  header { height: 46px; }
  aside { top: 46px; }
  body.parts-open #scrim { inset: 46px 0 0 0; }
}

.credit { margin: 0; padding: 6px 16px 8px; font-size: 11px; line-height: 1.3; opacity: .75; }
.credit a { text-decoration: underline; }
