/* Virtual MacroPad (assets/js/macropad-sim.js): 3D wireframe model */
.mp-sim {
  margin: 1.5rem 0 2rem; container-type: inline-size;
  --wire: color-mix(in srgb, var(--accent) 60%, transparent);
  --wire-dim: color-mix(in srgb, var(--accent) 30%, transparent);
}
.mp-wrap { position: relative; display: grid; grid-template-columns: 1fr; gap: 1rem; }
@container (min-width: 760px) { .mp-wrap { grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); align-items: start; } }
.mp-left { min-width: 0; --u: clamp(50px, 18.5cqi, 82px); }
@container (min-width: 760px) { .mp-left { --u: clamp(50px, 10cqi, 82px); } }

/* stage + model */
.mp-stage {
  position: relative; height: calc(var(--u) * 6.1); display: flex; align-items: center; justify-content: center;
  perspective: calc(var(--u) * 17); overflow: hidden; outline: none; border-radius: 10px;
  user-select: none; -webkit-user-select: none; touch-action: manipulation;
}
.mp-stage:focus-visible { box-shadow: 0 0 0 1px var(--accent); }
.mp3d {
  --rx: 26deg; --rz: 0deg; --ex: 0; --sc: 1; --ty: 0;
  position: relative; flex: none; width: calc(var(--u) * 3.6); height: calc(var(--u) * 5.7);
  transform-style: preserve-3d; transform: translateY(calc(var(--u) * var(--ty))) scale(var(--sc)) rotateX(var(--rx)) rotateZ(var(--rz));
  transition: transform 0.7s cubic-bezier(.3, .7, .2, 1);
}
.mp3d.exploded { --rx: 56deg; --rz: -30deg; --ex: 1; --sc: 0.7; --ty: 0.9; }
.ly { position: absolute; inset: 0; transform-style: preserve-3d; transition: transform 0.7s cubic-bezier(.3, .7, .2, 1); }
.ly-sw  { transform: translateZ(calc(var(--u) * (0.1 + var(--ex) * 1.3))); }
.ly-cap { transform: translateZ(calc(var(--u) * (0.32 + var(--ex) * 2.6))); }

/* generic solid: side faces are SVG polygons (so tapered edges keep their outline), top face is a div */
.bx {
  --line: var(--wire); --face: transparent; --topc: var(--face);
  position: absolute; left: calc(var(--u) * var(--x)); top: calc(var(--u) * var(--y));
  width: calc(var(--u) * var(--w)); height: calc(var(--u) * var(--d));
  transform-style: preserve-3d; transform: translateZ(calc(var(--u) * var(--z)));
  transition: transform 0.08s;
}
.bx > .f { position: absolute; pointer-events: none; }
.bx > .f > svg { display: block; width: 100%; height: 100%; overflow: visible; }
.bx > .f polygon { fill: var(--face); stroke: var(--line); stroke-width: 1; vector-effect: non-scaling-stroke; stroke-linejoin: round; pointer-events: visiblePainted; }
.bx > .f-top { box-sizing: border-box; border: 1px solid var(--line); background: var(--topc); pointer-events: auto; }
.ring { position: absolute; box-sizing: border-box; border-radius: 50%; pointer-events: none; }

/* PCB */
.pcb { --face: rgba(12, 18, 28, 0.55); --topc: rgba(10, 15, 24, 0.82); }
.pcb > .f-top { border-radius: calc(var(--u) * 0.08); }
.pcb .f-top > span { position: absolute; box-sizing: border-box; left: calc(var(--u) * var(--x)); top: calc(var(--u) * var(--y)); width: calc(var(--u) * var(--w)); height: calc(var(--u) * var(--d)); }
.pcb .sock { border: 1px dashed var(--wire-dim); border-radius: 3px; }
.pcb .led { border: 1px solid var(--wire); background: var(--led); }
.pcb .led.off { background: transparent; }
.pcb .usb { border: 1px solid var(--wire); border-radius: 3px; }
.pcb .enc { border: 1px solid var(--wire-dim); border-radius: 50%; }
.pcb .silk { left: calc(var(--u) * 0.3) !important; top: auto !important; bottom: calc(var(--u) * 0.1); width: auto !important; height: auto !important;
  font-family: var(--mono); font-size: calc(var(--u) * 0.12); color: var(--text3); letter-spacing: 0.06em; white-space: nowrap; }

/* OLED module */
.oled { --face: rgba(14, 16, 22, 0.9); --topc: #05060a; }
.oled .screen { position: absolute; inset: 7% 5%; background: #000; display: flex; flex-direction: column; font-family: var(--mono); color: #fff; overflow: hidden; }
.oled .o-title { background: #fff; color: #000; font-size: calc(var(--u) * 0.13); line-height: calc(var(--u) * 0.17); text-align: center; white-space: nowrap; overflow: hidden; }
.oled .o-labels { flex: 1; display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(4, 1fr); }
.oled .o-labels span { font-size: calc(var(--u) * 0.115); line-height: 1; display: flex; align-items: center; justify-content: center; white-space: nowrap; overflow: hidden; }

/* switches: MX-style, one wire color */
.swg { position: absolute; inset: 0; transform-style: preserve-3d; pointer-events: none; }
.sw { --line: var(--wire); --face: rgba(10, 16, 26, 0.35); --topc: rgba(10, 16, 26, 0.35); }
.sw.stem, .sw.stem-body { --line: color-mix(in srgb, var(--accent) 85%, #fff); --face: color-mix(in srgb, var(--accent) 16%, transparent); --topc: var(--face); }
.sw-ring { border: 1.5px solid var(--wire); }
.sw-hole { position: absolute; left: 50%; top: 50%; width: 40%; height: 40%; transform: translate(-50%, -50%);
  background: linear-gradient(var(--wire), var(--wire)) 50% 0 / 30% 100% no-repeat, linear-gradient(var(--wire), var(--wire)) 0 50% / 100% 30% no-repeat; opacity: 0.35; }

/* keycaps: tapered sides, dished top, real cap colors, no glow */
.cap { cursor: pointer; outline: none; touch-action: none; }
.cap-orange { --topc: #f7a31e; --face: rgba(196, 118, 8, 0.96); --line: #ffd48a; }
.cap-black  { --topc: #2a2d38; --face: rgba(19, 21, 28, 0.96); --line: #7d8aa3; }
.cap-red    { --topc: #ef2a50; --face: rgba(152, 18, 44, 0.96); --line: #ffa0b3; }
.cap > .f-top { border-radius: calc(var(--u) * 0.05); background: radial-gradient(ellipse 70% 70% at 50% 46%, color-mix(in srgb, var(--topc) 78%, #000) 0%, var(--topc) 72%); }
.cap > .f-top::after { content: ''; position: absolute; inset: 10%; border-radius: 40%; border: 1px solid color-mix(in srgb, var(--line) 35%, transparent); }
.cap.detail { --face: rgba(196, 118, 8, 0.45); }
.cap.detail > .f-top { opacity: 0.85; }
.socket { --line: #ffd48a; --face: rgba(196, 118, 8, 0.3); --topc: rgba(196, 118, 8, 0.3); }
.socket-x { --line: #3b2408; --face: rgba(30, 18, 4, 0.85); --topc: rgba(30, 18, 4, 0.9); }
.cap-label { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-family: var(--mono); font-size: calc(var(--u) * 0.13); white-space: nowrap; pointer-events: none; }
.cap-orange .cap-label { color: rgba(70, 36, 0, 0.75); }
.cap-black  .cap-label { color: rgba(220, 232, 245, 0.7); }
.cap-red    .cap-label { color: rgba(80, 0, 14, 0.75); }
.cap.down { transform: translateZ(calc(var(--u) * -0.13)); }
.cap.latched > .f-top { box-shadow: inset 0 0 0 2px #fff; }
.cap.latched > .f-top::before { content: 'held'; position: absolute; top: 4%; right: 6%; font-family: var(--mono); font-size: calc(var(--u) * 0.08); color: #fff; }
.cap:focus-visible > .f-top { box-shadow: inset 0 0 0 2px var(--accent); }

/* knob: a cylinder built from side panels */
.knob { position: absolute; left: calc(var(--u) * var(--x)); top: calc(var(--u) * var(--y)); width: 0; height: 0; transform-style: preserve-3d; cursor: ew-resize; outline: none; touch-action: none; }
.knob > i { position: absolute; box-sizing: border-box; }
.kpanel { left: calc(var(--u) * var(--pw) / -2); top: 0; width: calc(var(--u) * var(--pw)); height: calc(var(--u) * var(--kh));
  transform-origin: 50% 0; transform: rotateZ(var(--a)) translateY(calc(var(--u) * var(--r))) rotateX(90deg);
  background: rgba(58, 60, 68, 0.9); border-left: 1px solid rgba(170, 180, 200, 0.45); }
.kbase, .ktop { left: calc(var(--u) * var(--r) * -1); top: calc(var(--u) * var(--r) * -1); width: calc(var(--u) * var(--r) * 2); height: calc(var(--u) * var(--r) * 2); border-radius: 50%; }
.kbase { border: 1px solid var(--wire-dim); }
.ktop { background: radial-gradient(circle at 40% 35%, #7d808a, #33353c); border: 1px solid rgba(190, 200, 220, 0.6);
  transform: translateZ(calc(var(--u) * var(--kh))) rotate(var(--rot, 0deg)); transition: transform 0.12s; }
.knob.down .ktop { transform: translateZ(calc(var(--u) * (var(--kh) - 0.08))) rotate(var(--rot, 0deg)); }
.kind { position: absolute; left: 50%; top: 8%; width: 3px; height: 26%; margin-left: -1.5px; border-radius: 2px; background: #e8ecf2; }
.knob:focus-visible .ktop { box-shadow: 0 0 0 2px var(--accent); }

/* explore mode */
.mp-stage.exploring .bx, .mp-stage.exploring .knob { cursor: zoom-in; }
.mp3d[data-hl="pcb"] .pcb, .mp3d[data-hl="pcb"] .oled, .mp3d[data-hl="switches"] .sw { --line: #fff; }
.mp3d[data-hl="switches"] .sw-ring { border-color: #fff; }
.mp3d[data-hl="keycaps"] .cap > .f-top { box-shadow: inset 0 0 0 2px #fff; }
.mp3d[data-hl="pcb"] .ktop { box-shadow: 0 0 0 2px #fff; }

/* toolbar */
.mp-tools { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 0.5rem; }
.mp-btn { font-family: var(--mono); font-size: 11px; letter-spacing: 0.04em; padding: 7px 11px; border-radius: 4px; border: 1px solid var(--border2); background: var(--bg2); color: var(--text2); cursor: pointer; touch-action: manipulation; user-select: none; }
.mp-btn:hover { border-color: var(--accent); color: var(--accent); }
.mp-btn[aria-pressed="true"] { border-color: var(--accent); color: var(--bg); background: var(--accent); }
.mp-parts { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 0.6rem; }
.mp-parts[hidden] { display: none; }

/* text box + log */
.mp-side { min-width: 0; display: flex; flex-direction: column; gap: 0.75rem; }
.mp-field-wrap { background: var(--bg2); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.mp-field-head { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; padding: 6px 10px; background: var(--bg3); border-bottom: 1px solid var(--border); font-family: var(--mono); font-size: 11px; color: var(--text3); }
.mp-toggles { display: flex; gap: 6px; }
.mp-chip { font-family: var(--mono); font-size: 10.5px; padding: 3px 9px; border-radius: 3px; border: 1px solid var(--border2); background: transparent; color: var(--text3); cursor: pointer; }
.mp-chip:hover { color: var(--accent); border-color: var(--accent); }
.mp-chip[aria-pressed="true"], .mp-chip.on { color: var(--accent); border-color: var(--accent); }
.mp-field { cursor: text; font-family: var(--mono); font-size: 18px; color: var(--text); padding: 12px; min-height: 52px; white-space: pre-wrap; word-break: break-all; }
.mp-text.sel { background: color-mix(in srgb, var(--accent) 45%, transparent); }
.mp-caret { display: inline-block; width: 2px; height: 1.1em; vertical-align: text-bottom; background: var(--accent); animation: blink 1.1s step-end infinite; }
.mp-field.flash { animation: mp-flash 0.5s; }
@keyframes mp-flash { 0% { background: color-mix(in srgb, var(--accent) 25%, transparent); } 100% { background: transparent; } }
.mp-log { height: 168px; overflow-y: auto; background: var(--bg2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-family: var(--mono); font-size: 11.5px; line-height: 1.7; color: var(--text2); }
.mp-log .k { display: inline-block; padding: 0 5px; border: 1px solid var(--border2); border-radius: 3px; line-height: 1.4; color: var(--text); }
.mp-log .v { color: var(--accent); }
.mp-log .key { color: var(--text); }
.mp-log .dim { color: var(--text3); }
.mp-help { font-family: var(--mono); font-size: 11px; line-height: 1.8; color: var(--text3); }
.mp-help b { color: var(--text2); font-weight: 400; }

/* AutoHotkey tolerance box */
.mp-ahk { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,0.55); border-radius: 10px; z-index: 5; }
.mp-ahk[hidden] { display: none; }
.mp-ahk-box { background: #f0f0f0; color: #111; border: 1px solid #999; width: min(280px, 92%); font-family: 'Segoe UI', system-ui, sans-serif; box-shadow: 0 10px 40px rgba(0,0,0,0.6); }
.mp-ahk-bar { background: #fff; padding: 6px 10px; font-size: 12px; border-bottom: 1px solid #ccc; display: flex; justify-content: space-between; }
.mp-ahk-bar span { color: #888; font-size: 11px; }
.mp-ahk-in { display: block; width: calc(100% - 20px); margin: 10px; font-size: 22px; padding: 4px 6px; border: 1px solid #7a7a7a; font-family: inherit; }
.mp-ahk-in.bad { border-color: #d22; background: #fff0f0; }
.mp-ahk-hint { font-size: 11px; color: #444; padding: 0 10px; line-height: 1.5; }
.mp-ahk-btns { display: flex; gap: 6px; justify-content: flex-end; padding: 10px; }
.mp-ahk-btns button { font: inherit; font-size: 12px; padding: 3px 14px; border: 1px solid #888; background: #e6e6e6; cursor: pointer; }

/* enlarged part view */
body.mp-ov-open { overflow: hidden; }
.mp-ov {
  --wire: color-mix(in srgb, var(--accent) 60%, transparent); --wire-dim: color-mix(in srgb, var(--accent) 30%, transparent);
  position: fixed; inset: 0; z-index: 300; background: var(--bg);
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(260px, 380px);
}
.mp-ov-stage { --u: clamp(52px, 11vmin, 120px); position: relative; display: flex; align-items: center; justify-content: center; perspective: calc(var(--u) * 18); overflow: hidden; cursor: grab; touch-action: none; }
.mp-ov-stage:active { cursor: grabbing; }
.ov-model { transition: none; }
.ov-model.part-switches, .ov-model.part-keycaps { --u: clamp(150px, 30vmin, 300px); width: var(--u); height: var(--u); }
.ov-model.part-switches { --u: clamp(110px, 21vmin, 220px); --ty: 0.75; }
.mp-ov-hint { position: absolute; bottom: 1rem; left: 0; right: 0; text-align: center; font-family: var(--mono); font-size: 11px; color: var(--text3); letter-spacing: 0.08em; pointer-events: none; }
.mp-ov-info { background: var(--bg2); border-left: 1px solid var(--border); padding: 1.5rem; overflow-y: auto; }
.mp-ov-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 1rem; padding-bottom: 0.75rem; border-bottom: 1px solid var(--border); }
.mp-ov-head span { font-family: var(--mono); font-size: 13px; color: var(--accent); letter-spacing: 0.1em; text-transform: uppercase; }
.mp-ov-close { font-family: var(--mono); font-size: 12px; color: var(--text3); background: none; border: 0; cursor: pointer; }
.mp-ov-close:hover { color: var(--text); }
.mp-ov-info p { font-size: 14px; line-height: 1.75; color: var(--text2); margin-bottom: 0.9rem; }
.mp-ov-next { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 1.25rem; }
@media (max-width: 700px) {
  .mp-ov { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1.1fr) minmax(0, 1fr); }
  .mp-ov-info { border-left: 0; border-top: 1px solid var(--border); }
  .mp-ov-stage { --u: clamp(40px, 8vh, 80px); }
}
