/* One palette: near-black neutrals with a single amber accent (it is a sandbox, the accent is
   sand). One radius scale (8 px on everything interactive, 999 on the one pill). System sans for
   labels, mono only where a number is being read. No emoji glyphs: they render differently on
   every platform and the panel is not a chat window. */
:root {
  --bg: #101216;
  --panel: #171a20;
  --panel2: #1f232b;
  --panel3: #272c36;
  --line: #2b303b;
  --line2: #384050;
  --text: #e3e6ec;
  --dim: #8a93a3;
  --dim2: #5f6878;
  --accent: #f2b45a;
  --accent-ink: #1a1205;
  --danger: #e5786a;
  --r: 8px;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--text);
  font-family: var(--sans); font-size: 13px; line-height: 1.3;
  user-select: none; -webkit-user-select: none;
  -webkit-font-smoothing: antialiased;
}
/* touch-action:none belongs on the canvas only. On html/body it also kills scrolling of
   the control panel, which on an iPad means you cannot reach half the materials. */
#stage, #stage canvas { touch-action: none; }
#app { display: flex; flex-direction: column; height: 100%; }

header {
  display: flex; align-items: center; gap: 14px;
  height: 44px; padding: 0 16px; background: var(--panel); border-bottom: 1px solid var(--line);
  flex: none;
}
h1 { font-size: 14px; margin: 0; font-weight: 650; letter-spacing: .01em; }
h1 b { color: var(--accent); font-weight: 700; }
.sub { color: var(--dim); font-size: 12px; }
header .spacer { flex: 1; }
#stats { color: var(--dim); font-size: 11.5px; font-family: var(--mono); white-space: nowrap; }

main { flex: 1; display: flex; min-height: 0; }
#stage { flex: 1; position: relative; min-width: 0; background: #0c0e13; cursor: crosshair; }
#stage.orbit { cursor: grab; }
#stage.orbit:active { cursor: grabbing; }
canvas { display: block; width: 100%; height: 100%; }
#hint {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%);
  display: flex; gap: 0; align-items: center;
  background: rgba(16,18,22,0.78); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.08); border-radius: 999px;
  padding: 7px 8px; font-size: 12px; color: var(--dim); pointer-events: none;
  transition: opacity .5s; max-width: 92%; white-space: nowrap;
}
#hint span { padding: 0 10px; }
#hint span + span { border-left: 1px solid rgba(255,255,255,0.10); }
#hint kbd {
  font-family: var(--mono); font-size: 11px; color: var(--text);
  background: rgba(255,255,255,0.07); border: 1px solid rgba(255,255,255,0.10);
  border-radius: 4px; padding: 1px 5px; margin-right: 5px;
}
#hint.msg { color: var(--text); }

/* ---- side panel ---- */
#panel {
  width: 300px; flex: none; background: var(--panel); border-left: 1px solid var(--line);
  overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; padding-bottom: 32px;
  scrollbar-width: thin; scrollbar-color: var(--line2) transparent;
}
.group { padding: 14px 16px 16px; border-bottom: 1px solid var(--line); }
.glabel {
  display: flex; align-items: baseline; justify-content: space-between;
  font-size: 12px; font-weight: 600; color: var(--dim); margin-bottom: 10px;
}
.glabel .val { font-family: var(--mono); font-weight: 500; color: var(--text); font-size: 12px; }

/* Material tiles. The swatch colour tints the whole tile so the palette reads as colour rather
   than as a list of grey boxes with a dot in each. */
.mats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.mat {
  --c: #888;
  display: flex; flex-direction: column; align-items: flex-start; gap: 7px; padding: 8px 9px 7px;
  white-space: nowrap; overflow: hidden;
  background: color-mix(in srgb, var(--c) 10%, var(--panel2));
  border: 1px solid transparent; border-radius: var(--r);
  cursor: pointer; font-size: 12px; color: var(--text); min-height: 52px;
  transition: background .12s, border-color .12s, transform .08s;
}
.mat .sw { width: 100%; height: 6px; border-radius: 3px; background: var(--c); box-shadow: inset 0 0 0 1px rgba(0,0,0,.25); }
.mat:hover { background: color-mix(in srgb, var(--c) 18%, var(--panel2)); border-color: var(--line2); }
.mat.on { border-color: var(--accent); background: color-mix(in srgb, var(--c) 22%, var(--panel3)); box-shadow: 0 0 0 1px var(--accent); }
.mat:active { transform: scale(.97); }
.mat.erase { --c: #aab4c4; }
.mat.erase .sw { background: repeating-linear-gradient(135deg, #aab4c4 0 4px, transparent 4px 8px); }
.mats + .glabel { margin-top: 14px; }

.row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.row + .row { margin-top: 6px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
button.btn {
  flex: 1 1 0; min-width: 0; min-height: 36px; padding: 8px 10px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  background: var(--panel2); color: var(--text); border: 1px solid var(--line);
  border-radius: var(--r); cursor: pointer; font-family: inherit; font-size: 12.5px; font-weight: 500;
  transition: background .12s, border-color .12s, transform .08s;
}
button.btn:hover { background: var(--panel3); border-color: var(--line2); }
button.btn:active { transform: scale(.97); }
button.btn.on { border-color: var(--accent); color: #fff; background: var(--panel3); box-shadow: 0 0 0 1px var(--accent); }
button.btn.wide { flex-basis: 100%; }
button.btn.danger { color: var(--danger); }
button.btn.danger:hover { border-color: rgba(229,120,106,.5); }
button.btn:disabled { opacity: .38; cursor: default; }
button.btn:disabled:hover { background: var(--panel2); border-color: var(--line); }
.seg { display: flex; background: var(--panel2); border: 1px solid var(--line); border-radius: var(--r); padding: 3px; }
.seg button {
  flex: 1; min-height: 30px; border: 0; border-radius: 6px; background: transparent; color: var(--dim);
  font-family: inherit; font-size: 12.5px; font-weight: 500; cursor: pointer;
}
.seg button.on { background: var(--panel3); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.35); }

/* Enter VR lives OUTSIDE the panel: bottom-centre of the viewport, deliberately hard to miss.
   Same #bXR element, same handler and Enter/Exit text swap, so there is no second piece of
   state that could disagree with the first. Only shown once a headset is confirmed. */
#bXR {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: max(22px, env(safe-area-inset-bottom, 0px));
  z-index: 60;
  display: flex; align-items: center; gap: 10px;
  padding: 15px 30px; min-height: 0;
  font-family: inherit; font-size: 17px; font-weight: 600; letter-spacing: .01em;
  color: var(--accent-ink); background: var(--accent);
  border: 1px solid rgba(255,255,255,.28); border-radius: 999px;
  box-shadow: 0 6px 26px rgba(0,0,0,.5), 0 0 0 4px rgba(0,0,0,.22);
  cursor: pointer; white-space: nowrap;
  animation: xrPulse 2.6s ease-in-out 3;
}
#bXR:hover { filter: brightness(1.08); }
#bXR:active { transform: translateX(-50%) scale(.97); }
@keyframes xrPulse {
  0%, 100% { box-shadow: 0 6px 26px rgba(0,0,0,.5), 0 0 0 4px rgba(0,0,0,.22); }
  50%      { box-shadow: 0 6px 26px rgba(0,0,0,.5), 0 0 0 12px rgba(242,180,90,.26); }
}
@media (prefers-reduced-motion: reduce) { #bXR { animation: none; } .mat, button.btn { transition: none; } }
@media (max-width: 520px) { #bXR { font-size: 15px; padding: 13px 22px; bottom: 14px; } }

.stepper { display: flex; align-items: center; gap: 6px; width: 100%; }
.stepper button {
  width: 40px; height: 36px; font-size: 18px; line-height: 1; flex: none;
  background: var(--panel2); color: var(--text); border: 1px solid var(--line);
  border-radius: var(--r); cursor: pointer; font-family: inherit;
}
.stepper button:hover { background: var(--panel3); border-color: var(--line2); }
.stepper button:active { transform: scale(.94); }
.stepper .val { flex: 1; text-align: center; font-size: 12.5px; color: var(--dim); }
.stepper .val b { font-family: var(--mono); font-weight: 500; color: var(--text); font-size: 13px; }

/* mobile / iPad: panel becomes a bottom sheet */
@media (max-width: 820px) {
  main { flex-direction: column; }
  #panel { width: 100%; height: 46%; border-left: none; border-top: 1px solid var(--line); }
  header { padding: 0 12px; height: 40px; }
  .sub { display: none; }
  .mats { grid-template-columns: repeat(4, 1fr); }
  #hint { display: none; }
}
