*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    background-color: var(--bg-base);
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    margin: 0;
    min-height: 100vh;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.container {
    width: 100%;
    max-width: 800px;
    margin: auto;
    display: flex;
    flex-direction: column;
    gap: 25px;
}

.menu {
    display: flex;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
}

.menu a {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    padding: 8px 12px;
    border-radius: 8px;
    background-color: var(--bg-surface);
    display: inline-block;
    transition: background-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
    white-space: nowrap;
}

.menu a:hover {
    color: var(--text-primary);
    background-color: var(--bg-surface-hover);
    box-shadow: 0 2px 5px var(--shadow-color-light);
}

.menu a.active {
    color: var(--button-text-color);
    background-color: var(--accent-primary);
    box-shadow: 0 3px 8px var(--shadow-color);
}

.header {
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.header-icon {
    width: 45px;
    height: 45px;
    margin-right: 15px;
}

h1 {
    color: var(--accent-primary);
    font-size: clamp(1.8rem, 5vw, 2.2rem);
    font-weight: 700;
    margin: 0;
}

.tool-description {
    text-align: center;
}

.tool-description h2 {
    color: var(--text-secondary);
    font-size: clamp(1.1rem, 3vw, 1.3rem);
    font-weight: 400;
    margin: 0 0 15px 0;
}

.telegram-link {
    color: var(--accent-tertiary);
    text-decoration: none;
    font-size: 1rem;
    transition: color 0.2s ease;
}

.telegram-link:hover {
    color: var(--accent-tertiary-hover);
    text-decoration: underline;
}

.main-card {
    background-color: var(--bg-mantle);
    border-radius: 20px;
    padding: 30px;
    box-shadow: 0 8px 25px var(--shadow-color);
    transition: background-color 0.3s ease;
    border: 1px solid var(--border-color);
}

.input-section {
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin-bottom: 25px;
}

.input-section h3 {
    color: var(--accent-secondary);
    font-size: 1.4rem;
    margin: 0;
    font-weight: 700;
    text-align: center;
}

.input-controls {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.input-group {
    display: flex;
    align-items: center;
    position: relative;
    background-color: var(--bg-surface);
    border-radius: 12px;
    border: 1.5px solid var(--border-color);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    overflow: hidden;
}

.input-group:focus-within {
    border-color: var(--input-focus-color);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--input-focus-color) 30%, transparent);
}

.input-group .icon-prefix {
    position: absolute;
    left: 15px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-tertiary);
    font-size: 1.1em;
    pointer-events: none;
}

.input-group input[type="text"] {
    flex-grow: 1;
    padding: 14px 15px 14px 45px;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 1rem;
    outline: none;
}

.input-group input[type="text"]::placeholder {
    color: var(--text-placeholder);
    opacity: 1;
}

.paste-button {
    background-color: transparent;
    color: var(--text-tertiary);
    border: none;
    border-left: 1.5px solid var(--border-color);
    padding: 0 15px;
    cursor: pointer;
    font-size: 1.1rem;
    transition: background-color 0.2s ease, color 0.2s ease;
    align-self: stretch;
    display: flex;
    align-items: center;
}

.paste-button:hover {
    background-color: var(--bg-surface-hover);
    color: var(--text-secondary);
}

#fetchStoryButton {
    background-color: var(--accent-primary);
    color: var(--button-text-color);
    border: none;
    padding: 14px 25px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    border-radius: 12px;
    transition: background-color 0.2s ease, transform 0.1s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
}

#fetchStoryButton:hover {
    background-color: var(--accent-primary-hover);
    transform: translateY(-1px);
}

#fetchStoryButton:active {
    transform: translateY(0);
}

#fetchStoryButton:disabled {
    background-color: var(--ctp-overlay0);
    cursor: not-allowed;
    transform: none;
}

.message-area {
    text-align: center;
    padding: 20px 0;
    color: var(--text-secondary);
    display: none;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    gap: 10px;
}

.message-area .loader {
    width: 30px;
    height: 30px;
    border: 3px solid var(--ctp-surface2);
    border-bottom-color: var(--accent-primary);
    border-radius: 50%;
    display: inline-block;
    animation: rotation 1s linear infinite;
    margin-bottom: 5px;
}

.message-area p {
    margin: 0;
    font-size: 1rem;
}

.message-area .error {
    color: var(--error-color);
    font-weight: 500;
}

.instruction-card {
    background-color: var(--bg-mantle);
    border-radius: 20px;
    padding: 30px;
    box-shadow: 0 8px 25px var(--shadow-color);
    transition: background-color 0.3s ease;
    border: 1px solid var(--border-color);
    text-align: center;
    display: none;
}

.instruction-card.show {
    display: block;
}

.instruction-card p {
    color: var(--text-secondary);
    font-size: 1.1rem;
    margin: 0;
    line-height: 1.6;
}

.stories-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 20px;
    margin-top: 25px;
}

.story-item {
    background-color: var(--bg-surface);
    border-radius: 10px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 4px 8px var(--shadow-color-light);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.story-item:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 12px var(--shadow-color);
}

.story-media-box {
    position: relative;
    width: 100%;
    padding-top: 177.78%;
    overflow: hidden;
    background-color: var(--rp-base);
    cursor: pointer;
}

.story-media-box video,
.story-media-box img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.play-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.3);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2;
    transition: background-color 0.2s ease;
    pointer-events: none;
}

.play-overlay i {
    font-size: 2.8rem;
    color: rgba(255, 255, 255, 0.9);
    text-shadow: 0 0 5px rgba(0, 0, 0, 0.5);
}

.story-item:hover .play-overlay {
    background-color: rgba(0, 0, 0, 0.4);
}

.story-actions {
    display: flex;
    gap: 8px;
    padding: 10px;
    background-color: var(--bg-surface);
    border-top: 1px solid var(--border-color);
    flex-wrap: wrap;
}

.story-actions button {
    flex: 1 1 auto;
    min-width: 60px;
    padding: 8px 10px;
    font-size: 0.8rem;
    font-weight: 500;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    color: var(--button-text-color);
}

.story-actions button:hover {
    transform: translateY(-1px);
}

.story-actions button:active {
    transform: translateY(0);
}

.story-actions button:disabled {
    background-color: var(--ctp-overlay0);
    cursor: not-allowed;
    transform: none;
    color: var(--text-tertiary);
}

.story-action-view-play {
    background-color: var(--accent-primary);
}

.story-action-view-play:hover {
    background-color: var(--accent-primary-hover);
}

.story-action-download {
    background-color: var(--accent-secondary);
}

.story-action-download:hover {
    background-color: var(--accent-secondary-hover);
}

.story-action-info {
    background-color: var(--accent-tertiary);
}

.story-action-info:hover {
    background-color: var(--accent-tertiary-hover);
}

.story-player-modal {
    display: none;
    position: fixed;
    z-index: 10000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: var(--modal-bg);
    -webkit-backdrop-filter: blur(5px);
    backdrop-filter: blur(5px);
    padding: 20px;
}

.story-player-modal-content {
    background-color: var(--bg-crust);
    margin: auto;
    padding: 20px;
    border: 1px solid var(--border-color);
    border-radius: 15px;
    width: 90%;
    max-width: 500px;
    position: relative;
    box-shadow: 0 5px 15px var(--shadow-color);
    display: flex;
    flex-direction: column;
}

.story-player-modal-close {
    color: var(--text-tertiary);
    align-self: flex-end;
    font-size: 28px;
    font-weight: bold;
    line-height: 1;
    padding: 0 5px;
    margin-bottom: 10px;
    cursor: pointer;
}

.story-player-modal-close:hover,
.story-player-modal-close:focus {
    color: var(--text-primary);
    text-decoration: none;
}

#modalMediaContainer,
#infoModalBody {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 300px;
    background-color: var(--bg-surface);
    border-radius: 8px;
    overflow: hidden;
}

#modalMediaContainer video,
#modalMediaContainer img {
    max-width: 100%;
    max-height: calc(100vh - 120px);
    display: block;
    object-fit: contain;
}

#infoModalBody {
    min-height: auto;
    padding: 25px;
    align-items: flex-start;
    gap: 15px;
}

.info-row {
    display: flex;
    align-items: center;
    width: 100%;
    font-size: 1rem;
}

.info-icon {
    color: var(--accent-primary);
    width: 25px;
    text-align: center;
    margin-right: 15px;
    font-size: 1.1rem;
}

.info-label {
    font-weight: 500;
    color: var(--text-secondary);
    margin-right: 10px;
}

.info-value {
    color: var(--text-primary);
    font-weight: 400;
    word-break: break-word;
}

.credits {
    color: var(--text-tertiary);
    font-size: 0.85rem;
    text-align: center;
    line-height: 1.6;
}

.credits a {
    color: var(--accent-tertiary);
    text-decoration: none;
    transition: color 0.2s ease;
}

.credits a:hover {
    color: var(--accent-tertiary-hover);
    text-decoration: underline;
}

.credits span {
    color: var(--error-color);
}

#kofi-widget-overlay,
iframe[id^='kofiframe'] {
    z-index: 10001 !important;
}

@keyframes rotation {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

#support-toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background-color: var(--bg-mantle);
    color: var(--text-secondary);
    padding: 12px 18px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 15px var(--shadow-color);
    display: flex;
    align-items: center;
    gap: 15px;
    z-index: 9999;
    font-size: 0.9rem;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.5s ease, transform 0.5s ease;
    pointer-events: none;
}

#support-toast.visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

#support-toast p {
    margin: 0;
}

#support-toast a {
    color: var(--button-text-color);
    background-color: var(--accent-tertiary);
    text-decoration: none;
    padding: 6px 12px;
    border-radius: 8px;
    font-weight: 500;
    transition: background-color 0.2s ease;
}

#support-toast a:hover {
    background-color: var(--accent-tertiary-hover);
}

#support-toast-close {
    background: none;
    border: none;
    color: var(--text-tertiary);
    font-size: 1.2rem;
    cursor: pointer;
    line-height: 1;
    padding: 0 5px;
}

#support-toast-close:hover {
    color: var(--text-primary);
}

@media (max-width: 680px) {
    body {
        padding: 10px;
    }

    .container {
        gap: 20px;
    }

    .main-card,
    .instruction-card {
        padding: 20px;
    }

    .input-controls {
        gap: 12px;
    }

    .input-group input[type="text"] {
        padding-top: 12px;
        padding-bottom: 12px;
    }

    #fetchStoryButton {
        padding-top: 12px;
        padding-bottom: 12px;
        font-size: 1rem;
    }

    .stories-list {
        grid-template-columns: repeat(2, 1fr);
        gap: 15px;
    }

    .play-overlay i {
        font-size: 2.2rem;
    }

    .story-player-modal-content {
        width: 95%;
        padding: 15px;
    }

    #support-toast {
        left: 10px;
        right: 10px;
        bottom: 10px;
        justify-content: space-between;
    }
}

@media (max-width: 400px) {
    .stories-list {
        gap: 10px;
    }

    #support-toast p {
        font-size: 0.8rem;
    }
}