/* Holographic look: dark room, cyan light, everything glowing and moving. */

:root {
  --bg: #04080f;
  --holo: #4fd8ff;
  --warm: #ff9a3c;
  --cold: #48d9ff;
  --ink: #cbeeff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1200px 700px at 50% 12%, #0b2033 0%, transparent 70%),
    radial-gradient(900px 600px at 80% 90%, #071c2b 0%, transparent 70%),
    var(--bg);
  color: var(--ink);
  font: 15px/1.5 "Segoe UI", system-ui, sans-serif;
  letter-spacing: 0.02em;
}

header {
  padding: 22px 28px 6px;
  text-align: center;
}

.title-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 500;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: #eaf9ff;
  text-shadow: 0 0 18px rgba(79, 216, 255, 0.75);
}

/* The help button carries an icon and nothing else — the explanation it opens
   is where all the words live now. */
.help-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid rgba(79, 216, 255, 0.4);
  border-radius: 50%;
  background: rgba(10, 34, 52, 0.85);
  color: var(--holo);
  cursor: pointer;
}

.help-button:hover {
  border-color: rgba(120, 230, 255, 0.9);
  box-shadow: 0 0 14px rgba(79, 216, 255, 0.45);
}

.help-icon {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
}

.help-icon .help-dot {
  fill: currentColor;
  stroke: none;
}

#help-dialog {
  width: min(760px, 92vw);
  max-height: 82vh;
  padding: 0;
  border: 1px solid rgba(79, 216, 255, 0.35);
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(10, 30, 46, 0.98), rgba(4, 10, 18, 0.99));
  color: var(--ink);
  box-shadow: 0 0 60px rgba(20, 120, 170, 0.35);
}

#help-dialog::backdrop {
  background: rgba(2, 6, 12, 0.72);
}

.help-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(79, 216, 255, 0.2);
}

.help-head h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: #eaf9ff;
}

.help-close {
  border: 1px solid rgba(79, 216, 255, 0.4);
  border-radius: 8px;
  background: rgba(10, 34, 52, 0.85);
  color: var(--holo);
  font-size: 13px;
  padding: 4px 9px;
  cursor: pointer;
}

.help-body {
  overflow: auto;
  max-height: calc(82vh - 60px);
  padding: 4px 20px 20px;
}

.help-body h3 {
  margin: 18px 0 4px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--holo);
}

.help-body p {
  margin: 0;
  font-size: 13.5px;
  color: #a8cfe2;
}

main {
  display: flex;
  justify-content: center;
  padding: 10px 20px 32px;
}

/* The scene takes whatever room the window offers instead of stopping at a fixed
   box: the same look, drawn larger. The frame shrink-wraps the plan. */
#scene-frame {
  position: relative;
  border: 1px solid rgba(79, 216, 255, 0.22);
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(10, 30, 46, 0.65), rgba(4, 10, 18, 0.9));
  box-shadow: 0 0 60px rgba(20, 120, 170, 0.25) inset, 0 0 40px rgba(0, 0, 0, 0.6);
  overflow: hidden;
}

/*
 * The plan grows with the window: it is drawn as wide as the window leaves room
 * for once the page around it is counted, so a roomier screen gets a bigger
 * house. Two bounds hold it — it never falls below the 1080px box the page used
 * to stop at, whatever the window, and it never runs wider than the window.
 * `--scene-aspect` is the shape of the plan as it is actually drawn; the height
 * follows the width, so the plan is only ever scaled, never squashed.
 */
#scene {
  display: block;
  width: min(
    calc(100vw - 44px),
    max(1080px, calc((100dvh - 130px) * var(--scene-aspect, 1)))
  );
  height: auto;
  touch-action: none;
}

/* ---------- the plan ---------- */

.outside {
  stroke: none;
}

.grid-line {
  fill: none;
  stroke: rgba(79, 216, 255, 0.09);
  stroke-width: 1;
}

/*
 * The outside walls of the house. The house is a block of rectangles, so the
 * outline is every stretch of wall with no room on the far side.
 */
.shell {
  fill: none;
  stroke: rgba(120, 230, 255, 0.55);
  stroke-width: 2.5;
  filter: url(#glow-line);
}

.shell-wall {
  stroke-linecap: round;
}

.room-fill {
  opacity: 0.13;
  transition: opacity 0.4s ease;
}

.room-edge {
  fill: none;
  stroke-width: 1.6;
  opacity: 0.65;
  filter: url(#glow);
}

.room-labels {
  pointer-events: none; /* the labels float over the scene; clicks reach the elements */
}

.room-name {
  fill: #8fd3ec;
  font-size: 13px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.room-temp {
  font-size: 24px;
  font-variant-numeric: tabular-nums;
  filter: url(#glow);
}

.outside-temp {
  font-size: 16px;
  letter-spacing: 0.12em;
  filter: url(#glow);
}

/* ---------- air streams ---------- */

.stream {
  transition: opacity 0.5s ease;
  pointer-events: none;
}

.stream-glow {
  opacity: 0.28;
  stroke-linecap: round;
  filter: url(#glow-line);
}

.stream-dash {
  stroke-linecap: round;
  stroke-dasharray: 11 15;
  animation: march 1.15s linear infinite;
  filter: url(#glow-line);
}

@keyframes march {
  to {
    stroke-dashoffset: -52;
  }
}

.head.warm {
  fill: var(--warm);
}

.head.cold {
  fill: var(--cold);
}

/* ---------- elements ---------- */

.hit {
  fill: transparent;
  stroke: transparent;
  stroke-width: 10;
  cursor: pointer;
}

.element,
.sun {
  cursor: pointer;
}

.opening-frame {
  stroke: rgba(120, 220, 255, 0.28);
  stroke-width: 9;
  stroke-linecap: round;
}

.opening-leaf {
  stroke: var(--holo);
  stroke-width: 5;
  stroke-linecap: round;
  filter: url(#glow-line);
  transition: opacity 0.25s ease;
}

.door.open .opening-leaf {
  stroke-dasharray: 4 9;
  opacity: 0.5;
}

/* ---------- windows: one rectangle, three looks ---------- */

/* A window and its shutter are the same rectangle. Its fill and edge are
   painted by the renderer — open (the colour of the air coming through),
   closed behind glass, or closed behind the shutter — so the shape on the
   plan never changes, only what it looks like. */
.window-pane {
  stroke-width: 2.5;
  transition: fill 0.3s ease, stroke 0.3s ease;
}

/* An open window is drawn with a broken edge: the sash is not shut. */
.window.open .window-pane {
  stroke-dasharray: 6 5;
}

/* The slats of the shutter, striped across that same rectangle. */
.window-shutter {
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.shutter-slat {
  stroke: rgba(178, 200, 220, 0.85);
  stroke-width: 2.4;
  stroke-linecap: round;
}

/* ---------- the sky: the day arc and the sun ---------- */

.sun-arc {
  fill: none;
  stroke: rgba(255, 210, 120, 0.28);
  stroke-width: 1.6;
  stroke-dasharray: 7 9;
  filter: url(#glow-line);
}

.sun-tick {
  fill: rgba(255, 210, 120, 0.4);
}

.compass {
  fill: rgba(140, 200, 225, 0.6);
  font-size: 15px;
  letter-spacing: 0.2em;
}

.sun {
  cursor: grab;
}

.sun-core {
  fill: rgba(255, 205, 90, 0.85);
  stroke: #ffd66b;
  stroke-width: 1.6;
  filter: url(#glow);
  animation: pulse 3.2s ease-in-out infinite;
}

.sun-ray {
  stroke: #ffd66b;
  stroke-width: 2;
  stroke-linecap: round;
  filter: url(#glow-line);
  animation: pulse 3.2s ease-in-out infinite;
}

.sun.down .sun-core {
  fill: rgba(90, 120, 150, 0.55);
  stroke: rgba(150, 190, 215, 0.7);
  animation: none;
}

.sun.down .sun-ray {
  stroke: rgba(150, 190, 215, 0.45);
  animation: none;
}

/* By night the same marker is the moon: the rays go out and a shadow set off to
   one side of the disc leaves a crescent. */
.moon-shade {
  display: none;
  fill: var(--bg);
  stroke: none;
}

.sun.moon .sun-ray {
  display: none;
}

.sun.moon .moon-shade {
  display: block;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.55;
  }
  50% {
    opacity: 1;
  }
}

.airco-body {
  fill: rgba(30, 120, 160, 0.18);
  stroke: var(--holo);
  stroke-width: 1.8;
  filter: url(#glow);
}

.airco-louvre {
  stroke: rgba(120, 225, 255, 0.55);
  stroke-width: 1.2;
}

/* The set temperature is written inside the airco and has to read at a glance. */
.airco-set {
  fill: #d9f4ff;
  font-size: 19px;
  font-weight: 600;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
  filter: url(#glow);
  pointer-events: none;
}

.airco.on .airco-body {
  fill: rgba(60, 200, 255, 0.28);
  animation: breathe 2.6s ease-in-out infinite;
}

.airco.warm .airco-body {
  stroke: #ffb066;
}

.airco.on.warm .airco-body {
  fill: rgba(255, 150, 70, 0.3);
}

.airco.warm .airco-set {
  fill: #ffe0bd;
}

.airco.warm .airco-louvre {
  stroke: rgba(255, 176, 102, 0.6);
}

.airco.off .airco-body,
.radiator.off .radiator-body {
  opacity: 0.5;
}

@keyframes breathe {
  0%,
  100% {
    opacity: 0.75;
  }
  50% {
    opacity: 1;
  }
}

.radiator-body {
  fill: rgba(120, 80, 40, 0.14);
  stroke: #ffb066;
  stroke-width: 1.6;
  filter: url(#glow);
}

.radiator-fin {
  stroke: rgba(255, 176, 102, 0.6);
  stroke-width: 1.2;
}

.radiator.on .radiator-body {
  fill: rgba(255, 140, 60, 0.35);
  animation: breathe 1.8s ease-in-out infinite;
}

/* ---------- the portable electric heater ---------- */

.heater-body {
  fill: rgba(120, 80, 40, 0.16);
  stroke: #ffb066;
  stroke-width: 1.8;
  filter: url(#glow);
}

.heater-coil {
  stroke: rgba(255, 176, 102, 0.65);
  stroke-width: 1.6;
  stroke-linecap: round;
}

.heater-set {
  fill: #ffe0bd;
  font-size: 17px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  filter: url(#glow);
  pointer-events: none;
}

.heater.on .heater-body {
  fill: rgba(255, 140, 60, 0.4);
  animation: breathe 1.4s ease-in-out infinite;
}

.heater.on .heater-coil {
  stroke: #ffd0a0;
}

.heater.off .heater-body {
  opacity: 0.5;
}

/* ---------- the built-in extractor fans ---------- */

/* A slim box lying flat against the wall it vents through. */
.extractor-body {
  fill: rgba(10, 40, 60, 0.75);
  stroke: rgba(150, 190, 215, 0.8);
  stroke-width: 1.8;
  filter: url(#glow);
}

.extractor-slat {
  stroke: rgba(150, 235, 255, 0.75);
  stroke-width: 1.8;
  stroke-linecap: round;
}

.extractor.on .extractor-body {
  fill: rgba(60, 200, 255, 0.28);
  stroke: #8ff0ff;
}

.extractor.on .extractor-slat {
  animation: pulse 0.9s ease-in-out infinite;
}

.extractor.off .extractor-slat {
  opacity: 0.4;
}

.fan-ring {
  fill: rgba(10, 40, 60, 0.55);
  stroke: var(--holo);
  stroke-width: 1.8;
  filter: url(#glow);
}

.fan-blade {
  fill: rgba(150, 235, 255, 0.75);
}

.ventilator.on .fan-blades {
  animation: spin 0.75s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.fan-beam {
  fill: rgba(79, 216, 255, 0.07);
  stroke: rgba(79, 216, 255, 0.22);
  stroke-width: 1;
}

.ventilator.on .fan-beam {
  fill: rgba(79, 216, 255, 0.16);
  stroke: rgba(120, 235, 255, 0.5);
  animation: breathe 1.6s ease-in-out infinite;
}

.fan-handle-dot {
  fill: rgba(10, 40, 60, 0.8);
  stroke: var(--holo);
  stroke-width: 1.6;
}

.fan-handle-tip {
  fill: var(--holo);
  filter: url(#glow-line);
}

.fan-handle {
  cursor: grab;
}

.ventilator.off .fan-beam,
.ventilator.off .fan-blade {
  opacity: 0.45;
}

/* ---------- panels that sit on the scene ---------- */

.on-scene {
  position: absolute;
  padding: 8px 12px;
  border: 1px solid rgba(79, 216, 255, 0.4);
  border-radius: 10px;
  background: rgba(6, 22, 34, 0.88);
  box-shadow: 0 0 24px rgba(30, 160, 210, 0.35);
  color: var(--ink);
  font-size: 12.5px;
}

/* Each panel is pinned to its own corner of the scene and scaled from that
   corner, so it keeps its place beside the plan however large the scene is. */
.outside-control,
.speed-control,
.add-control,
.change-map-control,
.map-controls {
  transform: scale(var(--ui-scale, 1));
}

.outside-control {
  top: 14px;
  left: 16px;
  display: flex;
  gap: 10px;
  align-items: center;
  transform-origin: top left;
}

/* The simulated time reads directly above the slider that sets its speed. */
.speed-control {
  bottom: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: stretch;
  transform-origin: bottom right;
}

.speed-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

#clock {
  color: var(--holo);
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 12px rgba(79, 216, 255, 0.6);
}

.speed-control label,
.outside-control label {
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-size: 11px;
  color: #7fb9d4;
}

#steady-weather {
  padding: 3px 10px;
  border: 1px solid rgba(79, 216, 255, 0.5);
  border-radius: 6px;
  background: rgba(10, 40, 60, 0.8);
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  white-space: nowrap;
}

#steady-weather[data-on="true"] {
  background: rgba(60, 200, 255, 0.3);
  box-shadow: 0 0 14px rgba(79, 216, 255, 0.6);
}

#speed {
  width: 110px;
}

#speed-value {
  min-width: 34px;
}

/* ---------- adding and removing elements ---------- */

.add-control {
  left: 16px;
  bottom: 16px;
  padding: 0;
  transform-origin: bottom left;
  border: none;
  background: none;
  box-shadow: none;
}

#add-element {
  width: 42px;
  height: 42px;
  border: 1px solid rgba(79, 216, 255, 0.55);
  border-radius: 50%;
  background: rgba(6, 26, 40, 0.9);
  box-shadow: 0 0 20px rgba(30, 160, 210, 0.45);
  color: var(--holo);
  font: 400 24px/1 "Segoe UI", system-ui, sans-serif;
  cursor: pointer;
}

#add-element[data-open="true"] {
  background: rgba(60, 200, 255, 0.3);
}

.add-list {
  position: absolute;
  left: 0;
  bottom: 52px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 140px;
  padding: 10px 12px;
  border: 1px solid rgba(79, 216, 255, 0.4);
  border-radius: 10px;
  background: rgba(6, 22, 34, 0.94);
  box-shadow: 0 0 24px rgba(30, 160, 210, 0.35);
}

.add-list[hidden] {
  display: none;
}

.add-list button {
  padding: 5px 10px;
  border: 1px solid rgba(79, 216, 255, 0.35);
  border-radius: 6px;
  background: rgba(10, 40, 60, 0.8);
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  text-align: left;
}

.add-list button:hover {
  background: rgba(60, 200, 255, 0.25);
}

.element-menu {
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  align-items: center;
  z-index: 2;
}

.element-menu[hidden] {
  display: none;
}

.element-menu [hidden] {
  display: none;
}

.panel-title {
  letter-spacing: 0.08em;
  color: #8fd3ec;
  white-space: nowrap;
}

#airco-power,
#airco-mode,
#window-open,
#window-shutter,
#element-trash {
  min-width: 46px;
  padding: 3px 10px;
  border: 1px solid rgba(79, 216, 255, 0.5);
  border-radius: 6px;
  background: rgba(10, 40, 60, 0.8);
  color: var(--ink);
  cursor: pointer;
  font: inherit;
}

#airco-power[data-on="true"] {
  background: rgba(60, 200, 255, 0.3);
  box-shadow: 0 0 14px rgba(79, 216, 255, 0.6);
}

#airco-mode[data-mode="warm"] {
  border-color: rgba(255, 176, 102, 0.7);
  background: rgba(255, 140, 60, 0.28);
  color: #ffe0bd;
}

#window-open[data-open="true"],
#window-shutter[data-shutter="closed"] {
  background: rgba(60, 200, 255, 0.3);
  box-shadow: 0 0 14px rgba(79, 216, 255, 0.6);
}

/* Over an open window the shutter cannot be worked, and says so. */
#window-shutter:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

#window-open,
#window-shutter {
  min-width: 92px;
  white-space: nowrap;
}

#element-trash {
  min-width: 36px;
  border-color: rgba(255, 130, 130, 0.5);
  color: #ffc9c9;
}

#element-trash:hover {
  background: rgba(255, 90, 90, 0.3);
}

output {
  font-variant-numeric: tabular-nums;
  color: var(--holo);
  min-width: 58px;
}

input[type="range"] {
  width: 150px;
  accent-color: #4fd8ff;
  cursor: pointer;
}

/* ---------- change-map mode ---------- */

/*
 * With change-map mode on, the home itself goes away: the appliances, the air
 * streams and every heat reading. What is left is the map and its own controls.
 */
#scene.editing .appliances,
#scene.editing .streams,
#scene.editing .room-temp,
#scene.editing .outside-temp {
  display: none;
}

#scene.editing .room-fill {
  opacity: 0.2;
}

#scene.editing .element {
  cursor: grab;
}

#scene-frame[data-editing="true"] .outside-control,
#scene-frame[data-editing="true"] .speed-control,
#scene-frame[data-editing="true"] .add-control,
#scene-frame[data-editing="true"] .element-menu {
  display: none;
}

/* The map's own menus only exist while the map is being changed. */
#scene-frame[data-editing="false"] .map-controls,
#scene-frame[data-editing="false"] .room-menu,
#scene-frame[data-editing="false"] .map-element-menu {
  display: none;
}

.change-map-control {
  top: 14px;
  right: 16px;
  padding: 0;
  transform-origin: top right;
  border: none;
  background: none;
  box-shadow: none;
}

#change-map-toggle {
  padding: 6px 14px;
  border: 1px solid rgba(79, 216, 255, 0.55);
  border-radius: 8px;
  background: rgba(6, 22, 34, 0.88);
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  letter-spacing: 0.08em;
  white-space: nowrap;
}

#change-map-toggle[data-on="true"] {
  background: rgba(60, 200, 255, 0.3);
  box-shadow: 0 0 18px rgba(79, 216, 255, 0.6);
}

.map-controls {
  top: calc(62px * var(--ui-scale, 1));
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: stretch;
  transform-origin: top right;
  z-index: 2;
}

.map-controls[hidden] {
  display: none;
}

.map-controls button {
  padding: 4px 10px;
  border: 1px solid rgba(79, 216, 255, 0.5);
  border-radius: 6px;
  background: rgba(10, 40, 60, 0.8);
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  text-align: left;
  white-space: nowrap;
}

.map-controls button:hover {
  background: rgba(60, 200, 255, 0.25);
}

#map-message {
  max-width: 190px;
  min-width: 0;
  color: #ffc9c9;
  font-size: 11.5px;
  white-space: normal;
}

.room-menu,
.map-element-menu {
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  align-items: center;
  z-index: 3;
}

.room-menu[hidden],
.map-element-menu[hidden] {
  display: none;
}

.room-size {
  display: flex;
  gap: 4px;
  align-items: center;
}

.room-size label {
  color: #7fb9d4;
  font-size: 11px;
}

#room-name {
  width: 130px;
}

#room-width,
#room-height {
  width: 62px;
}

#room-name,
#room-width,
#room-height {
  padding: 3px 6px;
  border: 1px solid rgba(79, 216, 255, 0.5);
  border-radius: 6px;
  background: rgba(4, 16, 26, 0.9);
  color: var(--ink);
  font: inherit;
}

.panel-hint {
  color: #7fb9d4;
  font-size: 11px;
  white-space: nowrap;
}

#room-delete,
#map-element-delete {
  min-width: 36px;
  padding: 3px 10px;
  border: 1px solid rgba(255, 130, 130, 0.5);
  border-radius: 6px;
  background: rgba(10, 40, 60, 0.8);
  color: #ffc9c9;
  cursor: pointer;
  font: inherit;
}

#room-delete:hover,
#map-element-delete:hover {
  background: rgba(255, 90, 90, 0.3);
}

#room-delete:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
