:root {
  --text: #333333;
  --muted: #5A6268;
  --wall: #F4F6F7;
  --line: #E3E7EA;
  --edge: #9AA3A8;
  --teal: #008C8C;
  --teal-soft: #C9F6F6;
  --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, 47fr) minmax(0, 53fr) auto;
  grid-template-areas: "stage" "panel" "foot";
}

.app.comparing { grid-template-rows: minmax(0, 60fr) minmax(0, 40fr) auto; }

/* 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;
}

.vps {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.vp {
  position: absolute;
  pointer-events: none;
}

.vp.divide-r { border-right: 2px solid #FFFFFF; box-shadow: 1px 0 0 var(--line); }
.vp.divide-b { border-bottom: 2px solid #FFFFFF; box-shadow: 0 1px 0 var(--line); }

.vp.active::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 3px solid var(--teal);
  pointer-events: none;
}

.cap {
  position: absolute;
  top: 8px;
  left: 8px;
  right: 8px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 6px;
}

.cap-name {
  max-width: 100%;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--text);
  font-size: 17px;
  font-weight: 700;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cap-tag {
  margin-left: 6px;
  color: var(--teal);
  font-size: 17px;
  font-weight: 700;
}

.keep {
  flex: none;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--teal);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.95);
  color: var(--teal);
  font: 700 17px/1 var(--font);
  cursor: pointer;
  pointer-events: auto;
}

.keep:hover { background: var(--teal); color: #FFFFFF; }

.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); }

.reset[hidden] { display: none; }

.stage-foot {
  position: absolute;
  left: 10px;
  bottom: 10px;
  right: 130px;
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.views {
  flex: none;
  background: rgba(255, 255, 255, 0.92);
  pointer-events: auto;
}

.views[hidden] { display: none; }

.views.seg button {
  flex: none;
  min-height: 40px;
  padding: 0 12px;
  font-size: 17px;
  background: transparent;
}

.hint {
  min-width: 0;
  margin: 0;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.85);
  color: var(--muted);
  font-size: 17px;
  line-height: 1.3;
  pointer-events: none;
  transition: opacity 0.4s;
}

.hint.gone { opacity: 0; }

.loading {
  position: absolute;
  left: 50%;
  top: 50%;
  margin: 0;
  padding: 8px 14px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--muted);
  font-size: 17px;
  font-weight: 600;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.loading[hidden] { display: none; }

.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;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 8px 12px 10px;
  border-top: 1px solid var(--line);
  background: #FFFFFF;
}

/* Narrow screens: painting first, the text readout after the controls */
.panel { display: flex; flex-direction: column; }
.panel > * { flex: none; }
.title { order: 0; }
.actions { order: 1; }
.ctl-targets { order: 2; }
.ctl-swatches { order: 3; }
.light { order: 4; }
.readout { order: 5; margin: 14px 0 0; }
.note { order: 6; }

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

.scheme {
  margin: 0;
  color: var(--teal);
  font-size: 17px;
  font-weight: 700;
  line-height: 1.3;
}

.summary {
  margin: 1px 0 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;
}

.ctl { min-width: 0; margin-top: 10px; }

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

.ctl-label b { color: var(--text); font-weight: 700; }

.action-row {
  display: flex;
  gap: 6px;
}

.select {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 44px;
  padding: 0 8px;
  border: 1px solid var(--edge);
  border-radius: 8px;
  background: #FFFFFF;
  color: var(--text);
  font: 600 17px/1.2 var(--font);
}

.btn {
  flex: none;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--edge);
  border-radius: 8px;
  background: #FFFFFF;
  color: var(--text);
  font: 600 17px/1 var(--font);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

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

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

.side-pick[hidden] { display: none; }

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

.seg button {
  flex: 1 1 0;
  min-width: 0;
  min-height: 40px;
  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;
}

/* Paint targets */
.targets {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.target {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  min-height: 44px;
  padding: 0 8px;
  border: 1px solid var(--edge);
  border-radius: 8px;
  background: #FFFFFF;
  color: var(--text);
  font: 600 17px/1.1 var(--font);
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

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

.target[aria-pressed="true"] {
  border: 2px solid var(--teal);
  padding: 0 7px;
  background: #EEFBFB;
  color: #006F6F;
}

.target .dot {
  flex: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.25);
  background-size: cover;
}

.target .t-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  margin-top: 4px;
  padding: 0 4px;
  border: 0;
  background: none;
  color: var(--text);
  font: 600 17px/1.2 var(--font);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.link .box {
  position: relative;
  flex: none;
  width: 20px;
  height: 20px;
  border: 2px solid var(--edge);
  border-radius: 4px;
  background: #FFFFFF;
}

.link[aria-pressed="true"] .box {
  border-color: var(--teal);
  background: var(--teal);
}

.link[aria-pressed="true"] .box::after {
  content: "";
  position: absolute;
  left: 5px;
  top: 1px;
  width: 5px;
  height: 10px;
  border: solid #FFFFFF;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

/* Swatches */
.sw-group {
  margin: 6px 0 2px;
  color: var(--muted);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.sw-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  gap: 4px;
}

.sw {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  height: 44px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.sw .chip {
  display: block;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.2);
  background-size: cover;
  background-position: center;
}

.sw:hover .chip { transform: scale(1.06); }

.sw[aria-pressed="true"] .chip {
  box-shadow: 0 0 0 2px #FFFFFF, 0 0 0 4px var(--teal);
}

/* Light sliders */
.range {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  font-size: 17px;
  font-weight: 600;
  color: var(--muted);
}

.range-end { flex: none; width: 3.4em; }
.range-end:last-child { text-align: right; }

.range input {
  flex: 1 1 auto;
  min-width: 0;
  height: 32px;
  margin: 0;
  accent-color: var(--teal);
  cursor: pointer;
}

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

.btn:focus-visible,
.seg button:focus-visible,
.target:focus-visible,
.link:focus-visible,
.sw:focus-visible,
.select:focus-visible,
.range input:focus-visible,
.reset:focus-visible,
.keep:focus-visible,
.foot a:focus-visible {
  outline: 3px solid #00DDDD;
  outline-offset: 1px;
}

/* 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[hidden] { display: none; }
.src:hover { text-decoration: underline; }

@media (min-width: 640px) {
  .panel { padding: 10px 16px 10px; }
  .foot { padding: 6px 16px 8px; }
  .targets { grid-template-columns: repeat(6, 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,
  .app.comparing {
    grid-template-columns: minmax(0, 1fr) 320px;
    grid-template-rows: minmax(0, 1fr) auto;
    grid-template-areas: "stage panel" "foot foot";
  }
  .panel {
    border-top: 0;
    border-left: 1px solid var(--line);
    padding: 14px 16px;
  }
  .title {
    position: static;
    width: auto;
    height: auto;
    overflow: visible;
    clip: auto;
    white-space: normal;
    margin: 0 0 8px;
    font-size: 20px;
    font-weight: 700;
    line-height: 1.25;
  }
  .targets { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .summary { font-size: 17px; }
  .readout { order: 1; margin: 0 0 8px; }
  .actions { order: 2; }
  .light { order: 3; }
  .ctl-targets { order: 4; }
  .ctl-swatches { order: 5; }
  .note { order: 6; }
  .light .range { min-height: 34px; }
  .sw-grid { grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); }
  .sw { min-width: 40px; height: 40px; }
  .sw .chip { width: 32px; height: 32px; }
}

@media (orientation: landscape) and (max-height: 560px) {
  .title { display: none; }
  .panel { padding: 8px 12px; }
  .targets { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .target { font-size: 17px; }
}

@media (min-width: 1280px) {
  .app, .app.comparing { grid-template-columns: minmax(0, 1fr) 360px; }
  .targets { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .target { padding: 0 6px; gap: 5px; font-size: 17px; }
  .target[aria-pressed="true"] { padding: 0 5px; }
}

@media (max-width: 360px) {
  .targets { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .btn { padding: 0 9px; font-size: 17px; }
  .hint { display: none; }
  .summary { font-size: 17px; }
  .cap-name { font-size: 17px; }
}

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

@media (max-width: 520px) {
  .views:not([hidden]) + .hint { display: none; }
  .stage-foot { right: 120px; }
}

/* Article text size (17px) needs room in the paint tabs: 3 per row in the article column, 2 per row on phones. */
@media (min-width: 640px) and (max-width: 999px) { .targets { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 480px) { .targets { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* Inside an article (rule 37): no inner scrolling. The photo keeps its proportion,
   the controls show in full, and the frame grows to the page height. */
.in-article, .in-article body { height: auto; overflow: visible; }
.in-article .app,
.in-article .app.comparing { height: auto; grid-template-rows: auto auto auto; }
.in-article .stage { height: 56vw; max-height: 560px; }
.in-article .panel { overflow: visible; }
