:root {
  --text: #333333;
  --muted: #5A6268;
  --wall: #F4F6F7;
  --line: #E3E7EA;
  --edge: #9AA3A8;
  --teal: #008C8C;
  --teal-soft: #C9F6F6;
  --red: #D0342C;
  --green: #2E8B57;
  --green-soft: #D5EADD;
  --amber: #9A6A14;
  --amber-soft: #FBE7C2;
  --font: 'Open Sans', 'Segoe UI', Helvetica, Arial, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #FFFFFF;
  color: var(--text);
  font-family: var(--font);
  -webkit-text-size-adjust: 100%;
}

.app {
  display: grid;
  height: 100%;
  width: 100%;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) auto auto;
  grid-template-areas: "stage" "panel" "foot";
}

/* Scene */
.stage {
  grid-area: stage;
  position: relative;
  min-height: 0;
  overflow: hidden;
  background: #FFFFFF;
  touch-action: none;
}

#scene {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
}

.labels {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.lbl {
  position: absolute;
  left: 0;
  top: 0;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
  color: var(--text);
  font-size: 17px;
  font-weight: 600;
  line-height: 1.25;
  white-space: nowrap;
  will-change: transform;
}

.lbl[hidden] { display: none; }
.lbl.cab { color: var(--teal); font-weight: 700; }
.lbl.top { font-weight: 700; }
.lbl.ceil { color: var(--muted); }
.lbl.red { color: var(--red); font-weight: 700; border: 2px solid var(--red); background: #FFFFFF; font-size: 17px; }
.lbl.green { color: var(--green); font-weight: 700; }
.lbl.amber { color: var(--amber); font-weight: 700; background: var(--amber-soft); }
.lbl.okshelf { color: var(--green); font-weight: 700; background: var(--green-soft); }

.reset {
  position: absolute;
  bottom: 10px;
  right: 10px;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--edge);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--text);
  font: 600 17px/1 var(--font);
  cursor: pointer;
}

.reset:hover { border-color: var(--teal); color: var(--teal); }

.hint {
  position: absolute;
  left: 10px;
  bottom: 12px;
  margin: 0;
  max-width: calc(100% - 140px);
  color: var(--muted);
  font-size: 17px;
  line-height: 1.3;
  pointer-events: none;
  transition: opacity 0.4s;
}

.hint.gone { opacity: 0; }

.nogl {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 24px;
  background: var(--wall);
  font-size: 17px;
  line-height: 1.5;
  text-align: center;
}

.nogl[hidden] { display: none; }
.nogl p { margin: 0 0 8px; }
.nogl a { color: var(--teal); font-weight: 600; }

/* Panel */
.panel {
  grid-area: panel;
  padding: 8px 12px 4px;
  border-top: 1px solid var(--line);
  background: #FFFFFF;
}

.title {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 10px;
}

.ctl { min-width: 0; }

.ctl-label {
  display: block;
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 17px;
  font-weight: 600;
  line-height: 1.2;
}

.seg {
  display: flex;
  border: 1px solid var(--edge);
  border-radius: 8px;
  overflow: hidden;
}

.seg button {
  flex: 1 1 0;
  min-width: 0;
  min-height: 44px;
  margin: 0;
  padding: 0 4px;
  border: 0;
  border-left: 1px solid var(--edge);
  background: #FFFFFF;
  color: var(--text);
  font: 600 17px/1 var(--font);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.seg button:first-child { border-left: 0; }
.seg button:hover { background: var(--wall); }

.seg button[aria-pressed="true"] {
  background: var(--teal);
  color: #FFFFFF;
}

.seg button:focus-visible,
.reset:focus-visible,
.foot a:focus-visible {
  outline: 3px solid #00DDDD;
  outline-offset: -3px;
}

.readout { margin-top: 6px; }

.summary {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  line-height: 1.35;
}

.info {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 17px;
  line-height: 1.4;
}

/* Footer */
.foot {
  grid-area: foot;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 2px 12px;
  padding: 5px 12px 7px;
  border-top: 1px solid var(--line);
  font-size: 17px;
  line-height: 1.3;
}

.foot a { text-decoration: none; }
.brand { display: inline-flex; align-items: center; gap: 6px; color: var(--text); font-weight: 700; }
.brand svg { display: block; flex: none; }
.src { color: var(--teal); font-weight: 600; }
.src:hover { text-decoration: underline; }

/* Medium widths: controls in one or two rows under the scene */
@media (min-width: 640px) {
  .controls { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .seg button { min-height: 40px; }
  .panel { padding: 10px 16px 6px; }
  .foot { padding: 6px 16px 8px; }
}

@media (min-width: 640px) and (max-width: 899px) {
  .controls { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* Wide screens and phones in landscape: side panel */
@media (min-width: 1000px) and (min-height: 480px),
       (orientation: landscape) and (min-width: 640px) and (max-height: 560px) {
  .app {
    grid-template-columns: minmax(0, 1fr) 300px;
    grid-template-rows: minmax(0, 1fr) auto;
    grid-template-areas: "stage panel" "foot foot";
  }
  .panel {
    border-top: 0;
    border-left: 1px solid var(--line);
    overflow-y: auto;
    padding: 16px 18px;
  }
  .title {
    position: static;
    width: auto;
    height: auto;
    overflow: visible;
    clip: auto;
    white-space: normal;
    margin: 0 0 12px;
    font-size: 20px;
    font-weight: 700;
    line-height: 1.25;
  }
  .controls { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .ctl-label { font-size: 17px; margin-bottom: 4px; }
  .readout { margin-top: 16px; }
  .summary { font-size: 17px; }
  .info { font-size: 17px; margin-top: 6px; }
}

@media (orientation: landscape) and (max-height: 560px) {
  .title { display: none; }
  .panel { padding: 10px 12px; }
  .app { grid-template-columns: minmax(0, 1fr) 320px; }
  .controls { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 10px; }
  .seg button { min-height: 38px; }
  .readout { margin-top: 8px; }
}

@media (min-width: 1280px) {
  .app { grid-template-columns: minmax(0, 1fr) 340px; }
}

@media (max-width: 519px) {
  .lbl.side {
    max-width: 5.2em;
    white-space: normal;
    text-align: right;
    line-height: 1.15;
    border-radius: 8px;
  }
}

@media (max-width: 380px) {
  .hint { display: none; }
  .seg button { font-size: 17px; }
  .lbl { font-size: 17px; padding: 1px 6px; }
  .lbl.red { font-size: 17px; }
  .summary { font-size: 17px; }
  .info { font-size: 17px; }
}

@media (prefers-reduced-motion: reduce) {
  .hint { transition: none; }
}
