:root {
    --a1: #00ffff; --a2: #0d4550;
    --b1: #ff00ff; --b2: #4a1048;
    --c1: #e6ff00; --c2: #3a3d12;
    --max-width: 1200px;
    --scale-duration: 0.4s;
    /* UI colors (pills & panel) */
    --ui-bg: rgba(0,0,0,0.6);
    --ui-bg-hover: rgba(0,0,0,0.75);
    --ui-bg-active: rgba(0,0,0,0.85);
    --ui-text: rgba(255,255,255,0.7);
    --ui-text-active: #fff;
    --ui-border: rgba(255,255,255,0.1);
    --ui-border-hover: rgba(255,255,255,0.25);
    --ui-highlight: rgba(255,255,255,0.15);
}
body.light-mode {
    --ui-bg: rgba(255,255,255,0.7);
    --ui-bg-hover: rgba(255,255,255,0.85);
    --ui-bg-active: rgba(255,255,255,0.95);
    --ui-text: rgba(0,0,0,0.7);
    --ui-text-active: #000;
    --ui-border: rgba(0,0,0,0.1);
    --ui-border-hover: rgba(0,0,0,0.25);
    --ui-highlight: rgba(0,0,0,0.1);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { overflow-x: hidden; background: #0a0a0a; }
body { font-family: 'Roboto Flex', sans-serif; }

.specimen-container { display: flex; flex-direction: column; width: 100%; }

.specimen-row {
    width: 100%;
    position: relative;
    cursor: grab;
    display: flex;
    touch-action: none; /* Prevent browser gestures during drag */
    justify-content: center;
    transition: filter 0.15s ease;
    overflow: hidden; /* Clip band highlights to row bounds */
}
.specimen-row:active { cursor: grabbing; }
/* Removed full-row hover - band highlights used instead */
.specimen-row:focus { outline: 2px solid var(--bright, #fff); outline-offset: -2px; }
.specimen-row:focus:not(:focus-visible) { outline: none; } /* Hide for mouse users */
.specimen-row.drop-target {
    outline: 3px dashed rgba(255,255,255,0.6);
    outline-offset: -3px;
    filter: brightness(1.15);
}
.specimen-row.keyboard-focus {
    outline: 2px solid var(--a1, #00ffff);
    outline-offset: -2px;
    filter: brightness(1.05);
}

.specimen-wrapper {
    position: relative;
    width: 100%;
    max-width: var(--max-width);
    overflow: hidden; /* Clip text when size multiplier > 100% */
    margin: 1vw 0.5vw;
}

.specimen-text {
    font-family: inherit;
    font-size: 100px;
    white-space: nowrap;
    line-height: 1;
    position: absolute;
    left: 0;
    outline: none;
    cursor: inherit;
    -webkit-user-select: none;
    user-select: none;
    /* No transition on font-size/top - scaling must be instant */
    transition: letter-spacing 0.1s ease-out;
}

/* Native text-box-trim (Safari 17.4+, Chrome 133+) */
@supports (text-box-trim: both) {
    .specimen-text.native-trim {
        text-box-trim: both;
        text-box-edge: cap alphabetic;
    }
}

.specimen-text.editing {
    cursor: text;
    -webkit-user-select: text;
    user-select: text;
    outline: 2px dashed rgba(255,255,255,0.3);
    outline-offset: 4px;
}

.specimen-text::selection { background: rgba(255,255,255,0.3); }

.row-0 { background: var(--a2); --bright: var(--a1); } .row-0 .specimen-text { color: var(--a1); }
.row-1 { background: var(--b2); --bright: var(--b1); } .row-1 .specimen-text { color: var(--b1); }
.row-2 { background: var(--c2); --bright: var(--c1); } .row-2 .specimen-text { color: var(--c1); }
.row-3 { background: var(--b2); --bright: var(--a1); } .row-3 .specimen-text { color: var(--a1); }
.row-4 { background: var(--c2); --bright: var(--b1); } .row-4 .specimen-text { color: var(--b1); }
.row-5 { background: var(--a2); --bright: var(--c1); } .row-5 .specimen-text { color: var(--c1); }
.row-6 { background: var(--c1); --bright: var(--a2); } .row-6 .specimen-text { color: var(--a2); }
.row-7 { background: var(--a1); --bright: var(--b2); } .row-7 .specimen-text { color: var(--b2); }
.row-8 { background: var(--b1); --bright: var(--c2); } .row-8 .specimen-text { color: var(--c2); }
.row-9 { background: var(--a2); --bright: var(--b1); } .row-9 .specimen-text { color: var(--b1); }
.row-10 { background: var(--b2); --bright: var(--c1); } .row-10 .specimen-text { color: var(--c1); }
.row-11 { background: var(--c2); --bright: var(--a1); } .row-11 .specimen-text { color: var(--a1); }

/* Light mode: transparent backgrounds, dark text, allow vertical overflow */
body.light-mode .specimen-row {
    background: transparent !important;
    overflow: visible !important;
    --bright: #1a1a1a;
}
body.light-mode .specimen-wrapper { overflow-y: visible; }
body.light-mode .specimen-row .specimen-text { color: #1a1a1a !important; }

/* Dark mode: transparent backgrounds, light text, allow vertical overflow */
body.dark-mode .specimen-row {
    background: transparent !important;
    overflow: visible !important;
    --bright: #e8e8e8;
}
body.dark-mode .specimen-wrapper { overflow-y: visible; }
body.dark-mode .specimen-row .specimen-text { color: #e8e8e8 !important; }

.axis-indicator {
    position: fixed;
    top: 16px;
    right: 16px;
    background: var(--ui-bg-hover);
    color: var(--ui-text-active);
    font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
    font-size: 10px;
    padding: 12px 16px 8px;
    border-radius: 8px;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    line-height: 1.5;
    backdrop-filter: blur(16px);
    border: 1px solid var(--ui-border);
    box-shadow: 0 4px 24px rgba(0,0,0,0.4);
    max-width: 280px;
}
/* Smaller panel on small screens */
@media (max-width: 600px) {
    .axis-indicator {
        top: 8px;
        right: 8px;
        font-size: 9px;
        padding: 8px 12px 6px;
        max-width: 200px;
        border-radius: 6px;
    }
    .axis-indicator .panel-btn {
        width: 20px;
        height: 20px;
        font-size: 10px;
    }
}
.axis-indicator.visible { opacity: 1; pointer-events: auto; }
.axis-indicator.pinned { opacity: 1; pointer-events: auto; }
.axis-indicator:hover { border-color: var(--ui-border-hover); }

/* Light mode panel: solid white bg, dark text */
body.light-mode .axis-indicator {
    background: rgba(255,255,255,0.95);
    box-shadow: 0 4px 24px rgba(0,0,0,0.15);
    border-color: rgba(0,0,0,0.15);
}
body.light-mode .axis-indicator .axis-value,
body.light-mode .axis-indicator .axis-label,
body.light-mode .axis-indicator .panel-btn .material-symbols-outlined,
body.light-mode .axis-indicator .panel-close .material-symbols-outlined {
    color: #1a1a1a !important;
}

.axis-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 2px 16px; }
.axis-row { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.axis-label {
    background: var(--ui-bg);
    border-radius: 9px;
    padding: 1px 6px;
    cursor: ew-resize;
    user-select: none;
    transition: background 0.1s, opacity 0.15s;
    opacity: 0.7;
}
.axis-label:hover {
    background: var(--ui-bg-hover);
    opacity: 1;
}
.axis-label.dragging {
    background: var(--ui-bg-active);
    opacity: 1;
}
.axis-label[data-vertical="true"] { cursor: ns-resize; }
.axis-label[data-axis-label="size"] { cursor: default; opacity: 0.5; background: transparent; }
.axis-label-icon { padding: 2px 5px; }
.axis-label-icon .material-symbols-outlined { font-size: 16px; line-height: 1; vertical-align: middle; }
.axis-value {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    background: transparent;
    border: none;
    outline: none;
    width: 48px;
    text-align: right;
    padding: 1px 2px;
    border-radius: 2px;
    transition: background 0.1s;
    color: inherit;
}
.axis-value:hover { background: var(--ui-highlight); }
.axis-value:focus { background: var(--ui-highlight); outline: 1px solid var(--ui-border-hover); }
.axis-value.extended { color: var(--c1) !important; }
.axis-value.active-param { background: rgba(255,255,100,0.25) !important; }
.axis-value[readonly] { opacity: 0.7; cursor: default; }
.axis-value[readonly]:hover { background: transparent; }

/* Collapsible panel sections */
.panel-section {
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid var(--ui-border);
}
.panel-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    user-select: none;
    padding: 2px 0;
    opacity: 0.7;
    transition: opacity 0.15s;
}
.panel-section-header:hover { opacity: 1; }
.panel-section-header .material-symbols-outlined {
    font-size: 14px;
    transition: transform 0.2s;
}
.panel-section.collapsed .panel-section-header .material-symbols-outlined {
    transform: rotate(-90deg);
}
.panel-section-content {
    margin-top: 6px;
    overflow: hidden;
    transition: max-height 0.2s ease;
    max-height: 200px;
}
.panel-section.collapsed .panel-section-content {
    max-height: 0;
    margin-top: 0;
}
.panel-textarea {
    width: 100%;
    min-height: 80px;
    max-height: 150px;
    resize: vertical;
    background: var(--ui-bg);
    border: 1px solid var(--ui-border);
    border-radius: 4px;
    color: inherit;
    font-family: inherit;
    font-size: 9px;
    line-height: 1.4;
    padding: 6px 8px;
    box-sizing: border-box;
}
.panel-textarea:focus {
    outline: none;
    border-color: var(--ui-border-hover);
}
.panel-textarea::placeholder {
    opacity: 0.5;
}
.panel-color-input {
    width: 100%;
    background: var(--ui-bg);
    border: 1px solid var(--ui-border);
    border-radius: 4px;
    color: inherit;
    font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
    font-size: 9px;
    padding: 6px 8px;
    box-sizing: border-box;
}
.panel-color-input:focus {
    outline: none;
    border-color: var(--ui-border-hover);
}
.panel-color-input::placeholder {
    opacity: 0.5;
}
.panel-color-input.error {
    border-color: #ff4444;
}

/* AI Generate section */
.panel-select {
    width: 100%;
    background: var(--ui-bg);
    border: 1px solid var(--ui-border);
    border-radius: 4px;
    color: inherit;
    font-family: inherit;
    font-size: 12px;
    padding: 6px 8px;
    box-sizing: border-box;
    cursor: pointer;
    margin-bottom: 6px;
}
.panel-select:focus {
    outline: none;
    border-color: var(--ui-border-hover);
}
.panel-input {
    width: 100%;
    background: var(--ui-bg);
    border: 1px solid var(--ui-border);
    border-radius: 4px;
    color: inherit;
    font-family: inherit;
    font-size: 12px;
    padding: 6px 8px;
    box-sizing: border-box;
    margin-bottom: 6px;
}
.panel-input:focus {
    outline: none;
    border-color: var(--ui-border-hover);
}
.panel-input::placeholder {
    opacity: 0.5;
}
.panel-btn-generate {
    width: 100%;
    background: var(--ui-highlight);
    border: 1px solid var(--ui-border);
    border-radius: 4px;
    color: inherit;
    font-family: inherit;
    font-size: 12px;
    padding: 8px 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: background 0.15s, transform 0.1s;
}
.panel-btn-generate:hover {
    background: var(--ui-border);
}
.panel-btn-generate:active {
    transform: scale(0.98);
}
.panel-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 12px;
    font-size: 12px;
    opacity: 0.7;
}
@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}
.spin {
    animation: spin 1s linear infinite;
}
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-4px); }
    40%, 80% { transform: translateX(4px); }
}
.shake {
    animation: shake 0.4s ease-in-out;
    border-color: #ff6666 !important;
}

.panel-buttons {
    display: flex;
    gap: 4px;
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid var(--ui-border);
    justify-content: center;
}
.panel-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: background 0.15s, transform 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
    color: inherit;
}
.panel-btn:hover { background: var(--ui-highlight); }
.panel-btn:active { transform: scale(0.92); }
.panel-btn.active { background: var(--ui-highlight); }
.panel-btn .material-symbols-outlined {
    font-size: 18px;
    font-variation-settings: 'FILL' 0, 'wght' 300, 'GRAD' 0, 'opsz' 20;
}
.panel-toggle {
    position: fixed;
    top: 20px;
    right: 20px;
    background: var(--ui-bg);
    border: 1px solid var(--ui-border);
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    z-index: 1001;
    transition: opacity 0.2s, background 0.15s;
    backdrop-filter: blur(8px);
}
.panel-toggle:hover { background: var(--ui-bg-hover); }
.panel-toggle .material-symbols-outlined {
    font-size: 18px;
    color: var(--ui-text);
    display: block;
    font-variation-settings: 'FILL' 0, 'wght' 300, 'GRAD' 0, 'opsz' 20;
}
.panel-toggle:hover .material-symbols-outlined { color: var(--ui-text-active); }
/* Hide toggle when panel is visible (close button inside panel instead) */
.axis-indicator.visible ~ .panel-toggle { display: none; }
@media (max-width: 600px) {
    .panel-toggle { top: 12px; right: 12px; padding: 5px; }
    .panel-toggle .material-symbols-outlined { font-size: 16px; }
}
.panel-close {
    position: absolute;
    top: 4px;
    right: 4px;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 2px;
    border-radius: 3px;
    opacity: 0.5;
    transition: opacity 0.15s;
    color: inherit;
}
.panel-close:hover { opacity: 1; }
.panel-close .material-symbols-outlined {
    font-size: 14px;
    font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 14;
    color: inherit;
}

.copy-toast {
    position: fixed;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    background: rgba(0,0,0,0.95);
    color: var(--a1);
    padding: 12px 24px;
    border-radius: 8px;
    font-family: 'SF Mono', monospace;
    font-size: 12px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s, transform 0.2s;
    z-index: 2000;
}
.copy-toast.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }

/* Loading Indicator */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: #0a0a0a;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 20px;
    transition: opacity 0.4s ease;
}
.loading-overlay.hidden { opacity: 0; pointer-events: none; }
.loading-spinner {
    width: 48px;
    height: 48px;
    border: 3px solid rgba(255,255,255,0.1);
    border-top-color: var(--a1);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { opacity: 0.5; } 50% { opacity: 1; } }
.loading-text {
    color: #888;
    font-family: 'SF Mono', monospace;
    font-size: 12px;
    animation: pulse 2s ease-in-out infinite;
}

/* Help Modal */
.help-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.85);
    backdrop-filter: blur(8px);
    z-index: 3000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}
.help-modal.visible { opacity: 1; pointer-events: auto; }
.help-content {
    background: rgba(20,20,20,0.98);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 12px;
    padding: 32px 40px;
    max-width: 600px;
    max-height: 85vh;
    overflow-y: auto;
    color: #ccc;
    font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
    font-size: 12px;
    line-height: 1.8;
}
.help-content h2 {
    color: var(--a1);
    font-size: 18px;
    margin: 0 0 20px 0;
    font-weight: 500;
}
.help-section {
    margin-bottom: 20px;
}
.help-section h3 {
    color: var(--b1);
    font-size: 12px;
    margin: 0 0 8px 0;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.help-row {
    display: flex;
    gap: 16px;
    margin-bottom: 4px;
}
.help-key {
    color: var(--c1);
    min-width: 140px;
    flex-shrink: 0;
}
.help-desc { color: #999; }
.help-close {
    position: absolute;
    top: 16px;
    right: 16px;
    background: transparent;
    border: none;
    color: #666;
    cursor: pointer;
    font-size: 24px;
    line-height: 1;
    padding: 8px;
    transition: color 0.15s;
}
.help-close:hover { color: #fff; }

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

/* Drop overlay for font uploads */
.drop-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    display: none;
    z-index: 9999;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-family: 'Roboto Flex', sans-serif;
}
.drop-overlay.active { display: flex; }
.drop-overlay-icon {
    font-size: 64px;
    margin-bottom: 24px;
    opacity: 0.7;
}
.drop-overlay-text {
    font-size: 24px;
    font-weight: 300;
    opacity: 0.9;
}
.drop-overlay-hint {
    font-size: 14px;
    opacity: 0.5;
    margin-top: 12px;
}

/* Row indicator */
.row-indicator {
    font-size: 10px;
    font-weight: 600;
    color: var(--ui-text-dim);
    background: var(--ui-highlight);
    border-radius: 4px;
    padding: 4px 8px;
    margin-right: 8px;
    margin-bottom: 8px;
    display: inline-block;
    vertical-align: middle;
}

/* Font dropdown in panel */
.font-dropdown {
    font-size: 10px;
    font-weight: 600;
    color: var(--ui-text);
    background: var(--ui-highlight);
    border: 1px solid var(--ui-border);
    border-radius: 4px;
    padding: 4px 8px;
    margin-bottom: 8px;
    width: 100%;
    cursor: pointer;
    outline: none;
    transition: background 0.15s, border-color 0.15s;
}
.font-dropdown:hover {
    background: var(--ui-bg-hover);
}
.font-dropdown:focus {
    border-color: var(--ui-text-active);
}
body.light-mode .font-dropdown {
    background: rgba(255,255,255,0.95);
    color: #1a1a1a;
    border-color: rgba(0,0,0,0.2);
}

/* Instance dropdown */
.instance-dropdown {
    font-size: 9px;
    font-weight: 500;
    color: var(--ui-text);
    background: var(--ui-bg);
    border: 1px solid var(--ui-border);
    border-radius: 4px;
    padding: 3px 6px;
    margin-bottom: 8px;
    width: 100%;
    cursor: pointer;
    outline: none;
}
.instance-dropdown:hover {
    background: var(--ui-bg-hover);
}
.instance-dropdown:focus {
    border-color: var(--ui-text-active);
}
body.light-mode .instance-dropdown {
    background: rgba(255,255,255,0.9);
    color: #1a1a1a;
    border-color: rgba(0,0,0,0.2);
}

/* Hidden file input */
#font-file-input { display: none; }

/* WYSIWYG Band Pills */
.band-pill {
    position: absolute;
    font-family: inherit;
    font-size: 14px;
    line-height: 1;
    letter-spacing: 0.05em;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s ease;
    z-index: 10;
    color: rgba(255,255,255,0.85);
    text-shadow: 0 0 4px rgba(0,0,0,0.9), 0 1px 2px rgba(0,0,0,0.7), 0 0 8px rgba(0,0,0,0.5);
}
.band-pill.visible { opacity: 0.7; }
.band-pill.at-limit { color: #ff4444 !important; opacity: 1 !important; }
body.light-mode .band-pill.at-limit { color: #cc0000 !important; }
.band-pill.at-extended { color: #ffaa00 !important; opacity: 1 !important; }
body.light-mode .band-pill.at-extended { color: #cc8800 !important; }
.pill-icon { font-size: 18px; line-height: 1; vertical-align: middle; }
body.light-mode .band-pill {
    color: rgba(0,0,0,0.7);
    text-shadow: 0 0 4px rgba(255,255,255,0.9), 0 1px 2px rgba(255,255,255,0.7), 0 0 8px rgba(255,255,255,0.5);
}

/* Position pills at edges - dynamic positioning via JS */
.band-pill-left {
    left: 8px;
    top: 50%;
    transform: translateY(-50%);
}
.band-pill-right {
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
}
.band-pill-top {
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
}
.band-pill-bottom {
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
}
/* Band line indicators (subtle lines at pill edges) */
.band-line {
    position: absolute;
    pointer-events: none;
    background: rgba(255,255,255,0.15);
    opacity: 0;
    transition: opacity 0.15s ease;
    z-index: 1;
}
.band-line.visible { opacity: 1; }
/* H-band lines: vertical lines at left/right edges, height set via JS */
.band-line-h-left, .band-line-h-right {
    width: 1px;
}
.band-line-h-left { left: 0; }
.band-line-h-right { right: 0; }
/* V-band lines: horizontal lines at top/bottom, width/left set via JS */
.band-line-v-top, .band-line-v-bottom {
    height: 1px;
}
.band-line-v-top { top: 0; }
.band-line-v-bottom { bottom: 0; }
body.light-mode .band-line {
    background: rgba(0,0,0,0.12);
}

/* Print styles */
@media print {
    body { background: white !important; }
    .specimen-row { background: transparent !important; overflow: visible !important; }
    .specimen-row .specimen-text { color: black !important; }
    .specimen-wrapper { max-width: none; margin: 0; overflow: visible !important; }
    .axis-indicator, .panel-toggle, .help-modal, .loading-overlay,
    .drop-overlay, .band-pill, .band-line, #copy-toast { display: none !important; }
    .font-dropdown, .instance-dropdown { display: none !important; }
}

/* Reduced motion: disable animations for accessibility */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    .loading-spinner { animation: none; }
}
