@font-face {
  font-family: "WF Bebas Neue";
  src: url("./assets/fonts/BebasNeue-Regular.ttf") format("truetype");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "WF Barlow Condensed";
  src: url("./assets/fonts/BarlowCondensed-Bold.ttf") format("truetype");
  font-weight: 700;
  font-display: swap;
}
@font-face {
  font-family: "WF Orbitron";
  src: url("./assets/fonts/Orbitron-Variable.ttf") format("truetype");
  font-weight: 400 900;
  font-display: swap;
}
@font-face {
  font-family: "WF Oswald";
  src: url("./assets/fonts/Oswald-Variable.ttf") format("truetype");
  font-weight: 200 700;
  font-display: swap;
}
@font-face {
  font-family: "WF Rajdhani";
  src: url("./assets/fonts/Rajdhani-Bold.ttf") format("truetype");
  font-weight: 700;
  font-display: swap;
}
@font-face {
  font-family: "WF Teko";
  src: url("./assets/fonts/Teko-Variable.ttf") format("truetype");
  font-weight: 300 700;
  font-display: swap;
}

:root {
  --ink: #06182e;
  --ink-2: #0c2947;
  --pink: #ff316f;
  --cyan: #28d7f2;
  --paper: #f4f7fb;
  --line: #dbe4ed;
  --muted: #66778a;
  --radius: 16px;
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
button, input, select, textarea { font: inherit; }
button { color: inherit; }
button, label, select, input[type="color"] { -webkit-tap-highlight-color: transparent; }

.app-shell {
  min-height: 100dvh;
  height: 100dvh;
  display: grid;
  grid-template-rows: 48px minmax(250px, 1fr) 54px minmax(186px, 31dvh);
  overflow: hidden;
}

.topbar {
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: max(6px, env(safe-area-inset-top)) 12px 6px;
  color: #fff;
  background: var(--ink);
  box-shadow: 0 2px 12px #06182e28;
}
.brand { display: flex; align-items: center; gap: 4px; color: #fff; text-decoration: none; }
.brand::after { content: "WATTFITS"; font-size: 12px; font-weight: 950; letter-spacing: .055em; }
.brand img { width: 28px; height: 28px; object-fit: contain; }
.topbar-copy { min-width: 0; display: grid; line-height: 1.05; }
.topbar-copy strong { font-size: 13px; }
.topbar-copy span { overflow: hidden; color: #a9bacb; font-size: 10px; white-space: nowrap; text-overflow: ellipsis; }
.history-actions { margin-left: auto; display: flex; gap: 6px; }
.history-actions button {
  width: 34px; height: 34px; border: 1px solid #ffffff25; border-radius: 50%;
  color: #fff; background: #ffffff0d; font-size: 19px;
}
.history-actions button:disabled { opacity: .28; }

.viewer {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 47%, #fff 0 17%, #edf3f8 52%, #dce6ef 100%);
}
.viewer::before {
  position: absolute; inset: 0; content: "";
  background-image: linear-gradient(#0a29420a 1px, transparent 1px), linear-gradient(90deg, #0a29420a 1px, transparent 1px);
  background-size: 24px 24px;
  mask-image: linear-gradient(to bottom, #000, transparent 74%);
}
.viewer-meta {
  z-index: 3; position: absolute; inset: 10px 12px auto;
  display: flex; justify-content: space-between; gap: 12px; pointer-events: none;
}
.viewer-meta span {
  display: inline-flex; align-items: center; min-height: 25px; padding: 0 9px;
  border: 1px solid #cbd8e3; border-radius: 999px; color: var(--ink);
  background: #ffffffd8; backdrop-filter: blur(7px); font-size: 10px; font-weight: 750;
}
#viewerHint { max-width: 52%; color: var(--muted); text-align: right; }
.model-mount { position: absolute; inset: 0; touch-action: none; cursor: grab; }
.model-mount.moving { cursor: crosshair; }
.model-mount canvas { display: block; width: 100%; height: 100%; outline: 0; touch-action: none; }
.model-fallback {
  position: absolute; inset: 5% 8% 2%; width: 84%; height: 93%;
  object-fit: contain; opacity: .92; transition: opacity .25s;
}
.model-mount.ready .model-fallback { opacity: 0; pointer-events: none; }
.model-loading {
  z-index: 2; position: absolute; inset: 0; display: grid; place-content: center; gap: 8px;
  color: var(--ink-2); text-align: center; font-size: 11px; transition: opacity .2s;
}
.model-loading span {
  justify-self: center; width: 26px; height: 26px; border: 3px solid #b9c9d7; border-top-color: var(--pink);
  border-radius: 50%; animation: spin .8s linear infinite;
}
.model-mount.ready .model-loading { opacity: 0; pointer-events: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.object-gizmo {
  z-index: 7; position: absolute; left: 50%; top: 45%; width: 92px; height: 92px;
  border-radius: 50%; transform: translate(-50%, -50%); pointer-events: none;
  filter: drop-shadow(0 5px 12px #06182e42);
}
.object-gizmo[hidden] { display: none; }
.gizmo-ring {
  position: absolute; inset: 0; border: 2px solid #fff; border-radius: 50%;
  box-shadow: 0 0 0 2px var(--pink), inset 0 0 0 1px #06182e28;
  background: #ffffff08;
}
.gizmo-handle {
  position: absolute; display: grid; width: 31px; height: 31px; place-items: center;
  border: 2px solid #fff; border-radius: 50%; color: #fff; background: var(--pink);
  box-shadow: 0 3px 10px #06182e3d; font-size: 16px; font-weight: 900;
  pointer-events: auto; touch-action: none;
}
.gizmo-handle.rotate { left: 31px; top: -18px; }
.gizmo-handle.scale { right: -16px; bottom: -4px; }
.gizmo-toolbar {
  position: absolute; top: 101px; left: 50%; display: flex; gap: 4px;
  padding: 4px; border: 1px solid #ffffffbb; border-radius: 999px;
  background: #06182ee8; transform: translateX(-50%); pointer-events: auto;
}
.gizmo-toolbar button {
  display: grid; width: 28px; height: 28px; place-items: center; border: 0; border-radius: 50%;
  color: #fff; background: #ffffff13; font-size: 13px; font-weight: 850;
}
.gizmo-toolbar button:active { background: var(--pink); }
.model-recovery {
  z-index: 9; position: absolute; inset: 0; display: grid; place-content: center; justify-items: center;
  gap: 6px; padding: 24px; color: #fff; background: #06182edb; text-align: center;
}
.model-recovery[hidden] { display: none; }
.model-recovery b { font-size: 13px; }
.model-recovery span { color: #c7d5e1; font-size: 10px; }
.model-recovery button {
  min-height: 34px; margin-top: 5px; border: 1px solid #ffffff55; border-radius: 9px;
  padding: 0 12px; color: #fff; background: var(--pink); font-size: 10px; font-weight: 800;
}
.model-mount.context-lost canvas { opacity: .14; }
.view-actions {
  z-index: 4; position: absolute; right: 10px; bottom: 8px; left: 10px;
  display: flex; justify-content: center; gap: 5px; pointer-events: none;
}
.view-actions button {
  min-height: 29px; padding: 0 11px; border: 1px solid #c9d6e1; border-radius: 999px;
  color: var(--ink-2); background: #fffffff0; box-shadow: 0 2px 9px #06182e13;
  font-size: 10px; font-weight: 760; pointer-events: auto;
}
.view-actions button.active { border-color: var(--ink); color: #fff; background: var(--ink); }

.stepper {
  z-index: 20; display: grid; grid-template-columns: repeat(5, 1fr);
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); background: #fff;
}
.stepper button {
  position: relative; display: grid; place-content: center; justify-items: center; gap: 1px;
  min-width: 0; border: 0; border-right: 1px solid #e8eef4; color: #748498;
  background: transparent; font-size: 9px; font-weight: 750;
}
.stepper button:last-child { border-right: 0; }
.stepper span {
  display: grid; width: 18px; height: 18px; place-items: center; border: 1px solid #b9c6d2;
  border-radius: 50%; font-size: 9px;
}
.stepper button.active { color: var(--ink); }
.stepper button.active::after { position: absolute; right: 18%; bottom: -1px; left: 18%; height: 3px; border-radius: 3px 3px 0 0; background: var(--pink); content: ""; }
.stepper button.active span { border-color: var(--pink); color: #fff; background: var(--pink); }

.tool-drawer { min-height: 0; overflow: hidden; background: #fff; }
.tool-panel { display: none; height: 100%; overflow: auto; padding: 12px 12px max(14px, env(safe-area-inset-bottom)); }
.tool-panel.active { display: block; animation: lift .18s ease-out; }
.tool-panel[data-panel="design"] {
  color: #fff;
  background:
    radial-gradient(circle at 100% 0, #123c5f 0, transparent 42%),
    linear-gradient(145deg, #06182e, #081f39);
}
.tool-panel[data-panel="design"] .panel-heading small { color: var(--cyan); }
.tool-panel[data-panel="design"] .panel-heading h1 { color: #fff; }
.tool-panel[data-panel="design"] .panel-heading p { color: #9eb6ca; }
@keyframes lift { from { opacity: .45; transform: translateY(4px); } }
.panel-heading { display: flex; align-items: end; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.panel-heading small { display: block; margin-bottom: 1px; color: var(--pink); font-size: 9px; font-weight: 850; letter-spacing: .08em; text-transform: uppercase; }
.panel-heading h1, .panel-heading h2 { margin: 0; font-size: 17px; line-height: 1; letter-spacing: -.02em; }
.panel-heading p { margin: 0; color: var(--muted); font-size: 10px; }
.mini-button, .primary-button, .secondary-button, .danger-button, .upload-button {
  min-height: 37px; border: 1px solid var(--line); border-radius: 10px; padding: 0 13px;
  background: #fff; font-size: 11px; font-weight: 780; cursor: pointer;
}
.mini-button { min-height: 31px; padding: 0 10px; }
.primary-button { border-color: var(--pink); color: #fff; background: var(--pink); box-shadow: 0 6px 16px #ff316f2b; }
.secondary-button, .upload-button { color: var(--ink); background: #f7fafc; }
.danger-button { border-color: #f0c7cf; color: #b4233b; background: #fff7f8; }
.wide { width: 100%; }

.design-rail { display: grid; grid-auto-flow: column; grid-auto-columns: 142px; gap: 9px; overflow-x: auto; padding: 1px 1px 8px; scroll-snap-type: x mandatory; }
.design-card {
  position: relative; min-height: 158px; padding: 8px; overflow: hidden; scroll-snap-align: start;
  border: 1px solid #60d7ff30; border-radius: 13px; color: #fff;
  background: #0a2340; text-align: left; box-shadow: 0 7px 18px #00000025;
}
.design-card::before {
  position: absolute; inset: 0; content: "";
  background: linear-gradient(145deg, transparent 0 72%, #28d7f244 72% 82%, #ff316f88 82%);
}
.design-card::after { position: absolute; inset: 0; border: 2px solid transparent; border-radius: inherit; content: ""; pointer-events: none; }
.design-card.active { background: #0d2c4d; transform: translateY(-1px); }
.design-card.active::after { border-color: var(--cyan); box-shadow: inset 0 -4px 0 var(--pink); }
.design-card img {
  position: relative; z-index: 1; display: block; width: 100%; height: 105px;
  border-radius: 8px; object-fit: contain;
  background: radial-gradient(circle, #ffffff16, transparent 70%);
  filter: drop-shadow(0 7px 6px #0008);
}
.generated-kit {
  position: relative; z-index: 1; width: 68px; height: 82px; margin: 3px auto 3px;
  border: 2px solid #ffffffaa; border-radius: 13px 13px 8px 8px;
  background: linear-gradient(135deg, #ffffff22 0 42%, #fff 43% 49%, #ffffff22 50%);
  clip-path: polygon(20% 0, 37% 8%, 63% 8%, 80% 0, 100% 17%, 87% 34%, 77% 27%, 77% 100%, 23% 100%, 23% 27%, 13% 34%, 0 17%);
  filter: drop-shadow(0 5px 5px #06182e35);
}
.design-card strong {
  position: relative; z-index: 1; display: block; overflow: hidden;
  padding: 6px 3px 1px; color: #fff; font-size: 11px; white-space: nowrap; text-overflow: ellipsis;
}
.design-card > span {
  position: relative; z-index: 1; display: block; overflow: hidden; padding: 0 3px;
  color: #a9bfd2; font-size: 8px; line-height: 1.25; white-space: nowrap; text-overflow: ellipsis;
}
.startup-failure-card {
  display: grid; align-content: center; gap: 5px; min-width: min(310px, 82vw); min-height: 112px;
  padding: 16px; border: 1px solid #ff316f66; border-radius: 13px; color: #fff; background: #0a2340;
}
.startup-failure-card b { font-size: 12px; }
.startup-failure-card span { color: #a9bfd2; font-size: 10px; line-height: 1.4; }
.model-loading button {
  min-height: 34px; margin-top: 5px; padding: 0 15px; border: 0; border-radius: 9px;
  color: #fff; background: var(--pink); font-size: 10px; font-weight: 850;
}

.zone-list { display: grid; gap: 9px; }
.zone-card {
  display: grid; grid-template-columns: 32px minmax(72px, .8fr) 1fr; align-items: center; gap: 9px;
  padding: 9px; border: 1px solid var(--line); border-radius: 13px; background: #fbfcfe;
}
.zone-card > input[type="color"] { width: 32px; height: 32px; padding: 0; border: 2px solid #fff; border-radius: 50%; overflow: hidden; box-shadow: 0 0 0 1px var(--line); background: none; }
.zone-card label { min-width: 0; }
.zone-card label span { display: block; overflow: hidden; font-size: 11px; font-weight: 800; white-space: nowrap; text-overflow: ellipsis; }
.zone-card label small { display: block; color: var(--muted); font-size: 8px; }
.zone-controls { display: grid; grid-template-columns: 1fr; gap: 6px; }
.zone-controls select, .property-grid select, .property-grid input:not([type="color"]) {
  width: 100%; min-width: 0; height: 32px; border: 1px solid var(--line); border-radius: 8px;
  padding: 0 7px; color: var(--ink); background: #fff; font-size: 10px;
}
.pattern-colour { display: none; width: 31px; height: 31px; padding: 0; border: 1px solid var(--line); border-radius: 8px; background: none; }
.zone-card.pattern .pattern-colour { display: block; }
.zone-card.pattern .zone-controls { grid-template-columns: minmax(0, 1fr) 31px; }

.composer { display: grid; grid-template-columns: minmax(125px, .85fr) minmax(165px, 1.15fr); gap: 10px; }
.composer-left { min-width: 0; }
.inline-add, .add-row { display: flex; gap: 6px; margin-bottom: 8px; }
.inline-add input, .add-row input {
  min-width: 0; flex: 1; height: 36px; border: 1px solid var(--line); border-radius: 9px; padding: 0 10px;
  outline: none; font-size: 11px;
}
.inline-add input:focus, .add-row input:focus { border-color: var(--cyan); box-shadow: 0 0 0 3px #28d7f21c; }
.add-row button {
  min-width: 54px; border: 0; border-radius: 9px; color: #fff; background: var(--ink);
  font-size: 10px; font-weight: 800;
}
.object-list { display: grid; gap: 5px; max-height: 98px; overflow: auto; }
.object-row {
  display: flex; align-items: center; gap: 7px; min-width: 0; min-height: 33px; border: 1px solid var(--line);
  border-radius: 9px; padding: 4px 7px; background: #fff; font-size: 10px; text-align: left;
}
.object-row.active { border-color: var(--pink); background: #fff7fa; }
.object-row span { width: 20px; height: 20px; flex: none; border-radius: 5px; background: var(--thumb, var(--ink)); }
.object-row img { width: 23px; height: 23px; object-fit: contain; border-radius: 4px; background: #edf2f6; }
.object-row b { min-width: 0; flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.object-row em { color: var(--muted); font-size: 8px; font-style: normal; }
.properties { min-width: 0; padding-left: 10px; border-left: 1px solid var(--line); }
.properties.empty { display: grid; place-content: center; color: var(--muted); font-size: 10px; text-align: center; }
.property-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
.property-grid .span-2 { grid-column: span 2; }
.property-grid .surface-field[hidden] { display: none; }
.property-grid label { min-width: 0; color: var(--muted); font-size: 8px; font-weight: 700; }
.property-grid label span { display: block; margin-bottom: 3px; }
.property-grid input[type="color"] { width: 100%; height: 32px; padding: 2px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.property-actions { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; margin-top: 8px; }
.property-actions button { min-height: 30px; padding: 0 5px; font-size: 9px; }
.property-actions .danger-button { grid-column: span 2; }
.upload-button { display: grid; place-items: center; min-height: 36px; cursor: pointer; }
.upload-button input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.muted-note { margin: 8px 0 0; color: var(--muted); font-size: 9px; line-height: 1.4; }

.final-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.final-grid button:last-child { grid-column: span 2; }
.final-grid > button, .final-import {
  display: grid; align-content: center; gap: 2px; min-height: 58px; padding: 9px 11px;
  border: 1px solid var(--line); border-radius: 11px; color: var(--ink);
  background: #f8fafc; text-align: left; cursor: pointer;
}
.final-grid b { font-size: 10px; }
.final-grid span { color: var(--muted); font-size: 8px; }
.final-import { position: relative; }
.final-import input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.final-grid .primary-final { border-color: var(--pink); color: #fff; background: var(--pink); }
.final-grid .primary-final span { color: #ffe4ed; }
.completion-card {
  display: flex; align-items: center; gap: 11px; margin-bottom: 10px; padding: 10px;
  border: 1px solid #b9e5db; border-radius: 13px; color: #075e4d; background: #f0fff9;
}
.completion-card span { display: grid; width: 28px; height: 28px; place-items: center; border-radius: 50%; color: #fff; background: #17a77f; font-weight: 900; }
.completion-card b { display: block; font-size: 11px; }
.completion-card small { font-size: 9px; color: #468375; }

dialog {
  width: min(92vw, 460px); max-height: 86dvh; padding: 0; border: 0; border-radius: 18px;
  color: var(--ink); background: #fff; box-shadow: 0 28px 80px #06182e55;
}
dialog::backdrop { background: #06182e99; backdrop-filter: blur(4px); }
.app-dialog { padding: 18px; }
.app-dialog form { display: contents; }
.dialog-card { padding: 18px; overflow: auto; max-height: 86dvh; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.dialog-head h2 { margin: 0; font-size: 18px; }
.dialog-head button { width: 32px; height: 32px; border: 0; border-radius: 50%; background: #edf2f7; }
.saved-list { display: grid; gap: 8px; }
.saved-row { display: flex; align-items: center; gap: 8px; padding: 9px; border: 1px solid var(--line); border-radius: 11px; }
.saved-row button:first-of-type { flex: 1; min-height: 35px; border: 0; background: transparent; text-align: left; }
.saved-row b, .saved-row small { display: block; }
.saved-row small { color: var(--muted); font-size: 9px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-grid label { display: grid; gap: 4px; color: var(--muted); font-size: 10px; font-weight: 700; }
.form-grid label.full, .form-grid label.wide { grid-column: span 2; }
.form-grid input, .form-grid textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 9px; padding: 9px; color: var(--ink); background: #fff;
}
.form-grid textarea { min-height: 70px; resize: vertical; }
.form-grid button { grid-column: span 2; }
.app-dialog > form > p { color: var(--muted); font-size: 9px; line-height: 1.45; }
.submit-enquiry {
  width: 100%; min-height: 43px; border: 0; border-radius: 10px; color: #fff;
  background: var(--pink); font-size: 11px; font-weight: 850;
}

.toast {
  z-index: 100; position: fixed; right: 14px; bottom: calc(14px + env(safe-area-inset-bottom));
  max-width: min(360px, calc(100vw - 28px)); padding: 10px 14px; border-radius: 11px;
  color: #fff; background: var(--ink); box-shadow: 0 10px 35px #06182e44;
  font-size: 11px; font-weight: 720; opacity: 0; transform: translateY(10px); pointer-events: none; transition: .2s;
}
.toast.show { opacity: 1; transform: translateY(0); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@media (min-width: 850px) {
  body { background: #dfe7ef; }
  .app-shell {
    width: min(1440px, 100vw); margin: auto;
    grid-template-columns: minmax(480px, 1.35fr) minmax(410px, .65fr);
    grid-template-rows: 56px 62px minmax(0, 1fr);
    box-shadow: 0 0 70px #06182e24;
  }
  .topbar { grid-column: 1 / -1; padding: 8px 18px; }
  .brand img { width: 32px; height: 32px; }
  .viewer { grid-column: 1; grid-row: 2 / 4; }
  .stepper { grid-column: 2; grid-row: 2; }
  .tool-drawer { grid-column: 2; grid-row: 3; }
  .tool-panel { padding: 20px 20px 28px; }
  .panel-heading { margin-bottom: 16px; }
  .panel-heading h1, .panel-heading h2 { font-size: 23px; }
  .design-rail { grid-auto-flow: row; grid-template-columns: repeat(3, 1fr); overflow: visible; }
  .design-card { min-height: 184px; }
  .design-card img { height: 126px; }
  .zone-list { gap: 11px; }
  .zone-card { padding: 12px; }
  .composer { grid-template-columns: .8fr 1.2fr; }
  .object-list { max-height: 250px; }
  .properties { padding-left: 15px; }
  .final-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-height: 700px) and (max-width: 849px) {
  .app-shell { grid-template-rows: 44px minmax(220px, 1fr) 48px minmax(170px, 30dvh); }
  .topbar { padding-top: 5px; }
  .viewer-meta { top: 7px; }
  .view-actions { bottom: 5px; }
  .tool-panel { padding-top: 9px; }
  .panel-heading { margin-bottom: 7px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
