* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --success: #16a34a;
    --danger: #dc2626;
    --text: #1e293b;
    --muted: #64748b;
    --border: #dbe3ef;
    --panel: #ffffff;
    --panel-soft: #f8fafc;
    --workspace: #eef3f9;
    --shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
    --radius: 12px;
}

html,
body {
    width: 100%;
    height: 100%;
}

body {
    font-family:
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        "Noto Sans TC",
        Roboto,
        Arial,
        sans-serif;
    background:
        radial-gradient(circle at top right, rgba(37, 99, 235, 0.07), transparent 30%),
        var(--workspace);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
}

/* ---------- Main layout ---------- */

.app-container {
    display: flex;
    width: 100%;
    height: 100vh;
}

/* ---------- Left control panel ---------- */

.sidebar {
    width: 450px;
    min-width: 450px;
    background: rgba(255, 255, 255, 0.96);
    border-right: 1px solid var(--border);
    padding: 20px 18px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow-y: auto;
    box-shadow: 6px 0 24px rgba(15, 23, 42, 0.06);
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar::-webkit-scrollbar {
    width: 7px;
}

.sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 99px;
}

.sidebar h2 {
    padding: 2px 4px 4px;
    font-size: 1.3rem;
    font-weight: 750;
    letter-spacing: 0.2px;
    color: #0f172a;
}

.sidebar h2::after {
    content: "Chromosome / Gene Layout Tool";
    display: block;
    margin-top: 4px;
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 450;
    letter-spacing: 0.3px;
}

.sidebar h3 {
    font-size: 0.88rem;
    font-weight: 700;
    color: #334155;
    margin-bottom: 7px;
}

/* Desktop Collapsed Sidebar State */
.app-container.sidebar-collapsed .sidebar {
    margin-left: -450px;
    opacity: 0;
    pointer-events: none;
}

/* ---------- Sidebar Toggle Button ---------- */

.sidebar-toggle-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    margin-right: 12px;
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: #334155;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.06);
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.sidebar-toggle-btn:hover {
    background: #f1f5f9;
    color: #0f172a;
    border-color: #cbd5e1;
}

.sidebar-toggle-btn:active {
    transform: scale(0.95);
}

/* Toggle Icon Rotation Modes */
.toggle-icon {
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    transform: rotate(0deg); /* Desktop Open: Inward Left Arrow */
}

/* Desktop Collapsed Mode: Outward Right Arrow */
.app-container.sidebar-collapsed .toggle-icon {
    transform: rotate(180deg);
}

/* ---------- Buttons ---------- */

.btn-group {
    display: flex;
    gap: 8px;
}

.btn {
    flex: 1;
    min-height: 38px;
    padding: 8px 12px;
    font-size: 0.84rem;
    font-weight: 700;
    border: 1px solid transparent;
    border-radius: 99px;
    cursor: pointer;
    transition:
        transform 0.15s ease,
        box-shadow 0.15s ease,
        background-color 0.15s ease,
        border-color 0.15s ease;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn:active {
    transform: translateY(0);
}

.btn:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 3px solid rgba(37, 99, 235, 0.18);
    outline-offset: 1px;
}

.btn.primary {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: #fff;
    box-shadow: 0 5px 14px rgba(37, 99, 235, 0.22);
}

.btn.primary:hover {
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
}

.btn.secondary {
    background: #f1f5f9;
    color: #334155;
    border-color: #dbe3ef;
}

.btn.secondary:hover {
    background: #e2e8f0;
}

.btn.danger {
    background: #fff1f2;
    color: #b91c1c;
    border-color: #fecdd3;
}

.btn.danger:hover {
    background: #ffe4e6;
}

.btn.success {
    background: linear-gradient(135deg, #22c55e, #16a34a);
    color: #fff;
    box-shadow: 0 5px 14px rgba(22, 163, 74, 0.18);
}

.btn.success:hover {
    background: linear-gradient(135deg, #16a34a, #15803d);
}

/* ---------- Configuration cards ---------- */

.config-section {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 11px 13px;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.025);
    transition:
        border-color 0.2s ease,
        box-shadow 0.2s ease;
}

.config-section:hover {
    border-color: #c7d5e8;
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.045);
}

.config-section summary {
    position: relative;
    padding: 1px 22px 1px 2px;
    font-weight: 700;
    font-size: 0.86rem;
    color: #1e3a8a;
    cursor: pointer;
    user-select: none;
    list-style: none;
}

.config-section summary::-webkit-details-marker {
    display: none;
}

.config-section summary::after {
    content: "›";
    position: absolute;
    right: 2px;
    top: 50%;
    transform: translateY(-55%) rotate(0deg);
    color: #64748b;
    font-size: 1.15rem;
    transition: transform 0.2s ease;
}

.config-section[open] summary::after {
    transform: translateY(-55%) rotate(90deg);
}

.config-section[open] summary {
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid #edf2f7;
}

/* ---------- Form ---------- */

.form-row {
    display: flex;
    flex-wrap: wrap;
    gap: 7px 10px;
    align-items: center;
    margin-bottom: 8px;
    font-size: 0.79rem;
    color: #475569;
}

.form-row:last-child {
    margin-bottom: 0;
}

.form-row label {
    display: flex;
    align-items: center;
    gap: 5px;
    min-height: 28px;
}

.form-row input[type="text"],
.form-row input[type="number"],
.form-row select {
    height: 29px;
    padding: 4px 8px;
    border: 1px solid #cbd5e1;
    border-radius: 7px;
    font-family: inherit;
    font-size: 0.78rem;
    color: #1e293b;
    width: 76px;
    background: #fff;
    transition:
        border-color 0.15s ease,
        box-shadow 0.15s ease;
}

.form-row input[type="text"]:focus,
.form-row input[type="number"]:focus,
.form-row select:focus,
textarea:focus {
    border-color: #60a5fa;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.08);
    outline: none;
}

.form-row select {
    width: auto;
    max-width: 245px;
}

.form-row input[type="text"] {
    width: 88px;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
    margin-top: 6px;
}

.input-group + .input-group {
    margin-top: 11px;
}

.input-group label {
    font-size: 0.78rem;
    font-weight: 700;
    color: #475569;
}

.input-group small {
    color: #94a3b8;
    font-weight: 500;
}

textarea {
    width: 100%;
    padding: 9px 10px;
    min-height: 82px;
    font-family: "Cascadia Code", "Consolas", monospace;
    font-size: 0.77rem;
    line-height: 1.5;
    color: #334155;
    background: #fbfdff;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    resize: vertical;
    transition:
        border-color 0.15s ease,
        box-shadow 0.15s ease;
}

textarea::placeholder {
    color: #a0aec0;
}

/* ---------- Export ---------- */

.export-group {
    padding: 12px 13px;
    background: linear-gradient(135deg, #f8fafc, #f1f5f9);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.export-controls {
    display: flex;
    gap: 8px;
}

.export-controls select {
    flex: 1;
    min-width: 0;
    height: 36px;
    padding: 6px 9px;
    border-radius: 8px;
    border: 1px solid #cbd5e1;
    background: #fff;
    color: #334155;
    font-size: 0.8rem;
}

/* ---------- Copyright ---------- */

.copyright-section {
    padding: 10px 16px;
    font-size: 0.75rem;
    line-height: 1.5;
    color: var(--muted);
    background: rgba(255, 255, 255, 0.94);
    border-top: 1px solid var(--border);
    text-align: center;
    backdrop-filter: blur(8px);
}

.copyright-section p:first-child {
    color: #475569;
}

.copyright-section p + p {
    margin-top: 2px;
}

/* ---------- Preview area ---------- */

.main-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    background:
        linear-gradient(rgba(148, 163, 184, 0.08) 1px, transparent 1px),
        linear-gradient(90deg, rgba(148, 163, 184, 0.08) 1px, transparent 1px),
        #f1f5f9;
    background-size: 24px 24px;
    overflow: hidden;
}

.canvas-header {
    display: flex;
    align-items: center;
    min-height: 58px;
    padding: 12px 22px;
    background: rgba(255, 255, 255, 0.94);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
    backdrop-filter: blur(8px);
}

.canvas-header h3 {
    font-size: 0.98rem;
    font-weight: 750;
    color: #1e293b;
}

.canvas-header small {
    color: #718096;
    font-weight: normal;
    margin-left: 8px;
}

.svg-viewport {
    flex: 1;
    min-height: 0;
    padding: 24px;
    overflow: auto;
    cursor: grab;
    user-select: none;
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;
    display: flex;
}

.svg-viewport::-webkit-scrollbar {
    width: 9px;
    height: 9px;
}

.svg-viewport::-webkit-scrollbar-track {
    background: transparent;
}

.svg-viewport::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 99px;
}

.svg-viewport.grabbing {
    cursor: grabbing;
}

.svg-container {
    display: inline-block;
    min-width: 100px;
    min-height: 100px;
    margin: auto;
    flex-shrink: 0;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    box-shadow:
        0 12px 30px rgba(15, 23, 42, 0.10),
        0 2px 6px rgba(15, 23, 42, 0.05);
    overflow: hidden;
}

.placeholder-msg {
    color: #94a3b8;
    padding: 90px 50px;
    text-align: center;
    font-size: 0.92rem;
}

svg {
    display: block;
    border-radius: 13px;
}

/* ---------- Responsive ---------- */

@media (max-width: 900px) and (min-width: 701px) {
    .sidebar {
        width: 350px;
        min-width: 350px;
    }

    .app-container.sidebar-collapsed .sidebar {
        margin-left: -350px;
    }

    .svg-viewport {
        padding: 18px;
    }
}

@media (max-width: 700px) {
    body {
        overflow: auto;
    }

    .app-container {
        min-height: 100vh;
        height: auto;
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        min-width: 0;
        max-height: 58vh;
        border-right: 0;
        border-bottom: 1px solid var(--border);
        transition: max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                    padding 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                    opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .app-container.sidebar-collapsed .sidebar {
        margin-left: 0;
        max-height: 0;
        padding-top: 0;
        padding-bottom: 0;
        overflow: hidden;
        border-bottom: none;
        opacity: 0;
        pointer-events: none;
    }

    /* Mobile Open Mode: Upward Close Arrow */
    .toggle-icon {
        transform: rotate(90deg);
    }

    /* Mobile Collapsed Mode: Downward Open Arrow */
    .app-container.sidebar-collapsed .toggle-icon {
        transform: rotate(270deg);
    }

    .main-content {
        min-height: 42vh;
    }

    .svg-viewport {
        min-height: 360px;
    }
}
