@font-face {
  font-family: Axiforma;
  src: url("./brand/axiforma-book.ttf") format("truetype");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

:root {
  color-scheme: dark;
  --ink: #f7f3ea;
  --shade: #302d29;
  --surface: #302d29f2;
  --hover: #4b443a;
  --muted: #d8d0c1;
  --accent: #c6b189;
  --line: #f7f3ea26;
  font-family: Axiforma, "Avenir Next", system-ui, sans-serif;
  background: var(--shade);
  color: var(--ink);
}

*, *::before, *::after { box-sizing: border-box }
[hidden] { display: none !important }
body {
  margin: 0;
  min-width: 280px;
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}
button, input, select { font: inherit; color: inherit }
button { -webkit-tap-highlight-color: transparent; cursor: pointer; touch-action: manipulation }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px }

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .7rem;
  min-height: 4.5rem;
  padding: max(.5rem, env(safe-area-inset-top)) max(1.2rem, env(safe-area-inset-right)) .5rem max(1.2rem, env(safe-area-inset-left));
  border-bottom: 1px solid var(--line);
}
.identity { display: flex; align-items: center; gap: .85rem; min-width: 0 }
.brand-logo { display: block; width: 4.05rem; height: auto; flex: none }
.property { display: grid; gap: .16rem; border-left: 1px solid var(--line); padding-left: .85rem; font-size: .94rem; line-height: 1.28 }
.property small { font-size: .68rem; color: var(--muted) }
.stage {
  display: inline-flex;
  flex: none;
  padding: .2rem;
  border: 1px solid var(--line);
  border-radius: .5rem;
  background: #221f1b;
}
.stage button {
  appearance: none;
  border: 0;
  border-radius: .32rem;
  min-height: 2.3rem;
  padding: .1rem .8rem 0;
  background: transparent;
  color: var(--muted);
  font-size: .8rem;
}
.stage button:hover { background: var(--hover); color: var(--ink) }
.stage button[aria-pressed="true"] { background: var(--ink); color: var(--shade) }

.tour {
  --edge: clamp(.75rem, 2.3vw, 2rem);
  --bottom: max(var(--edge), env(safe-area-inset-bottom));
  --left: max(var(--edge), env(safe-area-inset-left));
  --right: max(var(--edge), env(safe-area-inset-right));
  position: relative;
  min-height: 0;
  background: #777065;
  isolation: isolate;
  overflow: hidden;
}
.tour:fullscreen { width: 100%; height: 100% }
.viewport, .loading { position: absolute; inset: 0 }
.viewport { outline-offset: -4px; cursor: grab; touch-action: none }
.viewport.over-cabinet, .viewport.over-window { cursor: pointer }
.viewport:active { cursor: grabbing }
.viewport canvas { display: block; width: 100%; height: 100% }
.loading { display: grid; place-content: center; text-align: center; z-index: 5; background: var(--shade); padding: 2rem }
.loading span { width: 1.75rem; height: 1.75rem; margin: auto; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 1.2s linear infinite }
.loading.error span { display: none }
@keyframes spin { to { transform: rotate(360deg) } }

.location {
  position: absolute;
  top: var(--edge);
  left: var(--left);
  max-width: min(calc(100% - 2 * var(--edge)), 24rem);
  pointer-events: none;
}
.location h1 {
  width: fit-content;
  max-width: 100%;
  margin: 0;
  padding: .58rem .85rem .48rem;
  border: 1px solid var(--line);
  border-radius: .42rem;
  background: var(--surface);
  font-size: clamp(1rem, 1.9vw, 1.55rem);
  font-weight: 400;
  line-height: 1.25;
}
.cabinet-tools { width: fit-content; max-width: 19rem; margin: .45rem 0 0; border-radius: .42rem; background: var(--surface); padding: .6rem .68rem; font-size: .76rem }
.cabinet-tools p { margin: 0 }
.cabinet-tools button { pointer-events: auto; margin-top: .4rem; padding: .4rem .55rem; border: 1px solid var(--line); border-radius: .3rem; background: var(--hover) }
.cabinet-tools button:hover { border-color: var(--accent) }
.window-view-trigger { margin-top: .4rem; pointer-events: auto }

.navigation {
  position: absolute;
  right: var(--right);
  bottom: var(--bottom);
  display: grid;
  grid-template-columns: auto auto;
  align-items: end;
  justify-items: end;
  gap: .38rem;
  pointer-events: none;
}
.actions, .auto-controls { display: flex; gap: .3rem; pointer-events: auto }
.auto-controls { order: 1 }
.actions { order: 2 }
.auto-status, .map, .lighting-panel { grid-column: 1 / -1; pointer-events: auto }
.auto-status { order: -1; width: fit-content; max-width: min(14.5rem, 63vw); padding: .4rem .58rem; border-radius: .35rem; background: var(--surface); color: var(--ink); font-size: .74rem; text-align: right }
.utility, .move-pad button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .42rem;
  min-width: 2.75rem;
  min-height: 2.75rem;
  border: 1px solid var(--line);
  border-radius: .42rem;
  background: var(--surface);
  color: var(--ink);
  padding: .18rem .65rem 0;
  font-size: .77rem;
  line-height: 1.1;
  white-space: nowrap;
}
.utility:hover, .move-pad button:hover, .move-pad button:active { background: var(--hover) }
.utility[aria-expanded="true"] { border-color: var(--accent); color: var(--accent) }
.utility.auto-toggle { background: var(--accent); border-color: var(--accent); color: #241f19 }
.utility.auto-toggle:hover, .utility.auto-toggle:active { background: #ddc8a1 }
.auto-toggle::before { content: ""; width: .55rem; height: .65rem; flex: none; background: currentColor; clip-path: polygon(0 0, 100% 50%, 0 100%) }
.auto-toggle[data-playing="true"]::before { clip-path: none; background: linear-gradient(to right, currentColor 36%, transparent 36% 64%, currentColor 64%) }
.icon-button { padding: 0 }
.home-icon { position: relative; width: .7rem; height: .66rem; margin-top: .25rem; border: 1px solid currentColor; border-top: 0 }
.home-icon::before { content: ""; position: absolute; top: -.28rem; left: .01rem; width: .54rem; height: .54rem; border-top: 1px solid currentColor; border-left: 1px solid currentColor; transform: rotate(45deg) }
.map-icon { width: .9rem; height: .71rem; border: 1px solid currentColor; position: relative; flex: none }
.map-icon::after { content: ""; position: absolute; top: 0; bottom: 38%; left: 54%; right: 0; border-left: 1px solid currentColor; border-bottom: 1px solid currentColor }
.fullscreen span {
  width: .92rem;
  height: .92rem;
  background: linear-gradient(currentColor, currentColor) top left / 35% 1px,
    linear-gradient(currentColor, currentColor) top right / 35% 1px,
    linear-gradient(currentColor, currentColor) bottom left / 35% 1px,
    linear-gradient(currentColor, currentColor) bottom right / 35% 1px,
    linear-gradient(currentColor, currentColor) top left / 1px 35%,
    linear-gradient(currentColor, currentColor) top right / 1px 35%,
    linear-gradient(currentColor, currentColor) bottom left / 1px 35%,
    linear-gradient(currentColor, currentColor) bottom right / 1px 35%;
  background-repeat: no-repeat;
}

.map, .lighting-panel {
  width: min(17rem, calc(100vw - 2 * var(--edge)));
  max-height: calc(100dvh - 11rem);
  padding: .75rem;
  background: var(--shade);
  border: 1px solid var(--line);
  border-radius: .55rem;
  font-size: .81rem;
  overflow: auto;
}
.map canvas { display: block; width: min(100%, 12rem); height: auto; margin: auto }
.room-picker { display: grid; gap: .36rem; color: var(--ink) }
.lighting-time { display: flex; justify-content: space-between; align-items: center; gap: .55rem }
.room-picker select, .lighting-panel input[type=time], .lighting-panel select {
  padding: .39rem .42rem .32rem;
  background: #241f19;
  border: 1px solid var(--line);
  border-radius: .29rem;
}
.lighting-panel input[type=time], .lighting-panel select { max-width: 8.5rem }
.lighting-panel input[type=range] { display: block; width: 100%; accent-color: var(--accent); margin: .7rem 0 }
.lighting-panel small { display: block; margin-top: .65rem; color: var(--muted); font-size: .71rem }

.instructions {
  position: absolute;
  bottom: var(--bottom);
  left: var(--left);
  font-size: .74rem;
  pointer-events: none;
}
.desktop-instructions {
  display: flex;
  align-items: center;
  gap: .25rem;
  padding: .42rem .52rem;
  border: 1px solid var(--line);
  border-radius: .42rem;
  background: var(--surface);
}
.desktop-instructions kbd { display: grid; place-items: center; width: 1.2rem; height: 1.25rem; border: 1px solid var(--line); border-radius: .2rem; font: .72rem/1 system-ui, sans-serif }
.desktop-instructions span:first-of-type { margin-left: .2rem }
.desktop-instructions span:last-of-type { border-left: 1px solid var(--line); margin-left: .2rem; padding-left: .48rem }
.touch-instructions, .walk-joystick { display: none }
.move-pad {
  position: absolute;
  bottom: calc(var(--bottom) + 2.5rem);
  left: var(--left);
  display: grid;
  grid-template-columns: repeat(3, 2.5rem);
  gap: .22rem;
}
.move-pad button { min-width: 0; min-height: 2.5rem; touch-action: none; padding: 0; font: 1.05rem/1 system-ui, sans-serif }
.move-pad button:first-child { grid-column: 2 }
.move-pad button:nth-child(2) { grid-column: 1 }

.window-video {
  width: min(100% - 1.5rem, 980px);
  max-height: calc(100dvh - 1.5rem);
  padding: 0;
  color: var(--ink);
  background: var(--shade);
  border: 1px solid var(--line);
  border-radius: .6rem;
  overflow: auto;
}
.window-video::backdrop { background: #161410d9 }
.window-video-header { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .46rem .65rem .46rem 1rem }
.window-video h2 { margin: 0; font-size: clamp(.82rem, 2.5vw, 1.2rem); font-weight: 400 }
.window-video-close { flex: none; font: 1.35rem/1 system-ui, sans-serif; padding: 0 }
.window-video video { display: block; width: 100%; max-height: 78dvh; aspect-ratio: 16 / 9; background: #181610 }
.window-video-error { margin: 0; padding: .6rem 1rem }

@media (max-width: 960px) {
  .navigation { grid-template-columns: auto }
  .map, .lighting-panel { max-height: calc(100dvh - 13rem) }
}
@media (pointer: coarse), (max-width: 570px) {
  .tour { --stick-size: clamp(5.2rem, 24vw, 6rem) }
  .header { min-height: 3.75rem }
  .brand-logo { width: 2.9rem }
  .property { font-size: .83rem }
  .move-pad, .desktop-instructions { display: none }
  .instructions { bottom: calc(var(--bottom) + var(--stick-size) + .9rem) }
  .touch-instructions {
    display: grid;
    padding: .35rem .46rem .28rem;
    border-radius: .35rem;
    background: var(--surface);
    font-size: .65rem;
    line-height: 1.45;
  }
  .walk-joystick {
    position: absolute;
    bottom: var(--bottom);
    left: var(--left);
    width: var(--stick-size);
    aspect-ratio: 1;
    display: grid;
    place-items: center;
    border: 1px solid #f7f3ea54;
    border-radius: 50%;
    background: #302d29d9;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    cursor: grab;
  }
  .walk-joystick.is-active { cursor: grabbing; border-color: var(--accent); background: var(--shade) }
  .joystick-ring { position: absolute; inset: 17%; border: 1px solid var(--line); border-radius: 50%; pointer-events: none }
  .joystick-thumb {
    --thumb-x: 0px;
    --thumb-y: 0px;
    width: 41%;
    aspect-ratio: 1;
    border: 1px solid #e7d7bb;
    border-radius: 50%;
    background: var(--accent);
    transform: translate(var(--thumb-x), var(--thumb-y));
    pointer-events: none;
  }
  .tour:has(#map:not([hidden]), #lighting-panel:not([hidden])) :is(.walk-joystick, .instructions) { visibility: hidden }
}
@media (max-width: 570px) {
  .header { padding-right: max(.7rem, env(safe-area-inset-right)); padding-left: max(.7rem, env(safe-area-inset-left)); gap: .4rem }
  .identity { gap: .55rem }
  .property { padding-left: .55rem; font-size: .74rem }
  .property small { font-size: .59rem }
  .stage button { min-height: 2.75rem; padding-inline: .46rem; font-size: .72rem }
  .tour { --edge: .65rem }
  .navigation, .actions, .auto-controls { gap: .23rem }
  .auto-status { max-width: min(14.5rem, calc(100vw - 8.7rem)) }
  .utility { font-size: .7rem; padding-inline: .46rem }
  .icon-button { padding: 0 }
  .map-icon { display: none }
}
@media (max-width: 340px) {
  .tour { --stick-size: 5rem }
  .property { border-left: 0; padding-left: 0 }
  .identity { gap: .38rem }
  .property small { display: none }
  .utility { padding-inline: .28rem }
}
@media (max-height: 460px) and (min-width: 670px) {
  .navigation { grid-template-columns: auto auto }
  .map, .lighting-panel { max-height: calc(100dvh - 8.5rem) }
  .map canvas { width: min(100%, 9.5rem) }
}
@media (prefers-reduced-motion: reduce) {
  .loading span { animation: none }
}
