:root {
  --bg: #eef1f4; --card: #fff; --ink: #18212b; --muted: #637080; --line: #dbe1e7; --field: #f5f7f9;
  --accent: #1f6feb; --brand: #1f3b57; --brand-ink: #fff; --good: #0b7a52;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1418; --card: #182027; --ink: #e8eef3; --muted: #93a1ad; --line: #2a343d; --field: #11181d; --accent: #58a6ff; color-scheme: dark; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); overscroll-behavior: none; }
body { font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; display: flex; flex-direction: column; -webkit-text-size-adjust: 100%; }
button, input, select { font: inherit; color: inherit; }

#bar { display: flex; align-items: center; gap: 6px; padding: calc(env(safe-area-inset-top) + 8px) 10px 8px; background: var(--brand); color: var(--brand-ink); }
#titles { flex: 1; min-width: 0; padding-left: 4px; }
#title { margin: 0; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#subtitle { font-size: 12px; opacity: .8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { width: 40px; height: 40px; border: 0; border-radius: 11px; background: rgba(255,255,255,.13); color: inherit; display: grid; place-items: center; cursor: pointer; flex: none; }
.icon-btn svg { width: 21px; height: 21px; }

#tabs { display: flex; gap: 4px; padding: 6px 8px; background: var(--card); border-bottom: 1px solid var(--line); }
#tabs button { flex: 1; border: 0; background: none; padding: 8px; border-radius: 10px; font-weight: 600; color: var(--muted); cursor: pointer; }
#tabs button.on { background: var(--field); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }

#main { flex: 1; min-height: 0; position: relative; }
.pane { position: absolute; inset: 0; display: none; flex-direction: column; }
.pane.on { display: flex; }
@media (min-width: 1000px) {
  #tabs button[data-tab="view"] { display: none; }
  #planPane.on, #viewPane.wide { display: flex; }
  #planPane { right: 50%; border-right: 1px solid var(--line); }
  #viewPane { left: 50%; }
  #housePane { right: 50%; }
}

/* plan */
#canvasWrap { flex: 1; min-height: 0; position: relative; }
#plan { display: block; touch-action: none; }
#tools { display: flex; gap: 4px; padding: 6px 6px calc(env(safe-area-inset-bottom) + 6px); background: var(--card); border-top: 1px solid var(--line); overflow-x: auto; -webkit-overflow-scrolling: touch; }
#tools button { flex: 1 0 auto; min-width: 54px; border: 0; background: none; border-radius: 10px; padding: 6px 4px; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--muted); cursor: pointer; }
#tools button b { font-size: 20px; line-height: 1; font-weight: 400; }
#tools button.on { background: var(--field); color: var(--accent); box-shadow: inset 0 0 0 1px var(--line); }
#tools .sep { width: 1px; background: var(--line); margin: 4px 2px; flex: none; }
#selPanel { position: absolute; left: 8px; right: 8px; bottom: calc(env(safe-area-inset-bottom) + 74px); background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; box-shadow: 0 6px 22px rgba(0,0,0,.18); z-index: 5; max-width: 560px; margin: 0 auto; }
#selPanel h4 { margin: 0 0 8px; font-size: 14px; display: flex; justify-content: space-between; align-items: center; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.fld { display: flex; flex-direction: column; gap: 3px; flex: 1 1 90px; min-width: 0; }
.fld > span { font-size: 11.5px; color: var(--muted); }
.fld input, .fld select { width: 100%; padding: 9px 10px; border: 1px solid var(--line); border-radius: 9px; background: var(--field); font-size: 16px; }
.fld input[type=color] { padding: 2px; height: 40px; }
.btn { border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 9px 13px; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.danger { color: #d23b3b; }
.btn.small { padding: 6px 10px; font-size: 13.5px; }
.btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

/* 3D */
#view3d { flex: 1; min-height: 0; position: relative; background: #a9d3f0; }
#view3d canvas { display: block; touch-action: none; }
#viewTop { position: absolute; top: 8px; left: 8px; right: 8px; pointer-events: none; }
#viewBottom { position: absolute; left: 8px; right: 8px; bottom: calc(env(safe-area-inset-bottom) + 8px); display: flex; flex-direction: column; gap: 6px; pointer-events: none; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; pointer-events: auto; }
.chip { border: 0; border-radius: 999px; padding: 7px 12px; background: rgba(255,255,255,.88); color: #18212b; font-size: 13.5px; box-shadow: 0 1px 4px rgba(0,0,0,.18); cursor: pointer; backdrop-filter: blur(6px); }
.chip.off { opacity: .55; text-decoration: line-through; }
.chip.primary { background: #1f6feb; color: #fff; font-weight: 600; }
.sun { pointer-events: auto; align-self: flex-start; display: flex; align-items: center; gap: 8px; background: rgba(255,255,255,.88); color: #18212b; border-radius: 999px; padding: 5px 12px; font-size: 13.5px; box-shadow: 0 1px 4px rgba(0,0,0,.18); }
.sun input { width: 150px; }

/* house settings */
#housePane { overflow: auto; }
#house { padding: 12px; max-width: 760px; margin: 0 auto; width: 100%; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 13px; margin-bottom: 12px; }
.card h3 { margin: 0 0 4px; font-size: 15.5px; }
.card .sub { margin: 0 0 10px; color: var(--muted); font-size: 12.5px; }
.seg { display: flex; background: var(--field); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 3px; width: 100%; }
.seg button { flex: 1; border: 0; background: none; border-radius: 8px; padding: 8px 4px; cursor: pointer; font-size: 13.5px; }
.seg button.on { background: var(--card); color: var(--accent); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; }
.stat { background: var(--field); border-radius: 10px; padding: 8px 10px; }
.stat small { display: block; color: var(--muted); font-size: 11.5px; }
.stat b { font-size: 17px; }
.credit { text-align: center; color: var(--muted); font-size: 12px; margin: 18px 0 30px; }
.credit img { display: block; width: 118px; height: auto; margin: 0 auto 6px; border-radius: 9px; }
.credit a { color: inherit; white-space: nowrap; }

/* sheets */
#sheet { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.4); display: flex; align-items: flex-end; justify-content: center; }
#sheet .panel { width: 100%; max-width: 560px; background: var(--card); border-radius: 18px 18px 0 0; padding: 12px 14px calc(env(safe-area-inset-bottom) + 16px); max-height: 90vh; overflow: auto; }
#sheet .panel h3 { margin: 4px 4px 10px; }
#sheet .item { display: flex; width: 100%; gap: 12px; align-items: center; text-align: left; border: 0; background: none; padding: 12px 6px; border-top: 1px solid var(--line); cursor: pointer; font-size: 15.5px; }
#sheet .item small { display: block; color: var(--muted); font-size: 12.5px; }
#sheet img.preview { width: 100%; max-height: 40vh; object-fit: contain; border-radius: 10px; background: var(--field); }
.spinner { width: 22px; height: 22px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.9s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
#toast { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 90px); transform: translateX(-50%) translateY(20px); background: #1c2530; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; opacity: 0; pointer-events: none; transition: .2s; z-index: 60; max-width: 90vw; text-align: center; }
#toast.show { opacity: 1; transform: translateX(-50%); }
