/* Animation CSS */
@keyframes fill-progress {
  0% {
    width: 0;
  }
  100% {
    width: 40vw;
  }
}

@keyframes rainbow-animation {
    0% {
        background-position: 0%;
    }
    100% {
        background-position: 100%;
    }
}

/* Element-level CSS */
* {
    box-sizing: border-box;
}

html {
    height: 100%;
    width: 100%;
}

table {
    border-collapse: collapse;
    border: 1px solid black;
    font-size: 1.04em;
}

table td {
    border: 2px solid black;
}

body {
    margin: 0;
    background: #050505;
    color: #f5f5f5;
    font-family: "Hack", monospace;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 20px;
    background: linear-gradient(140deg, #121212, #1f1f1f 65%, #0b0b0b);
    border-bottom: 1px solid #242424;
}

h1 {
    margin: 0;
    font-size: 1.05rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

select,input,textarea,date {
    background-color: #161616;
    color: #f5f5f5;
    border: 1px solid #303030;
}

main {
    flex: 1 1 auto;
    position: relative;
    overflow: hidden;
}

pre {
    white-space: pre-wrap;
    background-color: #ecedec;
    color: #000;
    padding: 12px;
    padding-right: 3vw;
}

button {
    background-color: #ff7800;
    color: #050505;
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    font-family: 'Hack', monospace;
}

footer {
    background: #121212;
    color: #f5f5f5;
    text-align: center;
    padding: 12px 20px;
    font-size: 0.9rem;
    border-top: 1px solid #242424;
}

audio {
    width: 30vw;
    height: auto;
}

a {
    color: #ff9a3c;
}

/* Pseudo-class and attribute CSS */
a:visited {
    color: #7a4723;
}

button[data-tool] {
    border: 1px solid #303030;
    background: #161616;
    color: inherit;
    font: inherit;
    padding: 8px 18px;
    cursor: pointer;
    border-radius: 6px;
    transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}

button[data-tool]:hover {
    background: #252525;
}

button[data-tool].active {
    background: #ff7800;
    color: #050505;
    border-color: #ff7800;
}

span.checkmark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    position: relative;
    background-color: #161616;
    border: 2px solid #303030;
    border-radius: 4px;
    flex-shrink: 0;
}

[data-mic-container] {
    margin-bottom: 8px;
}

button:disabled,
button[disabled] {
    background-color: #3a3a3a;
    color: #777777;
    cursor: not-allowed;
    border-color: #3a3a3a;
}

/* ID-level CSS */
#faq-link {
    background: linear-gradient(270deg, #ff0000, #ff7f00, #ffff00, #00ff00, #5b5bf1, #7612bd, #8b00ff, #ff0000);
    background-size: 1400% 1400%;
    -webkit-background-clip: text;
    -moz-background-clip: text;
    background-clip: text;
    color: transparent;
    -webkit-text-fill-color: transparent;
    animation: rainbow-animation 60s ease infinite;
}

#audioPlayback {
    display: block;
    margin-top: 8px;
    padding: 6px;
    background: #1a1a1a;
    border: 1px solid #303030;
    border-radius: 6px;
    min-height: 40px;
}

.generatedHeader {
    background-color: #222;
    color: #f5f5f5;
    padding: 6px;
    border-radius: 4px;
    display: inline-block;
    margin-top: 6px;
}

#status {
    font-family: Hack;
}

#balconTable table,#balconTable th, #balconTable td {
    border: 1px solid white;
}

#crawlExportProgress {
    height: 1.25rem;
    width: 100%;
    background-color: #000000;
    border: 1px solid #444444;
    border-radius: 10px;
    appearance: none;
    overflow: hidden;
    display: block;
}

#crawlExportProgress::-webkit-progress-bar {
    background-color: #000000;
}

#crawlExportProgress::-webkit-progress-value {
    background-color: #ff7800;
    border-radius: 10px;
    transition: width 150ms linear;
}

#crawlExportProgress::-moz-progress-bar {
    background-color: #ff7800;
    transition: width 150ms linear;
}

#decoder-panel #output {
    font-family: "Hack", monospace;
    white-space: pre-wrap;
}

#decoder-panel #sync {
    font-family: monospace;
    font-size: 1.5em;
}

#decoder-panel .level-meter {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 12px 0 18px;
}

#decoder-panel .level-meter__label {
    font-size: 0.75rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #9a9a9a;
    min-width: 56px;
}

#decoder-panel .level-meter__bars {
    position: relative;
    flex: 1 1 auto;
    height: 10px;
    border-radius: 999px;
    overflow: hidden;
    background: #141414;
    border: 1px solid #232323;
}

#decoder-panel .level-meter__fill {
    position: absolute;
    inset: 0;
    width: 0%;
    background: linear-gradient(90deg, #34c759, #ffcc00 60%, #ff453a 90%);
    transition: width 80ms linear;
}

#decoder-panel .modalContainer {
    left: 0;
    top: 0;
    z-index: 999;
    position: fixed;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

#decoder-panel .modalBox {
    z-index: 1000;
    font-family: monospace;
    padding: 10px;
    margin: 15px;
    background-color: #0e0e0e;
    border: 1px solid #2b2b2b;
}

#decoder-panel .modalContent {
    padding: 20px;
    height: 50%;
    position: relative;
}

#decoder-panel .modalClose {
    position: absolute;
    font-size: 1.5em;
    cursor: pointer;
    z-index: 1001;
    margin: 2px;
}

#decoder-panel .watch {
    color: #ff7800;
}

#decoder-panel .warning {
    color: #ff4d4d;
}

#encoder-panel a {
    color: #ff9a3c;
}

#encoder-panel table,
#encoder-panel th,
#encoder-panel td {
    border: 1px solid #444;
}

#encoder-panel table {
    border-collapse: collapse;
    font-size: 1.04em;
}

#encoder-panel td,
#encoder-panel th {
    padding: 6px 8px;
}

#encoder-panel .control-panel button {
    display: inline-block;
}

#spliceWaveform {
    width: 100%;
    height: auto;
    border-radius: 6px;
    background: linear-gradient(180deg, #0f0f0f 0%, #111 100%);
}

#tab-set {
    display: flex;
    gap: 10px;
}

#cheader {
    width: 35vw;
    text-wrap: wrap;
}

#ttsVoice2 {
    width: 100%;
    height: 15rem;
    font-family: "Hack", monospace;
    font-size: 1rem;
    padding: 8px;
    border-radius: 6px;
    resize: vertical;
}

#ttsText:disabled {
    opacity: 0.65;
}

#ttsText, #ttsText2 {
    display: none;
}

#ttsVoice2 {
    height: auto;
}

#mobile-controls {
    display: none;
}

#stateselect, #countyselect {
    width: 10vw;
}

#rgselect {
    width: 3vw;
}

#spliceSilence,
#spliceLoudness {
    width: 7.5vw;
}

#spliceMacros {
    width: 15vw;
}

/* Class-level CSS */
.funny-haha {
    color: #f5f5f5 !important;
    text-decoration: none;
}

.codemirror-example > .cm-s-dracula .CodeMirror-cursor {
    border-left: solid thin #282a36 !important;
}

.inner-copy-paste-paragraph {
    margin: 0;
    margin-bottom: -12px;
}

.codemirror-example, .CodeMirror.vtml-codemirror-pre, .CodeMirror.bal-codemirror-pre {
    font-family: "Hack", monospace;
    font-size: 1rem;
    margin-top: 12px;
    height: 25vh;
}

.copy-paste-code-container {
    border: 1px solid #303030;
    border-radius: 6px;
    padding: 12px;
    background-color: #121212;
}

.copy-text {
    position: relative;
    bottom: -4vh;
    left: 92vw;
    background-color: #ff7800;
    color: #050505;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.9rem;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    opacity: 0.9;
    z-index: 10000;
    cursor: pointer;
    text-anchor: end;
}

.crawl-export-progress {
    padding: 12px 16px;
    border-radius: 12px;
    margin-top: 12px;
}

.crawl-export-progress__row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.crawl-export-progress__row progress {
    flex: 1 1 auto;
}

.ttsText--editor {
    display: block;
    width: 100%;
    margin: 0 auto;
}

.CodeMirror.ttsText--editor {
    display: inline-block;
    width: 100%;
    margin: 0 auto;
    background: #231c14;
    border: 1px solid #2b2b2b;
    border-radius: 6px;
    font-family: "Hack", monospace;
    font-size: 1rem;
}

.ttsText--editor .CodeMirror-scroll {
    min-height: 15rem;
}

.ttsText--editor .CodeMirror-gutters {
    background: #1b140c;
    border-right: 1px solid #2f271d;
}

.ttsText--editor .CodeMirror-linenumber {
    color: #fbec5d;
}

.ttsText--editor pre {
    background: transparent;
    color: inherit;
    padding: 0;
    margin: 0;
    white-space: pre-wrap;
}

.ttsText--editor .CodeMirror-wrap pre.CodeMirror-line,
.ttsText--editor .CodeMirror-wrap pre.CodeMirror-line-like {
    padding: 0 4px;
}

.footer-links {
    list-style: none;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0;
    margin: 0;
    padding: 0;
    flex-wrap: nowrap;
}

.footer-links li {
    display: inline-flex;
    align-items: center;
}

.footer-links li + li::before {
    content: "•";
    color: #555;
    margin: 0 12px;
}

.footer-links p {
    margin: 0;
}

.section-heading {
    font-size: 0.95rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    margin: 0 0 18px;
    color: #ff7800;
}

.hidden-checkbox {
    position: absolute;
    top: 50%;
    left: 0;
    width: 20px;
    height: 20px;
    margin: 0;
    opacity: 0;
    cursor: pointer;
    transform: translateY(-50%);
}

.custom-checkbox-container {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    user-select: none;
    line-height: 1.2;
}

.custom-checkbox-container input[type="checkbox"]:focus-visible~span.checkmark {
    box-shadow: 0 0 0 2px rgba(255, 120, 0, 0.55);
}

.custom-checkbox-container input[type="checkbox"]:checked~span.checkmark {
    background-color: #ff7800;
    border-color: #ff7800;
}

.custom-checkbox-container span.checkmark:after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 6px;
    height: 12px;
    border: solid white;
    border-width: 0 3px 3px 0;
    transform: translate(-50%, -60%) rotate(45deg);
    opacity: 0;
}

.custom-checkbox-container input[type="checkbox"]:checked~span.checkmark:after {
    opacity: 1;
}

.shorter-hr {
    border: none;
    border-top: 1px solid #303030;
    margin: 12px 0;
    width: 30%;
}

.eom-hr {
    border: none;
    border-top: 3px solid #303030;
    margin: 12px 0;
    width: 60%;
}

.control-panel button {
    display: inline-block;
}

.splice-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 16px;
    align-items: start;
}

.waveform-card {
    background: #0a0a0a;
    border: 1px solid #1e1e1e;
    border-radius: 8px;
    padding: 12px;
}

.waveform-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 8px;
    gap: 8px;
    flex-wrap: wrap;
}

.waveform-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.splice-controls {
    background: #0b0b0b;
    border: 1px solid #1e1e1e;
    border-radius: 8px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.status-line {
    display: block;
    min-height: 18px;
    opacity: 0.85;
}

.splice-action-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 8px;
}

.splice-storage {
    font-size: 0.9em;
}

.splice-timeline {
    margin-top: 16px;
}

.splice-timeline__hint {
    margin-top: 4px;
}

.splice-segment-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    gap: 8px;
}

.title {
    font-weight: bold;
}

.entry {
    cursor: pointer;
    user-select: none;
}

.tool-panel {
    position: absolute;
    inset: 0;
    overflow-y: auto;
    padding: 24px clamp(18px, 2vw, 32px);
    display: none;
}

.tool-panel.active {
    display: block;
}

.mobileBreak {
    display: none;
}

.CodeMirror-code {
    margin-right: 110px;
}

/* Media Queries */
/* Mobile devices */
@media screen and (max-width: 1079px) {
    .inner-copy-paste-paragraph {
        margin: 0;
        margin-bottom: -12px;
    }

    .codemirror-example, .CodeMirror.vtml-codemirror-pre, .CodeMirror.bal-codemirror-pre {
        font-family: "Hack", monospace;
        font-size: 1rem;
        margin-top: 50px;
        height: 25vh;
    }

    .copy-paste-code-container {
        border: 1px solid #303030;
        border-radius: 6px;
        padding: 12px;
        background-color: #121212;
    }

    .copy-text {
        position: relative;
        bottom: -2vh;
        left: 55vw;
        background-color: #ff7800;
        color: #050505;
        padding: 8px 12px;
        border-radius: 6px;
        font-size: 0.9rem;
        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
        opacity: 0.9;
        z-index: 1000;
        cursor: pointer;
        text-anchor: end;
    }

    footer {
        font-size: 0.8rem;
        position: sticky;
        bottom: 0;
        overflow-y: scroll;
        z-index: 10000;
    }

    .footer-links {
        list-style: none;
        display: flex;
        justify-content: left;
        align-items: left;
        gap: 0;
        margin: 0;
        padding: 0;
        flex-wrap: nowrap;
    }

    .footer-links li:last-child {
        padding-right: 5vw;
    }

    .footer-links li {
        display: inline-flex;
        align-items: left;
    }

    .footer-links li + li::before {
        content: "•";
        color: #555;
        margin: 0 12px;
    }

    .footer-links p {
        margin: 0;
    }

    .shorter-hr,
    .eom-hr,
    #cheader,
    #ttsVoice {
        width: 100%;
    }

    #cheader {
        height: 50px;
    }

    audio {
        width: 90vw;
    }

    .splice-grid {
        display: flex;
        flex-direction: column;
        gap: 12px;
    }

    .waveform-card,
    .splice-controls,
    .splice-timeline {
        width: 100%;
    }

    #spliceWaveform {
        height: 8rem;
    }

    .splice-segment-list li div {
        width: 3vw;
    }

    .splice-segment-list li {
        text-overflow: ellipsis;
        width: 100%;
        height: 8rem;
        overflow: scroll;
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    }

    #tab-set {
        flex: 1 1 auto;
        min-width: 0;
    }

    #nav-buttons {
        margin-left: 0;
        width: 100%;
        max-width: 100%;
        min-width: 0;
        display: flex;
        gap: 10px;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap;
    }

    #nav-buttons button {
        flex: 0 0 auto;
        white-space: nowrap;
    }

    #mobile-controls {
        display: inline-block;
    }

    #desktop-controls {
        display: none;
    }

    #stateselect, #countyselect, #rgselect {
        width: 70vw;
    }

    .generatedHeader {
        width: 100%;
        text-wrap: wrap;
    }

    .mobileBreak {
        display: block;
    }

    .ttsText--editor {
        width: 100% !important;
    }

    .CodeMirror.ttsText--editor {
        width: 100% !important;
    }

    .CodeMirror-code {
        margin-right: 0;
    }

    #spliceMacros {
        width: 40vw;
    }

    #spliceSilence,
    #spliceLoudness,
    #static-noise-level,
    #static-noise-fade-depth,
    #static-noise-fade-rate {
        width: 20vw;
    }
}

/* Light mode */
@media (prefers-color-scheme: light) {
    * {
        --orange: #c96209;
    }

    body {
        background: #f5f5f5;
        color: #050505;
    }

    #encoder-panel a {
        color: var(--orange);
    }

    a {
        color: var(--orange);
    }

    a:visited {
        color: #1d941d;
    }

    .section-heading {
        color: var(--orange);
    }

    header {
        background: linear-gradient(140deg, #e0e0e0, #f0f0f0 65%, #d0d0d0);
        border-bottom: 1px solid #c0c0c0;
    }

    button[data-tool] {
        background: #e0e0e0;
        border: 1px solid #b0b0b0;
        color: #050505;
    }

    button[data-tool]:hover {
        background: #d0d0d0;
    }

    button[data-tool].active {
        background: var(--orange);
        color: #050505;
        border-color: var(--orange);
    }

    button {
        background-color: var(--orange);
        color: #050505;
    }

    .tool-panel {
        background: #fff;
        color: #050505;
    }

    .custom-checkbox-container span.checkmark {
        background-color: #f0f0f0;
        border: 2px solid #b0b0b0;
    }

    .custom-checkbox-container input[type="checkbox"]:checked~span.checkmark {
        background-color: var(--orange);
        border-color: var(--orange);
    }

    select,input,textarea,date {
        background-color: #fff;
        color: #050505;
        border: 1px solid #b0b0b0;
    }

    footer {
        background: #e0e0e0;
        color: #050505;
        border-top: 1px solid #c0c0c0;
    }

    #decoder-panel .modalBox {
        background-color: #f0f0f0;
        border: 1px solid #b0b0b0;
    }

    #decoder-panel .level-meter__bars {
        background: #e0e0e0;
        border: 1px solid #b0b0b0;
    }

    #balconTable table, #balconTable th, #balconTable td {
        border: 1px solid #050505;
    }

    .CodeMirror-linenumber, .CodeMirror-gutter-elt {
        color: #fefefe !important;
    }

    .splice-controls,
    .waveform-card,
    .splice-segment-list,
    .splice-segment-list li {
        background-color: #f0f0f0 !important;
        border: 1px solid #b0b0b0 !important;
    }

    button:disabled,
    button[disabled] {
        background-color: #d0d0d0;
        color: #777777;
        cursor: not-allowed;
    }

    [data-splice-persist] {
        color: #1d941d !important;
    }

    .copy-paste-code-container {
        border: 1px solid #b0b0b0;
        background-color: #f0f0f0;
    }

    .cm-s-abbott .CodeMirror-line::selection,
    .cm-s-abbott .CodeMirror-line > span::selection,
    .cm-s-abbott .CodeMirror-line > span > span::selection,
    .cm-s-abbott .CodeMirror-selected,
    .cm-s-abbott.CodeMirror-focused .CodeMirror-selected,
    .cm-s-abbott .CodeMirror-line::-moz-selection,
    .cm-s-abbott .CodeMirror-line > span::-moz-selection,
    .cm-s-abbott .CodeMirror-line > span > span::-moz-selection,
    .cm-s-abbott .CodeMirror-selected,
    .cm-s-abbott.CodeMirror-focused .CodeMirror-selected {
        color: #ffd580 !important;
        background: #ffd580 !important;
    }

    .generatedHeader {
        background-color: #f5f5f5 !important;
        color: #050505 !important;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.001ms !important;
        transition-duration: 0.001ms !important;
    }
}
