:root,
[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0a0b0d;
    --bg-elevated: #14161a;
    --bg-card: #1a1d22;
    --bg-soft: #d9ebf7;
    --bg-stage: #050607;
    --ink: #f4f6f8;
    --muted: #9aa3ad;
    --line: #2a3038;
    --accent: #6ea8ff;
    --accent-strong: #4f8fff;
    --accent-soft: rgba(110, 168, 255, 0.18);
    --danger: #ef6b6b;
    --success: #5fd38d;
    --success-bg: rgba(95, 211, 141, 0.08);
    --success-line: #3a4f35;
    --success-ink: #b9f0cd;
    --alert-bg: rgba(239, 107, 107, 0.1);
    --alert-line: #6b3030;
    --alert-ink: #ffb4b4;
    --primary-ink: #173a66;
    --chip-active-ink: #d8e8ff;
    --brand-ink: #1d4f91;
    --header-bg: rgba(10, 11, 13, 0.92);
    --input-bg: #0f1217;
    --tab-bg: #12151a;
    --tab-active-bg: #1f242c;
    --btn-hover-bg: #20242b;
    --btn-hover-border: #3d4654;
    --measure-red: #dc2626;
    --ui-scale: 0.8;
    --viewport-fill: calc(100dvh / var(--ui-scale));
    --radius-lg: calc(18px * var(--ui-scale));
    --radius-md: calc(12px * var(--ui-scale));
    --radius-sm: calc(8px * var(--ui-scale));
    --shadow: 0 calc(24px * var(--ui-scale)) calc(60px * var(--ui-scale)) rgba(0, 0, 0, 0.45);
    --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

[data-theme="light"] {
    color-scheme: light;
    --bg: #f3f6fa;
    --bg-elevated: #ffffff;
    --bg-card: #ffffff;
    --bg-soft: #e8f3fc;
    --bg-stage: #e9edf2;
    --ink: #15202b;
    --muted: #5f6b78;
    --line: #d7dee7;
    --accent: #2f6fed;
    --accent-strong: #1f57c7;
    --accent-soft: rgba(47, 111, 237, 0.12);
    --danger: #c53b3b;
    --success: #1f8f5f;
    --success-bg: rgba(31, 143, 95, 0.08);
    --success-line: #b7e2cc;
    --success-ink: #176644;
    --alert-bg: rgba(197, 59, 59, 0.08);
    --alert-line: #efc2c2;
    --alert-ink: #8f2f2f;
    --primary-ink: #173a66;
    --chip-active-ink: #173a66;
    --brand-ink: #1d4f91;
    --header-bg: rgba(255, 255, 255, 0.92);
    --input-bg: #f8fafc;
    --tab-bg: #f4f7fb;
    --tab-active-bg: #ffffff;
    --btn-hover-bg: #eef3f8;
    --btn-hover-border: #b8c5d4;
    --shadow: 0 calc(18px * var(--ui-scale)) calc(40px * var(--ui-scale)) rgba(21, 32, 43, 0.08);
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    zoom: var(--ui-scale);
}

html,
body {
    margin: 0;
    min-height: 100%;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font);
}

body[data-page="workspace"],
body[data-page="dev-mode"] {
    height: var(--viewport-fill);
    min-height: var(--viewport-fill);
    overflow: hidden;
}

body {
    overscroll-behavior-y: none;
}

button,
input,
select {
    font: inherit;
}

a {
    color: inherit;
    text-decoration: none;
}

.app-shell {
    min-height: var(--viewport-fill);
    display: flex;
    flex-direction: column;
}

.app-shell.workspace,
.app-shell.dev-shell {
    height: var(--viewport-fill);
    max-height: var(--viewport-fill);
    min-height: var(--viewport-fill);
    overflow: hidden;
}

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-height: 84px;
    padding: 20px 24px;
    padding-top: max(20px, env(safe-area-inset-top));
    padding-left: max(24px, env(safe-area-inset-left));
    padding-right: max(24px, env(safe-area-inset-right));
    border-bottom: 1px solid var(--line);
    background: var(--header-bg);
    position: sticky;
    top: 0;
    z-index: 20;
    backdrop-filter: blur(10px);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 18px;
    min-width: 0;
    text-decoration: none;
    color: inherit;
}

.brand-logo {
    height: 52px;
    width: auto;
    display: block;
    object-fit: contain;
    flex-shrink: 0;
}

.brand-copy {
    min-width: 0;
    line-height: 1.3;
}

.brand-system {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--ink);
    letter-spacing: -0.01em;
}

.brand-mark {
    display: none;
}

.brand-short {
    font-size: 0.92em;
    font-weight: 600;
    color: var(--muted);
    white-space: nowrap;
}

.btn-icon svg,
.action-icon svg,
.tab-icon svg {
    width: 18px;
    height: 18px;
    display: block;
}

.action-icon {
    width: 68px;
    height: 68px;
    border-radius: 16px;
    display: grid;
    place-items: center;
    background: var(--bg-soft);
    color: var(--primary-ink);
    flex-shrink: 0;
}

.action-icon svg {
    width: 34px;
    height: 34px;
}

.btn {
    border: 1px solid var(--line);
    background: var(--bg-card);
    color: var(--ink);
    border-radius: var(--radius-md);
    padding: 11px 16px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.btn:hover:not(:disabled) {
    border-color: var(--btn-hover-border);
    background: var(--btn-hover-bg);
}

.btn:active:not(:disabled) {
    transform: translateY(1px);
}

.btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--bg-soft);
    color: var(--primary-ink);
    border-color: transparent;
}

.btn-primary:hover:not(:disabled) {
    filter: brightness(0.97);
}

.btn-icon-only {
    padding: 10px;
    min-width: 42px;
    min-height: 42px;
}

.btn-export .btn-label {
    white-space: nowrap;
}

.btn-ghost {
    background: transparent;
}

.btn-outline-light {
    background: transparent;
    border-color: var(--line);
}

.btn-block {
    width: 100%;
}

.btn-icon svg {
    width: 18px;
    height: 18px;
}

/* ARMS page backgrounds (landing, workspace, developer mode) */
body[data-page="landing"],
body[data-page="workspace"],
body[data-page="dev-mode"] {
    background-color: #0d0d0d;
}

[data-theme="light"] body[data-page="landing"],
[data-theme="light"] body[data-page="workspace"],
[data-theme="light"] body[data-page="dev-mode"] {
    background-color: #eef0f4;
}

.arms-page-bg {
    position: fixed;
    inset: 0;
    z-index: 0;
    overflow: hidden;
    pointer-events: none;
}

.arms-page-bg__img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
}

.arms-page-bg__light {
    display: none;
}

[data-theme="light"] .arms-page-bg__dark {
    display: none;
}

[data-theme="light"] .arms-page-bg__light {
    display: block;
}

body[data-page="landing"] .app-shell,
body[data-page="dev-mode"] .app-shell {
    position: relative;
    z-index: 1;
    background: transparent;
}

/* Workspace uses a solid shell so the wallpaper grid does not bleed beside the sidebar */
body[data-page="workspace"] .arms-page-bg {
    display: none;
}

body[data-page="workspace"] .app-shell {
    position: relative;
    z-index: 1;
    background: var(--bg);
}

body[data-page="workspace"] .workspace-main {
    background: var(--bg);
}

body[data-page="landing"] .app-header,
body[data-page="workspace"] .app-header,
body[data-page="dev-mode"] .app-header {
    background: rgba(10, 11, 13, 0.78);
    border-bottom-color: rgba(42, 48, 56, 0.72);
}

[data-theme="light"] body[data-page="landing"] .app-header,
[data-theme="light"] body[data-page="workspace"] .app-header,
[data-theme="light"] body[data-page="dev-mode"] .app-header {
    background: rgba(255, 255, 255, 0.82);
    border-bottom-color: rgba(215, 222, 231, 0.9);
}

body[data-page="workspace"] .thumb-strip,
body[data-page="dev-mode"] .dev-thumb-strip {
    background: rgba(10, 11, 13, 0.55);
    backdrop-filter: blur(8px);
}

[data-theme="light"] body[data-page="workspace"] .thumb-strip,
[data-theme="light"] body[data-page="dev-mode"] .dev-thumb-strip {
    background: rgba(255, 255, 255, 0.72);
}

.landing {
    flex: 1;
    display: grid;
    place-items: center;
    padding: 32px 24px 48px;
}

.landing-card {
    width: min(760px, 100%);
    text-align: center;
}

.landing h1 {
    margin: 0 0 16px;
    font-size: clamp(1.75rem, 5vw, 2.6rem);
    font-weight: 700;
    line-height: 1.22;
    padding: 0 8px;
}

.landing-title-end {
    white-space: nowrap;
}

.landing h1 .brand-short {
    font-size: 0.9em;
    font-weight: 600;
    color: var(--muted);
    white-space: nowrap;
}

.landing p {
    margin: 0;
    color: var(--muted);
    line-height: 1.55;
    font-size: clamp(1rem, 2.8vw, 1.12rem);
    max-width: 34ch;
    margin-left: auto;
    margin-right: auto;
}

.landing-toast {
    position: fixed;
    top: calc(72px + env(safe-area-inset-top, 0px));
    left: 50%;
    z-index: 1200;
    display: flex;
    align-items: center;
    gap: 10px;
    width: min(calc(100% - 32px), 320px);
    margin: 0;
    padding: 11px 12px 11px 14px;
    border-radius: 999px;
    border: 1px solid rgba(248, 113, 113, 0.35);
    background: linear-gradient(180deg, rgba(69, 10, 10, 0.94), rgba(42, 8, 8, 0.98));
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.32);
    text-align: left;
    transform: translateX(-50%);
    animation: landing-toast-in 0.28s ease-out;
}

@keyframes landing-toast-in {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(-10px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0) scale(1);
    }
}

.landing-toast[hidden] {
    display: none !important;
}

.landing-toast-icon {
    flex: 0 0 auto;
    display: inline-flex;
    width: 20px;
    height: 20px;
    color: #f87171;
}

.landing-toast-icon svg {
    width: 20px;
    height: 20px;
}

.landing-toast-text {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.landing-toast-text strong {
    font-size: 0.9rem;
    font-weight: 600;
    line-height: 1.2;
    color: #fecaca;
}

.landing-toast-text span {
    font-size: 0.78rem;
    line-height: 1.35;
    color: #fca5a5;
}

.landing-toast-text span:empty,
.landing-toast-text span[hidden] {
    display: none;
}

.landing-toast-close {
    flex: 0 0 auto;
    width: 26px;
    height: 26px;
    border: 0;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.04);
    color: #fca5a5;
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
}

.landing-toast-close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

[data-theme="light"] .landing-toast {
    border-color: rgba(220, 38, 38, 0.22);
    background: linear-gradient(180deg, #fff5f5, #fee2e2);
    box-shadow: 0 10px 28px rgba(15, 23, 42, 0.1);
}

[data-theme="light"] .landing-toast-text strong {
    color: #991b1b;
}

[data-theme="light"] .landing-toast-text span {
    color: #b91c1c;
}

[data-theme="light"] .landing-toast-icon,
[data-theme="light"] .landing-toast-close {
    color: #dc2626;
}

.action-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
    margin-top: 36px;
    max-width: 560px;
    margin-left: auto;
    margin-right: auto;
}

.action-card {
    border-radius: var(--radius-lg);
    padding: 28px 20px;
    min-height: 168px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    text-align: center;
    cursor: pointer;
    background: var(--bg-card);
    border: 1px solid var(--line);
    color: var(--ink);
    transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.action-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.action-card.selected {
    background: var(--bg-soft);
    border-color: transparent;
    color: var(--primary-ink);
    box-shadow: inset 0 0 0 1px rgba(47, 111, 237, 0.12);
}

.action-card.selected .action-icon {
    background: rgba(23, 58, 102, 0.12);
    color: var(--primary-ink);
}

.action-card .title {
    font-size: 1.15rem;
    font-weight: 700;
}

.action-card .subtitle {
    font-size: 0.95rem;
    color: var(--muted);
}

.action-card.selected .subtitle {
    color: var(--primary-ink);
    opacity: 0.72;
}

.hidden-input {
    display: none;
}

.queue-panel {
    margin-top: 24px;
    background: var(--bg-card);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 16px;
    text-align: left;
}

.queue-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.queue-head strong {
    font-size: 0.95rem;
}

.thumb-row {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding-bottom: 4px;
}

.thumb {
    position: relative;
    flex: 0 0 auto;
    width: 72px;
    height: 72px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 2px solid transparent;
    background: #0f1115;
}

.thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.thumb-remove {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 20px;
    height: 20px;
    border: 0;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.72);
    color: #fff;
    font-size: 0.75rem;
    cursor: pointer;
}

.start-row {
    margin-top: 16px;
}

/* Workspace */
.workspace {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: var(--viewport-fill);
    max-height: var(--viewport-fill);
    overflow: hidden;
}

.workspace .app-header {
    flex-shrink: 0;
}

.workspace .alert,
.workspace .result-banner {
    flex-shrink: 0;
    margin: 6px 12px 0;
    padding: 8px 12px;
    font-size: 0.82rem;
    line-height: 1.35;
}

.workspace-main {
    position: relative;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.workspace-main > .workspace-body {
    flex: 1;
    min-height: 0;
}

.workspace-batch-lock .control-dock .detection-tuning {
    opacity: 0.65;
}

html.workspace-detect-locked,
body.workspace-detect-locked {
    overflow: hidden !important;
    overscroll-behavior: none;
    touch-action: none;
    height: 100%;
}

body.workspace-detect-locked {
    position: fixed;
    width: 100%;
}

.app-shell.workspace.workspace-batch-lock {
    overflow: hidden;
    touch-action: none;
}

.app-shell.workspace.workspace-batch-lock > :not(.app-header):not(.batch-detect-overlay) {
    pointer-events: none;
    user-select: none;
}

.app-shell.workspace.workspace-batch-lock .app-header {
    pointer-events: auto;
    touch-action: manipulation;
    position: relative;
    z-index: 50;
}

.app-shell.workspace.workspace-batch-lock .workspace-body,
.app-shell.workspace.workspace-batch-lock .control-dock,
.app-shell.workspace.workspace-batch-lock .thumb-strip,
.app-shell.workspace.workspace-batch-lock .tab-scroll,
.app-shell.workspace.workspace-batch-lock .measure-results-section,
.app-shell.workspace.workspace-batch-lock .control-dock .tab-panel,
.app-shell.workspace.workspace-batch-lock .workspace-main {
    overflow: hidden !important;
}

.batch-detect-overlay {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: 0;
    z-index: 40;
    display: grid;
    place-items: center;
    padding: 24px 16px;
    padding-top: max(24px, env(safe-area-inset-top, 0px));
    background: rgba(4, 6, 10, 0.78);
    backdrop-filter: blur(6px);
    pointer-events: auto;
    touch-action: none;
    overscroll-behavior: contain;
}

.batch-detect-overlay[hidden] {
    display: none;
}

.batch-detect-card {
    width: min(360px, 100%);
    padding: 22px 20px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--line);
    background: var(--bg-card);
    box-shadow: var(--shadow);
    text-align: center;
}

.batch-detect-spinner {
    width: 40px;
    height: 40px;
    margin: 0 auto 14px;
    border-radius: 50%;
    border: 3px solid var(--line);
    border-top-color: var(--accent-strong);
    animation: batch-detect-spin 0.85s linear infinite;
}

@keyframes batch-detect-spin {
    to {
        transform: rotate(360deg);
    }
}

.batch-detect-title {
    margin: 0 0 8px;
    font-size: 1rem;
    font-weight: 700;
    color: var(--ink);
}

.batch-detect-detail {
    margin: 0;
    font-size: 0.84rem;
    line-height: 1.45;
    color: var(--muted);
}

.workspace-body {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto;
    gap: 0;
}

.thumb-strip {
    display: flex;
    gap: 8px;
    padding: 8px 12px;
    overflow-x: auto;
    border-bottom: 1px solid var(--line);
    flex-shrink: 0;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
}

.thumb-strip .thumb {
    cursor: pointer;
    width: 56px;
    height: 56px;
}

.thumb-strip .thumb.active {
    border-color: var(--accent-strong);
    scroll-snap-align: start;
    flex-shrink: 0;
}

.thumb-strip .thumb.detecting {
    opacity: 0.72;
}

.thumb-strip .thumb.detecting::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    border: 2px solid var(--accent-strong);
    animation: thumb-detect-pulse 1.1s ease-in-out infinite;
    pointer-events: none;
}

@keyframes thumb-detect-pulse {
    0%,
    100% {
        opacity: 0.35;
    }
    50% {
        opacity: 1;
    }
}

.stage-wrap {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding: 8px 12px 10px;
}

.stage-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 6px;
    flex-shrink: 0;
}

.stage-toolbar .selection-pill {
    font-size: 0.78rem;
    color: var(--muted);
    padding: 5px 10px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--bg-card);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: min(52vw, 280px);
}

.stage-toolbar .btn-icon-only {
    min-width: 34px;
    min-height: 34px;
    padding: 6px;
}

.zoom-controls {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.zoom-label {
    min-width: 40px;
    text-align: center;
    font-size: 0.76rem;
    color: var(--muted);
}

.stage {
    position: relative;
    flex: 1;
    min-height: 0;
    background: var(--bg-stage);
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    overflow: hidden;
    touch-action: none;
}

.stage canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
}

.stage img {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

.stage.stage-segment-mode {
    cursor: crosshair;
}

.segment-hint {
    position: absolute;
    left: 50%;
    bottom: 12px;
    transform: translateX(-50%);
    z-index: 4;
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    color: #fff;
    background: rgba(10, 11, 13, 0.82);
    border: 1px solid rgba(255, 255, 255, 0.14);
    pointer-events: none;
    white-space: nowrap;
}

.roof-segment-panel {
    display: grid;
    gap: 6px;
    padding: 8px 0 2px;
    border-top: 1px solid var(--line);
}

.roof-segment-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.roof-segment-label {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: var(--muted);
}

.roof-segment-status {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text);
}

.roof-segment-status.is-ready {
    color: #34d399;
}

.roof-segment-status.is-drawing {
    color: #f5b942;
}

.roof-segment-actions,
.roof-segment-apply-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.roof-segment-hint {
    margin: 0;
    font-size: 0.68rem;
    line-height: 1.35;
    color: var(--muted);
}

.detection-tuning-actions .btn-primary.btn-compact {
    min-height: 28px;
    padding: 4px 10px;
    font-size: 0.72rem;
    font-weight: 700;
}

.detection-tuning {
    padding: 8px 12px 10px;
    border-bottom: 1px solid var(--line);
    display: grid;
    gap: 6px;
    flex-shrink: 0;
}

.detection-tuning--in-tab {
    padding: 0;
    border-bottom: none;
    gap: 10px;
}

.detection-tuning--in-tab .detection-tuning-actions {
    justify-content: flex-end;
}

.detection-tuning-head {
    display: grid;
    gap: 8px;
}

.detection-tuning-lead {
    margin: 0;
    font-size: 0.78rem;
    line-height: 1.45;
    color: var(--muted);
}

.dock-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 0;
}

.dock-section + .dock-section {
    padding-top: 14px;
    border-top: 1px solid var(--line);
}

.dock-section-title {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--ink);
    line-height: 1.25;
}

.dock-section-step {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent-strong);
    font-size: 0.72rem;
    font-weight: 800;
    flex-shrink: 0;
}

.measure-section-label {
    margin: 0 0 8px;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
    line-height: 1.2;
}

.detection-tuning-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.detection-tuning-actions .btn-icon-only {
    min-width: 28px;
    min-height: 28px;
    padding: 5px;
}

.detection-tuning-actions .btn-icon svg {
    width: 15px;
    height: 15px;
}

.btn-compact {
    min-height: 30px;
    padding: 4px 10px;
    font-size: 0.76rem;
}

.tuning-field {
    display: grid;
    gap: 5px;
}

.tuning-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: 0.76rem;
    color: var(--ink);
}

.tuning-label em {
    font-style: normal;
    font-variant-numeric: tabular-nums;
    color: var(--accent-strong);
    font-weight: 600;
}

.tuning-field input[type="range"] {
    width: 100%;
    margin: 0;
    accent-color: var(--accent-strong);
}

.detection-mode-panel {
    display: grid;
    gap: 8px;
    padding: 2px 0 4px;
}

.detection-mode-panel.is-disabled {
    opacity: 0.72;
}

.tuning-field--mode {
    gap: 8px;
}

.detection-mode-buttons {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.detection-mode-btn {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 3px;
    min-height: 58px;
    margin: 0;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--bg-elevated, rgba(255, 255, 255, 0.04));
    color: var(--ink);
    font: inherit;
    text-align: left;
    cursor: pointer;
    transition:
        border-color 0.15s ease,
        background-color 0.15s ease,
        box-shadow 0.15s ease,
        transform 0.15s ease;
}

.detection-mode-btn:hover:not(:disabled) {
    border-color: color-mix(in srgb, var(--accent-strong) 35%, var(--line));
    transform: translateY(-1px);
}

.detection-mode-btn:focus-visible {
    outline: none;
    border-color: var(--accent-strong);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-strong) 22%, transparent);
}

.detection-mode-btn.is-active {
    border-color: var(--accent-strong);
    background: var(--accent-soft);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent-strong) 18%, transparent);
}

.detection-mode-btn:disabled {
    cursor: not-allowed;
    opacity: 0.55;
    transform: none;
}

.detection-mode-btn-label {
    font-size: 0.78rem;
    font-weight: 700;
    line-height: 1.2;
    color: var(--ink);
}

.detection-mode-btn-meta {
    font-size: 0.66rem;
    line-height: 1.25;
    color: var(--muted);
}

.detection-mode-select-wrap {
    position: relative;
}

.detection-mode-select {
    width: 100%;
    appearance: none;
    -webkit-appearance: none;
    margin: 0;
    padding: 10px 36px 10px 12px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--bg-elevated, rgba(255, 255, 255, 0.04));
    color: var(--ink);
    font: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    line-height: 1.2;
    cursor: pointer;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.detection-mode-select:hover {
    border-color: color-mix(in srgb, var(--accent-strong) 35%, var(--line));
}

.detection-mode-select:focus {
    outline: none;
    border-color: var(--accent-strong);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-strong) 22%, transparent);
}

.detection-mode-select-chevron {
    position: absolute;
    top: 50%;
    right: 14px;
    width: 7px;
    height: 7px;
    border-right: 2px solid var(--muted);
    border-bottom: 2px solid var(--muted);
    transform: translateY(-65%) rotate(45deg);
    pointer-events: none;
}

.detection-mode-tagline {
    margin: 0;
    font-size: 0.72rem;
    line-height: 1.4;
    color: var(--muted);
}

.detection-mode-meta {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
}

.detection-mode-chip {
    display: grid;
    gap: 2px;
    min-width: 0;
    padding: 7px 8px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: color-mix(in srgb, var(--accent-strong) 6%, transparent);
    text-align: center;
}

.detection-mode-chip-label {
    font-size: 0.62rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.detection-mode-chip strong {
    font-size: 0.78rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--accent-strong);
}

html[data-theme="light"] .detection-mode-select {
    background: #fff;
}

html[data-theme="light"] .detection-mode-chip {
    background: #f8fafc;
}

html[data-theme="light"] .detection-mode-btn {
    background: #fff;
}

html[data-theme="light"] .detection-mode-btn.is-active {
    background: color-mix(in srgb, var(--accent-soft) 88%, white);
}

@media (min-width: 420px) {
    .detection-mode-buttons {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (min-width: 1180px) {
    .detection-mode-buttons {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 720px) {
    .detection-mode-buttons {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .detection-mode-btn {
        min-height: 54px;
        padding: 9px 10px;
    }

    .detection-mode-meta {
        grid-template-columns: 1fr;
    }

    .detection-mode-chip {
        grid-template-columns: 1fr auto;
        align-items: center;
        text-align: left;
    }
}

.control-dock {
    margin: 0 12px 10px;
    background: var(--bg-card);
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    overflow: hidden;
    flex-shrink: 0;
    max-height: min(52vh, 420px);
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.mobile-dock-handle,
.mobile-dock-backdrop {
    display: none;
}

.mobile-dock-sheet {
    display: contents;
}

.tab-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    padding: 6px;
    border-bottom: 1px solid var(--line);
    flex-shrink: 0;
}

.tab-btn {
    border: 1px solid var(--line);
    background: var(--tab-bg);
    color: var(--ink);
    border-radius: var(--radius-sm);
    padding: 8px 6px;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 40px;
}

.tab-btn.active {
    background: var(--tab-active-bg);
    border-color: var(--accent-strong);
    box-shadow: inset 0 0 0 1px rgba(79, 143, 255, 0.08);
}

.tab-panel {
    display: none;
    padding: 0;
    overflow: hidden;
    min-height: 0;
}

.tab-panel.active {
    display: flex;
    flex: 1;
    flex-direction: column;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.areas-panel {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 12px;
    min-height: min-content;
}

.measure-filter-section,
.measure-results-section,
.measure-adjust-wrap {
    display: flex;
    flex-direction: column;
    gap: 0;
    min-width: 0;
}

.measure-adjust-wrap {
    padding-top: 14px;
    border-top: 1px solid var(--line);
}

.measure-adjust-wrap[hidden] {
    display: none !important;
}

.area-tag-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
}

.area-tag {
    border: 1px solid var(--line);
    background: var(--tab-bg);
    color: var(--ink);
    border-radius: var(--radius-sm);
    padding: 7px 10px;
    font-size: 0.76rem;
    font-weight: 600;
    cursor: pointer;
    user-select: none;
    text-align: center;
    line-height: 1.25;
    min-height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.area-tag.active {
    border-color: var(--accent);
    background: rgba(79, 143, 255, 0.18);
    color: var(--ink);
    box-shadow: inset 0 0 0 1px rgba(79, 143, 255, 0.12);
}

.area-tag-all {
    grid-column: 1 / -1;
    justify-self: stretch;
    font-weight: 700;
}

.measure-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 0;
}

.measure-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--input-bg);
    font-size: 0.8rem;
    line-height: 1.35;
}

.measure-item > span {
    flex: 1;
    min-width: 0;
}

.measure-item button {
    border: 0;
    background: transparent;
    color: var(--danger);
    cursor: pointer;
    font-weight: 700;
    font-size: 0.76rem;
    padding: 4px 8px;
    flex-shrink: 0;
    border-radius: 6px;
}

.measure-item button:hover {
    background: rgba(220, 38, 38, 0.1);
}

.measure-adjust-stack {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.measure-adjust-empty {
    margin: 0;
    padding: 12px;
    border: 1px dashed var(--line);
    border-radius: var(--radius-sm);
    font-size: 0.76rem;
    line-height: 1.4;
    color: var(--muted);
    text-align: center;
    background: var(--bg);
}

.measure-adjust {
    display: grid;
    gap: 8px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--tab-bg);
}

.measure-adjust-head strong {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
}

.measure-adjust-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-width: 0;
    flex-wrap: wrap;
}

.measure-adjust-target {
    margin: 0;
    flex: 1 1 120px;
    min-width: 0;
    font-size: 0.8rem;
    line-height: 1.35;
    color: var(--ink);
}

.measure-adjust-actions {
    display: flex;
    flex-shrink: 0;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.measure-adjust-reset {
    padding: 2px 8px;
}

.measure-adjust-hint {
    margin: 10px 0 0;
    font-size: 0.72rem;
    line-height: 1.45;
    color: var(--muted);
}

.action-bar,
.workspace-measure-bar {
    display: none;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    padding: 12px;
    margin: 0;
    border-top: 1px solid var(--line);
    flex-shrink: 0;
    background: var(--bg-card);
}

.control-dock--areas .workspace-measure-bar {
    display: grid;
}

.workspace-measure-bar .btn,
.action-bar .btn {
    padding: 9px 12px;
    font-size: 0.86rem;
    min-height: 40px;
}

#tab-tile.active,
#tab-custom.active {
    display: flex;
    flex: 1;
    flex-direction: column;
    min-height: 0;
    overflow-y: auto;
    padding: 0;
    gap: 0;
}

.workspace-tab-body {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 12px;
    min-height: min-content;
}

.workspace-tab-hint {
    margin: 0;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--line);
    background: var(--accent-soft);
    color: var(--ink);
    font-size: 0.8rem;
    line-height: 1.45;
}

.workspace-tab-hint strong {
    font-weight: 700;
    color: var(--accent-strong);
}

.workspace-tab-hint-icon {
    display: inline-block;
    font-size: 0.9em;
    opacity: 0.85;
}

.workspace-tab-hint--compact {
    padding: 9px 11px;
    font-size: 0.78rem;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.tile-picker-selected {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--line));
    background: var(--accent-soft);
}

.tile-picker-selected-label {
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--muted);
}

.tile-picker-selected-size {
    margin-left: auto;
    font-size: 0.76rem;
    font-weight: 600;
    color: var(--muted);
}

.tile-picker-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.tile-picker-card {
    display: grid;
    gap: 4px;
    padding: 12px 10px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--tab-bg);
    color: var(--ink);
    text-align: left;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    min-height: 72px;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.tile-picker-card.active {
    border-color: var(--accent);
    background: rgba(79, 143, 255, 0.12);
    box-shadow: inset 0 0 0 1px rgba(79, 143, 255, 0.2);
}

.tile-picker-name {
    font-size: 0.8rem;
    font-weight: 700;
    line-height: 1.25;
}

.tile-picker-size {
    font-size: 0.74rem;
    font-weight: 600;
    color: var(--accent-strong);
}

.tile-picker-notes {
    font-size: 0.68rem;
    line-height: 1.3;
    color: var(--muted);
}

.tile-picker-empty {
    margin: 0;
    padding: 14px 12px;
    border: 1px dashed var(--line);
    border-radius: var(--radius-sm);
    text-align: center;
    font-size: 0.8rem;
    color: var(--muted);
}

.field-tile-select--fallback {
    margin-top: 2px;
}

.custom-tile-preview {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 12px;
    border-radius: 14px;
    border: 1px solid var(--line);
    background: linear-gradient(135deg, var(--accent-soft), var(--tab-bg));
}

.custom-tile-preview-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border-radius: 10px;
    background: var(--bg-card);
    border: 1px solid var(--line);
    font-size: 1.2rem;
    color: var(--accent-strong);
    flex-shrink: 0;
}

.custom-tile-preview-copy {
    display: grid;
    gap: 2px;
    min-width: 0;
}

.custom-tile-preview-label {
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--muted);
}

.custom-tile-preview-size {
    font-size: 1rem;
    font-weight: 700;
    color: var(--ink);
    line-height: 1.2;
}

.unit-chip-row {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
}

.unit-chip {
    min-height: 44px;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--tab-bg);
    color: var(--ink);
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: border-color 0.15s ease, background 0.15s ease;
}

.unit-chip.active {
    border-color: var(--accent);
    background: rgba(79, 143, 255, 0.14);
    color: var(--accent-strong);
}

.field-touch input {
    min-height: 48px;
    font-size: 1rem;
}

.btn-touch {
    min-height: 50px;
    font-size: 0.95rem;
    font-weight: 700;
}

.custom-tile-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.custom-tile-unit-field {
    grid-column: 1 / -1;
}

.field-tile-select select {
    min-height: 48px;
}

.measure-list-empty {
    margin: 0;
    padding: 14px 12px;
    border: 1px dashed var(--line);
    border-radius: var(--radius-sm);
    background: var(--input-bg);
    color: var(--muted);
    font-size: 0.8rem;
    line-height: 1.45;
    text-align: center;
}

.measure-list-empty strong {
    color: var(--accent-strong);
    font-weight: 700;
}

.field {
    display: grid;
    gap: 6px;
    margin-bottom: 0;
}

.field span {
    color: var(--muted);
    font-size: 0.8rem;
}

.field input,
.field select {
    width: 100%;
    border: 1px solid var(--line);
    background: var(--input-bg);
    color: var(--ink);
    border-radius: var(--radius-sm);
    padding: 9px 12px;
    font-size: 0.9rem;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

#tab-custom .btn-block {
    margin-top: 4px;
    min-height: 40px;
    padding: 9px 12px;
    font-size: 0.86rem;
}

.result-banner {
    margin: 0 16px 12px;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--success-line);
    background: var(--success-bg);
    color: var(--success-ink);
    font-size: 0.92rem;
    line-height: 1.45;
}

.alert {
    margin: 12px 16px 0;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--alert-line);
    background: var(--alert-bg);
    color: var(--alert-ink);
}

.alert.alert-error {
    border-color: rgba(220, 38, 38, 0.45);
    background: rgba(220, 38, 38, 0.12);
    color: #fecaca;
}

.loading-overlay {
    position: absolute;
    inset: 0;
    display: none;
    place-items: center;
    background: rgba(0, 0, 0, 0.55);
    z-index: 5;
    color: var(--ink);
    font-weight: 600;
}

.loading-overlay.visible {
    display: grid;
}

.help-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: grid;
    place-items: center;
    padding: 16px;
    background: rgba(4, 6, 10, 0.62);
    backdrop-filter: blur(6px);
}

.help-overlay[hidden] {
    display: none;
}

.help-modal {
    width: min(640px, 100%);
    max-height: min(88vh, 760px);
    display: flex;
    flex-direction: column;
    background: var(--bg-card);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.help-modal--wide {
    width: min(960px, 100%);
    max-height: min(90vh, 900px);
}

.help-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 18px 20px;
    border-bottom: 1px solid var(--line);
    background: var(--bg-elevated);
}

.help-header h2 {
    margin: 0;
    font-size: 1.15rem;
}

.help-body {
    padding: 16px 20px 20px;
    overflow-y: auto;
}

.help-intro {
    margin: 0 0 16px;
    color: var(--muted);
    line-height: 1.55;
    font-size: 0.94rem;
}

.help-block {
    margin-bottom: 20px;
}

.help-block-title {
    margin: 0 0 12px;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--ink);
}

.help-steps {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 10px;
}

.help-step {
    display: grid;
    grid-template-columns: 32px 1fr;
    gap: 12px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: var(--input-bg);
}

.help-step-num {
    width: 32px;
    height: 32px;
    border-radius: 999px;
    display: grid;
    place-items: center;
    background: var(--accent-soft);
    color: var(--accent-strong);
    font-size: 0.88rem;
    font-weight: 700;
    flex-shrink: 0;
}

.help-step h4 {
    margin: 0 0 4px;
    font-size: 0.92rem;
    font-weight: 700;
    color: var(--ink);
}

.help-step p {
    margin: 0;
    color: var(--muted);
    font-size: 0.86rem;
    line-height: 1.5;
}

.help-grid {
    display: grid;
    gap: 12px;
}

.help-card {
    display: grid;
    grid-template-columns: 40px 1fr;
    gap: 12px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: var(--input-bg);
}

.help-card-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: grid;
    place-items: center;
    background: var(--accent-soft);
    color: var(--accent-strong);
}

.help-card-icon svg {
    width: 20px;
    height: 20px;
}

.help-card h3 {
    margin: 0 0 4px;
    font-size: 0.98rem;
}

.help-card p {
    margin: 0;
    color: var(--muted);
    font-size: 0.88rem;
    line-height: 1.5;
}

.help-card kbd,
.help-tip kbd {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 5px;
    border: 1px solid var(--line);
    background: var(--bg-card);
    color: var(--ink);
    font-size: 0.8rem;
    font-family: inherit;
}

.help-block-tiles {
    margin-bottom: 18px;
}

.tile-sample-intro {
    margin: 0 0 14px;
    color: var(--muted);
    font-size: 0.88rem;
    line-height: 1.55;
}

.tile-sample-intro strong {
    color: var(--ink);
    font-weight: 600;
}

.tile-sample-gallery {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.tile-sample-card {
    min-width: 0;
    min-height: 0;
    perspective: 1200px;
}

.tile-sample-card.is-flipped {
    z-index: 2;
}

.tile-sample-flip {
    width: 100%;
    margin: 0;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: transparent;
    cursor: pointer;
    text-align: left;
    color: inherit;
    font: inherit;
    -webkit-tap-highlight-color: transparent;
    transition:
        border-color 0.22s ease,
        box-shadow 0.22s ease,
        transform 0.22s ease;
}

.tile-sample-flip:hover {
    border-color: rgba(56, 189, 248, 0.35);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.12);
    transform: translateY(-1px);
}

.tile-sample-card.is-flipped .tile-sample-flip {
    border-color: rgba(56, 189, 248, 0.42);
    box-shadow: 0 14px 36px rgba(14, 116, 144, 0.18);
}

.tile-sample-flip:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.tile-sample-flip-inner {
    display: block;
    position: relative;
    width: 100%;
    min-height: 200px;
    transform-style: preserve-3d;
    transition: transform 0.55s cubic-bezier(0.33, 1, 0.38, 1);
}

.tile-sample-card.is-flipped .tile-sample-flip-inner {
    transform: rotateY(180deg);
}

.tile-sample-face {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    width: 100%;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    border-radius: 11px;
    overflow: hidden;
    background: var(--input-bg);
}

.tile-sample-front {
    transform: rotateY(0deg);
}

.tile-sample-back {
    transform: rotateY(180deg);
    padding: 12px;
    background: var(--bg-elevated);
}

.tile-sample-back-inner {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 10px;
    width: 100%;
    height: 100%;
    min-height: 0;
}

.tile-sample-media {
    position: relative;
    flex: 1 1 auto;
    min-height: 112px;
    aspect-ratio: 4 / 3;
    background: #0f1419;
    overflow: hidden;
}

.tile-sample-media-shade {
    position: absolute;
    inset: auto 0 0;
    height: 42%;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.42), transparent);
    pointer-events: none;
}

.tile-sample-media img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    pointer-events: none;
}

.tile-sample-front-copy {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 11px 11px;
    border-top: 1px solid var(--line);
    background: var(--input-bg);
}

.tile-sample-name {
    margin: 0;
    flex: 1;
    min-width: 0;
    font-size: 0.78rem;
    font-weight: 600;
    line-height: 1.35;
    color: var(--ink);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.tile-sample-hint {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
    font-size: 0.68rem;
    font-weight: 500;
    color: var(--muted);
    white-space: nowrap;
}

.tile-sample-hint-icon {
    display: inline-grid;
    place-items: center;
    width: 16px;
    height: 16px;
    border-radius: 999px;
    background: rgba(56, 189, 248, 0.12);
    color: #38bdf8;
    font-size: 0.62rem;
    line-height: 1;
}

[data-theme="light"] .tile-sample-hint-icon {
    background: rgba(2, 132, 199, 0.1);
    color: #0284c7;
}

.tile-sample-back-name {
    margin: 0;
    font-size: 0.72rem;
    font-weight: 600;
    line-height: 1.35;
    color: var(--muted);
    text-align: center;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.tile-sample-size-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 14px 10px 12px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: var(--input-bg);
}

.tile-sample-size-label {
    font-size: 0.68rem;
    font-weight: 500;
    letter-spacing: 0.02em;
    color: var(--muted);
}

.tile-sample-size-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
}

.tile-sample-size-cell {
    display: flex;
    flex: 1;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    min-width: 0;
}

.tile-sample-size-value {
    font-size: 1.15rem;
    font-weight: 700;
    line-height: 1;
    color: var(--ink);
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.02em;
}

.tile-sample-size-unit {
    margin-left: 2px;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--muted);
}

.tile-sample-size-caption {
    font-size: 0.64rem;
    font-weight: 500;
    color: var(--muted);
    letter-spacing: 0.03em;
}

.tile-sample-size-sep {
    flex-shrink: 0;
    padding-bottom: 14px;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--muted);
    opacity: 0.7;
}

.tile-sample-footnote {
    margin: 12px 0 0;
    color: var(--muted);
    font-size: 0.78rem;
    line-height: 1.45;
}

.tile-sample-footnote code {
    font-size: 0.76rem;
}

@media (min-width: 560px) {
    .tile-sample-gallery {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 14px;
    }

    .tile-sample-flip-inner {
        min-height: 208px;
    }

    .tile-sample-name {
        font-size: 0.82rem;
    }

    .tile-sample-size-value {
        font-size: 1.22rem;
    }
}

@media (min-width: 820px) {
    .tile-sample-gallery {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

@media (min-width: 1040px) {
    .tile-sample-gallery {
        grid-template-columns: repeat(5, minmax(0, 1fr));
    }
}

@media (prefers-reduced-motion: reduce) {
    .tile-sample-flip-inner {
        transition: none;
        transform: none !important;
    }

    .tile-sample-back {
        position: absolute;
        transform: none;
    }

    .tile-sample-card:not(.is-flipped) .tile-sample-back {
        display: none;
    }

    .tile-sample-card.is-flipped .tile-sample-front {
        display: none;
    }
}

.help-tip {
    margin-top: 14px;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--line);
    background: var(--accent-soft);
    color: var(--ink);
    font-size: 0.86rem;
    line-height: 1.5;
}

/* Developer mode password popup — no page backdrop */
.dev-auth-overlay {
    position: fixed;
    inset: 0;
    z-index: 110;
    display: grid;
    place-items: center;
    padding: max(12px, env(safe-area-inset-left)) max(12px, env(safe-area-inset-right));
    padding-top: max(12px, env(safe-area-inset-top));
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    background: transparent;
    pointer-events: none;
}

.dev-auth-overlay:not([hidden]) {
    pointer-events: auto;
}

.dev-auth-overlay[hidden] {
    display: none;
}

.dev-auth-modal {
    position: relative;
    width: min(460px, calc(100vw - 24px));
    max-height: min(92dvh, 720px);
    overflow: auto;
    pointer-events: auto;
    background: var(--bg-card);
    color: var(--ink);
    border: 1px solid var(--line);
    border-radius: clamp(16px, 4vw, 24px);
    box-shadow: var(--shadow);
    padding: clamp(22px, 5vw, 34px) clamp(18px, 4.5vw, 34px) clamp(20px, 4vw, 28px);
    -webkit-overflow-scrolling: touch;
}

.dev-auth-accent {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    border-radius: 24px 24px 0 0;
    background: linear-gradient(90deg, var(--accent-strong) 0%, var(--success) 100%);
}

.dev-auth-info-btn {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 32px;
    height: 32px;
    border: 1.5px solid var(--accent-strong);
    border-radius: 50%;
    background: transparent;
    color: var(--accent-strong);
    font-size: 0.82rem;
    font-weight: 700;
    font-style: italic;
    font-family: Georgia, "Times New Roman", serif;
    line-height: 1;
    cursor: pointer;
    display: grid;
    place-items: center;
    padding: 0;
}

.dev-auth-info-btn:hover {
    background: var(--accent-soft);
}

.dev-auth-header {
    text-align: center;
    margin-bottom: 28px;
    padding-top: 6px;
}

.dev-auth-logo {
    height: 52px;
    width: auto;
    display: block;
    margin: 0 auto 18px;
    object-fit: contain;
}

.dev-auth-header h2 {
    margin: 0 0 8px;
    font-size: clamp(1.35rem, 4.5vw, 1.65rem);
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.dev-auth-subtitle {
    margin: 0;
    font-size: 0.95rem;
    color: var(--muted);
    line-height: 1.45;
}

.dev-auth-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.dev-auth-label {
    font-size: 0.92rem;
    font-weight: 700;
}

.dev-auth-required {
    color: var(--danger);
}

.dev-auth-password-wrap {
    position: relative;
}

.dev-auth-input {
    width: 100%;
    min-height: 52px;
    padding: 14px 48px 14px 18px;
    border: 1.5px solid var(--line);
    border-radius: 14px;
    background: var(--input-bg);
    color: var(--ink);
    font-size: 1rem;
    line-height: 1.2;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.dev-auth-input::placeholder {
    color: var(--muted);
    opacity: 0.75;
}

.dev-auth-input:focus {
    border-color: var(--accent-strong);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.dev-auth-input:disabled {
    opacity: 0.65;
    cursor: not-allowed;
}

.dev-auth-toggle {
    position: absolute;
    top: 50%;
    right: 8px;
    transform: translateY(-50%);
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    flex-shrink: 0;
}

.dev-auth-toggle:hover:not(:disabled) {
    color: var(--ink);
    background: var(--btn-hover-bg);
}

.dev-auth-toggle:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.dev-auth-eye {
    width: 20px;
    height: 20px;
    display: block;
    flex-shrink: 0;
}

.dev-auth-error {
    margin: 2px 0 0;
    font-size: 0.88rem;
    line-height: 1.4;
    color: var(--danger);
}

.dev-auth-error[hidden] {
    display: none;
}

.dev-auth-submit {
    margin-top: 8px;
    width: 100%;
    min-height: 52px;
    border: none;
    border-radius: 999px;
    background: linear-gradient(180deg, var(--accent) 0%, var(--accent-strong) 100%);
    color: #ffffff;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 10px 24px rgba(37, 99, 235, 0.28);
}

.dev-auth-submit:hover:not(:disabled) {
    filter: brightness(1.05);
}

.dev-auth-submit:disabled {
    opacity: 0.65;
    cursor: not-allowed;
    box-shadow: none;
}

.dev-auth-cancel {
    width: 100%;
    min-height: 42px;
    margin-top: 4px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: transparent;
    color: var(--muted);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
}

.dev-auth-cancel:hover {
    background: var(--btn-hover-bg);
    border-color: var(--btn-hover-border);
    color: var(--ink);
}

.dev-auth-footer {
    margin-top: 28px;
    text-align: center;
}

.dev-auth-footer p {
    margin: 0;
    font-size: 0.82rem;
    color: var(--muted);
}

.dev-auth-info-panel {
    margin-top: 14px;
    padding: 14px 16px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--input-bg);
}

.dev-auth-info-panel[hidden] {
    display: none;
}

.dev-auth-info-panel h3 {
    margin: 0 0 8px;
    font-size: 1rem;
}

.dev-auth-info-panel p {
    margin: 0;
    color: var(--muted);
    font-size: 0.9rem;
    line-height: 1.5;
}

@media (max-width: 480px) {
    .dev-auth-modal {
        width: calc(100vw - 20px);
        max-height: calc(100dvh - 20px);
    }

    .dev-auth-header {
        margin-bottom: 22px;
    }

    .dev-auth-logo {
        height: 44px;
        margin-bottom: 14px;
    }

    .dev-auth-info-btn {
        top: 10px;
        right: 10px;
        width: 44px;
        height: 44px;
    }

    .dev-auth-input,
    .dev-auth-submit {
        min-height: 48px;
        font-size: 16px;
    }

    .dev-auth-footer {
        margin-top: 22px;
    }
}

.arms-confirm-overlay {
    position: fixed;
    inset: 0;
    z-index: 120;
    display: grid;
    place-items: center;
    padding: 16px;
    background: rgba(4, 6, 10, 0.62);
    backdrop-filter: blur(6px);
}

.arms-confirm-overlay[hidden] {
    display: none;
}

.arms-confirm-modal {
    width: min(420px, 100%);
    padding: 22px 24px;
    background: var(--bg-card);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}

.arms-confirm-modal h2 {
    margin: 0 0 10px;
    font-size: 1.1rem;
}

.arms-confirm-modal p {
    margin: 0 0 20px;
    color: var(--ink-muted);
    line-height: 1.5;
    font-size: 0.95rem;
}

.arms-confirm-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    flex-wrap: wrap;
}

@media (min-width: 600px) {
    .help-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .help-card.span-2 {
        grid-column: span 2;
    }
}

@media (min-width: 721px) {
    .brand-mark {
        display: none;
    }

    .brand-system--desktop {
        display: inline;
    }

    .brand-logo {
        height: 52px;
        max-width: none;
    }
}

@media (max-width: 720px) and (pointer: coarse) {
    html {
        zoom: 1;
    }

    :root {
        --ui-scale: 1;
        --viewport-fill: 100dvh;
    }

    .app-header {
        flex-direction: row;
        align-items: center;
        justify-content: flex-start;
        gap: 8px;
        min-height: 56px;
        padding: 10px 12px;
        padding-top: max(10px, env(safe-area-inset-top));
        padding-left: max(12px, env(safe-area-inset-left));
        padding-right: max(12px, env(safe-area-inset-right));
    }

    .brand {
        flex: 1 1 auto;
        gap: 8px;
        min-width: 0;
        max-width: calc(100% - 172px);
        align-items: center;
        overflow: hidden;
    }

    .brand-copy {
        flex: 0 1 auto;
        min-width: 0;
        overflow: hidden;
    }

    .brand-logo {
        height: 34px;
        max-width: min(104px, 30vw);
        flex-shrink: 0;
    }

    .brand-system--desktop {
        display: none;
    }

    .brand-mark {
        display: block;
        font-size: 1.05rem;
        font-weight: 700;
        color: var(--ink);
        letter-spacing: 0.03em;
        line-height: 1;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .header-actions {
        flex: 0 0 auto;
        flex-shrink: 0;
        gap: 3px;
        margin-left: auto;
        position: relative;
        z-index: 2;
    }

    .app-header .btn-outline-light {
        border-color: transparent;
        background: var(--input-bg);
    }

    .app-header .btn-icon-only,
    .app-header .btn-export {
        min-width: 40px;
        min-height: 40px;
        width: 40px;
        height: 40px;
        padding: 0;
    }

    .app-header .btn-export .btn-label {
        display: none;
    }

    .app-header .btn-icon svg {
        width: 17px;
        height: 17px;
    }
}

@media (max-width: 720px) {
    .app-header {
        gap: 8px;
        min-height: 56px;
        padding: 10px 12px;
        padding-top: max(10px, env(safe-area-inset-top));
        padding-left: max(12px, env(safe-area-inset-left));
        padding-right: max(12px, env(safe-area-inset-right));
    }

    .brand {
        flex: 1 1 auto;
        min-width: 0;
        max-width: calc(100% - 172px);
        overflow: hidden;
        gap: 8px;
    }

    .brand-copy {
        min-width: 0;
        overflow: hidden;
    }

    .brand-logo {
        height: 34px;
        max-width: min(104px, 30vw);
    }

    .brand-system--desktop {
        display: none;
    }

    .brand-mark {
        display: block;
        font-size: 1.05rem;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .header-actions {
        flex: 0 0 auto;
        margin-left: auto;
        gap: 3px;
        z-index: 2;
    }

    .app-header .btn-icon-only,
    .app-header .btn-export {
        min-width: 40px;
        min-height: 40px;
        width: 40px;
        height: 40px;
    }

    .app-header .btn-export .btn-label {
        display: none;
    }

    .action-grid {
        grid-template-columns: 1fr;
    }

    .landing {
        padding: 24px 16px calc(32px + env(safe-area-inset-bottom));
    }

    .landing h1 {
        font-size: clamp(1.5rem, 6.2vw, 2rem);
        padding: 0 4px;
    }

    .landing p {
        font-size: 1rem;
        padding: 0 6px;
    }

    .action-grid {
        gap: 14px;
        margin-top: 28px;
        max-width: none;
    }

    .action-card {
        min-height: 156px;
        padding: 24px 16px;
        gap: 12px;
    }

    .action-icon {
        width: 64px;
        height: 64px;
    }

    .action-icon svg {
        width: 32px;
        height: 32px;
    }

    .action-card .title {
        font-size: 1.08rem;
    }

    .action-card .subtitle {
        font-size: 0.9rem;
    }

    .result-banner,
    .alert {
        margin-left: 12px;
        margin-right: 12px;
        font-size: 0.88rem;
    }

    .app-shell.workspace {
        height: var(--viewport-fill);
        min-height: var(--viewport-fill);
        max-height: var(--viewport-fill);
        overflow: hidden;
    }

    .workspace .thumb-strip,
    .workspace .result-banner,
    .workspace .alert {
        flex-shrink: 0;
    }

    .thumb-strip {
        padding: 6px 10px;
    }

    .thumb-strip .thumb {
        width: 48px;
        height: 48px;
    }

    .workspace-body {
        grid-template-rows: minmax(0, min(34vh, 260px)) minmax(0, 1fr);
        overflow: hidden;
    }

    .app-shell.workspace.is-mobile-workspace .workspace-body {
        display: flex;
        flex-direction: column;
        flex: 1;
        min-height: 0;
        overflow: hidden;
    }

    .app-shell.workspace.is-mobile-workspace .workspace-body > .stage-wrap {
        flex: 1 1 auto;
        min-height: 0;
    }

    .app-shell.workspace.is-mobile-workspace {
        --mobile-dock-peek: 198px;
    }

    .app-shell.workspace.is-mobile-workspace .workspace-main {
        padding-bottom: calc(var(--mobile-dock-peek) + env(safe-area-inset-bottom));
        transition: padding-bottom 0.32s cubic-bezier(0.22, 1, 0.36, 1);
    }

    .app-shell.workspace.is-mobile-workspace.mobile-dock-expanded .workspace-main {
        padding-bottom: calc(min(82dvh, 720px) + env(safe-area-inset-bottom));
    }

    body.mobile-dock-sheet-open {
        overflow: hidden;
        overscroll-behavior: none;
    }

    .app-shell.workspace.is-mobile-workspace .mobile-dock-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        top: 0;
        z-index: 24;
        border: 0;
        padding: 0;
        margin: 0;
        background: rgba(4, 8, 14, 0.42);
        backdrop-filter: blur(2px);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.28s ease;
    }

    .app-shell.workspace.is-mobile-workspace .mobile-dock-backdrop:not([hidden]) {
        opacity: 1;
        pointer-events: auto;
    }

    .app-shell.workspace.is-mobile-workspace .control-dock {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 28;
        width: 100%;
        max-width: 100%;
        margin: 0;
        border-radius: 22px 22px 0 0;
        border-left: none;
        border-right: none;
        border-bottom: none;
        box-shadow: 0 -16px 48px rgba(0, 0, 0, 0.28);
        max-height: calc(var(--mobile-dock-peek) + env(safe-area-inset-bottom));
        overflow: hidden;
        transition: max-height 0.34s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.28s ease;
        padding-bottom: env(safe-area-inset-bottom);
    }

    .app-shell.workspace.is-mobile-workspace .control-dock:not(.control-dock--expanded) {
        display: flex;
        flex-direction: column;
    }

    .app-shell.workspace.is-mobile-workspace .control-dock:not(.control-dock--expanded) .mobile-dock-sheet {
        display: flex;
        flex-direction: column;
        flex: 1 1 auto;
        min-height: 0;
        overflow: hidden;
    }

    .app-shell.workspace.is-mobile-workspace .control-dock:not(.control-dock--expanded) .tab-row {
        padding: 6px 8px;
    }

    .app-shell.workspace.is-mobile-workspace .control-dock:not(.control-dock--expanded) .mobile-dock-handle {
        padding: 14px 16px 6px;
    }

    .app-shell.workspace.is-mobile-workspace .control-dock:not(.control-dock--expanded) .workspace-measure-bar {
        margin-top: auto;
    }

    .app-shell.workspace.is-mobile-workspace .control-dock.control-dock--expanded {
        max-height: min(82dvh, 720px);
        box-shadow: 0 -20px 56px rgba(0, 0, 0, 0.34);
    }

    .app-shell.workspace.is-mobile-workspace .mobile-dock-handle {
        display: flex;
        flex-shrink: 0;
        align-items: center;
        gap: 12px;
        width: 100%;
        margin: 0;
        padding: 10px 16px 8px;
        border: 0;
        border-bottom: 1px solid var(--line);
        background: var(--bg-elevated);
        color: var(--ink);
        text-align: left;
        cursor: pointer;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
        position: relative;
        padding-top: 16px;
    }

    .app-shell.workspace.is-mobile-workspace .mobile-dock-grabber {
        position: absolute;
        top: 7px;
        left: 50%;
        width: 42px;
        height: 4px;
        border-radius: 999px;
        background: color-mix(in srgb, var(--muted) 55%, transparent);
        transform: translateX(-50%);
    }

    .app-shell.workspace.is-mobile-workspace .mobile-dock-handle-copy {
        display: grid;
        gap: 2px;
        flex: 1;
        min-width: 0;
    }

    .app-shell.workspace.is-mobile-workspace .mobile-dock-handle-title {
        font-size: 0.82rem;
        font-weight: 700;
        color: var(--ink);
    }

    .app-shell.workspace.is-mobile-workspace .mobile-dock-handle-meta {
        font-size: 0.72rem;
        color: var(--muted);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .app-shell.workspace.is-mobile-workspace .mobile-dock-chevron {
        width: 10px;
        height: 10px;
        flex-shrink: 0;
        border-right: 2px solid var(--muted);
        border-bottom: 2px solid var(--muted);
        transform: rotate(45deg);
        margin-top: -4px;
        transition: transform 0.28s ease;
    }

    .app-shell.workspace.is-mobile-workspace .control-dock.control-dock--expanded .mobile-dock-chevron {
        transform: rotate(-135deg);
        margin-top: 4px;
    }

    .app-shell.workspace.is-mobile-workspace .mobile-dock-sheet {
        display: flex;
        flex-direction: column;
        min-height: 0;
        flex: 1 1 auto;
        overflow: hidden;
    }

    .app-shell.workspace.is-mobile-workspace .control-dock:not(.control-dock--expanded) .mobile-dock-sheet > :not(.tab-row):not(.workspace-measure-bar) {
        display: none !important;
    }

    .app-shell.workspace.is-mobile-workspace .control-dock.control-dock--expanded .mobile-dock-sheet {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }

    .workspace .stage-wrap {
        padding: 60px 30px 4px;
        min-height: 0;
        max-height: min(34vh, 260px);
    }

    .app-shell.workspace.is-mobile-workspace .workspace .stage-wrap {
        padding: 4px 10px 0;
        min-height: 0;
        max-height: none;
        flex: 1 1 auto;
        display: flex;
        flex-direction: column;
    }

    .app-shell.workspace.is-mobile-workspace .workspace .stage {
        flex: 1 1 auto;
        min-height: 0;
        border-radius: 14px;
    }

    .app-shell.workspace.is-mobile-workspace .workspace .stage-toolbar {
        margin-bottom: 4px;
    }

    .workspace .stage {
        min-height: 160px;
    }

    .workspace .alert,
    .workspace .result-banner {
        margin: 4px 10px 0;
        padding: 7px 10px;
        font-size: 0.8rem;
    }

    .workspace .tab-row {
        position: sticky;
        top: 0;
        z-index: 4;
        background: var(--bg-card);
        flex-shrink: 0;
        padding: 8px;
        gap: 8px;
    }

    .app-shell.workspace.is-mobile-workspace .workspace .tab-btn {
        flex-direction: column;
        gap: 5px;
        min-height: 58px;
        padding: 10px 6px;
        font-size: 0.72rem;
        border-radius: 14px;
    }

    .app-shell.workspace.is-mobile-workspace .workspace .tab-btn .tab-icon svg {
        width: 22px;
        height: 22px;
    }

    .workspace .tab-btn {
        min-height: 48px;
        padding: 8px 6px;
        font-size: 0.74rem;
    }

    .workspace .tab-panel {
        display: none;
        flex: 1 1 auto;
        min-height: 0;
        overflow: hidden;
    }

    .workspace .tab-panel.active {
        display: flex;
        flex: 1 1 auto;
        flex-direction: column;
        min-height: 0;
        overflow-x: hidden;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
        padding: 0;
    }

    .workspace .workspace-tab-body {
        padding: 12px 12px 16px;
        gap: 14px;
    }

    .workspace .workspace-tab-hint {
        font-size: 0.78rem;
        padding: 9px 11px;
    }

    .app-shell.workspace.is-mobile-workspace .workspace .workspace-measure-bar {
        display: none;
        flex-shrink: 0;
        padding: 8px 16px 8px;
        gap: 10px;
        border-top: 1px solid var(--line);
        background: var(--bg-card);
        box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.16);
    }

    .app-shell.workspace.is-mobile-workspace .workspace .control-dock.control-dock--expanded .workspace-measure-bar {
        position: sticky;
        bottom: 0;
        z-index: 3;
        padding-bottom: calc(10px + env(safe-area-inset-bottom));
    }

    .workspace .workspace-measure-bar {
        display: none;
        flex-shrink: 0;
        padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
        gap: 10px;
        border-top: 1px solid var(--line);
        background: var(--bg-card);
        box-shadow: 0 -6px 20px rgba(0, 0, 0, 0.18);
    }

    .workspace .control-dock.control-dock--areas .workspace-measure-bar {
        display: grid;
        grid-template-columns: 1.15fr 1fr;
    }

    [data-theme="light"] .workspace .workspace-measure-bar {
        box-shadow: 0 -6px 18px rgba(21, 32, 43, 0.1);
    }

    .app-shell.workspace.is-mobile-workspace .workspace .control-dock.control-dock--areas .workspace-measure-bar,
    .app-shell.workspace.is-mobile-workspace .workspace .control-dock:not(.control-dock--expanded).control-dock--areas .workspace-measure-bar {
        display: grid;
        grid-template-columns: 1.2fr 1fr;
    }

    .app-shell.workspace.is-mobile-workspace .workspace .workspace-measure-bar .btn {
        min-height: 48px;
        font-size: 0.92rem;
        font-weight: 700;
        border-radius: 14px;
    }

    .workspace .workspace-measure-bar .btn {
        min-height: 48px;
        font-size: 0.9rem;
        font-weight: 700;
    }

    .workspace .area-tag-row {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .workspace .area-tag {
        font-size: 0.76rem;
        padding: 10px 8px;
        min-height: 44px;
    }

    .workspace .measure-item {
        padding: 12px;
        font-size: 0.82rem;
    }

    .workspace .measure-item button {
        min-height: 36px;
        padding: 6px 10px;
    }

    .app-shell.workspace.is-mobile-workspace .tile-picker-grid {
        grid-template-columns: 1fr;
    }

    .app-shell.workspace.is-mobile-workspace .tile-picker-card {
        min-height: 64px;
    }

    .app-shell.workspace.is-mobile-workspace .unit-chip {
        min-height: 48px;
    }

    .app-shell.workspace.is-mobile-workspace .field-touch input {
        min-height: 52px;
    }

    .workspace .custom-tile-grid {
        gap: 12px;
    }

    .workspace #tab-custom .btn-block {
        min-height: 48px;
        font-size: 0.92rem;
        font-weight: 700;
    }

    .workspace .detection-tuning-actions .btn-compact,
    .workspace .roof-segment-actions .btn-compact,
    .workspace .roof-segment-apply-row .btn-compact {
        min-height: 44px;
        padding: 8px 12px;
        font-size: 0.8rem;
    }

    .workspace .detection-tuning-actions .btn-primary.btn-compact {
        min-height: 44px;
        padding: 8px 14px;
    }

    .measure-adjust-hint,
    .roof-segment-hint {
        font-size: 0.7rem;
        line-height: 1.35;
    }

    .workspace .stage-toolbar .selection-pill {
        font-size: 0.74rem;
        padding: 4px 8px;
        max-width: 42vw;
    }

    .workspace .zoom-label {
        min-width: 36px;
        font-size: 0.72rem;
    }

    .workspace .stage-toolbar .btn-icon-only {
        min-width: 40px;
        min-height: 40px;
        width: 40px;
        height: 40px;
    }

    .segment-hint {
        white-space: normal;
        text-align: center;
        max-width: min(92vw, 360px);
        line-height: 1.35;
        bottom: 8px;
    }

    .arms-confirm-modal {
        padding: 20px 18px;
        max-height: calc(100dvh - 32px);
        overflow-y: auto;
    }

    .arms-confirm-actions .btn {
        min-height: 44px;
        flex: 1 1 auto;
    }

    .tab-btn {
        flex-direction: column;
        gap: 3px;
        padding: 6px 4px;
        font-size: 0.72rem;
        min-height: 44px;
    }

    .tab-icon svg {
        width: 16px;
        height: 16px;
    }

    .area-tag {
        font-size: 0.72rem;
        padding: 6px 8px;
        min-height: 36px;
    }

    .field input,
    .field select {
        min-height: 44px;
        font-size: 16px;
    }

    .help-overlay {
        padding: 12px;
        padding-top: max(12px, env(safe-area-inset-top));
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }

    .help-modal {
        max-height: min(92dvh, 760px);
    }

    .help-modal--wide {
        max-height: min(94dvh, 900px);
    }

    .help-grid {
        grid-template-columns: 1fr;
    }

    .help-card.span-2 {
        grid-column: auto;
    }
}

@media (max-width: 380px) and (pointer: coarse) {
    .brand-logo {
        height: 30px;
        max-width: min(88px, 28vw);
    }

    .brand-mark {
        display: none;
    }

    .header-actions {
        gap: 2px;
    }

    .app-header .btn-icon-only,
    .app-header .btn-export {
        min-width: 38px;
        min-height: 38px;
        width: 38px;
        height: 38px;
    }

    .brand {
        max-width: calc(100% - 158px);
    }
}

@media (max-width: 380px) {
    .tab-btn {
        font-size: 0.72rem;
        padding: 8px 4px;
    }
}

@media (min-width: 900px) {
    .app-header {
        min-height: 92px;
        padding: 22px 28px;
    }

    .brand-logo {
        height: 58px;
    }

    .brand-system {
        font-size: 1.32rem;
    }

    .workspace-body {
        grid-template-rows: none;
        grid-template-columns: minmax(0, 1fr) minmax(300px, 360px);
        gap: 0 12px;
        padding: 0 28px 12px 16px;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
        overflow: hidden;
    }

    .workspace .stage-wrap {
        padding: 8px 8px 0 0;
        min-height: 0;
        min-width: 0;
    }

    .workspace .control-dock {
        margin: 0;
        min-width: 0;
        width: 100%;
        max-width: 100%;
        max-height: none;
        height: 100%;
        min-height: 0;
        align-self: stretch;
        border-radius: var(--radius-md);
        overflow: hidden;
        background: var(--bg-card);
        box-shadow: var(--shadow);
        isolation: isolate;
    }

    .workspace .tab-row {
        padding: 8px 12px;
    }

    .workspace .workspace-tab-body {
        padding: 12px 16px 16px;
    }

    .workspace .detection-tuning--in-tab {
        padding: 0 2px;
    }

    .workspace .workspace-measure-bar {
        flex-shrink: 0;
        padding: 10px 16px 12px;
    }

    .workspace .tab-panel.active {
        min-height: 0;
        flex: 1 1 auto;
        overflow-x: hidden;
        overflow-y: auto;
        scrollbar-width: thin;
        scrollbar-color: color-mix(in srgb, var(--line) 70%, transparent) transparent;
    }

    .workspace .tab-panel.active::-webkit-scrollbar {
        width: 6px;
    }

    .workspace .tab-panel.active::-webkit-scrollbar-track {
        background: transparent;
    }

    .workspace .tab-panel.active::-webkit-scrollbar-thumb {
        background: color-mix(in srgb, var(--line) 80%, transparent);
        border-radius: 999px;
    }

    .workspace .tab-btn {
        flex-direction: row;
        min-height: 38px;
        font-size: 0.8rem;
    }
}

@media (min-width: 1200px) {
    .workspace-body {
        grid-template-columns: minmax(0, 1fr) minmax(320px, 380px);
        gap: 0 14px;
        padding: 0 32px 12px 20px;
    }

    .workspace .stage-wrap {
        padding-right: 12px;
    }

    .workspace .workspace-tab-body {
        padding-left: 18px;
        padding-right: 18px;
    }

    .workspace .tab-row {
        padding-left: 14px;
        padding-right: 14px;
    }
}

@media (min-width: 901px) {
    html {
        zoom: 1;
    }

    :root {
        --ui-scale: 1;
        --viewport-fill: 100dvh;
        --radius-lg: 18px;
        --radius-md: 12px;
        --radius-sm: 8px;
    }
}

@media (max-width: 900px) and (orientation: landscape) {
    .workspace-body {
        grid-template-rows: none;
        grid-template-columns: minmax(0, 1fr) minmax(260px, min(300px, 34vw));
        gap: 0 12px;
        padding: 0 16px 10px 10px;
    }

    .workspace .control-dock {
        margin: 0;
        min-width: 0;
        width: 100%;
        max-width: 100%;
        max-height: none;
        height: 100%;
        min-height: 0;
    }

    .workspace .stage-wrap {
        padding: 6px 8px 0 0;
    }
}

@supports not (zoom: 1) {
    :root {
        --viewport-fill: 100dvh;
    }

    html {
        font-size: 80%;
    }

    @media (max-width: 720px) and (pointer: coarse) {
        html {
            font-size: 100%;
        }
    }
}
