html {
    overflow-y: hidden;
}

body {
    font-family: var(--us-font-family-default);
    margin: 0;
    height: 100vh;
    background: var(--us-bg-canvas);
    color: var(--us-fg-default);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 16px;
    box-sizing: border-box;
    overflow: hidden;
}

#main-layout {
    display: flex;
    width: 100%;
    max-width: 1920px;
    gap: 1.5rem;
    height: calc(100vh - 32px);
    align-items: stretch;
    /* Allow wrap on smaller screens */
}

/* Controls container styles */
#controls-container {
    flex-basis: 300px;
    flex-shrink: 0;
    background-color: var(--us-bg-lowest);
    border-radius: var(--us-radii-micro-medium);
    padding: 1.5rem;
    border: 1px solid var(--us-border-soft);
    height: 100%;
    overflow-y: auto;
    margin-top: 16px;
    margin-bottom: 16px;
    box-sizing: border-box;
}

#controls {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    align-items: stretch;
}

/* Styles for items within the controls container */
.control-item {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    color: var(--us-fg-subtext);
}

.control-item label:not(.radio-label):not(.checkbox-label):not(.button-label):not(.color-label):not(.segment-label):not(.toggle-label) {
    margin-bottom: 0.5rem;
    width: 100%;
    display: flex;
    justify-content: space-between;
}

.control-item label .value-display {
    color: var(--us-fg-default);
}

.control-item input[type="range"] {
    width: 100%;
    cursor: pointer;
    accent-color: var(--us-accent-high);
    margin-top: 0.25rem;
}

/* Letter Controls Container */
.letter-controls-container {
    flex-direction: row;
    gap: 12px;
    width: 100%;
}

.letter-color-group {
    display: flex;
    flex-direction: column;
    flex: 1;
    gap: 0.5rem;
}

.letter-color-group label {
    margin-bottom: 0;
    text-align: left;
}

.letter-color-group input[type="color"] {
    width: 100%;
    height: 32px;
    border: 1px solid var(--us-border-medium);
    border-radius: var(--us-radii-micro-small);
    cursor: pointer;
    padding: 2px;
    background-color: var(--us-bg-low);
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    box-sizing: border-box;
}

/* Letter Input Full Width */
#letterInput {
    width: 100%;
    background-color: var(--us-bg-lowest);
    border: 1px solid var(--us-border-medium);
    border-radius: var(--us-radii-micro-small);
    padding: 0.4rem 0.6rem;
    color: var(--us-fg-default);
    box-sizing: border-box;
}

/* Segmented Control Styles */
.segmented-control {
    display: flex;
    background-color: var(--us-bg-low);
    border-radius: var(--us-radii-micro-small);
    border: 1px solid var(--us-border-medium);
    overflow: hidden;
    width: 100%;
}

.segmented-control input[type="radio"] {
    display: none;
}

.segmented-control .segment-label {
    flex: 1;
    padding: 0.5rem 0.75rem;
    text-align: center;
    cursor: pointer;
    background-color: transparent;
    color: var(--us-fg-subtext);
    border-right: 1px solid var(--us-border-medium);
    transition: all 0.2s ease;
    font-size: var(--us-font-size-label);
    line-height: var(--us-line-height-label);
    font-weight: var(--us-font-weight-regular);
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.segmented-control .segment-label:last-child {
    border-right: none;
}

.segmented-control input[type="radio"]:checked + .segment-label {
    background-color: var(--us-accent-high);
    color: var(--us-fg-inverse);
}

.segmented-control .segment-label:hover {
    background-color: var(--us-bg-mid);
}

.segmented-control input[type="radio"]:checked + .segment-label:hover {
    background-color: var(--us-accent-high);
    filter: brightness(0.9);
}

/* Toggle Switch Styles */
.toggle-item {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

.toggle-label {
    margin: 0;
    color: var(--us-fg-subtext);
}

.toggle-switch {
    position: relative;
    width: 44px;
    height: 24px;
}

.toggle-switch input[type="checkbox"] {
    opacity: 0;
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    cursor: pointer;
    z-index: 1;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--us-bg-mid);
    border: 1px solid var(--us-border-medium);
    transition: 0.3s;
    border-radius: 12px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background-color: var(--us-fg-default);
    transition: 0.3s;
    border-radius: 50%;
}

input[type="checkbox"]:checked + .toggle-slider {
    background-color: var(--us-accent-high);
    border-color: var(--us-accent-high);
}

input[type="checkbox"]:checked + .toggle-slider:before {
    transform: translateX(20px);
    background-color: var(--us-fg-inverse);
}

/* Fade Control Groups */
.fade-control-group {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.fade-control-group:last-of-type {
    margin-bottom: 1.5rem;
}

/* Timed Sequence Section */
.timed-sequence-section {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 1rem;
    background-color: var(--us-bg-low);
    border-radius: var(--us-radii-micro-small);
    border: 1px solid var(--us-border-soft);
}

/* Action Buttons Container */
.action-buttons-container {
    flex-direction: row;
    gap: 12px;
    width: 100%;
}

.action-button {
    flex: 1;
    background-color: var(--us-bg-mid);
    color: var(--us-fg-default);
    padding: 0.75rem 1rem;
    border-radius: var(--us-radii-micro-small);
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s;
    border: 1px solid var(--us-border-medium);
    text-align: center;
    box-sizing: border-box;
    font-size: var(--us-font-size-label-bold);
    line-height: var(--us-line-height-label-bold);
    font-weight: var(--us-font-weight-bold);
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.action-button:hover:not(:disabled) {
    background-color: var(--us-bg-high);
}

.action-button.stop-mode {
    background-color: var(--us-accent-high);
    color: var(--us-fg-inverse);
    border-color: transparent;
}

.action-button.stop-mode:hover:not(:disabled) {
    filter: brightness(0.9);
}

.action-button:disabled {
    background-color: var(--us-bg-low);
    color: var(--us-fg-subtext);
    cursor: not-allowed;
    border-color: var(--us-border-soft);
}

/* Manual Recording Controls */
.manual-recording-controls {
    flex-direction: column;
    gap: 0.75rem;
    width: 100%;
}

.manual-record-button {
    width: 100%;
    background-color: var(--us-bg-mid);
    color: var(--us-fg-default);
    padding: 0.75rem 1rem;
    border-radius: var(--us-radii-micro-small);
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s;
    border: 1px solid var(--us-border-medium);
    text-align: center;
    box-sizing: border-box;
    font-size: var(--us-font-size-label-bold);
    line-height: var(--us-line-height-label-bold);
    font-weight: var(--us-font-weight-bold);
}

.manual-record-button:hover:not(:disabled) {
    background-color: var(--us-bg-high);
}

.manual-record-button:disabled {
    background-color: var(--us-bg-low);
    color: var(--us-fg-subtext);
    cursor: not-allowed;
    border-color: var(--us-border-soft);
}

.control-item.file-upload-item,
.control-item.animation-action-controls,
.control-item.recording-controls,
.control-item.duration-controls {
    align-items: center;
    flex-direction: row;
    flex-wrap: nowrap;
    justify-content: center;
    width: 100%;
}

.control-item.file-upload-item.full-width {
    justify-content: stretch;
}

.control-item.file-upload-item.full-width .button-label {
    width: 100%;
}

/* Combined button styles */
.button-label {
    display: inline-block;
    background-color: var(--us-bg-mid);
    color: var(--us-fg-default);
    padding: 0.5rem 1rem;
    border-radius: var(--us-radii-micro-small);
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s;
    border: 1px solid var(--us-border-medium);
    text-align: center;
    box-sizing: border-box;
    width: auto;
}

.button-label:hover {
    background-color: var(--us-bg-high);
}

#bgUpload,
#cellImgUpload {
    display: none;
}

/* Color picker styles */
.color-picker-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.color-picker-item label {
    margin-bottom: 0;
}

.color-picker-item input[type="color"] {
    width: 28px;
    height: 28px;
    border: 1px solid var(--us-border-medium);
    border-radius: var(--us-radii-micro-small);
    cursor: pointer;
    padding: 2px;
    background-color: var(--us-bg-low);
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

.color-picker-item input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
    border-radius: 2px;
}

.color-picker-item input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 2px;
}

.color-picker-item input[type="color"]::-moz-color-swatch {
    border: none;
    border-radius: 2px;
}

.letter-color-group input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
    border-radius: 2px;
}

.letter-color-group input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 2px;
}

.letter-color-group input[type="color"]::-moz-color-swatch {
    border: none;
    border-radius: 2px;
}

/* Canvas and loading styles */
#canvas-container {
    flex-grow: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    min-width: 0;
    height: 100%;
    overflow: hidden;
}

canvas#noiseCanvas {
    display: block;
    max-width: 100%;
    max-height: 100%;
    height: auto;
    width: auto;
    border-radius: var(--us-radii-micro-medium);
    background-color: var(--us-bg-invert-canvas);
}

#loading {
    position: absolute;
    color: var(--us-fg-inverse);
    background-color: rgba(0, 0, 0, 0.7);
    padding: 0.75rem 1.25rem;
    border-radius: var(--us-radii-micro-medium);
    text-align: center;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 10;
    display: none;
}

.control-group-label {
    color: var(--us-fg-default);
    width: 100%;
}

#stopRecordButton {
    display: none;
}

hr {
    border: none;
    height: 1px;
    background-color: var(--us-border-medium);
    margin: 1.5rem 0;
}

/* Preview container styles */
.preview-container {
    margin-top: 0.75rem;
    padding: 0.75rem;
    background-color: var(--us-bg-low);
    border: 1px solid var(--us-border-soft);
    border-radius: var(--us-radii-micro-small);
    position: relative;
}

.preview-container.preview-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.preview-item {
    position: relative;
    display: inline-block;
}

.preview-image {
    width: 60px;
    height: 60px;
    object-fit: cover;
    border-radius: var(--us-radii-micro-small);
    border: 1px solid var(--us-border-medium);
}

.delete-button {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background-color: var(--us-accent-high);
    color: var(--us-fg-inverse);
    border: none;
    cursor: pointer;
    font-size: 12px;
    font-weight: bold;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
}

.delete-button:hover {
    background-color: #d32f2f;
}


