  :root{
    --bg:#e9edec;
    --surface:#ffffff;
    --surface-2:#dde3e1;
    --surface-3:#cfd7d4;
    --border:#c3cbc8;
    --text:#182220;
    --text-dim:#5c6663;
    --accent:#b0560e;
    --accent-ink:#ffffff;
    --accent-soft:#f0d9c2;
    --focus:#227a67;
    --focus-soft:rgba(34,122,103,0.14);
    --focus-line:rgba(34,122,103,0.55);
    --track:#d6dcda;
    --band-fill:rgba(196,42,42,0.26);
    --band-line:#b3241f;
    --silhouette-filter:none;
    --floor-fill:#b7c2bc;
    --floor-line:#93a19b;
    --overlay-bg:rgba(255,255,255,0.86);
    --overlay-border:rgba(20,30,28,0.08);
    --panel-overlay-bg:rgba(255,255,255,0.12);
    --panel-overlay-border:rgba(20,30,28,0.10);
    --shadow:0 1px 2px rgba(20,30,28,0.06), 0 8px 24px -12px rgba(20,30,28,0.18);
  }
  @media (prefers-color-scheme: dark){
    :root:not([data-theme="light"]){
      --bg:#15181a;
      --surface:#202426;
      --surface-2:#2a2f31;
      --surface-3:#34393c;
      --border:#3c4144;
      --text:#eae7e0;
      --text-dim:#9ba09f;
      --accent:#e8912f;
      --accent-ink:#1a1204;
      --accent-soft:rgba(232,145,47,0.16);
      --focus:#57d8ae;
      --focus-soft:rgba(87,216,174,0.14);
      --focus-line:rgba(87,216,174,0.55);
      --track:#383d40;
      --band-fill:rgba(255,99,90,0.30);
      --band-line:#ff6b5e;
      --silhouette-filter:invert(1);
      --floor-fill:#1c2022;
      --floor-line:#2b3032;
      --overlay-bg:rgba(21,24,26,0.82);
      --overlay-border:rgba(255,255,255,0.08);
      --panel-overlay-bg:rgba(15,17,18,0.16);
      --panel-overlay-border:rgba(255,255,255,0.10);
      --shadow:0 1px 2px rgba(0,0,0,0.3), 0 12px 30px -14px rgba(0,0,0,0.6);
    }
  }
  :root[data-theme="dark"]{
    --bg:#15181a;
    --surface:#202426;
    --surface-2:#2a2f31;
    --surface-3:#34393c;
    --border:#3c4144;
    --text:#eae7e0;
    --text-dim:#9ba09f;
    --accent:#e8912f;
    --accent-ink:#1a1204;
    --accent-soft:rgba(232,145,47,0.16);
    --focus:#57d8ae;
    --focus-soft:rgba(87,216,174,0.14);
    --focus-line:rgba(87,216,174,0.55);
    --track:#383d40;
    --band-fill:rgba(255,99,90,0.30);
    --band-line:#ff6b5e;
    --silhouette-filter:invert(1);
    --floor-fill:#1c2022;
    --floor-line:#2b3032;
    --overlay-bg:rgba(21,24,26,0.82);
    --overlay-border:rgba(255,255,255,0.08);
    --panel-overlay-bg:rgba(15,17,18,0.16);
    --panel-overlay-border:rgba(255,255,255,0.10);
    --shadow:0 1px 2px rgba(0,0,0,0.3), 0 12px 30px -14px rgba(0,0,0,0.6);
  }

  *{box-sizing:border-box;}
  :root{
    /* fluid scale: every rem-based size in the page grows and shrinks
       with the viewport instead of sitting at one fixed pixel size —
       16px at ~800px width (this design's original size), from 14px
       at 400px up to 19px at 1400px+ */
    font-size:clamp(14px, calc(12px + 0.5vw), 19px);
  }
  body{
    margin:0;
    background:var(--bg);
    color:var(--text);
    font-family:"IBM Plex Sans", ui-sans-serif, system-ui, sans-serif;
    padding:2rem 1rem 4rem;
    display:flex;
    justify-content:center;
    align-items:flex-start;
    -webkit-font-smoothing:antialiased;
  }
  .num{font-family:"IBM Plex Mono", ui-monospace, monospace; font-variant-numeric:tabular-nums;}

  .panel{
    width:100%;
    background:var(--surface);
    border:1px solid var(--border);
    border-radius:1.125rem;
    box-shadow:var(--shadow);
    overflow:hidden;
  }

  header{
    display:flex;
    align-items:center;
    justify-content:space-between;
    gap:1rem;
    padding:1.375rem 1.625rem 1.125rem;
    border-bottom:1px solid var(--border);
  }
  .brand{display:flex; align-items:center; gap:0.75rem;}
  .brand svg{flex:none; width:2.125em; height:2.125em;}
  .brand h1{font-size:1.15rem; font-weight:700; margin:0; letter-spacing:-0.01em;}
  .brand p{margin:0.125rem 0 0; font-size:0.8rem; color:var(--text-dim);}

  .stage{
    padding:1.375rem 1.625rem 0.375rem;
  }

  .ruler-wrap{
    background:var(--surface-2);
    border:1px solid var(--border);
    border-radius:0.875rem;
    padding:0.875rem 0.875rem 0.625rem;
    position:relative;
    overflow:hidden;
  }
  #scene-svg{
    display:block;
    width:100%;
    height:auto;
    max-height:22rem;
    margin:0 auto;
    /* the whole scene is the drag surface for the camera and the subject —
       never a scrollable/zoomable region — so touch input on it is always
       ours, on the outer svg itself rather than only the small drag
       targets, so a finger drifting off the icon mid-drag never hands the
       gesture back to the browser as a native pan */
    touch-action:none;
  }
  .silhouette-img{ filter:var(--silhouette-filter); }
  .cam-drag, .subj-drag{ cursor:grab; touch-action:none; -webkit-user-drag:none; user-select:none; -webkit-user-select:none; }
  .cam-drag:active, .subj-drag:active{ cursor:grabbing; }

  .drag-hint{
    margin-top:0.5rem;
    text-align:center;
    font-size:0.68rem;
    letter-spacing:0.02em;
    color:var(--text-dim);
    opacity:0.75;
  }

  /* author credit, pinned to the scene's own bottom-right corner (so it
     tracks the illustration in every layout, not just the fullscreen
     mobile one) — fades out of the way whenever scene content would
     otherwise collide with that corner, e.g. the subject pushed out to
     the far edge of the 10m frame; see the .tg-link.is-hidden toggle in
     render() */
  .tg-link{
    position:absolute;
    right:0.625rem;
    bottom:0.625rem;
    display:flex;
    align-items:center;
    gap:0.3rem;
    padding:0.3rem 0.55rem;
    border-radius:999px;
    border:1px solid var(--overlay-border);
    background-color:var(--overlay-bg);
    backdrop-filter:blur(10px);
    -webkit-backdrop-filter:blur(10px);
    color:var(--text-dim);
    font-size:0.66rem;
    text-decoration:none;
    z-index:20;
    transition:opacity 0.2s ease, transform 0.2s ease;
  }
  .tg-link:hover{ color:var(--text); }
  .tg-link.is-hidden{
    opacity:0;
    transform:translateY(0.25rem);
    pointer-events:none;
  }
  .tg-icon{ flex:0 0 auto; }


  .controls{
    padding:0.375rem 1.625rem 1.625rem;
    display:flex;
    flex-direction:column;
    gap:1.25rem;
  }
  /* pure grouping wrappers outside landscape mode — the fields inside
     behave as if they sat directly in .controls, so the normal vertical
     layout and its field order are unaffected */
  .hud-pills, .hud-sliders, .csel{ display:contents; }
  .csel-btn, .csel-list{ display:none; }
  .close-btn{ display:none; }
  .field{ display:flex; flex-direction:column; gap:0.5rem; }
  .field-head{
    display:flex;
    align-items:baseline;
    justify-content:space-between;
    gap:0.625rem;
  }
  .field-head .fname{
    font-size:0.78rem;
    font-weight:600;
    color:var(--text-dim);
    letter-spacing:0.02em;
  }
  .field-head .fval{
    font-size:0.88rem;
    font-weight:600;
    color:var(--accent);
  }

  select{
    width:100%;
    appearance:none;
    background:var(--surface-2) url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="10" height="6"><path d="M0 0L5 6L10 0Z" fill="%23888"/></svg>') no-repeat right 0.875em center;
    border:1px solid var(--border);
    color:var(--text);
    font:inherit;
    font-size:0.88rem;
    padding:0.6875rem 2.25rem 0.6875rem 0.875rem;
    border-radius:0.625rem;
    cursor:pointer;
  }
  select:focus-visible, input:focus-visible, button:focus-visible{
    outline:2px solid var(--accent);
    outline-offset:2px;
  }
  .lens-caption{
    font-size:0.72rem;
    color:var(--text-dim);
  }

  input[type="range"]{
    -webkit-appearance:none;
    appearance:none;
    width:100%;
    height:0.375rem;
    border-radius:999px;
    background:linear-gradient(to right, var(--accent) 0%, var(--accent) var(--pct,0%), var(--track) var(--pct,0%), var(--track) 100%);
    cursor:pointer;
  }
  input[type="range"]::-webkit-slider-thumb{
    -webkit-appearance:none;
    width:1.125rem; height:1.125rem;
    border-radius:50%;
    background:var(--surface);
    border:3px solid var(--accent);
    box-shadow:0 1px 3px rgba(0,0,0,0.3);
    margin-top:0;
    cursor:pointer;
  }
  input[type="range"]::-moz-range-thumb{
    width:1.125rem; height:1.125rem;
    border-radius:50%;
    background:var(--surface);
    border:3px solid var(--accent);
    box-shadow:0 1px 3px rgba(0,0,0,0.3);
    cursor:pointer;
  }
  input[type="range"]::-moz-range-track{
    height:0.375rem; border-radius:999px; background:transparent;
  }
  input[type="range"]:disabled{ opacity:0.5; cursor:not-allowed; }

  .tickline{
    display:flex;
    justify-content:space-between;
    font-size:0.66rem;
    color:var(--text-dim);
    padding:0 1px;
    font-family:"IBM Plex Mono", monospace;
  }

  footer{
    padding:0.875rem 1.625rem 1.5rem;
    text-align:center;
    font-size:0.72rem;
    color:var(--text-dim);
  }

  @media (max-width:520px){
    header{ flex-direction:column; align-items:flex-start; }
  }

  /* phone/tablet turned sideways: the scene fills the whole screen and
     every control floats over it, top-left, always visible — a row of
     compact icon pills (lens / sensor / subject) above a small translucent
     panel with just the two sliders that get touched often (focal,
     aperture). Subject distance is drag-only here (see the .subj-drag
     band in the scene itself), so its slider is hidden entirely. */
  @media (orientation:landscape) and (hover:none) and (pointer:coarse){
    body{ padding:0; }
    .panel{
      width:100vw;
      height:100dvh;
      border:none;
      border-radius:0;
      box-shadow:none;
      display:flex;
      flex-direction:column;
      overflow:hidden;
    }
    header, footer, .drag-hint{ display:none; }
    .stage{
      padding:0;
      flex:1;
      min-height:0;
    }
    .ruler-wrap{
      height:100%;
      padding:0;
      border:none;
      border-radius:0;
    }
    #scene-svg{
      width:100%;
      height:100%;
      max-height:none;
    }

    .controls{
      position:fixed;
      top:calc(0.875rem + env(safe-area-inset-top));
      left:calc(0.875rem + env(safe-area-inset-left));
      display:flex;
      flex-direction:column;
      gap:0.625rem;
      width:auto;
      padding:0;
      z-index:30;
    }
    .field-distance{ display:none; }

    .hud-pills{
      display:flex;
      gap:0.5rem;
      order:1;
    }
    .hud-pills .field{ gap:0; }
    .hud-pills .field-head, .hud-pills .lens-caption{ display:none; }

    /* custom dropdown replacing the native <select> picker — the OS's
       full-screen system list doesn't match the translucent glass HUD, so
       the select stays only as a hidden data/event source and this button
       + listbox pair (built in JS, see enhanceSelect()) is what's shown */
    /* the base rule makes .csel `display:contents` (no box of its own,
       for normal/desktop mode) — a `position` on a contents box has no
       effect, so without overriding display here too, .csel-list's
       `position:absolute` fell through to the next positioned ancestor
       (.controls, which is position:fixed), landing every list in the
       same spot under the whole HUD instead of under its own pill */
    .csel{ display:inline-block; position:relative; }
    .csel select{ display:none; }
    .csel-btn{
      display:flex;
      align-items:center;
      gap:0.4rem;
      width:auto;
      max-width:10rem;
      font:inherit;
      font-size:0.76rem;
      color:var(--text);
      padding:0.5rem 0.6rem;
      border-radius:999px;
      border:1px solid var(--overlay-border);
      box-shadow:var(--shadow);
      background-color:var(--overlay-bg);
      backdrop-filter:blur(12px);
      -webkit-backdrop-filter:blur(12px);
      cursor:pointer;
      -webkit-tap-highlight-color:transparent;
    }
    .csel-icon{
      flex:0 0 auto;
      width:0.95em;
      height:0.95em;
      background-repeat:no-repeat;
      background-size:contain;
    }
    .icon-lens{ background-image:url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><circle cx="12" cy="12" r="7.5" fill="none" stroke="%23888" stroke-width="2.2"/><circle cx="12" cy="12" r="2.8" fill="%23888"/></svg>'); }
    .icon-sensor{ background-image:url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><rect x="3" y="5.5" width="18" height="13" rx="2" fill="none" stroke="%23888" stroke-width="2.2"/></svg>'); }
    .icon-subject{ background-image:url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><circle cx="12" cy="7.3" r="3.6" fill="%23888"/><path d="M5 21c0-4.2 3.1-7.5 7-7.5s7 3.3 7 7.5" fill="none" stroke="%23888" stroke-width="2.2" stroke-linecap="round"/></svg>'); }
    .csel-label{
      overflow:hidden;
      text-overflow:ellipsis;
      white-space:nowrap;
    }
    .csel-chevron{
      flex:0 0 auto;
      width:0.6em;
      height:0.36em;
      margin-left:auto;
      background:no-repeat center / contain url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="10" height="6"><path d="M0 0L5 6L10 0Z" fill="%23888"/></svg>');
    }

    .csel-list{
      display:none;
      position:absolute;
      top:calc(100% + 0.375rem);
      left:0;
      min-width:14rem;
      max-width:19rem;
      max-height:min(60vh, 19rem);
      overflow-y:auto;
      background:var(--panel-overlay-bg);
      backdrop-filter:blur(20px) saturate(1.3);
      -webkit-backdrop-filter:blur(20px) saturate(1.3);
      border:1px solid var(--panel-overlay-border);
      border-radius:0.75rem;
      padding:0.375rem;
      box-shadow:0 8px 28px rgba(0,0,0,0.22);
      z-index:32;
    }
    .csel-list.is-open{ display:block; }
    .csel-group{
      padding:0.5rem 0.625rem 0.25rem;
      font-size:0.66rem;
      font-weight:600;
      letter-spacing:0.02em;
      color:var(--text-dim);
      text-transform:uppercase;
    }
    .csel-opt{
      padding:0.5rem 0.625rem;
      font-size:0.8rem;
      color:var(--text);
      border-radius:0.5rem;
      cursor:pointer;
      white-space:nowrap;
      overflow:hidden;
      text-overflow:ellipsis;
    }
    .csel-opt:hover{ background:var(--overlay-bg); }
    .csel-opt.is-selected{
      color:var(--accent);
      font-weight:600;
    }

    /* only ever created inside the Android app (see initAndroidBridge in
       script.js) — top-right, level with the pickers, in the same
       glass-pill language as they use. (Bottom-left, under the camera,
       collided with the scene's own distance label there.) */
    .close-btn{
      display:flex;
      align-items:center;
      gap:0.4rem;
      position:fixed;
      right:calc(0.875rem + env(safe-area-inset-right));
      top:calc(0.875rem + env(safe-area-inset-top));
      font:inherit;
      font-size:0.76rem;
      color:var(--text);
      padding:0.5rem 0.85rem;
      border-radius:999px;
      border:1px solid var(--overlay-border);
      box-shadow:var(--shadow);
      background-color:var(--overlay-bg);
      backdrop-filter:blur(12px);
      -webkit-backdrop-filter:blur(12px);
      z-index:30;
      cursor:pointer;
      -webkit-tap-highlight-color:transparent;
    }
    .close-icon{
      width:0.85em;
      height:0.85em;
      background:no-repeat center / contain url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M5 5L19 19M19 5L5 19" stroke="%23888" stroke-width="2.4" stroke-linecap="round"/></svg>');
    }

    .hud-sliders{
      display:flex;
      flex-direction:column;
      gap:0.5rem;
      width:21rem;
      order:2;
      background:var(--panel-overlay-bg);
      backdrop-filter:blur(20px) saturate(1.3);
      -webkit-backdrop-filter:blur(20px) saturate(1.3);
      border:1px solid var(--panel-overlay-border);
      border-radius:0.875rem;
      padding:0.75rem 0.875rem;
      box-shadow:0 4px 24px rgba(0,0,0,0.12);
    }
    .hud-sliders .field{
      flex-direction:row;
      align-items:center;
      gap:0.625rem;
    }
    .hud-sliders .field-head{
      flex:0 0 auto;
      min-width:3.25rem;
    }
    .hud-sliders input[type="range"]{ flex:1 1 auto; }
    .hud-sliders .fname{ display:none; }
    .hud-sliders .tickline{ display:none; }

    #scene-svg .scene-label{ display:none; }
  }
