:root {
  --bg: #14100c;
  --glass: rgba(24, 18, 13, 0.78);
  --line: rgba(214, 170, 96, 0.28);
  --brass: #d6aa60;
  --brass-hi: #f0cf8e;
  --text: #f3ead9;
  --muted: #b9a88d;
  color-scheme: dark;
}
/* The 3D viewer is dark by design in both themes */
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --bg: #14100c; --text: #f3ead9; } }
:root[data-theme="dark"] { --bg: #14100c; --text: #f3ead9; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
  font-family: 'IBM Plex Sans Arabic', system-ui, sans-serif; }
#viewport { position: fixed; inset: 0; }
#viewport canvas { display: block; }
.labels { position: absolute; inset: 0; pointer-events: none; direction: ltr; }
.labels > * { left: 0; top: 0; direction: rtl; }
button { font: inherit; color: inherit; cursor: pointer; }

.topbar { position: fixed; top: 12px; inset-inline: 12px; display: flex; gap: 12px; justify-content: space-between;
  align-items: center; pointer-events: none; }
.topbar > * { pointer-events: auto; }
.brand { display: flex; gap: 12px; align-items: center; background: var(--glass); backdrop-filter: blur(10px);
  border: 1px solid var(--line); border-radius: 14px; padding: 10px 16px; }
.brand .mark { color: var(--brass); font-size: 22px; }
.brand h1 { font-size: 17px; margin: 0; font-weight: 700; }
.brand p { margin: 2px 0 0; font-size: 11.5px; color: var(--muted); direction: rtl; }
.typs { display: flex; gap: 6px; background: var(--glass); backdrop-filter: blur(10px); border: 1px solid var(--line);
  border-radius: 14px; padding: 6px; }
.typs button { background: transparent; border: 1px solid transparent; border-radius: 10px; padding: 6px 12px;
  font-weight: 700; font-size: 13px; display: flex; flex-direction: column; align-items: center; letter-spacing: .3px; }
.typs button small { font-weight: 400; font-size: 11px; color: var(--muted); }
.typs button.active { background: rgba(214, 170, 96, 0.18); border-color: var(--brass); color: var(--brass-hi); }

.panel { position: fixed; top: 96px; right: 12px; width: 250px; max-height: calc(100vh - 170px); overflow: auto;
  background: var(--glass); backdrop-filter: blur(10px); border: 1px solid var(--line); border-radius: 14px; padding: 6px 14px 12px; }
.panel section { padding: 10px 0; border-bottom: 1px solid var(--line); }
.panel h3 { font-size: 13px; margin: 0 0 8px; display: flex; justify-content: space-between; color: var(--brass-hi); }
.panel h3 span { color: var(--text); font-weight: 400; font-variant-numeric: tabular-nums; }
.panel input[type=range] { width: 100%; accent-color: var(--brass); }
.panel .grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.panel .grid button, .panel .wide { background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 4px; font-size: 12.5px; }
.panel .grid button.active { border-color: var(--brass); color: var(--brass-hi); }
.panel .span2 { grid-column: span 2; }
.panel .wide { width: 100%; margin-top: 8px; background: rgba(214, 170, 96, 0.16); border-color: var(--brass); }
.toggles { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; font-size: 12.5px; }
.toggles input { accent-color: var(--brass); }
.hint { font-size: 11px; color: var(--muted); margin: 10px 0 0; }

.dim { font: 500 11.5px 'IBM Plex Sans Arabic', sans-serif; color: #2a1c0c; background: rgba(255, 214, 140, 0.92);
  padding: 1px 6px; border-radius: 4px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.dim.zone { background: rgba(20, 15, 10, 0.75); color: var(--brass-hi); transform: translateX(50%); }
.hotspot { pointer-events: auto; width: 26px; height: 26px; border-radius: 50%; border: 2px solid #fff;
  background: rgba(196, 140, 52, 0.9); color: #fff; font-weight: 700; font-size: 12px;
  box-shadow: 0 0 0 4px rgba(214, 170, 96, 0.3), 0 2px 8px rgba(0, 0, 0, 0.5); animation: pulse 2.4s infinite; }
.hotspot:hover { background: #e7b85f; }
@keyframes pulse { 50% { box-shadow: 0 0 0 9px rgba(214, 170, 96, 0.05), 0 2px 8px rgba(0, 0, 0, .5); } }
.layer-label { font-size: 11px; background: rgba(20, 15, 10, 0.82); border-inline-start: 2px solid var(--brass);
  padding: 3px 8px; border-radius: 4px; max-width: 230px; transform: translateX(55%); line-height: 1.35; }
.layer-label b { color: var(--brass-hi); }
.layer-label span { color: var(--muted); }
.section-title { font-size: 13px; font-weight: 700; background: rgba(20, 15, 10, 0.85); padding: 5px 10px;
  border-radius: 8px; text-align: center; border: 1px solid var(--line); }
.section-title span { font-weight: 400; color: var(--brass-hi); }

.info { position: fixed; left: 12px; top: 96px; width: 330px; background: var(--glass); backdrop-filter: blur(10px);
  border: 1px solid var(--brass); border-radius: 14px; padding: 14px 16px; opacity: 0; transform: translateY(-8px);
  pointer-events: none; transition: .25s; }
.info.show { opacity: 1; transform: none; pointer-events: auto; }
.info h4 { margin: 0 0 6px; color: var(--brass-hi); font-size: 15px; }
.info p { margin: 0; font-size: 13.5px; line-height: 1.7; }
#info-close { position: absolute; left: 10px; top: 6px; background: none; border: 0; font-size: 20px; color: var(--muted); }

.specs { position: fixed; bottom: 12px; inset-inline: 12px; background: var(--glass); backdrop-filter: blur(10px);
  border: 1px solid var(--line); border-radius: 14px; max-height: 46vh; display: flex; flex-direction: column; }
.specs-head { display: flex; align-items: center; gap: 12px; padding: 8px 12px; flex-wrap: wrap; }
.specs-head #spec-title { font-weight: 700; font-size: 13px; color: var(--brass-hi); flex: 1; }
.specs-head button { background: rgba(255, 255, 255, .05); border: 1px solid var(--line); border-radius: 8px; padding: 5px 10px; font-size: 12.5px; }
.specs-head .tab.active { border-color: var(--brass); color: var(--brass-hi); }
.specs nav { display: flex; gap: 6px; }
.specs-body { overflow: auto; padding: 0 12px 12px; }
.specs.collapsed .specs-body, .specs.collapsed nav { display: none; }
.pane { display: none; } .pane.show { display: block; }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th, td { text-align: start; padding: 5px 8px; border-bottom: 1px solid rgba(255, 255, 255, 0.07); vertical-align: top; }
th { color: var(--brass-hi); font-weight: 500; white-space: nowrap; }
td small { color: var(--muted); direction: ltr; display: inline-block; }
tr.total td { font-weight: 700; color: var(--brass-hi); }

.mech-grid { margin-top: 8px; }
.panel .grid button.active#btn-lock { background: rgba(255, 80, 60, 0.16); border-color: #e0634f; color: #ffb3a6; }
.panel .xray { display: flex; align-items: center; gap: 6px; font-size: 12px; border: 1px solid var(--line);
  border-radius: 8px; padding: 0 6px; }
.panel .xray input { accent-color: var(--brass); }
.mech-label { font-size: 11px; background: rgba(10, 30, 40, 0.85); border: 1px solid #2bb8e6; color: #dff6ff;
  padding: 2px 7px; border-radius: 5px; white-space: nowrap; }
.mech-label b { color: #7fe0ff; }

.seq { position: fixed; left: 12px; bottom: 70px; width: 360px; max-height: calc(100vh - 190px); overflow: auto;
  background: var(--glass); backdrop-filter: blur(10px); border: 1px solid #2bb8e6; border-radius: 14px;
  padding: 10px 14px; display: none; }
.seq.show { display: block; }
.seq-head { display: flex; gap: 8px; align-items: center; font-size: 13px; color: #7fe0ff; }
.seq-head span { margin-inline-start: auto; color: var(--muted); font-variant-numeric: tabular-nums; }
#seq-close { background: none; border: 0; font-size: 18px; color: var(--muted); }
.seq ol { margin: 8px 0 0; padding-inline-start: 20px; font-size: 12.5px; }
.seq li { margin: 0 0 6px; color: var(--muted); }
.seq li b { display: block; font-weight: 500; }
.seq li span { display: none; line-height: 1.6; }
.seq li.done { color: #7aa88c; }
.seq li.active { color: var(--text); }
.seq li.active b { color: #7fe0ff; }
.seq li.active span { display: block; }
.seq:not(.playing) li span { display: block; }
.seq-note { font-size: 11px; color: var(--muted); margin: 6px 0 0; }
.toast { position: fixed; top: 96px; left: 50%; transform: translate(-50%, -10px); opacity: 0; pointer-events: none;
  background: rgba(60, 20, 14, 0.92); border: 1px solid #e0634f; color: #ffd9d2; padding: 8px 14px; border-radius: 10px;
  font-size: 13px; transition: .25s; z-index: 5; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.loader { position: fixed; inset: 0; display: none; place-items: center; align-content: center; gap: 14px;
  background: rgba(14, 10, 7, 0.72); z-index: 10; }
.loader.show { display: grid; }
.loader p { margin: 0; font-size: 14px; color: var(--brass-hi); text-align: center; line-height: 1.8; padding: 0 16px; max-width: 520px; }
.loader.error .spin { display: none; }
.loader.error p { color: #ffd9d2; }
.spin { width: 46px; height: 46px; border: 3px solid var(--line); border-top-color: var(--brass); border-radius: 50%;
  animation: rot 1s linear infinite; }
@keyframes rot { to { transform: rotate(360deg); } }

/* ---- Simulation additions ---- */
.panel .kase { display: flex; gap: 10px; font-size: 12.5px; margin: 8px 0 4px; }
.panel .kase input, .panel .chk input { accent-color: var(--brass); }
.panel .chk { display: flex; gap: 6px; align-items: center; font-size: 12.5px; margin-top: 6px; }
.panel .wide.ghost { background: rgba(255, 255, 255, 0.05); border-color: var(--line); }
.eng { position: fixed; left: 12px; top: 96px; width: 380px; max-height: calc(100vh - 170px); overflow: auto;
  background: var(--glass); backdrop-filter: blur(10px); border: 1px solid var(--brass); border-radius: 14px;
  padding: 10px 14px; display: none; z-index: 3; }
.eng.show { display: block; }
.eng-head { display: flex; justify-content: space-between; align-items: center; color: var(--brass-hi); font-size: 14px; }
#eng-close { background: none; border: 0; font-size: 20px; color: var(--muted); }
.hud-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 8px 0; }
.hud-grid > div { background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px; }
.hud-grid span { display: block; font-size: 11px; color: var(--muted); }
.hud-grid b { font-size: 15px; font-variant-numeric: tabular-nums; }
.hud-grid small { font-size: 11px; color: var(--muted); font-weight: 400; }
.hud-grid .warn { border-color: #e0634f; background: rgba(224, 99, 79, 0.14); }
.hud-warn { margin: 4px 0 8px; color: #ffb3a6; font-size: 12.5px; }
.eng-row { display: block; font-size: 12.5px; margin: 4px 0 8px; }
.eng-row span { float: left; color: var(--brass-hi); }
.eng-row input { width: 100%; accent-color: var(--brass); }
.chart { position: relative; height: 170px; margin: 6px 0; direction: ltr; }
.eng-note { font-size: 11px; color: var(--muted); line-height: 1.6; margin: 6px 0 0; }
.clash-tag { font: 600 12px 'IBM Plex Sans Arabic', sans-serif; padding: 4px 9px; border-radius: 6px; white-space: nowrap; }
.clash-tag.bad { background: rgba(120, 18, 10, 0.9); border: 1px solid #ff6a55; color: #ffe1dc; }
.clash-tag.ok { background: rgba(14, 70, 36, 0.9); border: 1px solid #5fd08a; color: #dcffe8; }
body.recording .panel, body.recording .specs, body.recording .eng, body.recording .info { opacity: 0.35; }
body.recording #btn-rec { opacity: 1; }

@media (max-width: 820px) {
  .eng { width: auto; right: 12px; top: auto; bottom: 64px; max-height: 50vh; }
  .topbar { flex-direction: column; align-items: stretch; }
  .brand p { display: none; }
  .panel { top: auto; bottom: 64px; width: auto; left: 12px; max-height: 34vh; }
  .info { top: auto; bottom: 64px; width: auto; right: 12px; }
}
