:root {
    /* Pure Dark M3 Deep Purple Theme */
    --md-sys-color-primary: #D0BCFF;
    --md-sys-color-on-primary: #381E72;
    --md-sys-color-primary-container: #4F378B;
    --md-sys-color-on-primary-container: #EADDFF;

    --md-sys-color-secondary: #CCC2DC;
    --md-sys-color-on-secondary: #332D41;
    --md-sys-color-secondary-container: #4A4458;
    --md-sys-color-on-secondary-container: #E8DEF8;

    --md-sys-color-background: #141218;
    --md-sys-color-on-background: #E6E1E5;

    --md-sys-color-surface: #1D1B20;
    --md-sys-color-on-surface: #E6E1E5;
    --md-sys-color-surface-variant: #49454F;
    --md-sys-color-on-surface-variant: #CAC4D0;

    --md-sys-color-outline: #938F99;

    /* Slider Specific */
    --slider-active-track: var(--md-sys-color-primary);
    --slider-inactive-track: var(--md-sys-color-surface-variant);
    --slider-dot-on-active: var(--md-sys-color-on-primary);
    --slider-dot-on-inactive: var(--md-sys-color-primary);

    /* Typography */
    --md-sys-typescale-headline-large: 400 32px/40px 'Roboto', sans-serif;
    --md-sys-typescale-headline-small: 400 24px/32px 'Roboto', sans-serif;
    --md-sys-typescale-body-large: 400 16px/24px 'Roboto', sans-serif;
    --md-sys-typescale-body-small: 400 12px/16px 'Roboto', sans-serif;
    --md-sys-typescale-label-large: 500 14px/20px 'Roboto', sans-serif;

    /* Shape */
    --md-sys-shape-corner-medium: 12px;
    --md-sys-shape-corner-large: 14px;
    --md-sys-shape-corner-extra-large: 28px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Roboto', sans-serif;
    background-color: var(--md-sys-color-background);
    color: var(--md-sys-color-on-background);
    display: flex;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
    user-select: none;
    -webkit-user-select: none;
}

.app-container {
    width: 100%;
    max-width: 900px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

header.top-app-bar h1 {
    font: var(--md-sys-typescale-headline-small);
    color: var(--md-sys-color-on-background);
    text-align: center;
}

/* Card System */
.card {
    background-color: var(--md-sys-color-surface);
    border-radius: var(--md-sys-shape-corner-extra-large);
    padding: 24px;
    box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15), 0px 1px 2px 0px rgba(0, 0, 0, 0.3);
    background-image: linear-gradient(rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.05));
    transition: box-shadow 0.2s ease;
}

.card:hover {
    box-shadow: 0px 4px 8px 3px rgba(0, 0, 0, 0.15), 0px 1px 3px 0px rgba(0, 0, 0, 0.3);
}

.card-header {
    margin-bottom: 32px;
}

.card-header h2 {
    font: var(--md-sys-typescale-headline-small);
    margin-bottom: 8px;
}

.subtitle {
    font: var(--md-sys-typescale-body-large);
    color: var(--md-sys-color-on-surface-variant);
}

/* Layout Grid */
.form-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 48px;
    align-items: start;
}

@media (max-width: 768px) {
    .form-layout {
        grid-template-columns: 1fr;
        gap: 24px;
    }
}

.column {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* Material Text Field */
.text-field-container {
    margin-bottom: 12px;
}

.md-text-field {
    position: relative;
    width: 100%;
}

.md-text-field input {
    width: 100%;
    padding: 16px;
    background: transparent;
    border: 1px solid var(--md-sys-color-outline);
    border-radius: 4px;
    font: var(--md-sys-typescale-body-large);
    color: var(--md-sys-color-on-surface);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.1s;
    caret-color: var(--md-sys-color-primary);
}

.md-text-field input:focus {
    border-color: var(--md-sys-color-primary);
    box-shadow: inset 0 0 0 1px var(--md-sys-color-primary);
}

.md-text-field label {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    padding: 0 4px;
    background-color: var(--md-sys-color-surface);
    background-image: linear-gradient(rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.05));
    color: var(--md-sys-color-on-surface-variant);
    font: var(--md-sys-typescale-body-large);
    transition: top 0.2s, font-size 0.2s, color 0.2s, transform 0.2s;
    pointer-events: none;
    z-index: 1;
}

.md-text-field input:focus~label,
.md-text-field input:not(:placeholder-shown)~label {
    top: 0;
    font-size: 12px;
    font-weight: 500;
    color: var(--md-sys-color-primary);
}

.md-text-field input:not(:placeholder-shown):not(:focus)~label {
    color: var(--md-sys-color-on-surface-variant);
}

/* Select System */
.md-select-container {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.md-select {
    position: relative;
    width: 100%;
    cursor: pointer;
}

.md-select-field {
    width: 100%;
    padding: 16px;
    background: transparent;
    border: 1px solid var(--md-sys-color-outline);
    border-radius: 4px;
    font: var(--md-sys-typescale-body-large);
    color: var(--md-sys-color-on-surface);
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: border-color 0.2s, box-shadow 0.1s;
}

.md-select.active .md-select-field {
    border-color: var(--md-sys-color-primary);
    box-shadow: inset 0 0 0 1px var(--md-sys-color-primary);
}

.md-select label {
    position: absolute;
    left: 12px;
    top: 0;
    transform: translateY(-50%);
    padding: 0 4px;
    background-color: var(--md-sys-color-surface);
    background-image: linear-gradient(rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.05));
    color: var(--md-sys-color-on-surface-variant);
    font: var(--md-sys-typescale-label-large);
    font-size: 12px;
    pointer-events: none;
    z-index: 1;
}

.md-select.active label {
    color: var(--md-sys-color-primary);
}

.dropdown-icon {
    font-size: 24px;
    color: var(--md-sys-color-on-surface-variant);
    transition: transform 0.3s ease;
}

.md-select.active .dropdown-icon {
    transform: rotate(180deg);
    color: var(--md-sys-color-primary);
}

.md-select-menu {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    width: 100%;
    background-color: #2b2930;
    /* Elevated surface tint */
    border-radius: 20px;
    /* Stronger rounding */
    box-shadow: 0px 4px 16px rgba(0, 0, 0, 0.5);
    list-style: none;
    padding: 4px;
    /* Reduced padding */
    z-index: 10;

    /* Animation props */
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
    pointer-events: none;
}

.md-select.active .md-select-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    pointer-events: auto;
}

.md-select-option {
    padding: 12px 16px;
    color: var(--md-sys-color-on-surface);
    display: flex;
    align-items: center;
    border-radius: 16px;
    /* Rounded rect matching concentric radius (20px - 4px padding) */
    transition: background-color 0.2s;
    margin-bottom: 8px;
    /* More space between options */
}

.md-select-option:last-child {
    margin-bottom: 0;
}

.md-select-option:hover {
    background-color: rgba(208, 188, 255, 0.08);
}

.md-select-option.selected {
    background-color: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
}

/* Slider System */
.slider-wrapper .slider-label {
    display: flex;
    justify-content: space-between;
    margin-bottom: 12px;
    font: var(--md-sys-typescale-label-large);
    color: var(--md-sys-color-on-surface-variant);
}

.slider-container {
    position: relative;
    width: 100%;
    height: 48px;
    display: flex;
    align-items: center;
    touch-action: none;
}

.md-slider {
    position: absolute;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
    z-index: 5;
    pointer-events: none;
}

.slider-visual {
    position: relative;
    width: 100%;
    height: 16px;
    border-radius: 8px;
}

.slider-track-active {
    position: absolute;
    left: 0;
    height: 100%;
    background-color: var(--slider-active-track);
    border-radius: 8px 2px 2px 8px;
    /* Rounded start, nearly flat end */
    z-index: 1;
    transition: width 0.1s linear;
}

.slider-track-inactive {
    position: absolute;
    right: 0;
    height: 100%;
    background-color: var(--slider-inactive-track);
    border-radius: 2px 8px 8px 2px;
    /* Nearly flat start, rounded end */
    z-index: 1;
    transition: width 0.1s linear;
}

.slider-thumb {
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 4px;
    /* Normal width */
    height: 44px;
    /* Taller thumb as requested */
    background-color: var(--md-sys-color-primary);
    border-radius: 2px;
    /* Full rounding for 4px width */
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    z-index: 4;
    transition: left 0.1s linear, box-shadow 0.2s ease, width 0.1s linear, border-radius 0.1s linear;
}

.slider-container.dragging .slider-thumb {
    width: 2px;
    border-radius: 1px;
}

/* Dots */
.stop-dot {
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 4px;
    height: 4px;
    background-color: var(--slider-dot-on-inactive);
    border-radius: 50%;
    z-index: 2;
}

.stop-dot.active {
    background-color: var(--slider-dot-on-active);
}

.slider-labels-container {
    position: absolute;
    top: 100%;
    width: 100%;
    margin-top: 20px;
}

.slider-label-text {
    position: absolute;
    transform: translateX(-50%);
    font: var(--md-sys-typescale-body-small);
    color: var(--md-sys-color-on-surface-variant);
}

/* Tooltip Indicator */
/* Tooltip Indicator */
.value-indicator {
    position: absolute;
    top: -56px;
    left: 0;
    background-color: #0d0c11;
    /* Dark inverse surface color */
    color: #F4EFF4;
    /* Light inverse on-surface color */
    padding: 0 16px;
    height: 44px;
    min-width: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 22px;
    /* Pill shape */
    font-size: 14px;
    font-weight: 500;
    letter-spacing: 0.1px;
    font-variant-numeric: tabular-nums;
    transform: translateX(-50%) scale(0);
    transform-origin: bottom center;
    transition: transform 0.2s cubic-bezier(0.2, 0.0, 0, 1.0), opacity 0.1s, width 0.2s, min-width 0.2s, left 0.1s linear;
    opacity: 0;
    z-index: 6;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.value-indicator::after {
    display: none;
}

.slider-container:hover .value-indicator {
    transform: translateX(-50%) scale(1);
    opacity: 1;
}

/* Switches */
.toggles-container {
    margin-top: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.switch-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font: var(--md-sys-typescale-body-large);
}

.md-switch {
    position: relative;
    width: 52px;
    height: 32px;
    cursor: pointer;
}

.md-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.md-switch-track {
    position: absolute;
    inset: 0;
    background-color: var(--md-sys-color-surface-variant);
    border-radius: 100px;
    border: 2px solid var(--md-sys-color-outline);
    transition: background-color 0.2s, border-color 0.2s;
}

.md-switch-thumb {
    position: absolute;
    height: 16px;
    width: 16px;
    left: 6px;
    bottom: 6px;
    background-color: var(--md-sys-color-outline);
    border-radius: 50%;
    transition: all 0.2s;
}

.md-switch input:checked+.md-switch-track {
    background-color: var(--md-sys-color-primary);
    border-color: var(--md-sys-color-primary);
}

.md-switch input:checked+.md-switch-track .md-switch-thumb {
    transform: translateX(20px);
    background-color: var(--md-sys-color-on-primary);
    width: 24px;
    height: 24px;
    left: 2px;
    bottom: 2px;
}

/* Result Section */
.result-card {
    padding: 24px;
}

.result-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.result-header h3 {
    font: var(--md-sys-typescale-label-large);
    color: var(--md-sys-color-primary);
    letter-spacing: 0.5px;
}

.code-container {
    background-color: #0d0c11;
    /* Extra dark theme-consistent bg */
    padding: 20px;
    border-radius: 12px;
    border: 1px solid var(--md-sys-color-surface-variant);
    overflow-x: auto;
    overflow-y: hidden;
    /* Prevent scrollbars during expansion */
    user-select: text;
    -webkit-user-select: text;
    transition: height 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
    will-change: height;
}

#scriptOutput {
    font-family: 'Roboto Mono', monospace;
    font-size: 14px;
    color: var(--md-sys-color-on-surface);
    line-height: 1.6;
    white-space: pre-wrap;
    /* wrap text */
    word-break: break-all;
    /* break long words/strings if needed */
}

.result-actions {
    display: flex;
    gap: 12px;
}

.md-icon-button {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    background-color: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
    transition: transform 0.2s, filter 0.2s;
}

.md-icon-button:hover {
    filter: brightness(1.2);
    transform: scale(1.05);
}

.md-icon-button:active {
    transform: scale(0.95);
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--md-sys-color-surface-variant);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--md-sys-color-outline);
}