/* Toy-Brick Tabletop Studio - layout on top of kit_ui.css tokens (--kit-*) */
:root { --bg: #2a2018; --text: #f4f1ea; --soft: #c9c4b8; --warm: #ffb347; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: Inter, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; overflow: hidden; overscroll-behavior: none; }
body.embed-mode, body.embed-mode #app { height: 100vh; height: 100dvh; }
#app { position: relative; width: 100%; height: 100%; height: 100dvh; overflow: hidden; }
#c { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }
.sr { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
[hidden] { display: none !important; }
.muted { color: var(--soft); font-size: 12px; margin: 6px 0; line-height: 1.4; }

#top { position: absolute; left: 12px; right: 12px; top: 10px; display: flex; gap: 8px; align-items: center; pointer-events: none; z-index: 5; }
#top > * { pointer-events: auto; }
#title { display: flex; gap: 8px; align-items: center; font-size: 14px; background: var(--kit-panel); border: 1px solid var(--kit-line); border-radius: 12px; padding: 0 12px; min-height: 44px; backdrop-filter: blur(8px); }
#modes { margin: 0 auto; }
#topr { display: flex; gap: 6px; align-items: center; }
#hud { font: 500 11px 'JetBrains Mono', ui-monospace, monospace; color: var(--soft); background: var(--kit-panel); border: 1px solid var(--kit-line); border-radius: 10px; padding: 6px 8px; white-space: pre; line-height: 1.35; }

#tray { position: absolute; left: 12px; top: 66px; bottom: 76px; width: 232px; background: var(--kit-panel); border: 1px solid var(--kit-line); border-radius: 14px; padding: 10px; display: flex; flex-direction: column; gap: 8px; backdrop-filter: blur(8px); z-index: 4; overflow: hidden; }
.tray-h { display: flex; justify-content: space-between; align-items: baseline; font-size: 14px; }
#trayCount { font: 600 12px 'JetBrains Mono', monospace; color: var(--warm); }
.cats { display: flex; flex-wrap: wrap; gap: 4px; }
.cats button { min-height: 32px; padding: 3px 9px; border-radius: 999px; border: 1px solid var(--kit-line); background: var(--kit-panel2); color: var(--soft); font: 600 12px inherit; cursor: pointer; }
.cats button.on { color: #fff; border-color: var(--kit-accent); box-shadow: 0 0 0 2px rgba(70,166,255,.35) inset; }
.sortl { font-size: 12px; color: var(--soft); display: flex; gap: 6px; align-items: center; }
select { background: #1b1d24; color: var(--text); border: 1px solid var(--kit-line); border-radius: 8px; min-height: 32px; font: inherit; padding: 2px 6px; max-width: 100%; }
#trayItems { overflow: auto; display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; align-content: start; padding: 2px; flex: 1; }
.item { position: relative; min-height: 58px; border-radius: 10px; border: 1px solid var(--kit-line); background: var(--kit-panel2); color: var(--text); cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; padding: 4px; font: 600 11px inherit; }
.item .sw { width: 34px; height: 16px; border-radius: 4px; border: 2px solid rgba(0,0,0,.4); }
.item .n { position: absolute; right: 4px; top: 2px; font: 700 11px 'JetBrains Mono', monospace; color: var(--soft); }
.item.zero { opacity: .45; }
.item.on { border-color: var(--kit-accent); box-shadow: 0 0 0 2px var(--kit-accent) inset; background: rgba(70,166,255,.16); }
.item.need { border-color: var(--warm); }
.item.need::after { content: 'need ' attr(data-need); position: absolute; left: 4px; top: 2px; font: 700 9px Inter, sans-serif; color: #2a1a00; background: var(--warm); padding: 1px 5px; border-radius: 999px; }
.item.pulse { animation: pulse 0.7s ease-in-out 3; }
@keyframes pulse { 50% { box-shadow: 0 0 0 4px rgba(255,179,71,.8); } }

#bar { position: absolute; left: 258px; right: 346px; bottom: 12px; z-index: 5; display: flex; justify-content: center; }
#side { position: absolute; right: 12px; top: 66px; width: 322px; max-height: calc(100% - 82px); overflow: auto; z-index: 4; display: flex; flex-direction: column; gap: 8px; scrollbar-width: thin; }
.card { background: var(--kit-panel); border: 1px solid var(--kit-line); border-radius: 14px; padding: 12px 14px; backdrop-filter: blur(8px); font-size: 13px; }
.card b { font-size: 14px; }
.step-h { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.chip { font: 600 11px inherit; background: rgba(255,179,71,.18); color: var(--warm); border: 1px solid rgba(255,179,71,.5); padding: 2px 9px; border-radius: 999px; }
#prog { height: 8px; border-radius: 5px; background: rgba(255,255,255,.12); margin: 8px 0; overflow: hidden; }
#prog i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #46a6ff, #5fd17a); transition: width .3s; }
#chips { display: flex; flex-wrap: wrap; gap: 6px; }
.pchip { min-height: 44px; display: inline-flex; align-items: center; gap: 8px; padding: 4px 10px 4px 6px; border-radius: 12px; border: 1px solid var(--kit-line); background: var(--kit-panel2); color: var(--text); font: 600 12px inherit; cursor: pointer; }
.pchip .sw { width: 26px; height: 16px; border-radius: 4px; border: 2px solid rgba(0,0,0,.4); }
.pchip .q { font: 700 13px 'JetBrains Mono', monospace; color: var(--warm); }
.pchip .turn { font-size: 10px; color: #9bd0ff; }
.pchip.on { border-color: var(--kit-accent); box-shadow: 0 0 0 2px var(--kit-accent) inset; background: rgba(70,166,255,.18); }
.pchip.done { opacity: .4; }
#hintText { margin: 8px 0 2px; font-size: 12.5px; line-height: 1.4; min-height: 18px; }
#pressText { margin: 0 0 6px; font-size: 11.5px; color: var(--soft); }
.row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.stats { display: flex; gap: 14px; margin-top: 8px; font-size: 12px; color: var(--soft); }
.stats b { color: var(--text); font-family: 'JetBrains Mono', monospace; }
#chalList { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 6px; }
#chalList li { display: flex; gap: 8px; align-items: flex-start; padding: 8px; border-radius: 10px; background: var(--kit-panel2); border: 1px solid var(--kit-line); font-size: 12.5px; line-height: 1.35; }
#chalList li.ok { border-color: var(--kit-good); }
#chalList .tick { width: 20px; flex: none; font-size: 16px; }
#inspDl { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; margin: 8px 0; font-size: 12.5px; }
#inspDl dt { color: var(--soft); } #inspDl dd { margin: 0; font-family: 'JetBrains Mono', monospace; text-align: right; }
.grp { border-top: 1px solid var(--kit-line); padding-top: 8px; margin-top: 8px; display: grid; gap: 6px; }
.grp label { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 12.5px; }
.grp .rng input { flex: 1; min-width: 70px; min-height: 30px; }
.grp .rng b { min-width: 52px; text-align: right; font: 600 12px 'JetBrains Mono', monospace; }
#verdict, #hangOut { font-size: 12.5px; line-height: 1.45; padding: 6px 8px; border-radius: 8px; background: rgba(0,0,0,.25); }
#verdict.bad, #hangOut.bad { border-left: 3px solid var(--kit-bad); } #verdict.good, #hangOut.good { border-left: 3px solid var(--kit-good); }
#trayX { display: none; min-height: 36px; padding: 0 12px; }
#trayBtn { display: none; position: absolute; left: 10px; z-index: 6; }
#live { }
#load { position: absolute; inset: 0; display: grid; place-items: center; background: #2a2018; z-index: 30; text-align: center; font-size: 15px; transition: opacity .3s; }
#load.gone { opacity: 0; pointer-events: none; }
.spin { width: 38px; height: 38px; margin: 0 auto 12px; border-radius: 50%; border: 4px solid rgba(255,255,255,.2); border-top-color: var(--warm); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#fail { position: absolute; inset: 0; z-index: 40; display: grid; place-items: center; background: #2a2018; }
.modal { position: absolute; inset: 0; z-index: 35; display: none; place-items: center; background: rgba(10,8,5,.6); padding: 12px; }
.modal.open { display: grid; }
.mbox { position: relative; background: #25272f; border: 1px solid var(--kit-line); border-radius: 16px; padding: 18px 20px; max-width: 640px; width: 100%; max-height: calc(100% - 8px); overflow: auto; font-size: 14px; line-height: 1.5; }
.mbox h2 { margin: 0 0 8px; font-size: 18px; }
.mbox h3 { margin: 12px 0 4px; font-size: 14px; }
.mbox .x { position: absolute; right: 8px; top: 6px; background: none; border: 0; color: var(--soft); font-size: 26px; cursor: pointer; min-width: 44px; min-height: 44px; }
.mbox details { border-top: 1px solid var(--kit-line); padding: 6px 0; }
.mbox summary { cursor: pointer; font-weight: 700; min-height: 32px; display: flex; align-items: center; }
.mbox code, .mbox .eq { font-family: 'JetBrains Mono', monospace; font-size: 12.5px; background: rgba(0,0,0,.3); padding: 1px 5px; border-radius: 5px; }
.mbox .eq { display: block; padding: 6px 8px; margin: 6px 0; overflow-x: auto; }
#checkOut { font: 12px/1.5 'JetBrains Mono', monospace; white-space: pre-wrap; margin-top: 8px; }
#checkOut .ok { color: var(--kit-good); } #checkOut .bad { color: var(--kit-bad); }
.mbox label.set { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--kit-line); }
.mbox .btns { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.mbox .kit-btn.pri { background: rgba(70,166,255,.3); border-color: var(--kit-accent); }
.tour-dots { display: flex; gap: 6px; margin-top: 10px; } .tour-dots i { width: 8px; height: 8px; border-radius: 50%; background: rgba(255,255,255,.25); } .tour-dots i.on { background: var(--kit-accent); }
.kit-toast { bottom: 90px; }

@media (max-width: 860px) {
  #hud { display: none; }
  #bar { left: 8px; right: 8px; bottom: auto; position: static; justify-content: flex-start; overflow-x: auto; }
  #dock { position: absolute; left: 0; right: 0; bottom: 0; z-index: 5; display: flex; flex-direction: column; gap: 6px; padding: 0 8px calc(8px + env(safe-area-inset-bottom)); pointer-events: none; }
  #dock > * { pointer-events: auto; }
  #side { position: static; width: 100%; max-height: 34vh; }
  #tray { left: 8px; right: 8px; top: auto; bottom: 0; width: auto; max-height: 46vh; border-radius: 14px 14px 0 0; display: none; z-index: 8; }
  #tray.open { display: flex; }
  #trayItems { grid-template-columns: repeat(auto-fill, minmax(86px, 1fr)); }
  #trayBtn { display: inline-flex; top: 62px; left: 8px; }
  #title b { display: none; }
  #title { display: none; }
  #top { left: 8px; right: 8px; top: 6px; gap: 4px; }
  #modes { margin: 0; flex: 1; overflow-x: auto; }
  .kit-mode { padding: 4px 10px; }
  .kit-mode span:not(.ic) { display: none; } .kit-mode.on span:not(.ic) { display: inline; }
  #trayX { display: inline-flex; align-items: center; }
  #topr .lb { display: none; }
  .kit-toast { bottom: 40vh; }
  .card { padding: 8px 10px; }
}
@media (max-width: 860px) and (max-height: 600px) { #side { max-height: 40vh; } }
@media (prefers-reduced-motion: reduce) { .item.pulse { animation: none; } .spin { animation-duration: 3s; } }
