:root {
  --ink: #1d2733; --muted: #5d6874; --line: rgba(0, 0, 0, .1); --panel: #fbfaf8; --accent: #2b6de0; --bar: #f4f2ee;
  --st: env(safe-area-inset-top, 0px); --sb: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  display: flex; flex-direction: column; background: var(--bar); color: var(--ink);
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
input, select, textarea { -webkit-user-select: text; user-select: text; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
button:disabled { opacity: .35; }
[hidden] { display: none !important; }

#top { display: flex; align-items: center; gap: 4px; padding: calc(var(--st) + 6px) 8px 6px; background: var(--bar); border-bottom: 1px solid var(--line); }
#top .sp { flex: 1; }
.ttl { display: flex; align-items: center; gap: 4px; font-weight: 650; font-size: 16px; padding: 6px 4px; max-width: 40vw; min-width: 0; }
.ttl #pname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.caret { font-size: 11px; color: var(--muted); }
#saveState { font-size: 12px; color: #2e7d4f; white-space: nowrap; min-width: 14px; }
#saveState.bad { color: #c62828; font-weight: 600; }
.ic { width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center; border-radius: 9px; font-size: 17px; }
.ic:active, .btn:active, .card:active, #tools button:active { background: rgba(0, 0, 0, .07); }
.svg { display: inline-flex; }

.seg { display: inline-flex; background: rgba(0, 0, 0, .06); border-radius: 9px; padding: 2px; gap: 2px; }
.seg button { padding: 6px 11px; border-radius: 7px; font-size: 14px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .15); }
.seg.small button { padding: 5px 9px; font-size: 13px; }

#floors { display: flex; align-items: center; gap: 8px; padding: 5px 8px; background: var(--bar); border-bottom: 1px solid var(--line); }
.ftabs { display: flex; gap: 4px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.ftabs::-webkit-scrollbar { display: none; }
.ftabs button { padding: 6px 13px; border-radius: 16px; background: rgba(0, 0, 0, .06); font-size: 14px; font-weight: 600; white-space: nowrap; }
.ftabs button.on { background: var(--ink); color: #fff; }
.area { font-size: 12px; font-weight: 650; white-space: nowrap; color: var(--ink); }
.area small { font-weight: 500; color: var(--muted); }

#stage { position: relative; flex: 1; min-height: 120px; overflow: hidden; background: #d7ddd2; }
#plan, #three { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#three canvas { display: block; touch-action: none; }
.fab { position: absolute; right: 10px; bottom: 10px; width: 42px; height: 42px; border-radius: 21px; background: rgba(255, 255, 255, .92); box-shadow: 0 1px 4px rgba(0, 0, 0, .2); display: flex; align-items: center; justify-content: center; }
body.m3d .fab, body.m3d #floors, body.m3d #tools { display: none; }

#toast { position: absolute; left: 50%; top: 10px; transform: translate(-50%, -8px); max-width: 88%; background: rgba(29, 39, 51, .92); color: #fff; font-size: 13px; padding: 8px 12px; border-radius: 12px; opacity: 0; transition: opacity .25s, transform .25s; pointer-events: none; text-align: center; z-index: 5; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

#placeBar { position: absolute; left: 8px; right: 8px; top: 8px; background: var(--accent); color: #fff; border-radius: 12px; padding: 8px 8px 8px 14px; display: flex; align-items: center; justify-content: space-between; font-size: 14px; z-index: 4; }
#placeBar button { background: rgba(255, 255, 255, .22); padding: 6px 12px; border-radius: 8px; font-weight: 600; }

#tools { display: flex; justify-content: space-around; background: var(--bar); border-top: 1px solid var(--line); padding: 4px 2px calc(var(--sb) + 4px); }
#tools button { display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 5px 4px; border-radius: 10px; font-size: 11px; font-weight: 600; color: #34404c; min-width: 56px; }
#tools button.on { background: #fde3e3; color: #b0242c; }

#insp { background: var(--panel); border-top: 1px solid var(--line); box-shadow: 0 -4px 14px rgba(0, 0, 0, .06); max-height: 42vh; display: flex; flex-direction: column; }
#insp.min .ibody { display: none; }
.ihead { display: flex; align-items: center; gap: 4px; padding: 6px 6px 4px 14px; }
.ihead b { flex: 1; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ibody { overflow-y: auto; padding: 0 14px 10px; -webkit-overflow-scrolling: touch; }

.field { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 5px 0; border-bottom: 1px solid rgba(0, 0, 0, .05); }
.field .fl { font-size: 14px; color: #3a4652; flex-shrink: 0; }
.field .fc { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.field input, .field select { font: inherit; font-size: 16px; border: 1px solid #d3d0ca; border-radius: 8px; padding: 6px 8px; background: #fff; color: var(--ink); }
.field input.ft { width: 58px; text-align: right; }
.field input.in { width: 54px; text-align: right; }
.field input.num { width: 74px; text-align: right; }
.field input.txt { width: 190px; max-width: 52vw; }
.field select { max-width: 56vw; }
.u { font-size: 13px; color: var(--muted); }
.tog { padding: 6px 14px; border-radius: 16px; background: rgba(0, 0, 0, .08); font-weight: 600; font-size: 14px; }
.tog.on { background: #2e7d4f; color: #fff; }
.rot { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.rot .btn { padding: 6px 8px; font-size: 13px; }
.note { font-size: 12.5px; color: var(--muted); margin: 8px 0; }
.warn { font-size: 13px; background: #fff4d6; border: 1px solid #f0d58a; border-radius: 10px; padding: 8px 10px; margin: 0 0 10px; }
.brow { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0 2px; }
.btn { padding: 8px 12px; border-radius: 10px; background: rgba(0, 0, 0, .07); font-weight: 600; font-size: 14px; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.danger { color: #c62828; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.qadd { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 8px; }
.qadd span { font-size: 13px; color: var(--muted); width: 100%; }

#sheetBack { position: fixed; inset: 0; background: rgba(0, 0, 0, .28); z-index: 20; }
#sheet { position: fixed; left: 0; right: 0; bottom: 0; max-height: 82vh; background: var(--panel); border-radius: 16px 16px 0 0; z-index: 21; display: flex; flex-direction: column; box-shadow: 0 -6px 30px rgba(0, 0, 0, .2); transform: translateY(20px); opacity: 0; transition: transform .2s, opacity .2s; }
#sheet.show { transform: none; opacity: 1; }
.shead { display: flex; align-items: center; padding: 12px 8px 6px 16px; }
.shead b { flex: 1; font-size: 17px; }
.sbody { overflow-y: auto; padding: 0 14px calc(var(--sb) + 16px); -webkit-overflow-scrolling: touch; }
.sbody h4 { margin: 14px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.card { background: #fff; border: 1px solid #e3e0da; border-radius: 12px; padding: 9px 8px; text-align: left; display: flex; flex-direction: column; gap: 2px; min-height: 58px; }
.card i { width: 22px; height: 8px; border-radius: 3px; border: 1px solid rgba(0, 0, 0, .15); margin-bottom: 3px; }
.card b { font-size: 13.5px; }
.card small { font-size: 11.5px; color: var(--muted); }
.list { display: flex; flex-direction: column; gap: 6px; }
.list .btn { text-align: left; padding: 12px 14px; background: #fff; border: 1px solid #e3e0da; }
.prow { display: flex; align-items: center; gap: 6px; background: #fff; border: 1px solid #e3e0da; border-radius: 12px; padding: 4px 6px 4px 4px; margin-top: 6px; }
.prow.cur { border-color: var(--accent); }
.pinfo { flex: 1; display: flex; flex-direction: column; text-align: left; padding: 8px 10px; min-width: 0; }
.pinfo b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pinfo small { color: var(--muted); font-size: 12px; }
.frow { border: 1px solid #e3e0da; border-radius: 12px; padding: 4px 10px 8px; margin-bottom: 8px; background: #fff; }
.help ul { padding-left: 18px; margin: 4px 0; }
.help li { margin: 4px 0; font-size: 14px; }

#hud3d { position: absolute; inset: 0; pointer-events: none; }
#hudTop { position: absolute; left: 8px; right: 8px; top: 8px; display: flex; flex-wrap: wrap; gap: 6px; pointer-events: none; }
#hudTop > * { pointer-events: auto; }
#hudTop .seg { background: rgba(255, 255, 255, .85); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.chip { background: rgba(255, 255, 255, .85); border-radius: 9px; padding: 6px 11px; font-weight: 600; font-size: 13px; color: var(--muted); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.chip.on { color: var(--ink); background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .15); }
#joy { position: absolute; left: 22px; bottom: calc(var(--sb) + 26px); width: 120px; height: 120px; border-radius: 60px; background: rgba(255, 255, 255, .25); border: 2px solid rgba(255, 255, 255, .7); pointer-events: auto; touch-action: none; }
#joy i { position: absolute; left: 35px; top: 35px; width: 46px; height: 46px; border-radius: 23px; background: rgba(255, 255, 255, .9); box-shadow: 0 2px 6px rgba(0, 0, 0, .25); }

#updateBar { position: fixed; left: 10px; right: 10px; bottom: calc(var(--sb) + 70px); background: #1d2733; color: #fff; border-radius: 14px; padding: 10px 10px 10px 14px; display: flex; align-items: center; justify-content: space-between; z-index: 30; font-size: 14px; box-shadow: 0 6px 20px rgba(0, 0, 0, .3); }
#updateBar button { background: #fff; color: #1d2733; padding: 7px 12px; border-radius: 9px; font-weight: 700; }
