:root {
  --bg: #E8E6E1;
  --panel: #F3F2EE;
  --card: #FCFBF8;
  --line: #DAD7D0;
  --line-strong: #C9C5BD;
  --ink: #1F2526;
  --ink-2: #5B625F;
  --ink-3: #868C88;
  --dark: #252B2F;
  --green: #506A67;
  --green-hover: #445C59;
  --tag-bg: #F6E6CC;
  --tag-ink: #94672C;
  --info-bg: #E3E8E4;
  --radius: 14px;
  --font: 'Lexend', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  font-weight: 400;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:focus-visible, a:focus-visible, input:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 2px;
}

h1, h2, h3 { margin: 0; font-weight: 500; letter-spacing: -0.01em; }
h2 { font-size: 1.28rem; }
h3 { font-size: 1rem; margin: 20px 0 10px; }
p { margin: 0; }

.muted { color: var(--ink-2); font-size: 0.86rem; }
.small { font-size: 0.8rem; }

.app {
  max-width: 1480px;
  margin: 0 auto;
  padding: 28px 32px 24px;
}

/* ---------- masthead ---------- */

.masthead {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
}

.title {
  font-size: clamp(2rem, 3.5vw, 3.35rem);
  line-height: 1.04;
  font-weight: 400;
  letter-spacing: -0.02em;
  max-width: 13.5em;
  text-wrap: balance;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  padding-bottom: 6px;
}
.brand img { border-radius: 4px; display: block; }
.brand strong { display: block; font-weight: 500; font-size: 0.95rem; }
.brand span { color: var(--ink-2); font-size: 0.86rem; }

/* ---------- layout ---------- */

.studio {
  display: grid;
  grid-template-columns: minmax(0, 1.72fr) minmax(340px, 1fr);
  gap: 28px;
  align-items: start;
}

/* ---------- room viewer ---------- */

.viewer {
  --aspect: 1794 / 1002;
  --ratio: 1.7904;
  position: relative;
  aspect-ratio: var(--aspect);
  border-radius: 12px;
  overflow: hidden;
  background: #2B3133;
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.06), 0 12px 32px -18px rgb(20 26 26 / 0.45);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.viewer canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.viewer-tag {
  position: absolute;
  top: 14px;
  z-index: 2;
  padding: 5px 12px;
  border-radius: 999px;
  background: rgb(20 26 26 / 0.78);
  color: #fff;
  font-size: 0.78rem;
  letter-spacing: 0.02em;
  backdrop-filter: blur(4px);
}
.viewer-tag[hidden] { display: none; }
.tag-left { left: 14px; }

.loading {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: #D6D2CA;
  color: var(--ink-2);
  font-size: 0.9rem;
}
.loading[hidden] { display: none; }
.spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid rgb(31 37 38 / 0.2);
  border-top-color: var(--ink);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.hint {
  margin: 10px 2px 14px;
  color: var(--ink-2);
  font-size: 0.84rem;
}

/* ---------- controls ---------- */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-size: 0.94rem;
}
.toolbar .push { margin-left: auto; }

.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
}
.segmented button {
  border: 0;
  background: transparent;
  border-radius: 999px;
  padding: 8px 16px;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.segmented button:hover { background: rgb(31 37 38 / 0.06); }
.segmented button[aria-pressed="true"] { background: var(--dark); color: #fff; }
.segmented.wide { display: flex; }
.segmented.wide button { flex: 1; padding: 10px 8px; }

.pill {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 999px;
  padding: 9px 16px;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  touch-action: manipulation;
}
.pill:hover { border-color: var(--line-strong); background: #fff; }
.pill.primary { background: var(--green); border-color: var(--green); color: #fff; }
.pill.primary:hover { background: var(--green-hover); }
.pill.hold { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: none; }
.pill.hold.is-held { background: var(--dark); border-color: var(--dark); color: #fff; }

/* option pills and round number chips in the panel */
.options { display: flex; flex-wrap: wrap; gap: 6px; }
.option {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 0.88rem;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.option:hover { border-color: var(--line-strong); background: #fff; }
.option[aria-pressed="true"] { background: var(--dark); border-color: var(--dark); color: #fff; }
.option:disabled { opacity: 0.45; cursor: not-allowed; }
.option.round { width: 40px; height: 40px; padding: 0; display: inline-flex; align-items: center; justify-content: center; }

/* ---------- summary ---------- */

.summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px 18px;
  margin-top: 18px;
}
.summary-item { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.summary-label { color: var(--ink-3); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; }
.summary-item strong { font-weight: 500; font-size: 0.95rem; }
.summary-note { color: var(--ink-2); font-size: 0.8rem; }

.checks { list-style: none; margin: 16px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.checks:empty { display: none; }
.check {
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 0.82rem;
  background: var(--info-bg);
  color: var(--ink-2);
}
.check.warn { background: var(--tag-bg); color: #6F4E22; }

.guide-note {
  margin-top: 18px;
  color: var(--ink-3);
  font-size: 0.8rem;
}

/* ---------- side panel ---------- */

.panel {
  position: sticky;
  top: 20px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 4px 22px 22px;
  scrollbar-width: thin;
}

.panel-section { padding: 20px 0 22px; border-bottom: 1px solid var(--line); }
.panel-section:last-child { border-bottom: 0; padding-bottom: 0; }
.panel-section > h2 { margin-bottom: 14px; }
.panel-section > .muted { margin: -6px 0 12px; }

/* main opening tiles */
.types { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.type {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 60px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  text-align: left;
  line-height: 1.25;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.type:hover { border-color: var(--line-strong); }
.type[aria-pressed="true"] { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.type svg { flex-shrink: 0; width: 46px; height: 34px; }

/* systems */
.systems { display: flex; flex-direction: column; gap: 4px; }
.system {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: none;
  text-align: left;
  transition: border-color 0.15s, background 0.15s;
}
.system:hover { background: rgb(255 255 255 / 0.55); }
.system[aria-pressed="true"] { border-color: var(--ink); background: #fff; }
.system svg { flex-shrink: 0; width: 60px; height: 36px; border-radius: 4px; }
.system strong { display: block; font-weight: 400; font-size: 0.98rem; }
.system span span { display: block; color: var(--ink-2); font-size: 0.82rem; }
.tag {
  display: inline-block;
  margin-left: 4px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--tag-bg);
  color: var(--tag-ink);
  font-size: 0.68rem;
  font-weight: 500;
  vertical-align: 1px;
}

/* labelled rows of controls */
.layout { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; flex-direction: column; gap: 7px; }
.row-label { color: var(--ink-2); font-size: 0.86rem; display: flex; justify-content: space-between; gap: 10px; }
.row-label em { font-style: normal; color: var(--ink-3); }
.row-note { color: var(--ink-3); font-size: 0.78rem; }
.row-note.warn { color: #94672C; }

.mm {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding-right: 12px;
  width: 160px;
}
.mm:focus-within { border-color: var(--ink); }
.mm input {
  width: 100%;
  min-width: 0;
  border: 0;
  background: none;
  padding: 9px 4px 9px 12px;
  outline: none;
  font-variant-numeric: tabular-nums;
}
.mm span { color: var(--ink-3); font-size: 0.86rem; }
.inline { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

/* colour swatches */
.colours { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; }
.colour {
  position: relative;
  aspect-ratio: 1;
  border: 0;
  border-radius: 50%;
  padding: 0;
  box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.14);
  transition: transform 0.12s;
}
.colour:hover { transform: scale(1.06); }
.colour[aria-pressed="true"] { outline: 2px solid var(--ink); outline-offset: 2px; }
.colour-name { color: var(--ink-2); font-size: 0.82rem; min-height: 1.2em; }
.colour-name em { display: block; font-style: normal; color: var(--ink-3); font-size: 0.76rem; }

/* examples */
.examples { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.example {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  text-align: left;
  line-height: 1.3;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.example:hover { border-color: var(--line-strong); }
.example.is-active { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.example strong { font-weight: 500; font-size: 0.9rem; }
.example span { color: var(--ink-2); font-size: 0.78rem; }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  z-index: 50;
  transform: translate(-50%, 16px);
  opacity: 0;
  pointer-events: none;
  padding: 11px 20px;
  border-radius: 999px;
  background: var(--dark);
  color: #fff;
  font-size: 0.88rem;
  box-shadow: 0 10px 30px -12px rgb(0 0 0 / 0.5);
  transition: opacity 0.2s, transform 0.2s;
  max-width: calc(100vw - 32px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- footer ---------- */

.foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 24px;
  margin-top: 40px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  color: var(--ink-3);
  font-size: 0.78rem;
}

/* ---------- narrow screens: the room stays pinned while you choose ---------- */

@media (max-width: 1100px) {
  .studio { grid-template-columns: minmax(0, 1.4fr) minmax(320px, 1fr); gap: 20px; }
  .toolbar .push { margin-left: 0; }
}

@media (max-width: 860px) {
  .app { padding: 16px 16px 20px; }
  .masthead { flex-direction: column-reverse; align-items: flex-start; gap: 14px; margin-bottom: 16px; }
  .title { font-size: clamp(1.7rem, 7vw, 2.3rem); }
  .brand img { width: 36px; height: 36px; }
  .brand { padding: 0; }

  .studio { display: flex; flex-direction: column; align-items: stretch; gap: 0; }
  .stage { display: contents; }
  .viewer-dock {
    position: sticky;
    top: 0;
    z-index: 10;
    margin: 0 -16px;
    padding: 8px 16px;
    background: var(--bg);
  }
  .viewer { width: min(100%, calc(36vh * var(--ratio))); margin: 0 auto; border-radius: 10px; }
  .hint { margin: 4px 2px 12px; }
  .toolbar .pill { padding: 8px 13px; font-size: 0.86rem; }
  .summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .guide-note { margin-bottom: 18px; }

  .panel { position: static; max-height: none; overflow: visible; padding: 0 16px 18px; }
  .types { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
