
        :root {
            --primary-color: #004aad;
            --primary-light: #e6f0fa;
            --secondary-color: #007bff;
            --accent-color: #0056b3;
            --text-color: #333;
            --border-color: #ccc;
            --bg-color: #f4f7f6;
            --part-fill: rgba(0, 74, 173, 0.05);
            --part-stroke: #004aad;
            --sheet-fill: #f8f9fa;
            --btn-bg: #f8f9fa;
            --btn-text: #333;
            --btn-border: #ccc;
            --btn-hover: #e2e6ea;
            --danger-text: #333;
            --danger-border: #888;
            --error-bg: #fff0f0;
        }

        body.theme-cvd1 {
            --primary-color: #000000;
            --primary-light: #f0f0f0;
            --secondary-color: #333333;
            --accent-color: #000000;
            --text-color: #000000;
            --border-color: #666666;
            --bg-color: #ffffff;
            --part-fill: rgba(0, 0, 0, 0.05);
            --part-stroke: #000000;
            --sheet-fill: #ffffff;
            --btn-bg: #ffffff;
            --btn-text: #000000;
            --btn-border: #000000;
            --btn-hover: #eeeeee;
            --danger-text: #000000;
            --danger-border: #000000;
        }

        body.theme-cvd2 {
            --primary-color: #0072B2;
            --primary-light: #D6EAF8;
            --secondary-color: #56B4E9;
            --accent-color: #004e80;
            --text-color: #333;
            --border-color: #ccc;
            --bg-color: #f9f9f9;
            --part-fill: rgba(0, 114, 178, 0.05);
            --part-stroke: #0072B2;
            --sheet-fill: #ffffff;
            --btn-bg: #ffffff;
            --btn-text: #D55E00;
            --btn-border: #D55E00;
            --btn-hover: #FDEBD0;
            --danger-text: #D55E00;
            --danger-border: #D55E00;
        }

        html {
            font-size: 16px;
        }

        html.fs-1 {
            font-size: 12px;
        }

        html.fs-2 {
            font-size: 14px;
        }

        html.fs-3 {
            font-size: 16px;
        }

        html.fs-4 {
            font-size: 18px;
        }

        html.fs-5 {
            font-size: 20px;
        }

        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            margin: 0;
            padding: 0;
            background-color: var(--bg-color);
            color: var(--text-color);
            display: flex;
            flex-direction: column;
            height: 100vh;
            height: 100dvh;
            overflow: hidden;
        }

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

        * {
            scrollbar-width: thin;
            scrollbar-color: rgba(0, 0, 0, 0.3) transparent;
        }

        *::-webkit-scrollbar {
            width: 6px;
            height: 6px;
        }

        *::-webkit-scrollbar-track {
            background: transparent;
        }

        *::-webkit-scrollbar-thumb {
            background-color: rgba(0, 0, 0, 0.3);
            border-radius: 3px;
        }

        *::-webkit-scrollbar-thumb:hover {
            background-color: rgba(0, 0, 0, 0.5);
        }

        .ai-banner {
            background-color: #fff3cd;
            color: #856404;
            text-align: center;
            padding: 5px;
            font-size: 0.85em;
            border-bottom: 1px solid #ffeeba;
            width: 100%;
        }

        header {
            background-color: var(--primary-color);
            color: white;
            padding: 10px 20px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            flex-wrap: wrap;
            gap: 10px;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
            z-index: 10;
        }

        .header-left {
            display: flex;
            align-items: center;
            width: 100%;
            justify-content: space-between;
            gap: 15px;
        }

        .header-title-group {
            display: flex;
            align-items: center;
            flex-shrink: 0;
        }

        .home-link {
            display: flex;
            align-items: center;
            gap: 8px;
            color: #ffffff;
            text-decoration: none;
            transition: opacity 0.2s;
        }

        .home-link:hover {
            opacity: 0.8;
        }

        .home-link span {
            font-size: 1.2em;
            font-weight: 700;
            letter-spacing: 0.5px;
        }

        header h1 {
            margin: 0;
            font-size: 1.2em;
            font-weight: 600;
            border-left: 1px solid rgba(255, 255, 255, 0.4);
            padding-left: 15px;
            margin-left: 15px;
        }

        .header-quick-controls {
            display: flex;
            align-items: center;
            gap: 10px;
            flex-grow: 1;
        }

        .menu-toggle-btn {
            display: none;
            background: transparent;
            border: 1px solid white;
            color: white;
            padding: 6px 12px;
            font-size: 1em;
            border-radius: 4px;
        }

        .header-controls {
            display: flex;
            gap: 10px;
            align-items: center;
            flex-wrap: wrap;
            width: 100%;
        }

        .project-bar {
            background-color: white;
            padding: 8px 20px;
            border-bottom: 1px solid var(--border-color);
            display: flex;
            align-items: center;
            gap: 10px;
            font-size: 0.9em;
            overflow-x: auto;
            white-space: nowrap;
        }

        .project-controls {
            display: flex;
            align-items: center;
            gap: 10px;
            min-width: 0;
        }

        #projectSelector {
            min-width: 250px;
            font-weight: bold;
        }

        footer {
            background-color: var(--primary-color);
            color: white;
            text-align: center;
            padding: 8px;
            font-size: 0.85em;
        }

        footer a {
            color: white;
            text-decoration: underline;
        }

        footer a:hover {
            text-decoration: none;
        }

        button {
            background-color: var(--secondary-color);
            color: white;
            border: none;
            padding: 8px 12px;
            border-radius: 4px;
            cursor: pointer;
            font-size: 0.9em;
            transition: background-color 0.2s;
            white-space: nowrap;
        }

        button:hover {
            background-color: var(--accent-color);
        }

        button:disabled {
            background-color: #ccc;
            cursor: not-allowed;
        }

        .btn-clear {
            background-color: #6c757d;
        }

        .btn-clear:hover {
            background-color: #5a6268;
        }

        .btn-success {
            background-color: #28a745;
        }

        .btn-success:hover {
            background-color: #218838;
        }

        .btn-delete {
            background-color: transparent;
            color: var(--danger-text);
            border: 1px solid var(--danger-border);
            padding: 2px 4px;
            font-size: 0.8em;
            border-radius: 3px;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            gap: 2px;
        }

        .btn-delete:hover {
            background-color: var(--btn-hover);
        }

        select,
        input[type="number"],
        input[type="text"],
        input[type="file"],
        textarea {
            padding: 6px;
            border: 1px solid var(--border-color);
            border-radius: 4px;
            font-size: 0.9em;
            background-color: white;
            color: var(--text-color);
            font-family: inherit;
        }

        input[type="file"] {
            padding: 4px;
        }

        input[type="number"]::-webkit-outer-spin-button,
        input[type="number"]::-webkit-inner-spin-button {
            -webkit-appearance: none;
            margin: 0;
        }

        input[type="number"] {
            -moz-appearance: textfield;
        }

        .mode-toggle {
            display: flex;
            background: white;
            border-radius: 4px;
            overflow: hidden;
        }

        .mode-toggle button {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            gap: 0.25em;
            background: transparent;
            color: var(--primary-color);
            border-radius: 0;
            padding: 6px 12px;
            font-weight: bold;
        }

        /* チェックは選択状態から描画し、文字列更新との不一致を防ぐ。 */
        .mode-toggle button::before {
            content: "";
            display: inline-block;
            width: 1em;
            flex: 0 0 1em;
            text-align: center;
        }

        .mode-toggle button.active {
            background: var(--primary-color);
            color: white;
        }

        .mode-toggle button.active::before {
            content: "✓";
        }

        .main-container {
            display: flex;
            flex: 1;
            overflow: hidden;
        }

        .input-panel {
            width: 400px;
            min-width: 280px;
            background-color: white;
            border-right: 1px solid var(--border-color);
            overflow-y: auto;
            padding: 15px;
            flex-shrink: 0;
        }

        .resizer {
            width: 6px;
            cursor: col-resize;
            background-color: transparent;
            flex-shrink: 0;
            display: block;
            z-index: 5;
            transition: background-color 0.2s;
        }

        .resizer:hover,
        .resizer.active {
            background-color: var(--primary-color);
        }

        .resizer-vertical {
            position: relative;
            height: 14px;
            margin: -4px 0;
            cursor: row-resize;
            background-color: transparent;
            flex: 0 0 14px;
            z-index: 5;
            touch-action: none;
            user-select: none;
        }

        .resizer-vertical::before {
            content: "";
            position: absolute;
            left: 50%;
            top: 50%;
            width: min(160px, 45%);
            height: 4px;
            border-radius: 999px;
            background: var(--border-color);
            transform: translate(-50%, -50%);
            transition: background-color 0.2s, height 0.2s;
        }

        .resizer-vertical:hover::before,
        .resizer-vertical.active::before,
        .resizer-vertical:focus-visible::before {
            height: 6px;
            background-color: var(--primary-color);
        }

        body.resizing-diagram {
            cursor: row-resize;
            user-select: none;
        }

        .output-panel {
            flex: 1;
            padding: 15px;
            overflow-y: auto;
            background-color: var(--bg-color);
            display: flex;
            flex-direction: column;
            gap: 15px;
            min-width: 0;
        }

        .section {
            margin-bottom: 20px;
            border: 1px solid var(--border-color);
            border-radius: 5px;
            background-color: #fff;
            overflow: hidden;
        }

        .section-header {
            background-color: var(--primary-light);
            padding: 8px 12px;
            font-weight: bold;
            color: var(--primary-color);
            border-bottom: 1px solid var(--border-color);
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .section-header-actions {
            display: flex;
            gap: 5px;
        }

        .section-header-actions button {
            padding: 4px 8px;
            font-size: 0.8em;
        }

        .table-responsive {
            overflow-x: auto;
            -webkit-overflow-scrolling: touch;
        }

        .data-table {
            width: 100%;
            border-collapse: collapse;
            font-size: 0.9em;
            min-width: 350px;
        }

        .data-table th,
        .data-table td {
            border: 1px solid #eee;
            padding: 0;
            text-align: center;
            white-space: nowrap;
        }

        .data-table th {
            background-color: #f8f9fa;
            color: #555;
            padding: 6px;
        }

        .data-table input {
            width: 100%;
            border: none;
            padding: 8px 4px;
            text-align: center;
            background: transparent;
            font-size: 1em;
            color: var(--text-color);
            min-width: 40px;
        }

        .data-table th input.bulk-input {
            border: 1px solid var(--border-color);
            background-color: white;
            padding: 4px;
            border-radius: 4px;
            min-width: 0;
            width: 100%;
            max-width: 70px;
        }

        .data-table input:focus {
            outline: 2px solid var(--secondary-color);
            background: #fff;
            z-index: 1;
            position: relative;
        }

        .data-table input.error {
            background-color: var(--error-bg);
            border: 1px solid red;
        }

        .col-narrow {
            width: 40px;
        }

        .col-action {
            width: 50px;
        }

        body.mode-1d .col-2d-only {
            display: none;
        }

        .stats {
            display: flex;
            flex-direction: column;
            gap: 10px;
        }

        .stat-card {
            background-color: white;
            padding: 10px 15px;
            border-radius: 5px;
            border-left: 5px solid var(--primary-color);
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
            color: var(--text-color);
            display: flex;
            flex-direction: column;
            justify-content: center;
        }

        .stat-card.full-width {
            flex-direction: row;
            align-items: center;
            gap: 15px;
            flex-wrap: wrap;
        }

        .stat-card.full-width h4 {
            margin: 0;
            white-space: nowrap;
            border-right: 1px solid var(--border-color);
            padding-right: 15px;
        }

        .stat-card.full-width #statSheets {
            display: flex;
            flex-wrap: wrap;
            gap: 10px;
            line-height: 1.4;
            flex: 1;
        }

        .stats-row {
            display: flex;
            gap: 10px;
            flex-wrap: wrap;
        }

        .stats-row .stat-card {
            flex: 1 1 140px;
            min-width: 140px;
        }

        .stats-row .stat-card.wide {
            flex: 2 1 250px;
        }

        .stat-card.no-print {
            flex: 1 1 180px;
            min-width: 180px;
            align-items: center;
        }

        .stat-card h4 {
            margin: 0 0 5px 0;
            font-size: 0.85em;
            color: #666;
        }

        .stat-card p {
            margin: 0;
            font-size: 1.2em;
            font-weight: bold;
            color: var(--primary-color);
        }

        .stat-card .scrap-list {
            font-size: 0.8em;
            max-height: 60px;
            overflow-y: auto;
            white-space: pre-wrap;
            color: #555;
            font-weight: normal;
        }

        .filter-bar {
            background-color: white;
            padding: 10px 15px;
            border-radius: 5px;
            border: 1px solid var(--border-color);
            display: flex;
            gap: 20px;
            flex-wrap: wrap;
            align-items: center;
            font-size: 0.9em;
            flex-shrink: 0;
        }

        .filter-bar label {
            display: flex;
            align-items: center;
            gap: 5px;
            cursor: pointer;
        }

        .diagram-area {
            --diagram-content-height: clamp(320px, 52dvh, 700px);
            display: flex;
            flex-direction: column;
            flex: 1;
            gap: 10px;
            min-height: 0;
        }

        .svg-container {
            background-color: white;
            border: 1px solid var(--border-color);
            border-radius: 5px;
            padding: 10px;
            overflow: hidden;
            height: var(--diagram-content-height);
            flex: 0 0 var(--diagram-content-height);
            min-height: 200px;
            max-height: 85dvh;
            cursor: grab;
            user-select: none;
            touch-action: none;
        }

        .svg-container:active {
            cursor: grabbing;
        }

        .text-container,
        .card-container {
            background-color: white;
            border: 1px solid var(--border-color);
            border-radius: 5px;
            padding: 20px;
            overflow: auto;
            height: var(--diagram-content-height);
            flex: 0 0 var(--diagram-content-height);
            min-height: 200px;
            max-height: 85dvh;
            display: none;
        }

        .text-container {
            font-family: monospace;
            font-size: 1.1em;
            line-height: 1.6;
            white-space: pre-wrap;
            word-break: break-all;
            overflow-wrap: break-word;
            color: var(--text-color);
        }

        .text-print-block {
            white-space: pre-wrap;
        }

        .text-print-block:not(:last-child) {
            margin-bottom: 1.6em;
        }

        .card-container {
            flex-direction: column;
            gap: 15px;
        }

        .card-item {
            border: 1px solid #eee;
            border-radius: 6px;
            padding: 15px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
        }

        .card-header {
            font-weight: bold;
            color: var(--primary-color);
            font-size: 1.2em;
            margin-bottom: 5px;
            border-bottom: 2px solid var(--primary-light);
            padding-bottom: 5px;
        }

        .card-info {
            font-size: 0.9em;
            color: #666;
            margin-bottom: 10px;
        }

        .card-parts {
            display: flex;
            flex-wrap: wrap;
            gap: 8px;
        }

        .card-part {
            background-color: var(--primary-light);
            color: var(--primary-color);
            padding: 6px 12px;
            border-radius: 4px;
            font-size: 0.95em;
            font-weight: 600;
        }

        .card-scrap {
            background-color: #fff3cd;
            color: #856404;
            border: 1px dashed #ffeeba;
            padding: 6px 12px;
            border-radius: 4px;
            font-size: 0.95em;
            font-weight: 600;
        }

        .mobile-tabs {
            display: none;
            background-color: var(--bg-color);
            padding: 8px 8px 0;
            gap: 4px;
            border-bottom: 1px solid var(--border-color);
            position: sticky;
            top: 0;
            z-index: 20;
        }

        .mobile-tab-button {
            flex: 1;
            background-color: transparent;
            color: var(--text-color);
            border: 1px solid transparent;
            border-bottom: none;
            padding: 8px 16px;
            font-size: 0.9em;
            border-top-left-radius: 8px;
            border-top-right-radius: 8px;
            cursor: pointer;
            transition: background-color 0.2s;
            margin-bottom: -1px;
        }

        .mobile-tab-button.active {
            background-color: #fff;
            color: var(--primary-color);
            font-weight: bold;
            border-color: var(--border-color);
        }

        .support-banner {
            background-color: var(--btn-bg);
            border: 1px solid var(--border-color);
            border-radius: 4px;
            padding: 7px 12px;
            min-height: 40px;
            display: flex;
            flex-direction: row;
            align-items: center;
            justify-content: center;
            gap: 8px;
            box-sizing: border-box;
        }

        .support-banner[hidden] { display: none; }

        .ad-slot__disclosure {
            font-size: 0.65rem;
            color: #888;
            background: rgba(0, 0, 0, 0.05);
            padding: 2px 4px;
            border-radius: 2px;
            letter-spacing: 0.05em;
            margin: 0;
            flex: 0 0 auto;
        }

        .ad-slot__items,
        .ad-text {
            min-width: 0;
        }

        .ad-slot__items {
            flex: 1 1 auto;
        }

        .ad-text__link {
            font-size: 0.85rem;
            color: var(--primary-color);
            text-decoration: none;
            font-weight: bold;
            display: inline-block;
            min-width: 0;
            max-width: 100%;
            overflow: hidden;
            overflow-wrap: anywhere;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 2;
        }

        .ad-text__link:hover {
            text-decoration: underline;
            color: var(--accent-color);
        }

        .ad-slot__destination {
            flex: 0 1 38%;
            min-width: 0;
            max-width: 38%;
            color: #666;
            font-size: 0.65rem;
            line-height: 1.25;
            overflow-wrap: anywhere;
        }

        @keyframes highlight-flash {
            0% {
                background-color: var(--primary-light);
                box-shadow: 0 0 10px var(--primary-color);
            }

            100% {
                background-color: white;
                box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
            }
        }

        .stat-card.flash,
        #statsArea.flash>.stat-card {
            animation: highlight-flash 1s ease-out;
        }

        .toast {
            position: fixed;
            bottom: 20px;
            right: 20px;
            background-color: #333;
            color: white;
            padding: 12px 20px;
            border-radius: 6px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
            opacity: 0;
            transform: translateY(20px);
            transition: all 0.3s ease;
            z-index: 4000;
            pointer-events: none;
            font-size: 0.9em;
            max-width: 90vw;
        }

        .toast.show {
            opacity: 1;
            transform: translateY(0);
        }

        .toast.error {
            background-color: #d9534f;
        }

        @media (max-width: 768px) {
            .toast {
                bottom: 80px;
                left: 50%;
                right: auto;
                transform: translateX(-50%) translateY(20px);
            }

            .toast.show {
                transform: translateX(-50%) translateY(0);
            }
        }

        .scrollable-x {
            position: relative;
        }

        .ga-progress-overlay {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.6);
            z-index: 2000;
            display: none;
            justify-content: center;
            align-items: center;
        }

        .ga-progress-box {
            background: white;
            padding: 30px;
            border-radius: 8px;
            text-align: center;
            width: 90%;
            max-width: 350px;
        }

        .ga-progress-bar-bg {
            width: 100%;
            height: 10px;
            background: #eee;
            border-radius: 5px;
            overflow: hidden;
            margin: 15px 0;
        }

        .ga-progress-bar-fill {
            height: 100%;
            background: var(--primary-color);
            width: 0%;
            transition: width 0.2s;
        }

        #modalOverlay {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.5);
            z-index: 3000;
            justify-content: center;
            align-items: center;
        }

        #modalBox {
            background: white;
            padding: 20px;
            border-radius: 8px;
            width: 90%;
            max-width: 500px;
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
        }

        #modalTitle {
            margin-top: 0;
            color: var(--primary-color);
        }

        #modalMessage {
            margin-bottom: 15px;
            line-height: 1.5;
        }

        #modalInput {
            width: 100%;
            margin-bottom: 15px;
            padding: 8px;
            box-sizing: border-box;
            display: none;
            border: 1px solid var(--border-color);
            border-radius: 4px;
            resize: vertical;
            min-height: 40px;
            height: 40px;
            font-family: inherit;
        }

        #modalInput.textarea-mode {
            height: 150px;
        }

        .modal-actions {
            display: flex;
            justify-content: flex-end;
            gap: 10px;
        }

        .reverse-settings {
            background: #fff;
            padding: 10px;
            border: 1px solid var(--border-color);
            border-radius: 4px;
            margin-bottom: 15px;
        }

        .reverse-settings h3 {
            margin: 0 0 10px 0;
            font-size: 1em;
            color: var(--primary-color);
        }

        .reverse-params {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
            gap: 8px;
            margin-top: 10px;
        }

        .reverse-params label {
            font-size: 0.8em;
            text-align: center;
        }

        .reverse-params input,
        .reverse-params select {
            width: 100%;
            margin-top: 2px;
            padding: 4px;
        }

        .reverse-ranking-item {
            border: 1px solid var(--border-color);
            border-radius: 6px;
            padding: 15px;
            margin-bottom: 10px;
            background: white;
        }

        .reverse-ranking-title {
            font-size: 1.2em;
            font-weight: bold;
            color: var(--primary-color);
            margin-bottom: 5px;
        }

        .reverse-ranking-badge {
            background: gold;
            color: black;
            padding: 2px 6px;
            border-radius: 4px;
            font-size: 0.8em;
            margin-left: 10px;
            vertical-align: middle;
        }

        .reverse-ranking-stats {
            display: flex;
            flex-direction: column;
            gap: 5px;
            font-size: 0.9em;
            margin-top: 10px;
        }

        .reverse-ranking-stats div {
            background: var(--bg-color);
            padding: 4px 8px;
            border-radius: 4px;
        }

        .print-header {
            display: none;
        }

        @media (max-width: 768px) {
            body {
                height: auto;
                min-height: 100dvh;
                overflow: auto;
            }

            header {
                padding: 10px;
                flex-direction: column;
                align-items: stretch;
                gap: 0;
            }

            .header-left {
                flex-wrap: wrap;
                gap: 10px;
            }

            .header-title-group {
                flex-grow: 1;
            }

            .header-quick-controls {
                order: 3;
                width: 100%;
                justify-content: space-between;
                margin-top: 5px;
                gap: 5px;
            }

            .header-quick-controls>* {
                flex: 1;
            }

            .menu-toggle-btn {
                display: block;
                flex-shrink: 0;
            }

            .header-controls {
                display: none;
                width: 100%;
                overflow-x: auto;
                white-space: nowrap;
                flex-wrap: nowrap;
                padding-bottom: 10px;
                margin-top: 10px;
                -webkit-overflow-scrolling: touch;
            }

            .header-controls.show {
                display: flex;
            }

            .header-controls>* {
                flex-shrink: 0;
            }

            .project-bar {
                flex-wrap: nowrap;
                padding: 8px 10px;
            }

            .main-container {
                flex-direction: column;
                overflow: visible;
                height: auto;
            }

            .resizer {
                display: none;
            }

            .input-panel {
                width: 100% !important;
                min-width: 0 !important;
            }

            .diagram-area {
                --diagram-content-height: clamp(280px, 60dvh, 600px);
            }

            .input-panel,
            .output-panel {
                width: 100%;
                min-width: 0;
                display: none;
                overflow-y: auto;
                flex: 1;
            }

            .mobile-tabs {
                display: flex;
            }

            .panel-visible {
                display: flex !important;
                flex-direction: column;
            }

            .stats,
            .diagram-area {
                display: none;
            }

            .stats.panel-visible {
                display: flex !important;
                flex-direction: column;
                gap: 10px;
            }

            .diagram-area.panel-visible {
                display: flex !important;
                flex-direction: column;
                gap: 15px;
                flex: 1;
                min-height: 0;
            }

            .filter-bar {
                overflow-x: auto;
                white-space: nowrap;
                flex-wrap: nowrap;
                -webkit-overflow-scrolling: touch;
                gap: 15px;
            }

            .filter-bar>* {
                flex-shrink: 0;
            }

            .section-header {
                flex-direction: column;
                align-items: stretch;
                gap: 8px;
            }

            .section-header>span {
                text-align: center;
            }

            .section-header-actions {
                width: 100%;
                display: flex;
                gap: 5px;
            }

            .section-header-actions button {
                flex: 1;
                padding: 8px 4px;
            }

            .reverse-params { grid-template-columns: repeat(2, minmax(0, 1fr)); }
        }

        @media print {
            body {
                background-color: white;
                overflow: visible;
                height: auto;
                -webkit-print-color-adjust: exact;
                print-color-adjust: exact;
            }

            header,
            .ai-banner,
            .project-bar,
            footer,
            .input-panel,
            .mobile-tabs,
            .no-print,
            .label-print-mode,
            .resizer,
            .resizer-vertical,
            .support-banner,
            .ga-progress-overlay,
            .toast,
            .modal-overlay,
            #modalOverlay,
            .skip-link {
                display: none !important;
            }

            .print-header {
                display: block;
                margin-bottom: 20px;
                padding-bottom: 10px;
                border-bottom: 2px solid #333;
            }

            .print-header h2 {
                margin: 0;
                font-size: 1.4em;
            }

            .print-header p {
                margin: 5px 0 0 0;
                font-size: 1em;
                color: #555;
            }

            .main-container,
            .output-panel {
                display: block;
                width: 100%;
                min-width: 0;
                max-width: none;
                height: auto;
                overflow: visible;
                padding: 0;
            }

            .stats {
                display: flex !important;
                margin-bottom: 8mm;
                break-inside: avoid;
                page-break-inside: avoid;
            }

            .stats-row {
                display: grid;
                grid-template-columns: repeat(auto-fit, minmax(42mm, 1fr));
                width: 100%;
            }

            .stats-row .stat-card,
            .stats-row .stat-card.wide {
                min-width: 0;
            }

            .diagram-area {
                display: block !important;
                width: 100%;
                min-height: 0;
                overflow: visible;
            }

            .svg-container {
                border: none;
                padding: 0;
                overflow: visible;
                cursor: default;
                page-break-inside: avoid;
                height: auto !important;
                min-height: 0 !important;
                max-height: none !important;
                flex: none !important;
                width: 100%;
            }

            .text-container,
            .card-container {
                border: none;
                padding: 0;
                overflow: visible;
                height: auto !important;
                min-height: 0 !important;
                max-height: none !important;
                flex: none !important;
                width: 100%;
            }

            .text-container {
                white-space: pre-wrap !important;
                word-break: break-all !important;
                overflow-wrap: break-word !important;
            }

            .card-container:not([hidden]) {
                display: block !important;
                gap: 0 !important;
            }

            body.print-monochrome .stat-card {
                border: 1px solid black;
                border-left: 5px solid black;
                box-shadow: none;
            }

            body.print-monochrome .stat-card p,
            body.print-monochrome .stat-card h4 {
                color: black !important;
            }

            svg {
                width: 100%;
                height: auto;
                max-width: 100% !important;
                max-height: none !important;
                display: block;
                overflow: visible;
            }

            body.print-monochrome svg rect.sheet-border {
                fill: none !important;
                stroke: black !important;
                stroke-width: 2px !important;
            }

            body.print-monochrome svg rect.part-rect {
                fill: #ffffff !important;
                stroke: black !important;
                stroke-width: 1px !important;
            }

            body.print-monochrome svg rect.part-rect.no-rotate {
                fill: url(#printHatch) !important;
            }

            body.print-monochrome svg text {
                fill: black !important;
            }

            body.print-monochrome .output-panel,
            body.print-monochrome .label-print-mode {
                filter: grayscale(1);
            }

            .text-print-block,
            .card-item {
                display: table !important;
                width: 100% !important;
                box-sizing: border-box !important;
                margin: 0 0 5mm;
                break-inside: avoid-page;
                page-break-inside: avoid;
                orphans: 3;
                widows: 3;
            }

            .text-print-block:last-child,
            .card-item:last-child {
                margin-bottom: 0;
            }

            body.printing-labels>*:not(.label-print-mode) {
                display: none !important;
            }

            body.printing-labels .label-print-mode {
                display: grid !important;
                position: absolute;
                top: 0;
                left: 0;
                width: 100%;
                height: 100%;
                background: white;
            }

            @page {
                size: auto;
                margin: 10mm;
            }
        }

        .label-print-mode {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: white;
            z-index: 100;
            padding: 10mm;
            box-sizing: border-box;
            display: none;
            grid-template-columns: repeat(3, 1fr);
            grid-auto-rows: 30mm;
            gap: 5mm;
        }

        .label-item {
            border: 1px dashed black;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            text-align: center;
            font-size: 10pt;
        }

        .label-item div {
            margin: 2px 0;
        }
    
/* Security/a11y/responsive overrides */
[hidden] { display: none !important; }
.sr-only { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0, 0, 0, 0) !important; white-space: nowrap !important; border: 0 !important; }
.skip-link { position: fixed; left: 12px; top: -80px; z-index: 5000; background: #fff; color: #000; padding: 10px 14px; border: 2px solid #000; border-radius: 4px; }
.skip-link:focus { top: 12px; }
button:focus-visible, select:focus-visible, input:focus-visible, textarea:focus-visible, a:focus-visible, [tabindex]:focus-visible { outline: 3px solid #ffbf47; outline-offset: 2px; }
.visually-hidden-file { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.header-control-group { display: flex; gap: 6px; align-items: center; }
.print-color-control { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; font-size: 0.84rem; }
.print-color-control select { min-width: 5.5rem; }
.button-link { display: inline-flex; align-items: center; padding: 8px 12px; border-radius: 4px; background: var(--secondary-color); color: #fff; text-decoration: none; white-space: nowrap; }
.button-link:hover { background: var(--accent-color); }
.project-label { font-weight: bold; color: var(--primary-color); }
.support-banner-top { margin: 10px 15px 0; }
.support-banner-bottom { margin-top: 27px; padding: 9px 12px; }
.bulk-input-wrap { margin-top: 4px; }
.section-help { padding: 7px 10px; font-size: 0.82em; color: #555; background: #f9f9f9; border-bottom: 1px solid var(--border-color); line-height: 1.45; }
.calculation-settings { border: 0; padding: 10px 0; }
.settings-card { background: #fff; padding: 10px; border: 1px solid var(--border-color); border-radius: 4px; }
.field-label, .strong-label { font-weight: bold; }
.field-description { font-size: 0.82em; color: #666; margin-top: 8px; line-height: 1.45; }
.checkbox-label { display: flex; align-items: center; gap: 7px; cursor: pointer; }
.settings-divider { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--border-color); }
.execution-settings { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(11rem, 100%), 1fr)); gap: 0.65rem; align-items: end; margin-top: 0.85rem; padding-top: 0.8rem; border-top: 1px solid var(--border-color); }
.execution-settings > strong { grid-column: 1 / -1; }
.execution-settings label { display: grid; min-width: 0; gap: 0.3rem; font-size: 0.9rem; overflow-wrap: anywhere; }
.execution-settings select { width: 100%; min-width: 0; max-width: 100%; text-overflow: ellipsis; }
.execution-details { margin-top: 0.55rem; font-size: 0.84em; color: #555; }
.execution-details summary { cursor: pointer; color: var(--primary-color); font-weight: 700; }
.execution-details p { margin: 0.45rem 0 0; line-height: 1.55; }
.execution-target-table { width: 100%; margin-top: 0.55rem; border-collapse: collapse; font-size: 0.94em; }
.execution-target-table th, .execution-target-table td { border: 1px solid var(--border-color); padding: 0.35rem; text-align: left; vertical-align: top; }
.execution-target-table th { background: var(--primary-light); color: var(--primary-color); }
@media (max-width: 768px) { .execution-settings { grid-template-columns: 1fr; } }
.calculation-actions { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-top: 12px; }
.btn-run { width: 100%; padding: 12px; font-size: 1.1em; background: var(--primary-color); }
.stat-card h3 { margin: 0 0 5px; font-size: 0.85em; color: #666; }
.stat-card.full-width h3 { margin: 0; white-space: nowrap; border-right: 1px solid var(--border-color); padding-right: 15px; }
.stock-card { align-items: center; }
.stock-card button { width: 100%; font-weight: bold; padding: 10px; white-space: normal; line-height: 1.3; }
.small-note { font-size: 0.75em; color: #666; margin-top: 5px; text-align: center; }
.filter-label { font-weight: bold; margin-left: 12px; }
.progress-detail { font-size: 0.82em; color: #666; }
.progress-eta { margin: 0.45rem 0; font-weight: 700; color: var(--primary-color); }
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 3000; display: flex; justify-content: center; align-items: center; }
#modalBox { max-height: min(90dvh, 720px); overflow: auto; }
#modalMessage { white-space: pre-line; }
#modalInput { display: none; }
#modalInput.is-visible { display: block; }
#modalInput.textarea-mode { height: 180px; }
.ga-progress-overlay { display: flex; }
.ga-progress-box button { margin-top: 8px; }
.data-table input[aria-invalid="true"] { background: var(--error-bg); border: 2px solid #c00; }
.data-table .row-error { background: #fff6f6; }
.card-part.colorized { background-color: var(--part-color); }
.stat-material-line { font-size: 1.1em; font-weight: bold; color: var(--text-color); }
.stat-material-count { color: var(--primary-color); font-weight: bold; }
.stat-material-shortage { color: #b00020; font-weight: bold; }
.reverse-ranking-recommend { font-size: 1.1em; font-weight: bold; }
.reverse-ranking-breakdown { margin-top: 5px; border-top: 1px dashed #ccc; padding-top: 5px; }
.label-item-label { font-weight: bold; font-size: 12pt; }
.label-item-date { font-size: 8pt; color: #666; }
.resizer:focus-visible { background: var(--primary-color); }

@media (max-width: 768px) {
  .header-control-group { flex-shrink: 0; }
  .calculation-actions { grid-template-columns: 1fr; }
  .support-banner-bottom { margin-top: 24px; }
  .support-banner { min-height: 44px; padding: 0 10px; gap: 6px; }
  .ad-text__link { min-height: 40px; -webkit-box-pack: center; }
  .ad-slot__destination { flex-basis: 45%; max-width: 45%; }
  .support-banner-top { margin-inline: 8px; white-space: normal; }
  .scrap-modal-overlay { padding: 0; }
  .scrap-modal { width: 100vw; height: 100dvh; max-width: 100vw; max-height: 100dvh; padding: 12px; border: 0; border-radius: 0; }
  .scrap-sort-label { align-items: stretch; flex-direction: column; gap: 5px; }
  .scrap-sort-label select { width: 100%; }
  .manual-page { padding: 0; }
  .manual-content { width: 100%; max-width: 100%; border: 0; border-radius: 0; padding: 16px; }
  .manual-table { font-size: 0.78em; }
  .manual-table th, .manual-table td { padding: 0.35rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}
#modalOverlay.modal-overlay:not([hidden]) { display: flex; }
#graphicContainer:not([hidden]) { display: block; }
#textContainer:not([hidden]) { display: block; }
#cardContainer:not([hidden]) { display: flex; }
.empty-table-message { padding: 20px !important; color: #777; text-align: center; }
.manual-page { min-height: 100dvh; overflow-x: hidden; overflow-y: auto; padding: 24px; }
.manual-content { max-width: 900px; margin: 0 auto; background: #fff; border: 1px solid var(--border-color); border-radius: 8px; padding: clamp(18px, 4vw, 42px); line-height: 1.7; }
.manual-content h1, .manual-content h2, .manual-content h3 { color: var(--primary-color); scroll-margin-top: 16px; }
.manual-content dt { font-weight: bold; margin-top: 12px; }
.manual-table { width: 100%; min-width: 0; table-layout: fixed; border-collapse: collapse; font-size: 0.9em; }
.manual-table th, .manual-table td { border: 1px solid var(--border-color); padding: 0.55rem; text-align: left; vertical-align: top; }
.manual-table th { background: var(--primary-light); color: var(--primary-color); }
.manual-table th, .manual-table td { overflow-wrap: anywhere; }
.manual-mode-nav, .manual-toc { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px; border: 1px solid var(--border-color); border-radius: 6px; background: var(--primary-light); }
.manual-mode-nav a, .manual-toc a { color: var(--primary-color); font-weight: 700; }
.manual-note { padding: 10px 12px; border-left: 4px solid var(--primary-color); background: #f7faff; }
.manual-back { text-align: right; font-size: 0.9em; }

.scrap-title-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; }
.scrap-title-row h3 { margin: 0; }
.scrap-expand-button { flex: 0 0 auto; min-width: 34px; min-height: 32px; padding: 3px 8px; font-size: 1.05rem; line-height: 1; }
body.scrap-modal-open { overflow: hidden !important; }
.scrap-modal-overlay { position: fixed; inset: 0; z-index: 4100; display: flex; align-items: center; justify-content: center; padding: 4dvh 4vw; background: rgba(0, 0, 0, 0.58); }
.scrap-modal-overlay[hidden] { display: none; }
.scrap-modal { display: flex; flex-direction: column; width: min(88vw, 1100px); height: min(86dvh, 850px); min-width: 0; max-width: 100%; max-height: 100%; padding: 18px; overflow: hidden; border: 1px solid var(--border-color); border-radius: 8px; background: #fff; box-shadow: 0 18px 48px rgba(0, 0, 0, 0.28); }
.scrap-modal-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.scrap-modal-header h2 { margin: 0; color: var(--primary-color); font-size: 1.25rem; }
.scrap-modal-close { flex: 0 0 auto; min-width: 42px; min-height: 42px; padding: 4px 10px; font-size: 1.5rem; line-height: 1; }
.scrap-sort-label { display: flex; align-items: center; gap: 10px; margin: 12px 0; font-weight: 700; }
.scrap-sort-label select { min-width: 0; max-width: 100%; }
.scrap-modal-list { flex: 1 1 auto; min-height: 0; overflow-y: auto; overflow-x: hidden; border: 1px solid var(--border-color); border-radius: 5px; padding: 6px; white-space: pre-wrap; overflow-wrap: anywhere; }
.scrap-modal-row { padding: 9px 10px; border-bottom: 1px solid #e5e5e5; font-variant-numeric: tabular-nums; }
.scrap-modal-row:last-child { border-bottom: 0; }


/* Focus mode, compact mobile controls and touch drawing — 2026-08-03 revision 8 */
#resultSvg {
  display: block;
  width: 100%;
  height: 100%;
  max-width: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.svg-container {
  overscroll-behavior: contain;
}

.amazon-associate-disclosure {
  margin: 0 0 4px;
  font-size: 0.8em;
  line-height: 1.45;
}

/* Focus mode bar indicator. */
body.diagram-focus .resizer-vertical::before {
  background-color: var(--primary-color);
}

/*
 * PC focus mode:
 * - Keep the left input pane and the horizontal split position unchanged.
 * - Hide only the result summary in the right pane.
 * - Keep the diagram filter and boundary bar visible.
 * - Let the diagram use the right pane's remaining space.
 */
@media (min-width: 769px) {
  .project-controls {
    flex: 0 0 auto;
  }

  .project-bar > .support-banner-top {
    flex: 1 1 20rem;
    width: auto;
    max-width: 42vw;
    min-width: 0;
    min-height: 40px;
    margin: 0 0 0 auto;
    padding: 5px 8px;
    white-space: normal;
  }

  .project-bar > .support-banner-top .ad-text__link,
  .project-bar > .support-banner-top .ad-slot__destination {
    display: block;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  body.diagram-focus .input-panel,
  body.diagram-focus .main-container > .resizer {
    display: block !important;
    visibility: visible !important;
  }

  body.diagram-focus .output-panel {
    position: static;
    inset: auto;
    z-index: auto;
    display: flex !important;
    flex: 1 1 auto;
    width: auto;
    height: auto;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    box-shadow: none;
  }

  body.diagram-focus .output-panel > .stats {
    display: none !important;
  }

  body.diagram-focus .diagram-area {
    display: flex !important;
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    flex: 1 1 auto;
  }

  body.diagram-focus .filter-bar {
    display: flex !important;
    flex: 0 0 auto;
  }

  body.diagram-focus .resizer-vertical {
    display: block !important;
    flex: 0 0 14px;
  }

  body.diagram-focus:not(.diagram-focus-resized) .svg-container,
  body.diagram-focus:not(.diagram-focus-resized) .text-container,
  body.diagram-focus:not(.diagram-focus-resized) .card-container {
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    flex: 1 1 0 !important;
  }

  body.diagram-focus.diagram-focus-resized .svg-container,
  body.diagram-focus.diagram-focus-resized .text-container,
  body.diagram-focus.diagram-focus-resized .card-container {
    height: var(--diagram-content-height) !important;
    min-height: 200px !important;
    max-height: 85dvh !important;
    flex: 0 0 var(--diagram-content-height) !important;
  }
}

@media (max-width: 768px) {
  /* One compact row: [1D/2D] [theme] [font size]. */
  header .header-quick-controls {
    display: grid !important;
    grid-template-columns: minmax(0, 1.24fr) minmax(0, 1.05fr) minmax(0, 0.72fr) !important;
    align-items: stretch;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    flex: 0 0 100%;
    gap: 5px;
    overflow: hidden;
  }

  header .header-quick-controls > .mode-toggle {
    grid-column: auto;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
    min-width: 0;
    max-width: 100%;
    min-height: 42px;
    margin: 0;
    overflow: hidden;
  }

  header .mode-toggle button {
    width: auto;
    min-width: 0;
    max-width: none;
    min-height: 42px;
    padding: 7px 2px;
    gap: 0.1em;
    font-size: clamp(11px, 3.2vw, 14px);
    line-height: 1.1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: clip;
  }

  header .mode-toggle button::before {
    width: 0.78em;
    flex-basis: 0.78em;
  }

  header .header-quick-controls > select {
    display: block;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    min-height: 42px;
    padding: 6px 3px;
    font-size: clamp(11px, 3.1vw, 14px);
    text-overflow: ellipsis;
  }

  #graphicContainer,
  #resultSvg {
    touch-action: none !important;
  }

  /* Smartphone focus mode: keep only the diagram filter, boundary bar and diagram. */
  body.diagram-focus {
    height: 100dvh;
    min-height: 100dvh;
    overflow: hidden;
  }

  body.diagram-focus .ai-banner,
  body.diagram-focus > header,
  body.diagram-focus > .project-bar,
  body.diagram-focus > .support-banner-top,
  body.diagram-focus > .mobile-tabs,
  body.diagram-focus > .print-header,
  body.diagram-focus > footer,
  body.diagram-focus .stats,
  body.diagram-focus .input-panel,
  body.diagram-focus .main-container > .resizer {
    display: none !important;
  }

  body.diagram-focus .main-container {
    display: flex !important;
    width: 100%;
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
  }

  body.diagram-focus .output-panel {
    display: flex !important;
    width: 100%;
    height: 100dvh;
    min-height: 0;
    padding: 0;
    overflow: hidden;
    flex: 1 1 auto;
  }

  body.diagram-focus .diagram-area {
    display: flex !important;
    width: 100%;
    height: 100%;
    min-height: 0;
    flex: 1 1 auto;
    gap: 0;
  }

  body.diagram-focus .filter-bar {
    display: flex !important;
    margin: 0;
    padding: 7px 9px;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    flex: 0 0 auto;
  }

  body.diagram-focus .resizer-vertical {
    margin: 0;
    flex: 0 0 18px;
    height: 18px;
    background: var(--bg-color);
  }

  body.diagram-focus .svg-container,
  body.diagram-focus .text-container,
  body.diagram-focus .card-container {
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    flex: 1 1 auto !important;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
  }
}

@media (max-width: 360px) {
  header .header-quick-controls {
    gap: 3px;
    grid-template-columns: minmax(0, 1.18fr) minmax(0, 1fr) minmax(0, 0.68fr) !important;
  }

  header .mode-toggle button,
  header .header-quick-controls > select {
    font-size: 11px;
  }
}


.card-print-frame {
  position: fixed !important;
  left: -10000px !important;
  top: 0 !important;
  width: 210mm !important;
  height: 297mm !important;
  border: 0 !important;
  background: #fff !important;
  visibility: visible !important;
  opacity: 1 !important;
  pointer-events: none !important;
}

body.card-print-document {
  display: block !important;
  width: auto !important;
  height: auto !important;
  min-height: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
  overflow: visible !important;
  background: #fff !important;
  color: var(--text-color) !important;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

body.card-print-document .card-print-root {
  display: block !important;
  width: 100% !important;
  min-width: 0 !important;
  height: auto !important;
  overflow: visible !important;
}

body.card-print-document .print-summary-page {
  display: block !important;
  width: 100% !important;
  margin: 0 0 8mm !important;
  overflow: visible !important;
}

body.card-print-document .stats {
  display: block !important;
  width: 100% !important;
  margin: 0 !important;
}

body.card-print-document .stats-row {
  display: grid !important;
  grid-template-columns: repeat(auto-fit, minmax(42mm, 1fr)) !important;
  gap: 3mm !important;
  width: 100% !important;
}

body.card-print-document .stat-card,
body.card-print-document .stat-card.wide,
body.card-print-document .stat-card.full-width {
  min-width: 0 !important;
  height: auto !important;
  overflow: visible !important;
}

body.card-print-document .print-card-item {
  display: block !important;
  box-sizing: border-box !important;
  width: 100% !important;
  max-width: 100% !important;
  height: auto !important;
  margin: 0 0 5mm !important;
  overflow: visible !important;
  break-inside: avoid-page !important;
  page-break-inside: avoid !important;
  break-before: auto !important;
  page-break-before: auto !important;
}

body.card-print-document .print-card-item:last-child {
  margin-bottom: 0 !important;
}

body.card-print-document .print-card-item .card-parts {
  display: flex !important;
  flex-wrap: wrap !important;
  height: auto !important;
  overflow: visible !important;
}

body.card-print-document.print-monochrome .print-card-item {
  border-color: #000 !important;
  box-shadow: none !important;
}

body.card-print-document.print-monochrome .card-header,
body.card-print-document.print-monochrome .card-info,
body.card-print-document.print-monochrome .card-part,
body.card-print-document.print-monochrome .card-scrap {
  color: #000 !important;
}

body.card-print-document.print-monochrome .card-part,
body.card-print-document.print-monochrome .card-scrap {
  background: #fff !important;
  border: 1px solid #000 !important;
}


@page cut-list {
  size: A4 portrait;
  margin: 10mm;
}

.cut-list-print-frame {
  position: fixed !important;
  left: -10000px !important;
  top: 0 !important;
  width: 210mm !important;
  height: 297mm !important;
  border: 0 !important;
  background: #fff !important;
  visibility: visible !important;
  opacity: 1 !important;
  pointer-events: none !important;
}

body.cut-list-print-document {
  display: block !important;
  width: auto !important;
  min-width: 0 !important;
  height: auto !important;
  min-height: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
  overflow: visible !important;
  background: #fff !important;
  color: #111 !important;
  font-family: system-ui, -apple-system, "Yu Gothic", "YuGothic", "Meiryo", sans-serif !important;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

body.cut-list-print-document .cut-list-print-root {
  display: block !important;
  width: 190mm !important;
  max-width: 190mm !important;
  margin: 0 auto !important;
  padding: 0 !important;
}

body.cut-list-print-document .cut-list-print-page {
  page: cut-list;
  display: grid !important;
  grid-template-rows: auto minmax(0, 1fr) auto !important;
  box-sizing: border-box !important;
  width: 190mm !important;
  height: 275mm !important;
  min-height: 275mm !important;
  margin: 0 !important;
  padding: 0 !important;
  overflow: hidden !important;
  break-after: page !important;
  page-break-after: always !important;
}

body.cut-list-print-document .cut-list-print-page:last-child {
  break-after: auto !important;
  page-break-after: auto !important;
}

body.cut-list-print-document .cut-list-print-header {
  display: block !important;
  background: #fff !important;
  color: #111 !important;
  box-shadow: none !important;
  z-index: auto !important;
  box-sizing: border-box !important;
  margin: 0 0 2.8mm !important;
  padding: 0 0 2.4mm !important;
  border-bottom: 0.35mm solid #333 !important;
}

body.cut-list-print-document .cut-list-print-header h1 {
  margin: 0 !important;
  font-size: 15.5pt !important;
  line-height: 1.2 !important;
  font-weight: 700 !important;
  overflow-wrap: anywhere !important;
}

body.cut-list-print-document .cut-list-print-details {
  margin: 1.2mm 0 0 !important;
  font-size: 8.8pt !important;
  line-height: 1.3 !important;
  color: #444 !important;
}

body.cut-list-print-document .cut-list-print-page-body {
  display: block !important;
  box-sizing: border-box !important;
  min-height: 0 !important;
  overflow: hidden !important;
}

body.cut-list-print-document .cut-list-print-block {
  display: block !important;
  box-sizing: border-box !important;
  width: 100% !important;
  margin: 0 !important;
  padding: 2.2mm 1mm 2.4mm !important;
  border: 0 !important;
  border-bottom: 0.18mm solid #d2d2d2 !important;
  border-radius: 0 !important;
  background: #fff !important;
  break-inside: avoid-page !important;
  page-break-inside: avoid !important;
}

body.cut-list-print-document .cut-list-print-block:last-child {
  margin-bottom: 0 !important;
  border-bottom: 0 !important;
}

body.cut-list-print-document .cut-list-print-block h2 {
  margin: 0 !important;
  font-size: 10.2pt !important;
  line-height: 1.3 !important;
  font-weight: 700 !important;
  overflow-wrap: anywhere !important;
}

body.cut-list-print-document .cut-list-print-meta,
body.cut-list-print-document .cut-list-print-remnant {
  margin: 0.65mm 0 0 !important;
  font-size: 9.1pt !important;
  line-height: 1.32 !important;
  overflow-wrap: anywhere !important;
}

body.cut-list-print-document .cut-list-print-items {
  display: block !important;
  list-style: none !important;
  margin: 0.7mm 0 0 !important;
  padding: 0 0 0 2mm !important;
  font-size: 9.1pt !important;
  line-height: 1.32 !important;
}

body.cut-list-print-document .cut-list-print-items li {
  position: relative !important;
  min-width: 0 !important;
  margin: 0.25mm 0 !important;
  padding: 0 0 0 3mm !important;
  overflow-wrap: anywhere !important;
  break-inside: avoid !important;
  page-break-inside: avoid !important;
}

body.cut-list-print-document .cut-list-print-items li::before {
  content: "・";
  position: absolute;
  left: 0;
  top: 0;
}

body.cut-list-print-document .cut-list-print-remnant {
  padding-top: 0 !important;
  border-top: 0 !important;
  font-weight: 700 !important;
}

body.cut-list-print-document .cut-list-print-footer {
  display: block !important;
  background: #fff !important;
  box-sizing: border-box !important;
  min-height: 5.5mm !important;
  padding: 1.8mm 0 0 !important;
  border-top: 0.18mm solid #bbb !important;
  color: #555 !important;
  font-size: 8pt !important;
  line-height: 1 !important;
  text-align: right !important;
}

body.cut-list-print-document .cut-list-print-page-oversized {
  height: auto !important;
  min-height: 275mm !important;
  overflow: visible !important;
}

body.cut-list-print-document .cut-list-print-page-oversized .cut-list-print-page-body {
  height: auto !important;
  min-height: 0 !important;
  overflow: visible !important;
}

.print-diagram-pages {
  display: none;
}

/* Final print cascade: screen focus/mobile rules above must never reintroduce clipping. */
@media print {
  .card-print-frame,
  .cut-list-print-frame {
    display: none !important;
  }

  body,
  body.diagram-focus {
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
  }

  body.diagram-focus .input-panel,
  body.diagram-focus .main-container > .resizer,
  body.diagram-focus .filter-bar,
  body.diagram-focus .resizer-vertical {
    display: none !important;
  }

  body.diagram-focus .main-container,
  body.diagram-focus .output-panel {
    display: block !important;
    position: static !important;
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
    padding: 0 !important;
  }

  body.diagram-focus .output-panel > .stats {
    display: flex !important;
  }

  body.diagram-focus .diagram-area {
    display: block !important;
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
    gap: 0 !important;
  }

  body.diagram-focus .svg-container,
  body.diagram-focus .text-container,
  body.diagram-focus .card-container {
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow: visible !important;
    flex: none !important;
    border: 0 !important;
  }

  .stat-card .scrap-list {
    max-height: none !important;
    overflow: visible !important;
  }

  body.printing-graphic-pages #graphicContainer {
    display: none !important;
  }

  body.printing-graphic-pages > main {
    display: none !important;
  }

  body.printing-content-pages > main {
    display: none !important;
  }

  body.printing-card-fallback .card-container {
    display: block !important;
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow: visible !important;
  }

  body.printing-card-fallback .card-item {
    display: block !important;
    width: 100% !important;
    height: auto !important;
    overflow: visible !important;
    break-inside: avoid-page !important;
    page-break-inside: avoid !important;
  }

  body.printing-graphic-pages > #printHeader {
    display: none !important;
  }

  body.printing-content-pages > #printHeader {
    display: none !important;
  }

  body.printing-graphic-pages > .print-diagram-pages {
    display: block !important;
    width: 100% !important;
  }

  body.printing-content-pages > .print-diagram-pages {
    display: block !important;
    width: 100% !important;
  }

  .print-summary-page {
    display: block !important;
    width: 100% !important;
    min-width: 0 !important;
    overflow: visible !important;
  }

  .print-page-limit-notice {
    display: block !important;
    box-sizing: border-box;
    width: 100% !important;
    margin: 20mm auto 0 !important;
    padding: 12mm !important;
    border: 1px solid #333 !important;
    break-inside: avoid-page;
    page-break-inside: avoid;
  }

  .print-page-limit-notice h1 {
    margin: 0 0 8mm !important;
    font-size: 18pt !important;
  }

  .print-page-limit-notice p {
    margin: 0 !important;
    font-size: 12pt !important;
    line-height: 1.7 !important;
  }


  .print-content-item {
    display: table !important;
    box-sizing: border-box !important;
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    margin: 0 0 5mm !important;
    overflow: visible !important;
    break-inside: avoid-page !important;
    page-break-inside: avoid !important;
    break-before: auto !important;
    page-break-before: auto !important;
  }

  .print-content-item:last-child {
    margin-bottom: 0 !important;
  }

  .print-card-item .card-parts {
    display: flex !important;
    flex-wrap: wrap !important;
  }

  .print-text-item {
    white-space: pre-wrap !important;
    word-break: break-all !important;
    overflow-wrap: break-word !important;
  }
  .print-diagram-row {
    display: block !important;
    box-sizing: border-box;
    width: var(--print-diagram-width, 180mm) !important;
    min-width: 1mm !important;
    max-width: 180mm !important;
    height: var(--print-diagram-height, 180mm) !important;
    min-height: 1mm !important;
    max-height: 180mm !important;
    margin: 0 auto 5mm !important;
    padding: 0 !important;
    overflow: hidden !important;
    break-inside: avoid-page !important;
    page-break-inside: avoid !important;
    break-before: auto !important;
    page-break-before: auto !important;
    break-after: auto !important;
    page-break-after: auto !important;
  }

  .print-diagram-row:last-child {
    margin-bottom: 0 !important;
  }

  .print-diagram-row svg {
    display: block !important;
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    max-height: 100% !important;
    margin: 0 auto !important;
    overflow: hidden !important;
  }
}

/* V34 desktop command bar: visual-only regrouping of existing controls. */
@media screen {
  /* V36: header menus must stay above the project bar.
     V35 raised the project bar to expose its own popover, which caused the
     upper portion of header popovers to be painted underneath it. */
  header {
    z-index: 200;
  }

  .toolbar-menu {
    position: relative;
    flex: 0 0 auto;
  }

  .toolbar-menu > summary {
    list-style: none;
    cursor: pointer;
    user-select: none;
  }

  .toolbar-menu > summary::-webkit-details-marker {
    display: none;
  }

  header .toolbar-menu > summary,
  .toolbar-primary-action {
    min-height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 7px 11px;
    border: 1px solid rgba(255, 255, 255, 0.62);
    border-radius: 6px;
    color: #fff;
    background: rgba(255, 255, 255, 0.08);
    font-size: 0.88rem;
    font-weight: 650;
    white-space: nowrap;
    transition: background-color 0.18s, border-color 0.18s;
  }

  header .toolbar-menu > summary::after,
  .project-actions-menu > summary::after {
    content: "▾";
    font-size: 0.7em;
    opacity: 0.82;
  }

  header .toolbar-menu[open] > summary,
  header .toolbar-menu > summary:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: #fff;
  }

  .toolbar-primary-action {
    border-color: #fff;
    background: #fff;
    color: var(--primary-color);
    font-weight: 750;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.16);
  }

  .toolbar-primary-action:hover {
    background: var(--primary-light);
    color: var(--primary-color);
  }

  .toolbar-primary-action:disabled {
    color: #666;
    background: #ddd;
    border-color: #ddd;
  }

  .toolbar-popover {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 120;
    width: max-content;
    min-width: 230px;
    max-width: min(340px, calc(100vw - 24px));
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: #fff;
    color: var(--text-color);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.2);
  }

  #viewMenu .toolbar-popover {
    min-width: 285px;
  }

  .toolbar-field {
    display: grid;
    grid-template-columns: minmax(82px, auto) minmax(120px, 1fr);
    align-items: center;
    gap: 10px;
    font-size: 0.88rem;
  }

  .toolbar-field + .toolbar-field,
  .toolbar-checks,
  .toolbar-action-list > * + * {
    margin-top: 9px;
  }

  .toolbar-field select {
    width: 100%;
    min-width: 0;
  }

  .toolbar-checks {
    display: grid;
    gap: 8px;
    padding-top: 9px;
    border-top: 1px solid #e8e8e8;
  }

  .toolbar-checks label {
    display: flex;
    align-items: center;
    gap: 7px;
    cursor: pointer;
    font-size: 0.88rem;
  }

  .toolbar-action-list {
    display: flex;
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar-action-list button,
  .toolbar-link {
    width: 100%;
    min-height: 36px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding: 8px 10px;
    border-radius: 5px;
    text-decoration: none;
    text-align: left;
  }

  .toolbar-action-list hr {
    width: 100%;
    height: 1px;
    margin: 10px 0 1px;
    border: 0;
    background: #e4e4e4;
  }

  .toolbar-link {
    background: var(--secondary-color);
    color: #fff;
    font-size: 0.9em;
  }

  .toolbar-link:hover {
    background: var(--accent-color);
  }

  .project-actions-menu > summary {
    min-height: 34px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    color: var(--text-color);
    background: var(--btn-bg);
    font-size: 0.86rem;
    font-weight: 650;
  }

  .project-actions-menu[open] > summary,
  .project-actions-menu > summary:hover {
    background: var(--btn-hover);
  }

  .project-actions-menu .toolbar-popover {
    left: auto;
    right: 0;
    min-width: 190px;
  }

  /* Keep the project popover outside the bar's former scroll clipping area. */
  .project-bar {
    position: relative;
    z-index: 130;
    overflow: visible;
  }

  .display-desktop-status {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-width: 0;
  }

  #displayStatusText {
    min-width: 0;
    color: #555;
    font-weight: 600;
  }

  .display-settings-shortcut {
    margin-left: auto;
    padding: 5px 9px;
    font-size: 0.82rem;
    background: var(--btn-bg);
    color: var(--btn-text);
    border: 1px solid var(--btn-border);
  }

  .display-settings-shortcut:hover {
    background: var(--btn-hover);
    color: var(--btn-text);
  }

  .display-mobile-controls {
    display: none;
  }
}

@media screen and (min-width: 1301px) {
  header {
    flex-wrap: nowrap;
    gap: 14px;
    padding: 8px 16px;
  }

  .header-left {
    width: auto;
    min-width: 0;
    flex: 1 1 auto;
    justify-content: flex-start;
  }

  .header-title-group {
    min-width: 0;
  }

  .header-quick-controls {
    flex: 0 0 auto;
    margin-left: auto;
  }

  .header-controls {
    width: auto;
    flex: 0 0 auto;
    flex-wrap: nowrap;
    gap: 6px;
    overflow: visible;
  }

  .appearance-quick-control {
    display: none;
  }
}

@media screen and (min-width: 769px) and (max-width: 1300px) {
  header {
    gap: 8px;
  }

  .header-controls {
    justify-content: flex-end;
    flex-wrap: nowrap;
    gap: 6px;
    overflow: visible;
  }

  .appearance-quick-control {
    display: none;
  }
}

@media screen and (max-width: 768px) {
  .project-bar {
    display: contents;
  }

  .project-controls {
    position: relative;
    z-index: 130;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border-color);
    background-color: white;
    font-size: 0.9em;
    overflow: visible;
    white-space: nowrap;
  }

  .appearance-quick-control {
    display: block;
    min-width: 0;
  }

  .appearance-quick-control select {
    width: 100%;
    height: 100%;
    min-width: 0;
  }

  header .header-controls.show {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
    overflow: visible;
    white-space: normal;
    padding-bottom: 4px;
  }

  .header-controls > .toolbar-primary-action {
    grid-column: 1 / -1;
  }

  header .toolbar-menu {
    width: 100%;
  }

  header .toolbar-menu > summary {
    width: 100%;
  }

  header .toolbar-popover {
    position: static;
    width: 100%;
    min-width: 0;
    max-width: none;
    margin-top: 6px;
    box-shadow: none;
  }

  .desktop-view-menu,
  .desktop-only-control {
    display: none;
  }

  .display-desktop-status {
    display: none;
  }

  .display-mobile-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    min-width: 0;
    overflow-x: auto;
    white-space: nowrap;
  }

  .display-mobile-controls > * {
    flex: 0 0 auto;
  }

  .project-bar {
    overflow: visible;
  }

  #projectSelector {
    min-width: 0;
    flex: 1 1 auto;
  }

  .project-actions-menu .toolbar-popover {
    right: 0;
    left: auto;
  }
}


/* v3.8.1: visible version, guarded advanced settings, and off-screen rendering containment. */
.app-version {
  display: inline-block;
  margin-left: 0.45em;
  font-size: 0.68em;
  font-weight: 500;
  line-height: 1;
  opacity: 0.76;
  vertical-align: 0.08em;
  white-space: nowrap;
}

.scrap-threshold-setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
  font-size: 0.9rem;
}

.scrap-threshold-input {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.scrap-threshold-input input {
  width: 7.5rem;
  max-width: 42vw;
}

.advanced-menu {
  width: 100%;
  margin-top: 9px;
  border-top: 1px solid #e4e4e4;
  padding-top: 9px;
}

.advanced-menu > summary {
  min-height: 36px;
  display: flex;
  align-items: center;
  padding: 8px 10px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 0.9em;
  font-weight: 650;
  user-select: none;
}

.advanced-menu > summary:hover {
  background: var(--primary-light);
}

.advanced-menu-actions {
  padding: 6px 0 0 12px;
}

.toolbar-action-list .advanced-menu-actions button.danger-subtle {
  color: #9b1c1c;
  border-color: #e7b6b6;
  background: #fffafa;
}

/* Skip layout/paint work for off-screen blocks inside long result lists. */
@media screen {
  .card-item,
  .text-print-block {
    content-visibility: auto;
    contain-intrinsic-size: auto 96px;
  }
}

@media (max-width: 768px) {
  .scrap-threshold-setting {
    align-items: flex-start;
    flex-direction: column;
    gap: 6px;
  }
  .scrap-threshold-input input {
    max-width: min(12rem, 70vw);
  }
}

@media print {
  .card-item,
  .text-print-block {
    content-visibility: visible !important;
    contain-intrinsic-size: none !important;
  }
}
