/* Toolbar group for consistent button alignment */
.toolbar-group {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

/* Unified toolbar button style */
.toolbar-btn {
    background: var(--toolbar-btn);
    color: var(--toolbar-btn-text);
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.3s;
    font-family: inherit;
    appearance: none;
    outline: none;
}

.toolbar-btn:hover, .toolbar-btn:focus {
    background: var(--toolbar-btn-hover);
}

/* Presets dropdown (base structure) */
.presets-dropdown {
    position: relative;
    display: inline-block;
}

.presets-menu {
    position: absolute;
    right: 0;
    top: 100%;
    min-width: 260px;
    background: var(--help-menu-bg);
    border: 1px solid var(--help-menu-border);
    border-radius: 6px;
    padding: 0.25rem;
    box-shadow: 0 6px 20px var(--panel-shadow);
    display: none; /* hidden by default */
    z-index: 1000;
    color: var(--help-menu-text);
}

.presets-dropdown.is-open .presets-menu {
    display: block;
}

/* Open Presets menu on hover or focus within */
.presets-dropdown:hover .presets-menu,
.presets-dropdown:focus-within .presets-menu {
    display: block;
}

.preset-item {
    display: block;
    width: 100%;
    text-align: left;
    padding: 0.5rem 0.75rem;
    background: transparent;
    border: 0;
    cursor: pointer;
    border-radius: 4px;
    font: inherit;
    color: var(--help-menu-text);
    text-decoration: none;
}

.preset-item:hover,
.preset-item:focus {
    background: var(--help-item-hover);
    outline: none;
}

/* Help dropdown (restored) */
.help-dropdown {
    position: relative;
    display: inline-block;
}

.help-menu {
    position: absolute;
    right: 0;
    top: 100%;
    min-width: 350px;
    background: var(--help-menu-bg);
    border: 1px solid var(--help-menu-border);
    border-radius: 6px;
    padding: 0.25rem;
    box-shadow: 0 6px 20px var(--panel-shadow);
    display: none;
    z-index: 1000;
    color: var(--help-menu-text);
}

.help-dropdown.is-open .help-menu { display: block; }

/* Hover/focus open (kept for desktop convenience) */
.help-dropdown:hover .help-menu,
.help-dropdown:focus-within .help-menu { display: block; }

.help-item {
    display: block;
    width: 100%;
    text-align: left;
    padding: 0.5rem 0.75rem;
    background: transparent;
    border: 0;
    cursor: pointer;
    border-radius: 4px;
    font: inherit;
    color: var(--help-menu-text);
    text-decoration: none;
}

.help-item:hover,
.help-item:focus {
    background: var(--help-item-hover);
    outline: none;
}

/* Modal (restored) */
.modal {
    position: fixed;
    inset: 0;
    background: var(--modal-overlay);
    display: none; /* toggled via class */
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 2rem;
}
.modal.show { display: flex; }
.modal-dialog {
    background: var(--modal-bg);
    color: var(--modal-text);
    width: min(900px, 92vw);
    max-height: 84vh;
    border-radius: 10px;
    box-shadow: 0 10px 30px var(--panel-shadow);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--modal-border);
}
.modal-header h3 { margin: 0; font-size: 1.2rem; }
.modal-close {
    background: transparent;
    border: none;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    color: var(--modal-close-text);
}
.modal-close:hover { color: var(--modal-close-hover); }
.modal-body {
    padding: 1rem 1.25rem;
    overflow: auto;
    line-height: 1.35;
    color: var(--modal-text);
}
.modal-body p { margin-bottom: 0.5rem; }
.modal-body ul { margin-left: 1.25rem; }

/* Make select look like a button */
select.toolbar-btn {
    position: relative;
    padding-right: 2.2em; /* leave space for caret */
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    min-width: 110px;
}
select.toolbar-btn::after {
    content: "▾";
    position: absolute;
    right: 0.7em;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
    color: var(--toolbar-btn-text);
}
/* Expandable section for text card options */
.expand-btn {
    margin: 1rem 0 0.5rem 0;
    background: var(--expand-btn-bg);
    border: none;
    border-radius: 4px;
    padding: 0.3rem 0.8rem;
    font-size: 0.95em;
    cursor: pointer;
    color: var(--expand-btn-text);
    transition: background 0.2s;
}
.expandable-section {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s cubic-bezier(0.4,0,0.2,1);
    background: var(--expand-panel-bg);
    border-radius: 4px;
    margin-bottom: 0.5rem;
    padding: 0 0.5rem;
}
.expandable-section.expanded {
    max-height: 500px;
    padding: 1rem 0.5rem;
}

        /* Dark-mode appearance driven solely by CSS variables.
           This media query is now kept minimal to ensure the browser
           advertises dark color-scheme capability without overriding
           explicit data-theme switching. */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    color: var(--body-text);
    background: var(--body-bg);
}

/* Hint browsers that both light and dark color schemes are supported */
:root {
    color-scheme: light dark;
}

/* Header */
header {
    background: linear-gradient(135deg, var(--header-bg-from) 0%, var(--header-bg-to) 100%);
    color: var(--header-text);
    padding: 0.9rem 1.5rem; /* reduced height */
    box-shadow: 0 2px 10px var(--panel-shadow);
}

nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

nav h1 {
    font-size: 1.7rem; /* slightly smaller */
    margin-bottom: 0.2rem; /* tighter */
}

nav p {
    font-size: 0.95rem;
    opacity: 0.9;
}

/* File Menu Styles */
.file-menu {
    position: relative;
    display: inline-block;
}

.file-menu-btn {
    background: var(--toolbar-btn);
    color: var(--toolbar-btn-text);
    border: none;
    padding: 8px 16px;
    cursor: pointer;
    border-radius: 4px;
    font-size: 14px;
    transition: background-color 0.3s;
}

.file-menu-btn:hover {
    background: var(--toolbar-btn-hover);
}

/* Import Bar Styles */
.import-bar {
    background: var(--import-bar-bg);
    border-top: 1px solid var(--import-bar-border);
    padding: 1rem 2rem;
    position: relative;
    backdrop-filter: blur(10px);
}

.import-content {
    max-width: 800px;
    margin: 0 auto;
}

.import-content label {
    display: block;
    color: var(--import-bar-text);
    font-weight: 500;
    margin-bottom: 0.5rem;
    font-size: 14px;
}

.import-bar .close-btn {
    position: absolute;
    top: 12px;
    right: 16px;
    background: transparent;
    border: none;
    font-size: 20px;
    color: var(--import-bar-close-btn-text);
    cursor: pointer;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.3s;
}

.import-bar .close-btn:hover {
    background: var(--import-bar-close-btn-hover);
    color: var(--body-text);
}

.import-bar input[type="text"] {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--input-border);
    border-radius: 4px;
    font-size: 14px;
    font-family: 'Courier New', monospace;
    margin-bottom: 0.75rem;
    background: var(--input-bg);
    color: var(--input-text);
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.1);
}

.import-bar input[type="text"]:focus {
    outline: none;
    border-color: var(--input-border-focus);
    box-shadow: 0 0 0 2px var(--focus-ring-shadow);
}

.import-bar textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--input-border);
    border-radius: 4px;
    font-size: 14px;
    font-family: 'Courier New', monospace;
    margin-bottom: 0.75rem;
    background: var(--input-bg);
    color: var(--input-text);
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.1);
    resize: none; /* Removes the corner grip */
    min-height: 70px;
    max-height: 70px;
    overflow: hidden; /* Removes the scroll bar */
    line-height: 1.4;
}

.import-bar textarea:focus {
    outline: none;
    border-color: var(--input-border-focus);
    box-shadow: 0 0 0 2px var(--focus-ring-shadow);
}

.import-bar .import-buttons {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
}

.import-bar .import-buttons button {
    background: var(--section-header-text);
    color: var(--primary-btn-text);
    border: none;
    padding: 8px 20px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.3s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.import-bar .import-buttons button:hover {
    background: var(--section-header-border);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.import-bar .import-buttons button:last-child {
    background: var(--secondary-btn);
}

.import-bar .import-buttons button:last-child:hover {
    background: var(--secondary-btn-hover);
}

/* Persistent Error Banner */
.error-banner {
    background: linear-gradient(135deg, var(--error-banner-bg-from) 0%, var(--error-banner-bg-to) 100%);
    color: var(--error-banner-text);
    padding: 12px 20px;
    box-shadow: 0 2px 8px var(--error-banner-shadow);
    z-index: 1000;
    position: sticky;
    top: 0;
    animation: slideDown 0.3s ease;
}

.error-content {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    max-width: 1200px;
    margin: 0 auto;
}

.error-icon {
    font-size: 18px;
    animation: pulse 2s infinite;
}

.error-message {
    font-weight: 500;
    font-size: 14px;
}

@keyframes slideDown {
    from { transform: translateY(-100%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* Main App Container - Vertical Sandwich Layout */
.app-container {
    display: flex;
    flex-direction: column;
    gap: 1.25rem; /* tighter vertical spacing */
    padding: 1.25rem; /* reduce outer padding */
    min-height: calc(100vh - 120px);
}

/* Side-by-side layout (restored) */
.side-by-side {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

@media (min-width: 1000px) {
    .side-by-side {
        flex-direction: row;
        align-items: flex-start;
        gap: 2.5rem;
    }
    .preview-section, .output-section {
        flex: 1 1 0;
        min-width: 0;
        max-width: 50%;
    }
    .preview-section { margin-right: 0; }
    .output-section { margin-left: 0; }
}

/* Section Headers */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--section-header-border);
}

.section-header h2 {
    color: var(--section-header-text);
    font-size: 1.5rem;
}

.shape-selector {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.shape-selector label {
    font-weight: 500;
    color: var(--section-header-text);
}

.shape-selector select {
    padding: 0.4rem 0.8rem;
    border: 2px solid var(--input-border);
    border-radius: 4px;
    font-size: 0.9rem;
    background: var(--input-bg);
    color: var(--input-text);
    cursor: pointer;
    transition: border-color 0.3s ease;
}

.shape-selector select:focus {
    outline: none;
    border-color: var(--input-border-focus);
}

.preview-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.zoom-controls {
    display: flex;
    gap: 0.25rem;
}

.zoom-controls button {
    padding: 0.4rem 0.6rem;
    border: 2px solid var(--zoom-btn-border);
    border-radius: 4px;
    background: var(--zoom-btn-bg);
    color: var(--body-text);
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.3s ease;
    min-width: 35px;
}

.zoom-controls button:hover {
    border-color: var(--zoom-btn-hover-border);
    background: var(--zoom-btn-hover-bg);
    transform: scale(1.05);
}

.zoom-controls button:active {
    transform: scale(0.95);
}



/* Design Section */
.design-section {
    background: var(--panel-bg);
    padding: 1.25rem; /* was 2rem */
    border-radius: 10px;
    box-shadow: 0 5px 15px var(--panel-shadow);
}

.add-button {
    background: var(--primary-btn);
    color: var(--primary-btn-text);
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.3s ease;
}

.add-button:hover:not(:disabled) {
    background: var(--primary-btn-hover);
    transform: translateY(-2px);
}

.add-button:disabled {
    background: var(--secondary-btn);
    cursor: not-allowed;
    transform: none;
}

.plus-button {
    background: var(--primary-btn);
    color: var(--primary-btn-text);
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    cursor: pointer;
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    flex-shrink: 0;
    align-self: center;
}

.plus-button:hover:not(:disabled) {
    background: var(--primary-btn-hover);
    transform: scale(1.1);
}

.plus-button:disabled {
    background: var(--secondary-btn);
    cursor: not-allowed;
    opacity: 0.5;
}

.cards-grid {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    align-content: flex-start;
}

.plus-button {
    background: var(--primary-btn);
    color: var(--primary-btn-text);
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    cursor: pointer;
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    flex-shrink: 0;
    align-self: center;
}

.plus-button:hover:not(:disabled) {
    background: var(--primary-btn-hover);
    transform: scale(1.1);
}

.plus-button:disabled {
    background: var(--secondary-btn);
    cursor: not-allowed;
    opacity: 0.5;
}

/* Ensure proper spacing when wrapping */
.plus-button {
    margin: 0.5rem 0;
}

.cards-container {
    min-height: 150px;
    border: 2px dashed var(--input-border);
    border-radius: 8px;
    padding: 0.75rem; /* tighter */
    background: var(--cards-bg-container);
}

.element-card {
    background: var(--card-bg);
    border: 2px solid var(--card-border);
    border-radius: 8px;
    padding: 0.75rem; /* tighter */
    cursor: default;
    transition: all 0.3s ease;
    min-width: 160px;
    flex-shrink: 0;
    margin: 0.5rem 0;
    position: relative;
}

.element-card.dash-card {
    width: 180px;
    min-width: unset;
}

.element-card.text-card {
    width: 280px;
    min-width: unset;
}

.element-card:hover {
    border-color: var(--card-hover-border);
    box-shadow: 0 3px 10px var(--card-hover-shadow);
}

.element-card.dragging {
    opacity: 0.7;
    transform: rotate(3deg) scale(0.95);
    z-index: 1000;
    box-shadow: 0 10px 25px rgba(0,0,0,0.3);
}

.element-card.drag-over {
    border-color: var(--card-drag-border);
    background: var(--card-drag-bg);
    transform: scale(1.02);
    box-shadow: 0 5px 20px var(--card-drag-shadow);
    position: relative;
}

.element-card.drag-over::before {
    content: 'Drop here to reorder';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--drag-indicator-bg);
    color: var(--primary-btn-text);
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: bold;
    pointer-events: none;
    z-index: 10;
}



/* Preview Section */
.preview-section {
    background: var(--panel-bg);
    padding: 1.25rem; /* was 2rem */
    border-radius: 10px;
    box-shadow: 0 5px 15px var(--panel-shadow);
}

.preview-window {
    height: 320px; /* reduced default height */
    border: 2px solid var(--input-border);
    border-radius: 8px;
    position: relative;
    overflow: hidden;
    background: var(--panel-bg);
}

.grid-background {
    /* Grid is now drawn dynamically on canvas */
    display: none;
}

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

/* Output Section */
.output-section {
    background: var(--panel-bg);
    padding: 1.25rem; /* was 2rem */
    border-radius: 10px;
    box-shadow: 0 5px 15px var(--panel-shadow);
}

/* Output Row Layout */
.output-row {
    display: flex;
    gap: 1.25rem; /* tighter spacing */
    align-items: flex-start;
}

.linetype-info {
    flex: 0 0 300px;
    margin-bottom: 0;
}

.input-group {
    margin-bottom: 0.75rem;
}

.input-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--section-header-text);
}

.input-group input {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid var(--input-border);
    border-radius: 5px;
    font-size: 1rem;
    transition: border-color 0.3s ease;
    background: var(--input-bg);
    color: var(--input-text);
}

.input-group input:focus {
    outline: none;
    border-color: var(--input-border-focus);
}

.code-output {
    flex: 1;
}

.code-output h3 {
    color: var(--section-header-text);
    margin-bottom: 0.75rem;
}

#outputCode {
    width: 100%;
    height: 130px; /* slightly shorter */
    padding: 0.75rem;
    border: 2px solid var(--input-border);
    border-radius: 5px;
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    background: var(--output-bg);
    color: var(--input-text);
    resize: vertical;
}

#outputCode.error {
    border-color: var(--output-error-border);
    background: var(--output-error-bg);
    color: var(--output-error-text);
}

.output-buttons {
    display: flex;
    gap: 0.75rem;
    margin-top: 0.75rem;
}

.output-buttons button {
    flex: 1;
    padding: 0.6rem;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.3s ease;
}

#copyCodeBtn {
    background: var(--copy-btn-bg);
    color: var(--primary-btn-text);
}

#copyCodeBtn:hover {
    background: var(--copy-btn-hover);
}

#downloadBtn {
    background: var(--secondary-btn);
    color: var(--primary-btn-text);
}

#downloadBtn:hover {
    background: var(--secondary-btn-hover);
}

/* Card Styles */
.empty-state {
    width: 100%;
    text-align: center;
    padding: 2rem;
    color: var(--help-menu-text);
    font-style: italic;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
    padding-bottom: 0.4rem;
    border-bottom: 1px solid var(--card-header-border);
}

.drag-handle {
    color: var(--drag-handle);
    font-weight: bold;
    cursor: grab;
    font-size: 1.2rem;
    user-select: none;
    padding: 0.25rem;
    margin-right: 0.5rem;
}

.drag-handle:hover {
    color: var(--drag-handle-hover);
}

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

.card-type-selector {
    background: none;
    border: none;
    color: var(--section-header-text);
    font-size: 1.1rem;
    font-weight: bold;
    cursor: pointer;
    padding: 0;
    margin: 0;
}

.card-type-selector:hover {
    color: var(--section-header-hover);
}

.remove-btn {
    background: var(--remove-btn-bg);
    color: var(--primary-btn-text);
    border: none;
    border-radius: 50%;
    width: 25px;
    height: 25px;
    cursor: pointer;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.card-content {
    color: var(--help-menu-text);
}

/* Card Control Styles */
.control-group {
    margin-bottom: 0.75rem;
}

.control-group:last-child {
    margin-bottom: 0;
}

.control-group label {
    display: block;
    font-weight: 600;
    color: var(--label-text);
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.number-input {
    position: relative;
    display: flex;
    align-items: stretch;
}

/* Hide browser default number input spinners */
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; /* Firefox */
    appearance: textfield; /* Standard property */
}

.length-input {
    flex: 1;
    padding: 0.5rem;
    border: 2px solid var(--input-border);
    border-radius: 4px 0 0 4px;
    border-right: none;
    font-size: 0.9rem;
    transition: border-color 0.3s ease;
    min-width: 0;
    background: var(--input-bg);
    color: var(--input-text);
}

.length-input:focus {
    outline: none;
    border-color: var(--input-border-focus);
}

.number-buttons {
    display: flex;
    flex-direction: column;
    border: 2px solid var(--input-border);
    border-left: none;
    border-radius: 0 4px 4px 0;
    overflow: hidden;
}

.length-input:focus + .number-buttons {
    border-color: var(--input-border-focus);
}

.number-btn {
    background: var(--number-btn-bg);
    border: none;
    padding: 0;
    cursor: pointer;
    font-size: 0.8rem;
    color: var(--help-menu-text);
    transition: all 0.2s ease;
    width: 24px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
}

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

.number-btn:active {
    background: var(--section-header-text);
    color: var(--primary-btn-text);
}

.up-btn {
    border-bottom: 1px solid var(--input-border);
}

.checkbox-label {
    display: flex !important;
    align-items: center;
    cursor: pointer;
    margin-bottom: 0 !important;
}

.checkbox-label input[type="checkbox"] {
    margin-right: 0.5rem;
    transform: scale(1.2);
}

.checkbox-label span {
    font-weight: 500;
    color: var(--label-text);
}

/* Text Card Specific Styles */
.control-row {
    display: flex;
    gap: 0.25rem;
}

.half-width {
    flex: 1;
}

.text-label-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.text-helper-buttons {
    display: flex;
    gap: 0.25rem;
}

.offset-label-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.case-btn, .center-btn, .format-btn {
    background: var(--number-btn-bg);
    border: 1px solid var(--input-border);
    border-radius: 3px;
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--help-menu-text);
}

.case-btn:hover, .center-btn:hover, .format-btn:hover {
    background: var(--number-btn-hover-bg);
    border-color: var(--section-header-text);
    color: var(--number-btn-hover-color);
}

.case-btn:active, .center-btn:active, .format-btn:active {
    background: var(--section-header-text);
    color: var(--primary-btn-text);
    transform: scale(0.95);
}

.center-btn {
    background: var(--center-btn-bg);
    border-color: var(--center-btn-border);
    color: var(--center-btn-text);
}

.center-btn:hover {
    background: var(--center-btn-bg);
    border-color: var(--center-btn-border);
    color: var(--center-btn-text);
    transform: scale(1.02);
}

/* Text input container */
.text-input-container {
    position: relative;
    width: 100%;
    min-height: 2.5rem; /* Ensure adequate height for clicking */
}

.text-input, .style-input {
    width: 100%;
    padding: 0.5rem;
    border: 2px solid var(--input-border);
    border-radius: 4px;
    font-size: 0.9rem;
    transition: border-color 0.3s ease;
    min-height: 1.5rem; /* Ensure minimum clickable height */
    box-sizing: border-box;
    position: relative;
    z-index: 2; /* Ensure input is above overlay by default */
    line-height: 1.5; /* Match overlay line-height exactly */
    font-family: Arial, sans-serif; /* Match overlay font exactly */
    background: var(--input-bg);
    color: var(--input-text);
}

.text-input:focus, .style-input:focus {
    outline: none;
    border-color: var(--input-border-focus);
}

/* Text display overlay for consistent formatting */
.text-display-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 0.5rem;
    border: 2px solid var(--input-border);
    border-radius: 4px;
    font-size: 0.9rem;
    background: var(--input-bg);
    pointer-events: auto; /* Allow clicking to switch back to input */
    white-space: pre;
    overflow: hidden;
    line-height: 1.5;
    z-index: 1; /* Below the input field by default */
    cursor: text; /* Show text cursor to indicate it's editable */
    
    /* Match input field styling exactly */
    font-family: Arial, sans-serif;
    color: var(--input-text);
    box-sizing: border-box;
    min-height: 1.5rem; /* Match input field minimum height */
    
    /* Disable all native text decorations - we use CSS lines instead */
    text-decoration: none !important;
    
    /* Use visibility instead of display to prevent layout shifts */
    visibility: hidden;
    display: block;
}

/* Ensure all text elements disable native text decoration */
.text-display-overlay * {
    text-decoration: none !important;
}

.text-display-overlay:empty::before {
    content: attr(placeholder);
    color: var(--placeholder-color);
}

/* Consistent formatting line positioning for text inputs */
.text-input {
    /* Use Arial font for consistent combining character positioning */
    font-family: Arial, sans-serif !important;
    font-size: 0.9rem;
    line-height: 1.5;
    
    /* Optimize text rendering for consistent formatting */
    text-rendering: geometricPrecision;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    
    /* Force consistent metrics regardless of character case */
    font-variant-numeric: tabular-nums;
    font-feature-settings: "kern" 1;
    
    /* Ensure consistent baseline and character positioning */
    vertical-align: baseline;
    
    /* Prevent text transformations that might affect combining characters */
    text-transform: none;
    letter-spacing: 0;
    word-spacing: normal;
    
    /* Disable native text decorations since we use CSS lines instead */
    text-decoration: none !important;
    
    /* Ensure combining characters position relative to the font's cap height */
    font-synthesis: none;
}

/* Force consistent positioning for combining characters (overline, underline, strikethrough) */
.text-input {
    /* The key is using a font that positions combining characters consistently */
    /* Arial has good combining character support with consistent positioning */
    font-stretch: normal;
    font-style: normal;
    font-weight: normal;
}

/* Simple text input styling */
.text-input {
    /* Position relative for potential overlay elements */
    position: relative;
}

/* Ensure preview canvas also uses consistent font metrics */
.preview-canvas {
    font-family: Arial, sans-serif !important;
}

/* Disabled old text-decoration rules - we now use CSS lines instead for all formatting */

/* Webkit-specific fixes for combining character positioning */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
    .text-input {
        -webkit-text-stroke: 0;
        -webkit-font-feature-settings: "kern" 1;
        font-feature-settings: "kern" 1; /* Standard property for compatibility */
    }
}

/* Simplified text formatting - removed complex CSS formatting system */

/* Symbol controls */
.symbol-dropdown {
    position: relative;
    display: inline-block;
}

.symbol-btn {
    background: var(--number-btn-bg);
    border: 1px solid var(--input-border);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.2s ease;
    color: var(--body-text);
    margin-left: 0.25rem;
}

.symbol-btn:hover {
    background: var(--number-btn-hover-bg);
    border-color: var(--symbol-btn-hover-border);
    transform: scale(1.02);
}

.symbol-dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    background: var(--panel-bg);
    border: 2px solid var(--input-border);
    border-radius: 6px;
    box-shadow: 0 4px 12px var(--symbol-menu-shadow);
    z-index: 1000;
    min-width: 320px;
    max-height: 400px;
    overflow-y: auto;
    margin-top: 0.25rem;
}

.symbol-header {
    background: var(--symbol-header-bg);
    padding: 0.75rem;
    border-bottom: 1px solid var(--symbol-header-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--body-text);
}

.symbol-grid-main {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(45px, 1fr));
    gap: 3px;
    padding: 0.75rem;
    max-height: 320px;
    overflow-y: auto;
}

.symbol-item-btn {
    background: var(--panel-bg);
    border: 1px solid var(--symbol-item-border);
    padding: 0.6rem;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    font-weight: 500;
}

.symbol-item-btn:hover {
    background: var(--symbol-item-hover-bg);
    border-color: var(--section-header-text);
    transform: scale(1.05);
    box-shadow: 0 2px 4px var(--symbol-item-hover-shadow);
}

.custom-symbol-btn {
    background: var(--center-btn-bg);
    border: 1px solid var(--center-btn-border);
    padding: 0.4rem 0.6rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
    color: var(--center-btn-text);
    transition: all 0.2s ease;
    pointer-events: auto;
    z-index: 10;
    position: relative;
    font-weight: 500;
}

.symbol-header .custom-symbol-btn {
    margin: 0;
}

.custom-symbol-btn:hover {
    background: var(--center-btn-border);
    color: var(--primary-btn-text);
    transform: scale(1.02);
}

.rotation-row {
    display: flex;
    gap: 0.15rem;
    align-items: stretch;
}

.rotation-type-select {
    width: 60px;
    padding: 0.2rem;
    border: 2px solid var(--input-border);
    border-radius: 4px;
    font-size: 0.9rem;
    background: var(--input-bg);
    color: var(--input-text);
    cursor: pointer;
    transition: border-color 0.3s ease;
}

.rotation-type-select:focus {
    outline: none;
    border-color: var(--input-border-focus);
}

/* Tooltip styles for rotation type dropdown */
.rotation-type-select {
    position: relative;
}

.rotation-type-select::after {
    content: "U = Upright/easy-to-read text" "\A" "R = Relative/tangential rotation with respect to line" "\A" "A = Absolute rotation with respect to origin";
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--tooltip-bg);
    color: var(--primary-btn-text);
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 0.8rem;
    white-space: pre-line;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    margin-bottom: 5px;
    min-width: 300px;
    text-align: left;
    line-height: 1.4;
}

.rotation-type-select::before {
    content: "";
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: var(--tooltip-bg);
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.rotation-type-select:hover::after,
.rotation-type-select:hover::before {
    opacity: 1;
}

.rotation-angle {
    flex: 1;
}

.angle-input {
    width: 60px;
    padding: 0.5rem;
    border: 2px solid var(--input-border);
    border-radius: 4px 0 0 4px;
    border-right: none;
    font-size: 0.9rem;
    transition: border-color 0.3s ease;
    background: var(--input-bg);
    color: var(--input-text);
}

.angle-input:focus {
    outline: none;
    border-color: var(--input-border-focus);
}

.angle-input:focus + .number-buttons {
    border-color: var(--input-border-focus);
}

.offset-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.offset-group {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    flex: 1;
}

.offset-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--help-menu-text);
    min-width: 15px;
}

.offset-input {
    width: 60px;
    padding: 0.4rem;
    border: 2px solid var(--input-border);
    border-radius: 4px 0 0 4px;
    border-right: none;
    font-size: 0.85rem;
    transition: border-color 0.3s ease;
    background: var(--input-bg);
    color: var(--input-text);
}

.offset-input:focus {
    outline: none;
    border-color: var(--input-border-focus);
}

.offset-input:focus + .number-buttons {
    border-color: var(--input-border-focus);
}

.scale-input {
    width: 60px;
    padding: 0.5rem;
    border: 2px solid var(--input-border);
    border-radius: 4px 0 0 4px;
    border-right: none;
    font-size: 0.9rem;
    transition: border-color 0.3s ease;
    background: var(--input-bg);
    color: var(--input-text);
}

.scale-input:focus {
    outline: none;
    border-color: var(--input-border-focus);
}

.scale-input:focus + .number-buttons {
    border-color: var(--input-border-focus);
}

/* Responsive Design */
@media (max-width: 768px) {
    .app-container {
        padding: 1rem;
        gap: 1.5rem;
    }
    
    .section-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }
    
    .output-buttons {
        flex-direction: column;
    }
    
    .output-row {
        flex-direction: column;
        gap: 1.5rem;
    }
    
    .linetype-info {
        flex: none;
    }
    
    header {
        padding: 1rem;
    }
    
    nav h1 {
        font-size: 1.5rem;
    }
}

/* Footer Styles */
footer {
    background: var(--footer-bg);
    color: var(--footer-text);
    padding: 2rem;
    padding-bottom: 3.5rem; /* extra space for fixed toggle */
    margin-top: 3rem;
    position: relative; /* anchor for absolute toggle */
}

.footer-content {
    max-width: 1200px;
    margin: 0 auto;
}

.footer-content h3 {
    color: var(--footer-h3);
    margin-bottom: 1rem;
    font-size: 1.5rem;
}

.footer-content p {
    margin-bottom: 1rem;
    line-height: 1.8;
    color: var(--footer-para);
}

/* Only show theme toggle and copyright in footer */
footer .footer-content > *:not(.theme-toggle):not(.copyright):not(.footer-github) {
    display: none !important;
}

.footer-github {
    position: absolute;
    left: 50%;
    bottom: 1rem;
    transform: translateX(-50%);
    margin: 0;
}
.footer-github a {
    color: var(--footer-h3);
    text-decoration: none;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border: 1px solid var(--theme-select-border);
    border-radius: 6px;
    background: var(--panel-bg);
    box-shadow: 0 2px 6px var(--panel-shadow);
    transition: background .2s, transform .15s;
}
.footer-github a:hover {
    background: var(--header-bg-from);
    color: var(--primary-btn-text);
    transform: translateY(-2px);
}
.footer-github a:active {
    transform: translateY(0);
}

.footer-links {
    margin: 2rem 0;
}

.footer-links h4 {
    color: var(--footer-h4);
    margin-bottom: 0.5rem;
    font-size: 1.2rem;
}

.footer-links ul {
    list-style: none;
    padding-left: 0;
}

.footer-links li {
    padding: 0.3rem 0;
    color: var(--footer-li);
    position: relative;
    padding-left: 1.2rem;
}

.footer-links li:before {
    content: "→";
    position: absolute;
    left: 0;
    color: var(--footer-li-before);
    font-weight: bold;
}

.footer-keywords {
    background: var(--footer-keywords-bg);
    box-shadow: 0 6px 20px var(--panel-shadow);
    border-radius: 5px;
    margin: 1.5rem 0;
}

.footer-keywords p {
    margin: 0;
    font-size: 0.9rem;
}

/* Theme toggle (footer) */
.theme-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0;
    position: absolute;
    right: 1rem;
    bottom: 1rem;
}
.theme-toggle label {
    font-weight: 600;
}
.theme-toggle select {
    background: var(--theme-select-bg);
    color: var(--theme-select-text);
    border: 1px solid var(--theme-select-border);
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 0.95rem;
}
.theme-toggle select:focus {
    outline: none;
    border-color: var(--theme-select-focus-border);
    box-shadow: 0 0 0 2px var(--theme-select-focus-shadow);
}

/* Hide SEO content from users but keep for search engines */
.seo-hidden {
    position: absolute;
    width: 0 !important;
    height: 0 !important;
    overflow: hidden !important;
    clip: rect(0 0 0 0) !important;
    clip-path: inset(50%) !important;
    white-space: nowrap !important;
    border: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
}

.copyright {
    text-align: center;
    margin: 0;
    padding: 1rem 0;
    color: var(--copyright);
    font-size: 0.9rem;
}

/* Dark mode via OS preference: minimal declaration to let browser know
    we support dark palette; actual colors are provided by data-theme vars. */
@media (prefers-color-scheme: dark) {}
/* Minimal theme declarations */
[data-theme="dark"] { color-scheme: dark; }
[data-theme="light"] { color-scheme: light; }