* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

*::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

*::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
}

*::-webkit-scrollbar-thumb {
    background-color: rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    border: 2px solid transparent;
    background-clip: content-box;
}

*::-webkit-scrollbar-thumb:hover {
    background-color: rgba(255, 255, 255, 0.5);
}

* {
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.3) transparent;
}

body {
    font-family: 'DM Sans', sans-serif;
    background: radial-gradient(ellipse at top, #1e1e2f, #0f0f1a);
    color: white;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1rem;
}

.container {
    max-width: 800px;
    width: 100%;
    padding: 0 1rem;
}

header {
    text-align: center;
    margin-bottom: 1.5rem;
}

header h1 {
    font-size: clamp(2rem, 6vw, 2.5rem);
    color: #fff;
}

header .colored {
    color: #00C2FF;
}

header p {
    color: #bbb;
    font-size: clamp(0.9rem, 3.5vw, 1.1rem);
}

textarea {
    width: 100%;
    height: clamp(80px, 20vw, 100px);
    max-height: 300px;
    border-radius: 8px;
    border: none;
    padding: 0.8rem;
    font-size: clamp(0.9rem, 3vw, 1rem);
    background: rgba(255, 255, 255, 0.1);
    color: white;
    resize: none;
    overflow-y: auto;
    box-sizing: border-box;
    text-align: justify;
}

.controls {
    display: flex;
    width: 100%;
    max-width: 600px;
    margin: 20px auto;
    flex-wrap: nowrap;
    gap: 0.8rem;
    justify-content: center;
}

.controls input,
.controls button {
    flex: 1;
    padding: 0.6rem 1rem;
    border-radius: 8px;
    border: none;
    font-size: clamp(0.9rem, 3vw, 1rem);
    min-width: 0;
}

.controls input {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.controls button {
    background: linear-gradient(135deg, #7B61FF, #00C2FF);
    color: white;
    cursor: pointer;
    transition: transform 0.2s ease;
}

.controls button.hidden {
    display: none;
}

.controls button:hover {
    transform: scale(1.05);
}

#modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    flex-direction: column;
}

#modal.hidden {
    display: none;
}

#modalContent {
    position: relative;
    width: 100%;
    height: 100%;
    padding-bottom: 100px;
    display: flex;
    justify-content: center;
    align-items: center;
}

#modalWordDisplay {
    font-size: clamp(2rem, 10vw, 3.5rem);
    font-weight: bold;
    color: white;
    user-select: none;
    text-align: center;
    max-width: 90vw;
    word-break: break-word;
}

.modal-bottom-line {
    position: fixed;
    bottom: 40px;
    left: 50%;
    transform: translateX(-50%);
    width: clamp(200px, 60vw, 350px);
    height: 4px;
    background: white;
    border-radius: 8px;
    z-index: 1100;
    transition: opacity 0.4s ease, transform 0.4s ease;
    opacity: 0;
}

.modal-bottom-line.visible {
    opacity: 1;
}

.modal-bottom-line.fadeout {
    opacity: 0;
    transform: translateX(-50%) translateY(20px);
}

#modalControls {
    position: fixed;
    bottom: 60px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    pointer-events: auto;
    background: transparent !important;
    padding: 0;
    opacity: 0;
    transform: translateY(20px) translateX(-50%);
    transition: opacity 0.3s ease, transform 0.3s ease;
    z-index: 1200;
    user-select: none;
    justify-content: center;
}

#modalControls.visible {
    opacity: 1;
    transform: translateY(0) translateX(-50%);
}

#modalControls.hidden {
    display: none;
}

#modalControls button,
#modalControls input[type="color"],
#modalControls select {
    background: rgba(81, 81, 81, 0.5);
    border: none;
    border-radius: 6px;
    padding: 0.4rem 0.7rem;
    color: white;
    cursor: pointer;
    font-size: clamp(0.9rem, 3vw, 1.1rem);
    opacity: 0;
    transform: translateY(20px);
    animation-fill-mode: forwards;
    animation-name: fadeSlideUp;
    animation-duration: 0.4s;
    position: relative;
    pointer-events: auto;
}

#modalControls input[type="color"] {
    width: 36px;
    height: 36px;
    padding: 0;
}

#modalControls select {
    font-size: clamp(0.8rem, 2.5vw, 0.9rem);
    width: 60px;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    text-align: center;
    background: rgba(81, 81, 81, 0.5) url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="white"><path d="M7 10l5 5 5-5z"/></svg>') no-repeat right 0.5rem center;
    background-size: 10px;
}

#modalControls select:focus {
    outline: none;
}

#modalControls select option {
    background: #1e1e2f;
    color: white;
}

#modalControls button:hover::after,
#modalControls input[type="color"]:hover::after,
#modalControls select:hover::after {
    content: attr(title);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: clamp(0.7rem, 2.5vw, 0.8rem);
    white-space: nowrap;
    z-index: 1300;
}

@keyframes fadeSlideUp {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

#modalControls.visible button:nth-child(1),
#modalControls.visible input:nth-child(1),
#modalControls.visible select:nth-child(1) {
    animation-delay: 0.05s;
}

#modalControls.visible button:nth-child(2),
#modalControls.visible input:nth-child(2),
#modalControls.visible select:nth-child(2) {
    animation-delay: 0.15s;
}

#modalControls.visible button:nth-child(3),
#modalControls.visible input:nth-child(3),
#modalControls.visible select:nth-child(3) {
    animation-delay: 0.25s;
}

#modalControls.visible button:nth-child(4) {
    animation-delay: 0.35s;
}

#modalControls.visible button:nth-child(5) {
    animation-delay: 0.45s;
}

#modalControls.visible button:nth-child(6) {
    animation-delay: 0.55s;
}

#modalControls.visible button:nth-child(7) {
    animation-delay: 0.65s;
}

#modalControls.visible button:nth-child(8) {
    animation-delay: 0.75s;
}

@keyframes fadeSlideDown {
    to {
        opacity: 0;
        transform: translateY(20px);
    }
}

#errorPopup {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background-color: #dc3545;
    color: white;
    padding: 0.8rem 1.2rem;
    border-radius: 6px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: clamp(0.8rem, 3vw, 0.9rem);
    z-index: 9999;
    opacity: 0;
    transform: translateY(20px);
    pointer-events: none;
    transition: opacity 0.4s ease, transform 0.4s ease;
    max-width: 90vw;
}

#errorPopup.visible {
    opacity: 1;
    transform: translateY(0);
}

#errorPopup i {
    font-size: clamp(0.9rem, 3vw, 1rem);
}

#errorPopup button {
    margin-top: 0.8rem;
    padding: 0.4rem 0.8rem;
    background: linear-gradient(135deg, #7B61FF, #00C2FF);
    border: none;
    border-radius: 6px;
    color: white;
    cursor: pointer;
    font-size: clamp(0.8rem, 3vw, 0.9rem);
}

#errorPopup button:hover {
    transform: scale(1.05);
}


@media (max-width: 600px) {
    body {
        padding: 0.5rem;
    }

    .container {
        padding: 0 0.5rem;
    }

    header {
        margin-bottom: 1rem;
    }

    header h1 {
        font-size: clamp(1.5rem, 5vw, 2rem);
    }

    header p {
        font-size: clamp(0.8rem, 3vw, 0.9rem);
    }

    textarea {
        height: clamp(60px, 18vw, 80px);
        padding: 0.6rem;
    }

    .controls {
        flex-direction: column;
        gap: 0.5rem;
    }

    .controls input,
    .controls button {
        padding: 0.5rem;
        font-size: clamp(0.8rem, 2.8vw, 0.9rem);
    }

    #modalWordDisplay {
        font-size: clamp(1.5rem, 8vw, 2.5rem);
        padding: 0 1rem;
    }

    .modal-bottom-line {
        bottom: 30px;
        width: clamp(150px, 70vw, 300px);
        height: 3px;
    }

    #modalControls {
        bottom: 50px;
        gap: 8px;
    }

    #modalControls button,
    #modalControls input[type="color"],
    #modalControls select {
        padding: 0.3rem 0.6rem;
        font-size: clamp(0.8rem, 2.5vw, 0.9rem);
    }

    #modalControls input[type="color"] {
        width: 32px;
        height: 32px;
    }

    #modalControls select {
        width: 50px;
        background-size: 8px;
    }

    #errorPopup {
        bottom: 15px;
        right: 15px;
        padding: 0.6rem 1rem;
    }

    #errorPopup button {
        padding: 0.3rem 0.6rem;
    }
}

@media (max-width: 400px) {
    #modalControls {
        flex-direction: column;
        align-items: end;
        width: 100%;
        padding: 20px;
    }

    #modalControls button,
    #modalControls input[type="color"],
    #modalControls select {
        width: 100%;
        max-width: 50px;
    }
}

#savedTextsWrapper {
    margin-top: 5rem;
}

#savedTextsTitle {
    margin: 10px;
}

#savedTextsTitle.hidden {
    display: none;
}

.saved-text-card {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    padding: 12px 16px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
    transition: all 0.2s ease;
    cursor: pointer;
    font-size: 14px;
    color: #bbb;
    white-space: pre-wrap;
    display: flex;
    align-items: flex-start;
    margin-bottom: 20px;
    position: relative;
}

.saved-text-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    background: #00111693;
    transform: translateY(-2px);
}

.saved-text-card .text-content {
    flex: 1;
    padding-right: 32px;
    padding-top: 20px;
}

.saved-text-card .metadata {
    font-size: 12px;
    color: #888;
    margin-top: 6px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    text-align: right;
    margin-left: 20px;
}

.saved-text-card .delete-btn {
    position: absolute;
    top: -10px;
    right: -10px;
    width: 35px;
    height: 35px;
    background-color: red;
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.saved-text-card .delete-btn:hover {
    background-color: darkred;
}

.saved-text-card .delete-btn:focus {
    outline: none;
}

#globalDropOverlay {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.85);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(1.5rem, 4vw, 2rem);
    z-index: 99999;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

#globalDropOverlay.visible {
    opacity: 1;
    pointer-events: all;
}

.drop-message {
    padding: 2rem 3rem;
    border: 2px dashed #00c2ff;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.05);
}

#selectStartContainer {
    display: none;
    max-width: 600px;
    margin: 10px auto;
    line-height: 1.6;
    cursor: pointer;
    max-height: 500px;
    border-radius: 8px;
    border: none;
    padding: 0.8rem;
    font-size: clamp(0.9rem, 3vw, 1rem);
    background: rgba(255, 255, 255, 0.1);
    color: white;
    resize: none;
    overflow-y: auto;
    overflow-x: hidden;
    box-sizing: border-box;
    text-align: justify;
}


.saved-text-card .copy-btn {
    position: absolute;
    top: -10px;
    right: 35px;
    width: 35px;
    height: 35px;
    background-color: #00C2FF;
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.saved-text-card .copy-btn:hover {
    background-color: #0099CC;
}

.saved-text-card .copy-btn:focus {
    outline: none;
}

#globalLoader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
}

#globalLoader.hidden {
    display: none;
}

#globalLoader .spinner {
    width: 50px;
    height: 50px;
    border: 5px solid rgba(255, 255, 255, 0.3);
    border-top: 5px solid #00C2FF;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* Only the new confirmation modal styles are shown */
#confirmModal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1100;
}

#confirmModal.hidden {
    display: none;
}

.confirm-modal-content {
    background: #1e1e2f;
    border-radius: 12px;
    padding: 1.5rem;
    max-width: 400px;
    width: 90%;
    text-align: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.confirm-modal-content p {
    font-size: clamp(1rem, 3vw, 1.1rem);
    color: #fff;
    margin-bottom: 1.5rem;
}

.confirm-modal-buttons {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

.confirm-modal-buttons button {
    flex: 1;
    padding: 0.6rem 1rem;
    border-radius: 8px;
    border: none;
    font-size: clamp(0.9rem, 3vw, 1rem);
    cursor: pointer;
    transition: transform 0.2s ease;
}

#confirmYesBtn {
    background: linear-gradient(135deg, #7B61FF, #00C2FF);
    color: white;
}

#confirmCancelBtn {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.confirm-modal-buttons button:hover {
    transform: scale(1.05);
}

@media (max-width: 600px) {
    .confirm-modal-content {
        padding: 1rem;
        max-width: 300px;
    }

    .confirm-modal-content p {
        font-size: clamp(0.9rem, 2.8vw, 1rem);
    }

    .confirm-modal-buttons button {
        padding: 0.5rem;
        font-size: clamp(0.8rem, 2.8vw, 0.9rem);
    }
}