:root {
  --panel-width: 380px;
  --mobile-canvas-height: 52svh;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
  html, body { height: 100%; overflow: hidden; background: #1a1a1a; color: #e8e0d5; font-family: 'Georgia', serif; }

  header { position: absolute; top: 0; left: 0; right: var(--panel-width); z-index: 10; padding: 14px 24px; display: flex; align-items: baseline; gap: 16px; background: linear-gradient(to bottom, rgba(17,17,17,0.9) 0%, rgba(17,17,17,0) 100%); pointer-events: none; }
  header h1 { font-size: 1.3rem; font-weight: normal; letter-spacing: 0.05em; color: #f0ebe4; }
  header span { font-size: 0.78rem; color: #888; letter-spacing: 0.1em; text-transform: uppercase; }

  .layout { display: flex; height: 100dvh; width: 100%; }

  #canvas-wrap { flex: 1; position: relative; background: #111; overflow: hidden; touch-action: none; }
  canvas { display: block; width: 100% !important; height: 100% !important; }

  .controls-hint { position: absolute; bottom: 12px; left: 12px; font-size: 0.72rem; color: #555; letter-spacing: 0.05em; }
  .reactivate-camera-btn {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 22;
    border: 1px solid #3f3f3f;
    border-radius: 4px;
    padding: 7px 10px;
    background: rgba(20, 20, 20, 0.85);
    color: #d8d0c3;
    font-size: 0.66rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    cursor: pointer;
  }
  .reactivate-camera-btn:hover {
    background: rgba(32, 32, 32, 0.9);
    border-color: #5b5b5b;
  }
  .reactivate-camera-btn.is-hidden { display: none; }
  .hover-info {
    position: absolute;
    top: 14px;
    left: 14px;
    z-index: 20;
    display: none;
    min-width: 250px;
    max-width: 320px;
    padding: 10px 12px;
    border: 1px solid #555;
    border-radius: 6px;
    background: rgba(10, 10, 10, 0.94);
    color: #e8e0d5;
    font-size: 0.8rem;
    line-height: 1.5;
    pointer-events: none;
    box-shadow: 0 5px 20px rgba(0,0,0,0.42);
  }
  .hover-info strong { color: #f0ebe4; letter-spacing: 0.02em; }

  .panel { width: var(--panel-width); height: 100dvh; background: #1e1e1e; border-left: 1px solid #2a2a2a; overflow-y: auto; padding: 24px 22px; flex-shrink: 0; }

  .panel h2 { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.15em; color: #888; margin-bottom: 16px; padding-bottom: 8px; border-bottom: 1px solid #2a2a2a; }

  .section { margin-bottom: 28px; }
  .section-collapsible { margin-bottom: 28px; }
  .section-collapsible details {
    border: 1px solid #2a2a2a;
    border-radius: 6px;
    background: #202020;
    overflow: hidden;
  }
  .section-collapsible details[open] { padding-bottom: 8px; }
  .section-summary {
    list-style: none;
    cursor: pointer;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: #888;
    padding: 12px 12px 10px;
    border-bottom: 1px solid #2a2a2a;
    user-select: none;
    position: relative;
  }
  .section-summary::-webkit-details-marker { display: none; }
  .section-summary::marker { content: ''; }
  .section-summary::before {
    content: '▾';
    position: absolute;
    right: 12px;
    top: 11px;
    color: #666;
    font-size: 0.8rem;
  }
  .section-collapsible details:not([open]) .section-summary {
    border-bottom: none;
  }
  .section-collapsible details:not([open]) .section-summary::before {
    content: '▸';
  }
  .section-collapse-body {
    padding: 12px 12px 0;
  }

  .dim-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 16px; }
  .dim-card { background: #252525; border: 1px solid #2f2f2f; border-radius: 4px; padding: 10px 12px; }
  .dim-card .label { font-size: 0.68rem; color: #666; text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 4px; }
  .dim-card .value { font-size: 1.05rem; color: #d4c9b8; letter-spacing: 0.03em; }

  .notes ul { list-style: none; padding: 0; }
  .notes ul li { position: relative; padding: 8px 0 8px 16px; border-bottom: 1px solid #252525; font-size: 0.82rem; line-height: 1.5; color: #c0b8ac; }
  .notes ul li::before { content: '—'; position: absolute; left: 0; color: #555; }

  .legend { display: flex; flex-direction: column; gap: 8px; }
  .leg-item { display: flex; align-items: center; gap: 10px; font-size: 0.78rem; color: #999; }
  .leg-swatch { width: 18px; height: 14px; border-radius: 2px; flex-shrink: 0; }

  .angle-row { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
  .angle-row label { font-size: 0.75rem; color: #777; width: 130px; flex-shrink: 0; }
  input[type=range] { flex: 1; accent-color: #c87941; }
  .angle-val { font-size: 0.82rem; color: #d4c9b8; width: 50px; text-align: right; }

  .tag { display: inline-block; background: #2a2218; border: 1px solid #5a3e24; color: #c87941; font-size: 0.65rem; letter-spacing: 0.1em; text-transform: uppercase; padding: 2px 7px; border-radius: 3px; margin-bottom: 10px; }

  .control-subhead {
    font-size: 0.7rem;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 8px;
  }

  .mt-12 { margin-top: 12px; }

  .control-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 12px;
  }

  .action-btn {
    border: 1px solid #4a4a4a;
    background: #2a2a2a;
    color: #d7d0c3;
    font-size: 0.68rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    padding: 6px 10px;
    border-radius: 4px;
    cursor: pointer;
  }

  .action-btn:hover {
    background: #333;
    border-color: #5a5a5a;
  }

  .action-btn--ghost {
    background: transparent;
    border-color: #3e3e3e;
    color: #a8a095;
  }

  .save-status {
    font-size: 0.68rem;
    color: #8cb08c;
    min-height: 1em;
  }

  .save-status.is-error { color: #c98c8c; }

  .toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 12px;
    padding: 8px 10px;
    border: 1px solid #2f2f2f;
    border-radius: 4px;
    background: #252525;
  }

  .toggle-label {
    font-size: 0.75rem;
    color: #d0c7ba;
    letter-spacing: 0.04em;
  }

  .toggle-input-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .toggle-input-wrap input[type=checkbox] {
    width: 16px;
    height: 16px;
    accent-color: #5a8bb8;
  }

  .toggle-meta {
    font-size: 0.66rem;
    color: #777;
    letter-spacing: 0.1em;
    text-transform: uppercase;
  }

  .control-note {
    font-size: 0.68rem;
    color: #555;
    margin-top: 4px;
    margin-bottom: 4px;
  }

  .control-note--spacious { margin-bottom: 16px; }

  .control-note--muted {
    color: #888;
    margin-top: 0;
    margin-bottom: 8px;
  }

  .control-note--muted-top {
    color: #888;
    margin-top: 10px;
    margin-bottom: 8px;
  }

  .wall-letter { color: #c8d88a; }

  .leg-swatch--a { background: #4a6741; }
  .leg-swatch--b { background: #4a6741; }
  .leg-swatch--c { background: #4a6741; }
  .leg-swatch--d { background: #4a6741; }
  .leg-swatch--e { background: #c87941; }
  .leg-swatch--f { background: #6a4174; }
  .leg-swatch--g { background: #2f76d2; }
  .leg-swatch--cap { background: #3d3d3d; }
  .leg-swatch--poly { background: #bfd6ea; }

  @media (max-width: 980px) {
    html, body { overflow: hidden; }

    .layout { height: 100dvh; min-height: 0; }

    header {
      right: 0;
      padding: 10px 12px;
      gap: 6px;
      align-items: flex-start;
      flex-direction: column;
    }

    header h1 { font-size: 1.05rem; letter-spacing: 0.03em; }
    header span { font-size: 0.62rem; letter-spacing: 0.07em; }

    .controls-hint {
      left: 8px;
      right: 8px;
      bottom: 8px;
      white-space: normal;
      line-height: 1.25;
      padding: 4px 6px;
      border-radius: 4px;
      background: rgba(10,10,10,0.5);
      font-size: 0.64rem;
    }

    .reactivate-camera-btn {
      top: auto;
      bottom: 56px;
      right: 8px;
      font-size: 0.62rem;
      padding: 6px 8px;
    }

    .hover-info {
      top: 8px;
      left: 8px;
      min-width: 0;
      max-width: min(90vw, 320px);
      font-size: 0.74rem;
      line-height: 1.4;
      padding: 8px 10px;
    }

    .panel {
      overflow-y: auto;
      -webkit-overflow-scrolling: touch;
      padding: 14px 12px calc(22px + env(safe-area-inset-bottom));
    }

    .section,
    .section-collapsible { margin-bottom: 20px; }

    .toggle-row { padding: 10px; }
    .toggle-meta { display: none; }
    .toggle-label { font-size: 0.72rem; }

    .angle-row { gap: 8px; }
    .angle-row label { width: 106px; font-size: 0.71rem; }
    .angle-val { width: 54px; font-size: 0.76rem; }

    .panel h2 { margin-bottom: 12px; }
    .control-subhead { margin-bottom: 6px; }
    .control-note { font-size: 0.64rem; }
    .notes ul li { font-size: 0.76rem; line-height: 1.45; }
  }

  @media (max-width: 980px) and (orientation: portrait) {
    .layout { flex-direction: column; }

    #canvas-wrap {
      flex: none;
      width: 100%;
      height: var(--mobile-canvas-height);
      min-height: 320px;
      max-height: 72svh;
    }

    .panel {
      width: 100%;
      flex: 1;
      min-height: 0;
      border-left: none;
      border-top: 1px solid #2a2a2a;
    }
  }

  @media (max-width: 980px) and (orientation: landscape) {
    .layout { flex-direction: row; }

    #canvas-wrap {
      flex: 1;
      min-width: 0;
      height: 100%;
    }

    .panel {
      width: min(44vw, 420px);
      height: 100%;
      flex: none;
      min-height: 0;
      border-top: none;
      border-left: 1px solid #2a2a2a;
      padding: 12px 10px calc(16px + env(safe-area-inset-bottom));
    }

    .controls-hint { font-size: 0.6rem; }
    .reactivate-camera-btn {
      top: 8px;
      bottom: auto;
      right: 8px;
      font-size: 0.58rem;
      padding: 5px 7px;
    }
    .panel h2 { margin-bottom: 10px; }
    .section, .section-collapsible { margin-bottom: 16px; }
  }

  @media (max-width: 640px) {
    :root { --mobile-canvas-height: 48svh; }

    .dim-grid { grid-template-columns: 1fr; }
    .action-btn { width: 100%; }
    .control-actions { flex-direction: column; align-items: stretch; }
    .leg-item { font-size: 0.72rem; }
    .section-summary { font-size: 0.66rem; }
    .panel h2 { font-size: 0.66rem; }
    .angle-row label { width: 98px; }
  }
