    :root {
      --border: #d1d5db;
      --panel: #f8fafc;
      --text: #111827;
      --muted: #4b5563;
      --bg: #ffffff;
      --toolbar-height: 56px;
    }

    * {
      box-sizing: border-box;
    }

    html,
    body {
      margin: 0;
      height: 100%;
      min-height: 100%;
      font-family: Inter, Arial, sans-serif;
      color: var(--text);
      background: #f3f4f6;
    }

    #site-header,
    #site-footer {
      background: #ffffff;
      border-bottom: 1px solid var(--border);
      padding: 14px 20px;
      color: var(--muted);
      text-align: center;
    }

    #site-footer {
      border-top: 1px solid var(--border);
      border-bottom: 0;
    }

    .demo-page {
      max-width: 1480px;
      margin: 0 auto;
      padding: 16px;
      display: flex;
      flex-direction: column;
      gap: 16px;
      min-height: 0;
    }

    .top-toolbar {
      min-height: var(--toolbar-height);
      border: 1px solid var(--border);
      border-radius: 10px;
      background: #ffffff;
      padding: 10px 12px;
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      justify-content: space-between;
      gap: 10px;
    }

    .top-toolbar-group {
      display: flex;
      flex-wrap: wrap;
      gap: 10px;
      align-items: center;
    }

    .top-toolbar button,
    .top-toolbar .back-link,
    .toolstrip button {
      display: inline-flex;
      align-items: center;
      border: 1px solid var(--border);
      border-radius: 6px;
      background: #ffffff;
      color: var(--text);
      font-size: 14px;
      padding: 8px 12px;
      text-decoration: none;
      line-height: 1;
      cursor: pointer;
    }

    .main-layout {
      min-height: 0;
      display: grid;
      grid-template-columns: minmax(0, 1fr) 320px;
      gap: 16px;
    }

    .viewer-column {
      min-width: 0;
      min-height: 0;
      display: grid;
      grid-template-rows: 1fr auto;
      gap: 16px;
    }

    .image-viewer {
      min-width: 0;
      min-height: 0;
      width: 100%;
      max-width: 90vw;
      max-height: 75vh;
      border: 1px solid var(--border);
      border-radius: 10px;
      background: #f3f4f6;
      margin: 0;
      padding: 0;
      display: flex;
      justify-content: center;
      align-items: center;
      justify-self: center;
      overflow: hidden;
      position: relative;
    }

    .image-viewer.portrait-mode {
      max-width: 60vw;
      max-height: 75vh;
    }

    .image-viewer.landscape-mode {
      max-width: 90vw;
      max-height: 75vh;
    }

    .hero-media {
      width: 100%;
      max-height: 100%;
      aspect-ratio: 16 / 9;
      border: 1px solid var(--border);
      border-radius: 8px;
      display: block;
      background: #e5e7eb;
    }

    .image-preview-stage {
      display: none;
      width: 100%;
      height: 100%;
      position: relative;
      align-items: center;
      justify-content: center;
    }

    .image-preview {
      display: none;
      object-fit: contain;
      object-position: center;
      max-width: 100%;
      max-height: 100%;
      width: auto;
      height: auto;
      border: 1px solid var(--border);
      border-radius: 8px;
      background: #e5e7eb;
    }

    .raw-preview-placeholder {
      display: none;
      max-width: 100%;
      padding: 12px 16px;
      border: 1px dashed var(--border);
      border-radius: 8px;
      background: #ffffff;
      color: var(--muted);
      font-size: 13px;
      text-align: center;
      z-index: 1;
    }

    .image-viewer.has-preview .raw-preview-placeholder.is-active {
      display: block;
    }

    .image-viewer.has-preview .hero-media {
      display: none;
    }

    .image-viewer.has-preview .image-preview-stage {
      display: flex;
    }

    .image-viewer.has-preview .image-preview.is-loaded {
      display: block;
    }

    .slider-mask {
      display: none;
      overflow: hidden;
    }

    .image-viewer.has-preview .slider-mask.has-edited {
      display: block;
    }

    .image-viewer.overlay-mode .image-preview-raw.is-loaded,
    .image-viewer.overlay-mode .slider-mask.has-edited .image-preview-edited.is-loaded {
      position: absolute;
      inset: 0;
      width: 100%;
      height: 100%;
      max-width: 100%;
      max-height: 100%;
      margin: 0;
    }

    .image-viewer.overlay-mode .image-preview-raw {
      z-index: 1;
    }

    .image-viewer.overlay-mode .slider-mask.has-edited {
      position: absolute;
      inset: 0;
      width: 100%;
      height: 100%;
      overflow: hidden;
      z-index: 2;
    }

    .image-viewer.overlay-mode .image-preview-edited {
      opacity: 1;
    }

    .image-viewer.side-by-side-mode .image-preview-stage {
      display: flex;
      align-items: center;
      justify-content: center;
    }

    .image-viewer.side-by-side-mode .image-preview-raw.is-loaded,
    .image-viewer.side-by-side-mode .slider-mask.has-edited {
      width: 50%;
      height: 100%;
      max-width: 50%;
      max-height: 100%;
    }

    .image-viewer.side-by-side-mode .slider-mask.has-edited .image-preview-edited.is-loaded {
      width: 100%;
      height: 100%;
      max-width: 100%;
      max-height: 100%;
    }

    .slider-container {
      display: none;
      position: absolute;
      inset: 0;
      z-index: 3;
      pointer-events: none;
    }

    .slider-container.is-active {
      display: block;
    }

    .slider-handle {
      position: absolute;
      left: 50%;
      top: 0;
      bottom: 0;
      width: 2px;
      transform: translateX(-50%);
      background: rgba(255, 255, 255, 0.95);
      box-shadow: 0 0 0 1px rgba(17, 24, 39, 0.28);
      cursor: grab;
      pointer-events: auto;
      touch-action: none;
    }

    .slider-handle:active {
      cursor: grabbing;
    }

    .viewer-upload-controls {
      position: absolute;
      left: 20px;
      bottom: 20px;
      display: grid;
      gap: 8px;
      z-index: 2;
      width: min(460px, calc(100% - 40px));
      overflow-y: auto;
      max-height: calc(100vh - 420px);
      min-height: 0;
    }

    .viewer-upload-controls button {
      border: 1px solid var(--border);
      border-radius: 999px;
      background: #ffffff;
      color: var(--text);
      font-size: 13px;
      padding: 8px 12px;
      cursor: pointer;
      z-index: 2;
    }

    .viewer-upload-controls button:disabled {
      opacity: 0.6;
      cursor: not-allowed;
    }

    .viewer-upload-section {
      border: 1px solid var(--border);
      border-radius: 10px;
      background: rgba(255, 255, 255, 0.95);
      padding: 8px;
      display: flex;
      flex-wrap: wrap;
      gap: 8px;
      align-items: center;
    }

    .viewer-upload-controls details > summary {
      cursor: pointer;
      font-size: 13px;
      color: var(--text);
      margin-bottom: 6px;
    }

    .section-metadata-panel {
      width: 100%;
      border-top: 1px solid var(--border);
      padding-top: 8px;
      color: var(--muted);
      font-size: 13px;
      line-height: 1.45;
    }

    .section-metadata-panel details + details {
      margin-top: 6px;
    }

    .section-metadata-panel ul {
      margin: 6px 0 0;
      padding-left: 18px;
    }

    .section-metadata-panel li + li {
      margin-top: 4px;
    }

    .toolstrip {
      border: 1px solid var(--border);
      border-radius: 10px;
      background: var(--panel);
      padding: 12px;
      display: flex;
      flex-wrap: wrap;
      gap: 10px;
    }

    .mobile-analysis-toggle,
    .mobile-toolstrip {
      display: none;
    }

    .sidebar {
      min-height: 0;
      border: 1px solid var(--border);
      border-radius: 10px;
      background: var(--panel);
      padding: 14px;
      overflow-y: auto;
    }

    .sidebar section {
      border: 1px solid var(--border);
      border-radius: 8px;
      background: #ffffff;
      padding: 12px;
    }

    .sidebar section + section {
      margin-top: 12px;
    }

    .sidebar h2 {
      margin: 0 0 8px;
      font-size: 16px;
    }

    .sidebar p {
      margin: 0;
      color: var(--muted);
      font-size: 14px;
      line-height: 1.45;
    }

    .coach-chat-dock {
      background: var(--panel);
    }

    .coach-chat-message {
      margin: 0 0 10px;
      padding: 8px 10px;
      border: 1px solid var(--border);
      border-radius: 8px;
      background: var(--bg);
      color: var(--muted);
      font-size: 13px;
    }

    .coach-chat-compose {
      display: flex;
      gap: 8px;
    }

    .coach-chat-input {
      flex: 1;
      min-width: 0;
      border: 1px solid var(--border);
      border-radius: 6px;
      padding: 8px 10px;
      font: inherit;
      font-size: 13px;
      color: var(--text);
      background: var(--bg);
    }

    .coach-chat-send {
      border: 1px solid var(--border);
      border-radius: 6px;
      padding: 8px 10px;
      background: var(--bg);
      color: var(--text);
      font-size: 13px;
      cursor: default;
    }

    .metadata-list {
      margin: 0;
      padding-left: 18px;
      color: var(--muted);
      font-size: 13px;
      line-height: 1.45;
    }

    .metadata-list li + li {
      margin-top: 6px;
    }

    body.app-mode {
      position: fixed;
      inset: 0;
      width: 100%;
      height: 100dvh;
      overflow: hidden;
    }
    body.app-mode #site-header { display: none; }
    body.app-mode #site-footer { display: none; }
    body.app-mode .demo-page { height: 100dvh; }
    body.app-mode .main-layout { flex: 1; min-height: 0; }
    body.app-mode .viewer-column { min-height: 0; overflow: hidden; }
    body.app-mode .image-viewer {
      min-height: 0;
      width: 100%;
      max-width: 100vw;
      max-height: calc(100vh - 40px);
      overflow: hidden;
      display: flex;
      justify-content: center;
      align-items: center;
    }

    body.app-mode .image-viewer.portrait-mode {
      max-width: 60vw;
      max-height: min(75vh, calc(100vh - 40px));
    }

    body.app-mode .image-viewer.landscape-mode {
      max-width: 90vw;
      max-height: min(75vh, calc(100vh - 40px));
    }
    body.app-mode .demo-page {
      max-width: none;
      padding: 0;
      gap: 0;
      overflow: hidden;
    }

    body.app-mode .top-toolbar {
      border-radius: 0;
      border-left: 0;
      border-right: 0;
    }

    body.app-mode .main-layout {
      padding: 16px;
      padding-bottom: calc(16px + env(safe-area-inset-bottom));
      overflow: hidden;
    }

    @media (width < 960px) {
      .main-layout {
        grid-template-columns: 1fr;
      }

      .sidebar {
        max-height: none;
        overflow: visible;
      }
    }

    /* Optional iPad portrait refinement only (820px aligns with common iPad portrait viewport width). */
    @media (max-width: 820px) and (orientation: portrait) and (min-width: 481px) {
      .main-layout {
        grid-template-columns: minmax(0, 1fr) 280px;
      }

      .image-viewer {
        min-height: 470px;
      }
    }

    /* Smart mobile layout: 480px targets phone portrait width and phone landscape height. */
    @media (max-width: 480px), (max-height: 480px) {
      .demo-page {
        padding: 12px;
        gap: 12px;
      }

      .main-layout {
        display: block;
        position: relative;
      }

      .viewer-column {
        display: block;
      }

      .image-viewer {
        width: 100%;
        /* Keep hero dominant on mobile while preserving room for controls below. */
        height: 52vh;
        border: 0;
        border-radius: 0;
        padding: 0;
        margin: 0;
      }

      @supports (height: 100dvh) {
        .image-viewer {
          height: 52dvh;
        }
      }

      .hero-media {
        border: 0;
        border-radius: 0;
        width: 100%;
        height: 100%;
        max-height: none;
        object-fit: cover;
      }

      .toolstrip {
        display: none;
      }

      .mobile-analysis-toggle {
        display: inline-flex;
        margin-top: 10px;
        border: 1px solid var(--border);
        border-radius: 999px;
        background: #ffffff;
        color: var(--text);
        font-size: 13px;
        padding: 8px 12px;
        cursor: pointer;
      }

      .mobile-toolstrip {
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        gap: 8px;
        border: 1px solid var(--border);
        border-radius: 999px;
        background: #ffffff;
        padding: 8px;
        margin-top: 12px;
        -webkit-overflow-scrolling: touch;
      }

      .mobile-toolstrip button {
        border: 1px solid var(--border);
        border-radius: 999px;
        background: var(--panel);
        color: var(--text);
        font-size: 12px;
        padding: 7px 10px;
        flex: 0 0 auto;
      }

      .sidebar {
        position: fixed;
        inset-inline: 0;
        bottom: 0;
        z-index: 30;
        border: 0;
        border-radius: 0;
        padding: 0;
        background: transparent;
        overflow: visible;
        pointer-events: none;
      }

      .mobile-bottom-sheet {
        /* Keep the sheet large enough for useful content without fully covering the hero area. */
        max-height: min(72dvh, 560px);
        overflow-y: auto;
        padding: 14px 14px calc(14px + env(safe-area-inset-bottom));
        border: 1px solid var(--border);
        border-bottom: 0;
        border-radius: 16px 16px 0 0;
        background: var(--panel);
        transform: translateY(105%);
        transition: transform 180ms ease-out;
        box-shadow: 0 -10px 24px rgba(17, 24, 39, 0.18);
        pointer-events: auto;
      }

      @supports not (height: 100dvh) {
        .mobile-bottom-sheet {
          max-height: min(72vh, 560px);
        }
      }

      .sidebar.mobile-sheet-open .mobile-bottom-sheet {
        transform: translateY(0);
      }

      body.app-mode .demo-page {
        padding-bottom: calc(72px + env(safe-area-inset-bottom));
      }

      body.app-mode .mobile-toolstrip {
        position: fixed;
        left: 8px;
        right: 8px;
        bottom: calc(8px + env(safe-area-inset-bottom));
        margin-top: 0;
        z-index: 40;
      }
    }
