:root {
  --ink: #1d2b28;
  --ink2: #5d6e67;
  --bg: rgba(250, 249, 245, 0.94);
  --line: rgba(29, 43, 40, 0.14);
  --acc: #c2571a;
  --on: #1d2b28;
  --onink: #fff;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #dfe6e8;
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink); overscroll-behavior: none; touch-action: none;
  -webkit-user-select: none; user-select: none;
}
canvas#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }

/* loading */
#loading { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: #eef0ec; }
#loading.gone { opacity: 0; pointer-events: none; transition: opacity .4s; }
.ld-box { width: min(320px, 80vw); text-align: center; }
.ld-title { font-size: 26px; font-weight: 700; letter-spacing: .02em; margin-bottom: 14px; }
.ld-bar { height: 8px; border-radius: 4px; background: #d7dcd6; overflow: hidden; }
#ld-fill { height: 100%; width: 0; background: var(--ink); transition: width .15s; }
#ld-text { margin-top: 10px; color: var(--ink2); font-size: 13px; }

/* top */
#top {
  position: fixed; top: calc(8px + var(--safe-t)); left: 8px; right: 8px; z-index: 10;
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap; pointer-events: none;
}
#top > * { pointer-events: auto; }
.seg { display: inline-flex; background: var(--bg); border-radius: 12px; padding: 3px; box-shadow: 0 1px 6px rgba(0,0,0,.12); }
.seg button { padding: 8px 12px; border-radius: 9px; font-weight: 600; font-size: 14px; color: var(--ink2); }
.seg button.on { background: var(--on); color: var(--onink); }
#cutwrap {
  display: flex; align-items: center; gap: 8px; background: var(--bg); border-radius: 12px;
  padding: 6px 12px; box-shadow: 0 1px 6px rgba(0,0,0,.12); flex: 1 1 160px; min-width: 150px;
}
#cutwrap label { font-size: 13px; color: var(--ink2); white-space: nowrap; }
#cutwrap span { color: var(--ink); font-weight: 700; }
#cutwrap input { flex: 1; accent-color: var(--ink); min-width: 60px; }
#cutwrap.off { display: none; }
#offline { font-size: 12px; color: var(--ink2); background: var(--bg); border-radius: 10px; padding: 4px 8px; display: none; }
#offline.show { display: block; }

/* bottom bar */
#bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex;
  background: var(--bg); border-top: 1px solid var(--line); padding-bottom: var(--safe-b);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
#bar button { flex: 1; padding: 8px 0 9px; display: flex; flex-direction: column; align-items: center; gap: 1px; font-size: 12px; font-weight: 600; color: var(--ink2); }
#bar button .ic { font-size: 20px; line-height: 24px; filter: grayscale(1); }
#bar button.on { color: var(--ink); }
#bar button.on .ic { filter: none; }

/* walk controls */
#joy, #updown { display: none; }
body.walk #joy, body.walk #updown { display: block; }
#joy {
  position: fixed; left: 18px; bottom: calc(80px + var(--safe-b)); width: 124px; height: 124px; z-index: 9;
  border-radius: 50%; background: rgba(255,255,255,.35); border: 2px solid rgba(255,255,255,.75);
  box-shadow: 0 2px 10px rgba(0,0,0,.18); touch-action: none;
}
#knob {
  position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px;
  border-radius: 50%; background: rgba(29,43,40,.78); box-shadow: 0 1px 6px rgba(0,0,0,.3);
}
#updown { position: fixed; right: 14px; bottom: calc(86px + var(--safe-b)); z-index: 9; }
#updown button {
  display: block; width: 52px; height: 52px; margin-top: 10px; border-radius: 50%;
  background: var(--bg); font-size: 18px; box-shadow: 0 1px 6px rgba(0,0,0,.18); touch-action: none;
}
#hint {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(76px + var(--safe-b)); z-index: 8;
  background: rgba(29,43,40,.82); color: #fff; font-size: 13px; padding: 7px 12px; border-radius: 10px;
  max-width: calc(100vw - 32px); text-align: center; opacity: 0; transition: opacity .3s; pointer-events: none;
}
#hint.show { opacity: 1; }

/* card */
#card {
  position: fixed; left: 8px; right: 8px; bottom: calc(66px + var(--safe-b)); z-index: 12;
  background: var(--bg); border-radius: 16px; box-shadow: 0 4px 22px rgba(0,0,0,.22);
  padding: 10px 12px 12px; max-width: 520px; margin: 0 auto;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
#card[hidden] { display: none; }
body.walk #card { bottom: calc(66px + var(--safe-b)); }
.card-head { display: flex; align-items: center; gap: 6px; }
.card-head button { width: 38px; height: 38px; border-radius: 10px; background: rgba(29,43,40,.07); font-size: 22px; line-height: 1; flex: none; }
.card-head button:disabled { opacity: .3; }
#c-close { font-size: 15px; background: none; }
.card-title { flex: 1; min-width: 0; text-align: center; }
#c-name { font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#c-lvl { font-size: 12px; color: var(--ink2); }
#c-dims { display: flex; justify-content: space-around; text-align: center; margin: 6px 0 4px; gap: 2px; }
#c-dims .d { flex: 1; min-width: 0; }
#c-dims .v { font-size: 21px; font-weight: 750; letter-spacing: -.01em; white-space: nowrap; }
#c-dims .k { font-size: 11px; color: var(--ink2); text-transform: uppercase; letter-spacing: .05em; }
#c-dims .mm { font-size: 11px; color: var(--ink2); white-space: nowrap; }
#c-dims .times { align-self: center; color: var(--ink2); flex: none; font-size: 14px; }
#c-rows { font-size: 13px; border-top: 1px solid var(--line); padding-top: 4px; }
#c-rows .r { display: flex; justify-content: space-between; gap: 10px; padding: 2px 0; }
#c-rows .r span:first-child { color: var(--ink2); }
#c-rows .r span:last-child { font-weight: 650; text-align: right; }
.walls { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin-top: 4px; text-align: center; }
.walls div { background: rgba(29,43,40,.06); border-radius: 8px; padding: 4px 0; }
.walls b { display: block; font-size: 11px; color: var(--ink2); font-weight: 600; }

/* sheets */
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; max-height: 72vh; overflow: auto;
  background: #faf9f5; border-radius: 18px 18px 0 0; box-shadow: 0 -4px 24px rgba(0,0,0,.25);
  padding: 0 0 calc(10px + var(--safe-b)); touch-action: pan-y; -webkit-overflow-scrolling: touch;
}
.sheet[hidden] { display: none; }
.sheet-head { position: sticky; top: 0; display: flex; justify-content: space-between; align-items: center; padding: 14px 16px 8px; background: #faf9f5; font-size: 17px; }
.x { width: 36px; height: 36px; border-radius: 50%; background: rgba(29,43,40,.08); font-size: 15px; }
.fl-h { padding: 10px 16px 4px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink2); font-weight: 700; }
.room { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-top: 1px solid var(--line); }
.room .nm { flex: 1; min-width: 0; }
.room .nm b { display: block; font-size: 15px; }
.room .nm span { font-size: 13px; color: var(--ink2); }
.room button { padding: 8px 12px; border-radius: 10px; background: rgba(29,43,40,.08); font-size: 13px; font-weight: 650; white-space: nowrap; }
.room button.walk { background: var(--ink); color: #fff; }

/* plans */
#plans { position: fixed; inset: 0; z-index: 30; background: #fff; display: flex; flex-direction: column; }
#plans[hidden] { display: none; }
.plans-head { display: flex; justify-content: space-between; align-items: center; padding: calc(8px + var(--safe-t)) 10px 8px; border-bottom: 1px solid var(--line); background: #faf9f5; }
#plan-view { flex: 1; position: relative; overflow: hidden; touch-action: none; background: #fff; }
#plan-view svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.plans-foot { font-size: 12px; color: var(--ink2); text-align: center; padding: 6px 8px calc(6px + var(--safe-b)); border-top: 1px solid var(--line); background: #faf9f5; }

@media (min-width: 760px) {
  #card { left: auto; right: 16px; bottom: calc(76px + var(--safe-b)); width: 420px; }
  .sheet { left: auto; right: 16px; bottom: 76px; width: 420px; border-radius: 18px; max-height: 70vh; }
}
