/* ==========================================================================
   sim3d.css — realistic 3D workbench (v10)
   Glass panels float over the scene; they stay readable on light and dark environments.
   ========================================================================== */
.sim3d-view { position: absolute; inset: 0; display: none; z-index: 100; overflow: hidden; font-family: var(--font, system-ui, sans-serif); background: #0E1116; }
.app[data-panel="sim3d"] .sim3d-view { display: flex !important; }
.app[data-panel="sim3d"] .right-panel, .app[data-panel="sim3d"] #splitRight, .app[data-panel="sim3d"] .side-panel,
.app[data-panel="sim3d"] #splitLeft, .app[data-panel="sim3d"] #dock, .app[data-panel="sim3d"] #btnRevealRight,
.app[data-panel="sim3d"] #tbUndoGroup { display: none !important; }

.s3 { --acc: #F37A33; --glass: rgba(18, 22, 29, .84); --glass2: rgba(255, 255, 255, .06); --line: rgba(255, 255, 255, .1); --tx: #E8ECF1; --mut: #98A2AF;
  display: flex; flex-direction: column; width: 100%; height: 100%; color: var(--tx); }
.s3 button { font: inherit; color: inherit; cursor: pointer; }
.s3 svg { width: 16px; height: 16px; flex: none; }

/* ---------- toolbar */
.s3-bar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: #151A21; border-bottom: 1px solid #222A35; flex-wrap: wrap; z-index: 5; }
.s3-bar-l, .s3-bar-r { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.s3-bar-l { flex: 1; min-width: 0; } .s3-bar-r { flex: 1; justify-content: flex-end; }
.s3-bar-c { display: flex; gap: 6px; }
.s3-badge { display: inline-flex; align-items: center; gap: 7px; padding: 6px 11px; border-radius: 9px; background: rgba(243, 122, 51, .14); color: #FFB27F; font-size: 13px; white-space: nowrap; }
.s3-select { background: #1E252F; color: var(--tx); border: 1px solid #2C3644; border-radius: 9px; padding: 6px 10px; font-size: 13px; max-width: 220px; }
.s3-btn { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 11px; border-radius: 9px; border: 1px solid #2C3644; background: #1E252F; font-size: 12.5px; font-weight: 600; transition: background .15s, border-color .15s, color .15s; white-space: nowrap; }
.s3-btn:hover:not(:disabled) { background: #263040; border-color: #3A475A; }
.s3-btn.on { border-color: var(--acc); color: #FFB27F; background: rgba(243, 122, 51, .12); }
.s3-btn:disabled { opacity: .45; cursor: default; }
.s3-btn.s3-run:not(:disabled) { background: var(--acc); border-color: var(--acc); color: #fff; }
.s3-btn.s3-icon { width: 32px; padding: 0; justify-content: center; }
.s3-seg { display: inline-flex; border: 1px solid #2C3644; border-radius: 9px; overflow: hidden; }
.s3-seg button { height: 30px; padding: 0 10px; background: #1E252F; border: 0; border-right: 1px solid #2C3644; font-size: 12px; font-weight: 600; }
.s3-seg button:last-child { border-right: 0; } .s3-seg button:hover { background: #263040; }

/* ---------- stage */
.s3-stage { position: relative; flex: 1; min-height: 0; overflow: hidden; outline: none; }
.s3-canvas { position: absolute; inset: 0; width: 100% !important; height: 100% !important; display: block; touch-action: none; }
.s3-labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.s3-label { position: absolute; left: 0; top: 0; pointer-events: auto; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 4px 9px 5px; border-radius: 9px; border: 1px solid rgba(255, 255, 255, .12);
  background: rgba(14, 18, 24, .72); backdrop-filter: blur(6px); color: #fff; font-size: 11px; line-height: 1.2; white-space: nowrap; box-shadow: 0 4px 14px rgba(0, 0, 0, .25); }
.s3-label b { font-weight: 700; font-size: 11.5px; } .s3-label span { color: #B9C3CF; font-size: 10.5px; font-family: var(--mono, monospace); }
.s3-label span:empty { display: none; }
.s3-label::after { content: ''; position: absolute; bottom: -5px; left: 50%; width: 8px; height: 8px; transform: translateX(-50%) rotate(45deg); background: inherit; border-right: 1px solid rgba(255, 255, 255, .12); border-bottom: 1px solid rgba(255, 255, 255, .12); }
.s3-label.active { border-color: rgba(60, 220, 120, .7); } .s3-label.active b::before { content: '● '; color: #3CE07A; }
.s3-label.sel { border-color: var(--acc); background: rgba(40, 24, 14, .82); }
.s3-tip { position: absolute; left: 0; top: 0; pointer-events: none; max-width: 300px; padding: 6px 10px; border-radius: 8px; background: rgba(12, 15, 20, .92); color: #fff; font-size: 12px; line-height: 1.35; opacity: 0; transition: opacity .12s; z-index: 6; }
.s3-tip.show { opacity: 1; } .s3-tip em { color: #FFB27F; font-style: normal; font-family: var(--mono, monospace); margin-left: 4px; }
.s3-status { position: absolute; left: 12px; top: 12px; display: flex; align-items: center; gap: 8px; padding: 6px 11px; border-radius: 9px; background: var(--glass); backdrop-filter: blur(8px); font-size: 12px; color: #CFD6DE; pointer-events: none; z-index: 2; }
.s3-status kbd { font: 600 10.5px var(--mono, monospace); padding: 0 4px; border-radius: 4px; background: rgba(255,255,255,.14); color: #fff; }
.s3-status i { width: 8px; height: 8px; border-radius: 50%; background: #6B7480; } .s3-status i.on { background: #3CE07A; box-shadow: 0 0 8px #3CE07A; }

/* on-screen navigation pad */
.s3-nav { position: absolute; left: 12px; bottom: calc(var(--dockH, 0px) + 12px); display: grid; grid-template-columns: repeat(3, 30px); grid-template-rows: repeat(3, 30px); gap: 3px; padding: 6px; border-radius: 12px; background: var(--glass); backdrop-filter: blur(8px); transition: bottom .2s; }
.s3-nav button { border: 0; border-radius: 7px; background: var(--glass2); font-size: 12px; }
.s3-nav button:hover { background: rgba(243, 122, 51, .3); }
.s3-nav [data-nav="up"] { grid-column: 2; } .s3-nav [data-nav="left"] { grid-column: 1; grid-row: 2; } .s3-nav [data-nav="home"] { grid-column: 2; grid-row: 2; } .s3-nav [data-nav="right"] { grid-column: 3; grid-row: 2; } .s3-nav [data-nav="down"] { grid-column: 2; grid-row: 3; }
.s3-zoom { position: absolute; left: calc(100% + 6px); bottom: 0; display: flex; flex-direction: column; gap: 3px; padding: 6px; border-radius: 12px; background: var(--glass); }
.s3-zoom button { width: 30px; height: 30px; font-size: 15px; }

/* help card */
.s3-help { position: absolute; left: 50%; top: 14px; transform: translate(-50%, -12px); width: min(560px, 90%); padding: 14px 18px 12px; border-radius: 14px; background: var(--glass); backdrop-filter: blur(10px); font-size: 12.5px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 7; }
.s3-help.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.s3-help h4 { margin: 0 0 8px; font-size: 13px; color: #FFB27F; }
.s3-help dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0; }
.s3-help dt { color: #fff; font-weight: 700; } .s3-help dd { margin: 0; color: #C6CED8; }
.s3-x { position: absolute; right: 8px; top: 8px; border: 0; background: none; color: #98A2AF; font-size: 14px; }

/* ---------- side panel */
.s3-panel { position: absolute; right: 12px; top: 12px; bottom: calc(var(--dockH, 0px) + 12px); width: 318px; display: flex; flex-direction: column; border-radius: 14px; background: var(--glass); backdrop-filter: blur(12px); border: 1px solid var(--line); box-shadow: 0 18px 40px rgba(0, 0, 0, .3); transition: transform .25s, opacity .25s, bottom .2s; z-index: 4; }
.s3.no-panel .s3-panel { transform: translateX(340px); opacity: 0; pointer-events: none; }
.s3-tabs { display: flex; padding: 6px; gap: 4px; border-bottom: 1px solid var(--line); }
.s3-tabs button { flex: 1; height: 30px; border: 0; border-radius: 8px; background: none; font-size: 12.5px; font-weight: 700; color: var(--mut); }
.s3-tabs button.active { background: rgba(243, 122, 51, .16); color: #FFB27F; }
.s3-panel-body { flex: 1; overflow: auto; padding: 4px 14px 14px; font-size: 12.5px; }
.s3-panel-body section { padding: 10px 0; border-bottom: 1px solid var(--line); } .s3-panel-body section:last-child { border-bottom: 0; }
.s3-panel-body h3 { margin: 2px 0 2px; font-size: 15px; } .s3-panel-body h4 { margin: 0 0 8px; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--mut); }
.s3-muted { color: var(--mut); margin: 4px 0; line-height: 1.45; } .s3-small { font-size: 11.5px; }
.s3-reading { margin: 6px 0 0; padding: 6px 9px; border-radius: 8px; background: rgba(0, 0, 0, .25); font-family: var(--mono, monospace); font-size: 12px; color: #9EF0B9; }
.s3-reading:empty { display: none; }
.s3-kv { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; margin-top: 8px; } .s3-kv span { color: var(--mut); }
.s3-pins { display: grid; gap: 4px; }
.s3-pins div { display: flex; justify-content: space-between; padding: 5px 9px; border-radius: 7px; background: var(--glass2); border-left: 3px solid #7A8089; }
.s3-pins .gnd { border-left-color: #8E949C; } .s3-pins .pwr { border-left-color: #E0452E; } .s3-pins .sig { border-left-color: #2F7CF6; }
.s3-pins span { font-family: var(--mono, monospace); color: #CFD6DE; }
.s3-parts { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 4px; }
.s3-parts button { width: 100%; display: flex; justify-content: space-between; padding: 7px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--glass2); text-align: left; }
.s3-parts button:hover { border-color: var(--acc); } .s3-parts em { font-style: normal; font-size: 10.5px; color: #FFB27F; }
.s3-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 6px 0; }
.s3-row > span { color: #CFD6DE; }
.s3-row2 { display: flex; gap: 6px; flex-wrap: wrap; margin: 6px 0; }
.s3-btn2 { flex: 1; min-height: 30px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--glass2); font-size: 12px; font-weight: 600; }
.s3-btn2:hover { border-color: var(--acc); } .s3-btn2.on { background: rgba(243, 122, 51, .2); border-color: var(--acc); }
.s3-seg2 { display: inline-flex; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); }
.s3-seg2 button { padding: 5px 9px; border: 0; background: none; font-size: 11.5px; font-weight: 600; color: #C6CED8; }
.s3-seg2 button.on { background: var(--acc); color: #fff; }
.s3-chips { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.s3-chips button { display: flex; align-items: center; gap: 7px; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--glass2); font-size: 11.5px; font-weight: 600; text-align: left; }
.s3-chips button.on { border-color: var(--acc); background: rgba(243, 122, 51, .14); }
.s3-chips i { width: 16px; height: 16px; border-radius: 5px; flex: none; border: 1px solid rgba(255, 255, 255, .25); }
.s3-colorrow { flex-wrap: wrap; } .s3-swatches { display: flex; gap: 5px; align-items: center; }
.s3-swatches button { width: 22px; height: 22px; border-radius: 6px; border: 1px solid rgba(255, 255, 255, .3); }
.s3 input[type=color] { width: 28px; height: 24px; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: none; cursor: pointer; }
.s3-check { display: flex; align-items: center; gap: 7px; margin: 6px 0; color: #CFD6DE; cursor: pointer; }
.s3-check input { accent-color: var(--acc); }
.s3-wire { display: flex; align-items: center; gap: 8px; font-weight: 600; } .s3-wire i { width: 22px; height: 6px; border-radius: 3px; flex: none; }
.s3-cc { display: inline-flex; align-items: center; gap: 4px; margin-right: 6px; } .s3-cc::before { content: ''; width: 14px; height: 4px; border-radius: 2px; background: var(--c); }

/* ---------- control widgets (panel + dock) */
.s3-ctls { display: grid; gap: 10px; }
.s3-ctl output { font-family: var(--mono, monospace); color: #FFB27F; font-size: 12px; }
.s3-ctl input[type=range] { flex: 1; accent-color: var(--acc); min-width: 60px; }
.s3-step { width: 26px; height: 26px; border-radius: 7px; border: 1px solid var(--line); background: var(--glass2); font-weight: 700; }
.s3-press { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; min-height: 40px; border-radius: 12px; border: 1px solid rgba(255, 255, 255, .15);
  background: linear-gradient(#2E3642, #222831); font-weight: 700; box-shadow: 0 3px 0 #11151A, inset 0 1px 0 rgba(255, 255, 255, .08); transition: transform .06s, box-shadow .06s; user-select: none; touch-action: none; }
.s3-press .dot { width: 9px; height: 9px; border-radius: 50%; background: #4A525D; }
.s3-press.on { transform: translateY(2px); box-shadow: 0 1px 0 #11151A; background: linear-gradient(#3A2A20, #2B2019); border-color: var(--acc); }
.s3-press.on .dot { background: var(--acc); box-shadow: 0 0 8px var(--acc); }
.s3-switch { display: flex; align-items: center; gap: 10px; width: 100%; padding: 6px 4px; border: 0; background: none; text-align: left; }
.s3-switch i { position: relative; width: 38px; height: 22px; border-radius: 11px; background: #3A424D; flex: none; transition: background .15s; }
.s3-switch i::after { content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; }
.s3-switch.on i { background: var(--acc); } .s3-switch.on i::after { transform: translateX(16px); }
.s3-enc button { flex: 1; height: 32px; border-radius: 8px; border: 1px solid var(--line); background: var(--glass2); font-weight: 600; }
.s3-pad { position: relative; width: 100%; max-width: 150px; aspect-ratio: 1; margin: 4px auto; border-radius: 14px; background: radial-gradient(circle, rgba(255, 255, 255, .08) 0 1px, transparent 2px) 0 0/14px 14px, #161B22; border: 1px solid var(--line); touch-action: none; cursor: grab; }
.s3-pad::before, .s3-pad::after { content: ''; position: absolute; background: rgba(255, 255, 255, .12); } .s3-pad::before { left: 50%; top: 8px; bottom: 8px; width: 1px; } .s3-pad::after { top: 50%; left: 8px; right: 8px; height: 1px; }
.s3-pad i { position: absolute; width: 22px; height: 22px; margin: -11px 0 0 -11px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #FFC39E, var(--acc)); box-shadow: 0 2px 8px rgba(0, 0, 0, .5); left: 50%; top: 50%; z-index: 1; }
.s3-keys { display: grid; gap: 4px; }
.s3-keys button { min-height: 30px; border-radius: 7px; border: 1px solid var(--line); background: linear-gradient(#2E3642, #232932); font-weight: 700; font-size: 12px; user-select: none; touch-action: none; }
.s3-keys button.on, .s3-keys button:active { background: var(--acc); border-color: var(--acc); }
.s3-choices { display: flex; gap: 5px; flex-wrap: wrap; }
.s3-choices button { display: inline-flex; align-items: center; gap: 6px; padding: 6px 9px; border-radius: 8px; border: 1px solid var(--line); background: var(--glass2); font-size: 12px; font-weight: 600; }
.s3-choices button.on { border-color: var(--acc); background: rgba(243, 122, 51, .2); }
.s3-choices i { width: 12px; height: 12px; border-radius: 50%; }

/* ---------- input dock */
.s3-dock { position: absolute; left: 0; right: 0; bottom: 0; height: 168px; display: flex; gap: 10px; padding: 10px 12px; overflow-x: auto; overflow-y: hidden;
  background: linear-gradient(rgba(14, 18, 24, .0), rgba(14, 18, 24, .55) 18%); z-index: 3; transition: transform .25s; scrollbar-width: thin; }
.s3 { --dockH: 168px; } .s3.no-dock { --dockH: 0px; } .s3.no-dock .s3-dock { transform: translateY(100%); }
.s3-card { flex: none; width: 210px; display: flex; flex-direction: column; gap: 6px; padding: 9px 11px; border-radius: 12px; background: var(--glass); backdrop-filter: blur(10px); border: 1px solid var(--line); overflow-y: auto; font-size: 12px; }
.s3-card header { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.s3-card header b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.s3-find { width: 24px; height: 24px; border-radius: 6px; border: 1px solid var(--line); background: var(--glass2); flex: none; }
.s3-card .s3-pad { max-width: 92px; } .s3-card .s3-row { margin: 2px 0; } .s3-card .s3-press { min-height: 34px; }
.s3-card .s3-keys button { min-height: 22px; font-size: 11px; }
.s3-dock-empty { margin: auto; color: #C6CED8; font-size: 12.5px; padding: 10px 16px; border-radius: 10px; background: var(--glass); }

@media (max-width: 900px) {
  .s3-btn span { display: none; } .s3-btn { padding: 0 9px; }
  .s3-panel { width: 280px; } .s3.no-panel .s3-panel { transform: translateX(300px); }
  .s3-nav { display: none; }
}
@media (max-width: 640px) {
  .s3-panel { left: 8px; right: 8px; width: auto; top: auto; height: 46%; }
  .s3.no-panel .s3-panel { transform: translateY(110%); }
  .s3-seg { display: none; }
}

/* v11: shown when the 3D drawing keeps failing (sim3d-view.js frame guard) */
.s3-paused { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 20; display: flex; flex-direction: column; gap: 6px; align-items: center;
  padding: 16px 20px; border-radius: 12px; background: rgba(21, 26, 33, .94); border: 1px solid #334155; color: #E2E8F0; font-size: 13px; text-align: center; }
/* v11: frame-rate meter and "running slowly" hint (below the status line) */
.s3-perf { position: absolute; left: 12px; top: 46px; display: flex; align-items: center; gap: 8px; padding: 5px 8px 5px 11px; border-radius: 9px; background: var(--glass); backdrop-filter: blur(8px); font-size: 12px; color: #CFD6DE; z-index: 2; }
.s3-perf[hidden] { display: none; }
.s3-perf b { font: 600 11.5px var(--mono, monospace); color: #fff; }
.s3-perf button { border: 0; border-radius: 6px; padding: 3px 8px; font: inherit; cursor: pointer; background: rgba(255,255,255,.14); color: #fff; }
.s3-perf button:hover { background: rgba(255,255,255,.24); }
.s3-perf button[data-perf="fast"] { background: #F37A33; }

/* v11: the bar fits on one line at 1280 px and narrower windows (it used to wrap "Panel" and "?"
   onto a second row): the badge shows only its cube icon and the part list gets narrower first,
   the right-hand buttons drop their words (their tooltips stay) only when it is narrower still. */
#sim3dView { container: s3host / inline-size; }
@container s3host (max-width: 1300px) {
  .s3-badge b { display: none; }
  .s3-badge { padding: 6px 8px; }
  .s3-select { max-width: 170px; }
  .s3-bar { gap: 8px; }
  .s3-bar-r { flex: 0 0 auto; }   /* the camera / view buttons keep their room; Run / Stop moves left */
}
@container s3host (max-width: 1080px) {
  .s3-bar-r .s3-btn span { display: none; }
  .s3-bar-r .s3-btn { padding: 0 9px; }
}
