:root {
        --bg: #0b0d10;
        --panel: rgba(12, 14, 18, 0.78);
        --text: #e8eaed;
        --muted: #9aa3ad;
        --accent: #3dd6c6;
        --danger: #ff6b6b;
      }

      * {
        box-sizing: border-box;
      }

      html,
      body {
        margin: 0;
        padding: 0;
        width: 100%;
        height: 100%;
        overflow: hidden;
        background: var(--bg);
        color: var(--text);
        font-family: "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif;
      }

      canvas {
        display: block;
      }

      #hud {
        position: fixed;
        top: 16px;
        left: 16px;
        z-index: 10;
        max-width: min(360px, calc(100vw - 32px));
        padding: 14px 16px;
        border: 1px solid rgba(255, 255, 255, 0.08);
        background: var(--panel);
        backdrop-filter: blur(10px);
        border-radius: 10px;
        pointer-events: none;
      }

      .hud-top {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 10px;
        pointer-events: auto;
      }

      #hud h1 {
        margin: 0;
        font-size: 15px;
        font-weight: 600;
        letter-spacing: 0.02em;
        min-width: 0;
      }

      .hud-toggle {
        appearance: none;
        flex-shrink: 0;
        width: 28px;
        height: 28px;
        padding: 0;
        border: 1px solid rgba(255, 255, 255, 0.14);
        border-radius: 6px;
        background: rgba(255, 255, 255, 0.06);
        color: var(--text);
        font: inherit;
        font-size: 16px;
        line-height: 26px;
        text-align: center;
        cursor: pointer;
      }

      .hud-toggle:hover {
        background: rgba(255, 255, 255, 0.12);
      }

      #hud-body {
        margin-top: 6px;
      }

      #hud.is-minimized {
        padding: 8px 10px;
        max-width: none;
      }

      #hud.is-minimized #hud-body {
        display: none;
      }

      #hud.is-minimized h1 {
        font-size: 13px;
      }

      #hud.is-minimized .role-badge {
        font-size: 9px;
        padding: 0 5px;
      }

      #hud p,
      #status {
        margin: 0;
        font-size: 12px;
        line-height: 1.5;
        color: var(--muted);
      }

      #status {
        margin-top: 10px;
        color: var(--accent);
      }

      #status.error {
        color: var(--danger);
      }

      #progress {
        margin-top: 10px;
        height: 3px;
        background: rgba(255, 255, 255, 0.08);
        border-radius: 999px;
        overflow: hidden;
      }

      #progress > span {
        display: block;
        height: 100%;
        width: 0%;
        background: var(--accent);
        transition: width 0.15s ease;
      }

      #toggles {
        margin-top: 12px;
        padding-top: 12px;
        border-top: 1px solid rgba(255, 255, 255, 0.08);
        display: grid;
        gap: 10px;
        pointer-events: auto;
      }

      .toggle-row {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        font-size: 12px;
        color: var(--text);
      }

      .toggle-row span.desc {
        color: var(--muted);
        font-size: 11px;
      }

      .toggle-row label {
        display: flex;
        flex-direction: column;
        gap: 2px;
      }

      .switch {
        position: relative;
        width: 40px;
        height: 22px;
        flex-shrink: 0;
      }

      .switch input {
        opacity: 0;
        width: 0;
        height: 0;
      }

      .switch .slider {
        position: absolute;
        inset: 0;
        cursor: pointer;
        background: rgba(255, 255, 255, 0.12);
        border: 1px solid rgba(255, 255, 255, 0.14);
        border-radius: 22px;
        transition: background 0.15s ease;
      }

      .switch .slider::before {
        content: "";
        position: absolute;
        width: 16px;
        height: 16px;
        left: 2px;
        top: 2px;
        background: #d7dbe0;
        border-radius: 50%;
        transition: transform 0.15s ease;
      }

      .switch input:checked + .slider {
        background: rgba(61, 214, 198, 0.35);
        border-color: var(--accent);
      }

      .switch input:checked + .slider::before {
        transform: translateX(18px);
        background: var(--accent);
      }

      .switch input:disabled + .slider {
        opacity: 0.4;
        cursor: not-allowed;
      }

      .slider-row {
        display: grid;
        gap: 6px;
        font-size: 12px;
        color: var(--text);
      }

      .slider-row .slider-head {
        display: flex;
        align-items: baseline;
        justify-content: space-between;
        gap: 8px;
      }

      .slider-row .slider-head .desc {
        color: var(--muted);
        font-size: 11px;
      }

      .slider-row .slider-value {
        font-variant-numeric: tabular-nums;
        color: var(--accent);
        font-size: 12px;
      }

      .slider-row input[type="range"] {
        width: 100%;
        margin: 0;
        accent-color: var(--accent);
        cursor: pointer;
      }

      .measure-box {
        display: grid;
        gap: 8px;
        font-size: 12px;
      }

      .measure-box .measure-head {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 8px;
      }

      .measure-box .measure-title {
        display: flex;
        flex-direction: column;
        gap: 2px;
      }

      .btn {
        appearance: none;
        border: 1px solid rgba(255, 255, 255, 0.14);
        background: rgba(255, 255, 255, 0.06);
        color: var(--text);
        font: inherit;
        font-size: 11px;
        padding: 5px 10px;
        border-radius: 6px;
        cursor: pointer;
      }

      .btn:hover {
        background: rgba(255, 255, 255, 0.1);
      }

      .btn:disabled {
        opacity: 0.4;
        cursor: not-allowed;
      }

      #measure-result {
        font-variant-numeric: tabular-nums;
        color: var(--accent);
        font-size: 18px;
        font-weight: 600;
        letter-spacing: 0.02em;
      }

      #measure-hint {
        color: var(--muted);
        font-size: 11px;
        line-height: 1.45;
      }

      #measure-overlay {
        position: fixed;
        inset: 0;
        z-index: 5;
        pointer-events: none;
        overflow: hidden;
      }

      #measure-overlay svg {
        position: absolute;
        inset: 0;
        width: 100%;
        height: 100%;
        overflow: visible;
      }

      #measure-overlay .measure-dot {
        position: absolute;
        width: 14px;
        height: 14px;
        margin: -7px 0 0 -7px;
        border-radius: 50%;
        background: #ffe14a;
        border: 2px solid #1a1a1a;
        box-shadow: 0 0 0 1px rgba(255, 225, 74, 0.55), 0 0 10px rgba(255, 225, 74, 0.45);
        transform-origin: center;
        z-index: 2;
      }

      #measure-label {
        position: absolute;
        z-index: 3;
        transform: translate(-50%, -130%);
        padding: 4px 8px;
        border-radius: 6px;
        background: rgba(12, 14, 18, 0.88);
        border: 1px solid rgba(255, 225, 74, 0.55);
        color: #ffe14a;
        font-size: 12px;
        font-weight: 600;
        font-variant-numeric: tabular-nums;
        white-space: nowrap;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
      }

      #measure-overlay .measure-dot[hidden],
      #measure-overlay #measure-label[hidden],
      #measure-overlay .measure-line-group[hidden] {
        display: none !important;
      }

      #bookmark-overlay {
        position: fixed;
        inset: 0;
        z-index: 6;
        pointer-events: none;
        overflow: hidden;
      }

      .bookmark-pin {
        position: absolute;
        appearance: none;
        min-width: 28px;
        height: 28px;
        margin: -28px 0 0 -14px;
        padding: 0 6px;
        border-radius: 14px 14px 14px 4px;
        transform: rotate(-45deg);
        background: #4ea1ff;
        border: 2px solid #0b0d10;
        box-shadow: 0 0 8px rgba(78, 161, 255, 0.45);
        color: #fff;
        font: inherit;
        font-size: 11px;
        font-weight: 700;
        line-height: 24px;
        text-align: center;
        pointer-events: auto;
        cursor: pointer;
        z-index: 1;
      }

      .bookmark-pin:hover {
        background: #6bb3ff;
      }

      .bookmark-pin[hidden] {
        display: none !important;
      }

      .bookmark-pin > span {
        display: inline-block;
        transform: rotate(45deg);
      }

      .bookmark-box {
        display: grid;
        gap: 8px;
        font-size: 12px;
      }

      .bookmark-box .measure-head {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 8px;
      }

      #bookmark-list {
        display: grid;
        gap: 6px;
        max-height: 220px;
        overflow: auto;
      }

      #bookmark-list:empty::before {
        content: "まだブックマークがありません";
        color: var(--muted);
        font-size: 11px;
      }

      .bookmark-item {
        display: grid;
        grid-template-columns: 1fr auto;
        gap: 6px 8px;
        align-items: start;
        padding: 8px;
        border: 1px solid rgba(255, 255, 255, 0.08);
        border-radius: 6px;
        background: rgba(255, 255, 255, 0.04);
      }

      .bookmark-item-clickable {
        cursor: pointer;
        transition: background 0.15s ease, border-color 0.15s ease;
      }

      .bookmark-item-clickable:hover,
      .bookmark-item-clickable:focus-visible {
        background: rgba(78, 161, 255, 0.12);
        border-color: rgba(78, 161, 255, 0.35);
        outline: none;
      }

      .bookmark-item .bm-meta {
        min-width: 0;
        display: grid;
        gap: 2px;
      }

      .bookmark-item .bm-name {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        color: var(--text);
        font-size: 12px;
        font-weight: 600;
      }

      .bookmark-item .bm-desc {
        color: var(--muted);
        font-size: 10px;
        line-height: 1.4;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
      }

      .bookmark-item .bm-badges {
        display: flex;
        flex-wrap: wrap;
        gap: 4px;
        margin-top: 2px;
      }

      .bookmark-item .bm-badge {
        font-size: 9px;
        padding: 1px 5px;
        border-radius: 3px;
        background: rgba(61, 214, 198, 0.15);
        color: var(--accent);
      }

      .bookmark-item .bm-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 4px;
        justify-content: flex-end;
      }

      .bookmark-item .btn {
        padding: 3px 7px;
        font-size: 10px;
      }

      #bookmark-hint {
        color: var(--muted);
        font-size: 11px;
        line-height: 1.45;
      }

      .btn-primary {
        background: rgba(61, 214, 198, 0.22);
        border-color: rgba(61, 214, 198, 0.45);
        color: var(--accent);
      }

      .bm-modal {
        position: fixed;
        inset: 0;
        z-index: 40;
        display: grid;
        place-items: center;
        padding: 16px;
      }

      .bm-modal[hidden] {
        display: none !important;
      }

      .bm-modal.is-fullscreen {
        padding: 0;
        place-items: stretch;
      }

      .bm-modal-backdrop {
        position: absolute;
        inset: 0;
        background: rgba(0, 0, 0, 0.55);
      }

      .bm-modal.is-fullscreen .bm-modal-backdrop {
        background: rgba(8, 10, 14, 0.98);
      }

      .bm-modal-panel {
        position: relative;
        width: min(420px, 100%);
        max-height: min(86vh, 640px);
        overflow: auto;
        padding: 16px;
        border-radius: 10px;
        border: 1px solid rgba(255, 255, 255, 0.1);
        background: rgba(14, 16, 20, 0.96);
        box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
      }

      .bm-modal.is-fullscreen .bm-modal-panel {
        width: 100%;
        max-width: none;
        height: 100%;
        max-height: none;
        border-radius: 0;
        border: none;
        box-shadow: none;
        background: transparent;
        display: flex;
        flex-direction: column;
        padding: 20px clamp(16px, 4vw, 40px) 24px;
        overflow: hidden;
      }

      .bm-modal-panel h2 {
        margin: 0 0 12px;
        font-size: 15px;
        font-weight: 600;
        flex-shrink: 0;
      }

      .bm-modal.is-fullscreen .bm-modal-panel h2 {
        font-size: 20px;
        margin-bottom: 16px;
      }

      .bm-form {
        display: grid;
        gap: 10px;
      }

      .bm-modal.is-fullscreen .bm-form {
        flex: 1;
        min-height: 0;
        overflow: auto;
        gap: 14px;
        align-content: start;
        max-width: 960px;
        width: 100%;
        margin: 0 auto;
        padding-bottom: 12px;
      }

      .bm-form label {
        display: grid;
        gap: 4px;
        font-size: 11px;
        color: var(--muted);
      }

      .bm-modal.is-fullscreen .bm-form label {
        font-size: 13px;
        gap: 6px;
      }

      .bm-modal.is-fullscreen .bm-form input[type="text"],
      .bm-modal.is-fullscreen .bm-form textarea {
        padding: 12px 14px;
        font-size: 14px;
      }

      .bm-modal.is-fullscreen .bm-form textarea {
        min-height: 120px;
      }

      .bm-modal.is-fullscreen .bm-image-gallery {
        max-height: none;
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 10px;
        padding: 10px;
      }

      .bm-modal.is-fullscreen .bm-modal-actions {
        position: sticky;
        bottom: 0;
        z-index: 2;
        flex-shrink: 0;
        max-width: none;
        width: 100%;
        margin: 8px 0 0;
        padding: 14px 0 4px;
        border-top: 1px solid rgba(255, 255, 255, 0.08);
        background: linear-gradient(to top, rgba(8, 10, 14, 0.98) 70%, rgba(8, 10, 14, 0.85));
        gap: 12px;
      }

      .bm-modal.is-fullscreen .bm-modal-actions .btn {
        padding: 10px 18px;
        font-size: 13px;
      }

      .bm-form input[type="text"],
      .bm-form textarea {
        width: 100%;
        padding: 8px 10px;
        border-radius: 6px;
        border: 1px solid rgba(255, 255, 255, 0.12);
        background: rgba(255, 255, 255, 0.04);
        color: var(--text);
        font: inherit;
        font-size: 12px;
      }

      .bm-form textarea {
        resize: vertical;
        min-height: 64px;
      }

      .bm-image-block {
        display: grid;
        gap: 6px;
      }

      .bm-image-label {
        font-size: 11px;
        color: var(--muted);
      }

      .bm-image-row {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        align-items: center;
      }

      .bm-image-row input[type="file"] {
        flex: 1;
        min-width: 0;
        font-size: 11px;
        color: var(--muted);
      }

      .bm-image-preview,
      .bm-image-gallery {
        border-radius: 6px;
        overflow: hidden;
        border: 1px solid rgba(255, 255, 255, 0.08);
        background: rgba(0, 0, 0, 0.25);
      }

      .bm-image-preview {
        max-height: 160px;
      }

      .bm-image-preview img {
        display: block;
        width: 100%;
        max-height: 160px;
        object-fit: contain;
      }

      .bm-image-gallery {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
        gap: 6px;
        padding: 6px;
        max-height: 220px;
        overflow: auto;
      }

      .bm-image-gallery[hidden] {
        display: none !important;
      }

      .bm-thumb {
        position: relative;
        aspect-ratio: 1;
        border-radius: 4px;
        overflow: hidden;
        background: rgba(255, 255, 255, 0.04);
        border: 1px solid rgba(255, 255, 255, 0.08);
      }

      .bm-thumb img {
        display: block;
        width: 100%;
        height: 100%;
        object-fit: cover;
      }

      .bm-thumb-remove {
        position: absolute;
        top: 2px;
        right: 2px;
        width: 20px;
        height: 20px;
        padding: 0;
        border: none;
        border-radius: 4px;
        background: rgba(0, 0, 0, 0.65);
        color: #fff;
        font-size: 12px;
        line-height: 20px;
        cursor: pointer;
      }

      .bm-thumb-remove:hover {
        background: rgba(255, 80, 80, 0.85);
      }

      .bm-modal-actions {
        display: flex;
        justify-content: flex-end;
        gap: 8px;
        margin-top: 4px;
      }

      .bm-detail {
        display: grid;
        gap: 10px;
      }

      .bm-detail-desc {
        margin: 0;
        font-size: 12px;
        line-height: 1.5;
        color: var(--muted);
        white-space: pre-wrap;
      }

      .bm-detail-desc:empty {
        display: none;
      }

      .bm-detail-link {
        color: var(--accent);
        font-size: 12px;
        word-break: break-all;
      }

      .bm-detail-empty {
        margin: 0;
        font-size: 12px;
        color: var(--muted);
      }

      .bm-carousel {
        position: relative;
        width: 100%;
        border-radius: 8px;
        overflow: hidden;
        border: 1px solid rgba(255, 255, 255, 0.1);
        background: rgba(0, 0, 0, 0.35);
        user-select: none;
        touch-action: pan-y;
      }

      .bm-carousel[hidden] {
        display: none !important;
      }

      .bm-carousel-viewport {
        position: relative;
        width: 100%;
        height: min(52vh, 360px);
        overflow: hidden;
        cursor: grab;
      }

      .bm-carousel-viewport.is-dragging {
        cursor: grabbing;
      }

      .bm-carousel-track {
        display: flex;
        width: 100%;
        height: 100%;
        transition: transform 0.28s ease;
        will-change: transform;
      }

      .bm-carousel-track.is-instant {
        transition: none;
      }

      .bm-carousel-slide {
        position: relative;
        flex: 0 0 100%;
        width: 100%;
        height: 100%;
        min-width: 0;
        min-height: 0;
        overflow: hidden;
        background: #0a0c10;
      }

      .bm-carousel-slide img {
        position: absolute;
        inset: 0;
        display: block;
        width: 100%;
        height: 100%;
        object-fit: contain;
        object-position: center;
        pointer-events: none;
      }

      .bm-carousel-btn {
        position: absolute;
        top: 50%;
        transform: translateY(-50%);
        z-index: 2;
        width: 36px;
        height: 36px;
        padding: 0;
        border: 1px solid rgba(255, 255, 255, 0.18);
        border-radius: 50%;
        background: rgba(12, 14, 18, 0.72);
        color: #fff;
        font-size: 22px;
        line-height: 34px;
        text-align: center;
        cursor: pointer;
      }

      .bm-carousel-btn:hover {
        background: rgba(61, 214, 198, 0.28);
        border-color: rgba(61, 214, 198, 0.45);
      }

      .bm-carousel-btn.prev {
        left: 8px;
      }

      .bm-carousel-btn.next {
        right: 8px;
      }

      .bm-carousel-btn[hidden] {
        display: none !important;
      }

      .bm-carousel-footer {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 8px;
        padding: 8px 10px;
        border-top: 1px solid rgba(255, 255, 255, 0.08);
        background: rgba(0, 0, 0, 0.25);
      }

      .bm-carousel-dots {
        display: flex;
        flex-wrap: wrap;
        gap: 6px;
        justify-content: center;
        flex: 1;
      }

      .bm-carousel-dot {
        width: 8px;
        height: 8px;
        padding: 0;
        border: none;
        border-radius: 50%;
        background: rgba(255, 255, 255, 0.28);
        cursor: pointer;
      }

      .bm-carousel-dot.is-active {
        background: var(--accent);
        transform: scale(1.15);
      }

      .bm-carousel-counter {
        flex-shrink: 0;
        font-size: 11px;
        color: var(--muted);
        font-variant-numeric: tabular-nums;
        min-width: 3.5em;
        text-align: right;
      }

      .bm-detail .bm-image-gallery {
        max-height: 280px;
      }

      #hint {
        position: fixed;
        right: 16px;
        bottom: 16px;
        z-index: 10;
        padding: 10px 12px;
        font-size: 11px;
        line-height: 1.55;
        color: var(--muted);
        background: var(--panel);
        border: 1px solid rgba(255, 255, 255, 0.08);
        border-radius: 8px;
        pointer-events: none;
      }

      #hint kbd {
        display: inline-block;
        min-width: 1.4em;
        padding: 1px 5px;
        margin: 0 1px;
        border: 1px solid rgba(255, 255, 255, 0.14);
        border-radius: 4px;
        background: rgba(255, 255, 255, 0.06);
        color: var(--text);
        font-family: inherit;
        font-size: 10px;
        text-align: center;
      }


.role-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 600;
  vertical-align: middle;
}
.role-badge.admin {
  background: rgba(255, 193, 7, 0.2);
  color: #ffc107;
  border: 1px solid rgba(255, 193, 7, 0.35);
}
.role-badge.viewer {
  background: rgba(78, 161, 255, 0.2);
  color: #4ea1ff;
  border: 1px solid rgba(78, 161, 255, 0.35);
}
.nav-links {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 8px;
  pointer-events: auto;
}
.nav-links a {
  color: var(--accent);
  font-size: 11px;
  text-decoration: none;
}
.nav-links a:hover { text-decoration: underline; }
.nav-links .btn {
  font-size: 11px;
  padding: 4px 8px;
}
.btn-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.folder-gate {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(ellipse at 30% 20%, rgba(78, 161, 255, 0.12), transparent 50%),
    radial-gradient(ellipse at 70% 80%, rgba(61, 214, 198, 0.1), transparent 45%),
    rgba(8, 10, 14, 0.92);
}
.folder-gate[hidden] {
  display: none !important;
}
.folder-gate-panel {
  width: min(440px, 100%);
  padding: 28px 24px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(14, 16, 20, 0.95);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
  text-align: center;
}
.folder-gate-panel h2 {
  margin: 0 0 12px;
  font-size: 18px;
  font-weight: 600;
}
.folder-gate-panel p {
  margin: 0 0 12px;
  font-size: 13px;
  line-height: 1.55;
  color: var(--muted);
}
.folder-gate-panel code {
  font-size: 12px;
  color: var(--accent);
}
.folder-gate-note {
  font-size: 12px !important;
}
.folder-gate-panel .btn-primary {
  margin-top: 8px;
  padding: 10px 18px;
  font-size: 13px;
}
.folder-gate-error {
  margin-top: 14px !important;
  color: var(--danger) !important;
}

/* --- 横画面強制（index） --- */
.orientation-gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: rgba(8, 10, 14, 0.96);
}
.orientation-gate[hidden] {
  display: none !important;
}
.orientation-gate-panel {
  width: min(420px, 100%);
  text-align: center;
  padding: 28px 20px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(14, 16, 20, 0.95);
}
.orientation-icon {
  font-size: 42px;
  line-height: 1;
  margin-bottom: 12px;
  color: var(--accent);
  animation: orientation-spin 1.8s ease-in-out infinite;
}
@keyframes orientation-spin {
  0%,
  100% {
    transform: rotate(0deg);
  }
  50% {
    transform: rotate(90deg);
  }
}
.orientation-gate-panel h2 {
  margin: 0 0 10px;
  font-size: 18px;
}
.orientation-gate-panel p {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}
body.is-portrait-blocked {
  overflow: hidden;
}
body.is-portrait-blocked #hud,
body.is-portrait-blocked #hint,
body.is-portrait-blocked #folder-gate,
body.is-portrait-blocked canvas {
  visibility: hidden !important;
  pointer-events: none !important;
}

/* --- モバイル / タブレット（主に横画面） --- */
@media (max-width: 960px), (max-height: 520px) {
  #hud {
    top: max(8px, env(safe-area-inset-top));
    left: max(8px, env(safe-area-inset-left));
    max-width: min(320px, calc(100vw - 16px - env(safe-area-inset-left) - env(safe-area-inset-right)));
    padding: 10px 12px;
    max-height: calc(100vh - 16px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }

  #hud h1 {
    font-size: 13px;
  }

  #hud p,
  #status,
  #measure-hint,
  #bookmark-hint {
    font-size: 11px;
  }

  .hud-toggle {
    width: 32px;
    height: 32px;
    line-height: 30px;
  }

  .btn,
  .nav-links .btn,
  .bookmark-item .btn {
    min-height: 32px;
    padding: 6px 10px;
    font-size: 12px;
  }

  .switch {
    width: 44px;
    height: 26px;
  }

  .switch .slider::before {
    width: 18px;
    height: 18px;
  }

  #hint {
    right: max(8px, env(safe-area-inset-right));
    bottom: max(8px, env(safe-area-inset-bottom));
    font-size: 10px;
    padding: 8px 10px;
    max-width: min(200px, 42vw);
  }

  .folder-gate {
    padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
      max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  }

  .folder-gate-panel {
    padding: 20px 16px;
  }

  .bm-modal:not(.is-fullscreen) {
    padding: 8px;
    align-items: stretch;
  }

  .bm-modal:not(.is-fullscreen) .bm-modal-panel {
    width: 100%;
    max-height: calc(100vh - 16px);
    margin: auto 0;
  }

  .bm-carousel-viewport {
    height: min(48vh, 280px);
  }

  .bm-carousel-btn {
    width: 40px;
    height: 40px;
    font-size: 24px;
    line-height: 38px;
  }

  canvas {
    touch-action: none;
  }
}

@media (max-height: 420px) and (orientation: landscape) {
  #hud {
    max-width: min(280px, 46vw);
  }

  #hint {
    display: none;
  }

  .bm-carousel-viewport {
    height: min(56vh, 220px);
  }
}

