:root {
    color-scheme: dark;
    --bg: #050d1f;
    --panel: #0e1a33;
    --panel-dark: #08112a;
    --accent: #ff4e47;
    --accent-2: #1dd181;
    --muted: #6f85c0;
    --text: #f1f4ff;
    --border: rgba(255, 255, 255, 0.1);
    --radius-lg: 20px;
    --radius-md: 12px;
    --radius-sm: 8px;
    --shadow: 0 12px 40px rgba(3, 6, 15, 0.65);
}

* {
    box-sizing: border-box;
}

.hidden {
    display: none !important;
}

body {
    margin: 0;
    font-family:
        "Inter",
        system-ui,
        -apple-system,
        BlinkMacSystemFont,
        sans-serif;
    background: radial-gradient(circle at top, #0d1f45, var(--bg));
    color: var(--text);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    padding: 32px;
}

.app-shell {
    width: min(1100px, 100%);
    background: rgba(14, 26, 51, 0.8);
    border-radius: var(--radius-lg);
    padding: 32px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.link-btn {
    background: #ffffff;
    color: #0b142d;
    border: none;
    border-radius: var(--radius-md);
    padding: 8px 16px;
    font-weight: 600;
    cursor: pointer;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.link-btn:hover {
    background: #f1f4ff;
}

.brand {
    display: flex;
    align-items: center;
    gap: 16px;
    cursor: pointer;
}

#brandReset:focus-visible {
    outline: 2px solid var(--accent-2);
    outline-offset: 4px;
}

.brand-logo {
    width: 56px;
    height: 56px;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.15);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
    background: rgba(255, 255, 255, 0.05);
}

.brand-logo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.brand-title {
    margin: 0;
    font-weight: 600;
    letter-spacing: 0.03em;
    font-size: 28px;
}

.brand-sub {
    margin: 0;
    font-size: 16px;
    color: var(--muted);
}

.input-bar {
    display: grid;
    grid-template-columns: 1fr auto auto auto;
    gap: 16px;
    margin-bottom: 20px;
}

.ios-hint {
    grid-column: 1 / -1;
    margin: 0;
    padding: 10px 14px;
    border-radius: var(--radius-md);
    border: 1px dashed rgba(255, 255, 255, 0.25);
    background: rgba(255, 255, 255, 0.04);
    font-size: 14px;
    color: var(--muted);
}

.ios-native-input {
    display: block;
    width: 100%;
    padding: 14px;
    border-radius: var(--radius-md);
    border: 1px dashed var(--accent-2);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text);
    font-weight: 600;
    cursor: pointer;
}

body.ios-device #fileInput.ios-native-input {
    grid-column: 1 / -1;
}

.ios-native-input::file-selector-button {
    font-family: inherit;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--accent-2);
    color: #03140f;
    padding: 8px 12px;
    font-weight: 600;
    margin-right: 12px;
    cursor: pointer;
}

.url-field {
    display: flex;
    flex-direction: column;
    background: var(--panel-dark);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    padding: 10px 14px;
    position: relative;
}

.url-field input {
    background: transparent;
    border: none;
    outline: none;
    color: var(--text);
    font-size: 16px;
    margin-top: 2px;
}

.url-field input::placeholder {
    color: rgba(255, 255, 255, 0.4);
}

.clear-input {
    position: absolute;
    top: 50%;
    right: 14px;
    transform: translateY(-20%);
    border: none;
    background: rgba(255, 255, 255, 0.1);
    color: var(--text);
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.clear-input:hover {
    background: rgba(255, 255, 255, 0.2);
}

.url-label {
    font-size: 12px;
    text-transform: uppercase;
    color: var(--muted);
    letter-spacing: 0.08em;
}

.player-panel {
    margin-bottom: 24px;
}

.player-wrapper {
    background: #0b142d;
    border-radius: var(--radius-lg);
    padding: 20px;
    min-height: 504px;
    position: relative;
    border: 1px solid var(--border);
    box-shadow: inset 0 0 40px rgba(3, 6, 15, 0.6);
}

.player-wrapper.drag-active {
    border-color: var(--accent-2);
    box-shadow:
        inset 0 0 40px rgba(3, 6, 15, 0.6),
        0 0 0 2px rgba(29, 209, 129, 0.2);
}

.media-viewer,
.player-placeholder {
    width: 100%;
    height: 432px;
    border-radius: var(--radius-md);
    background: #030711;
    object-fit: contain;
}

#youtubeWrapper {
    position: relative;
    overflow: hidden;
}

#youtubeWrapper iframe {
    width: 100%;
    height: 100%;
    border: none;
    border-radius: var(--radius-md);
    display: block;
    background: #000;
}

.media-viewer.hidden,
#playerPlaceholder.hidden {
    display: none;
}

.player-placeholder {
    border: 1px dashed rgba(255, 255, 255, 0.2);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    gap: 8px;
}

.drop-overlay {
    position: absolute;
    inset: 20px;
    border-radius: var(--radius-md);
    border: 2px dashed var(--accent-2);
    background: rgba(5, 13, 31, 0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 24px;
    color: var(--accent-2);
    font-weight: 600;
    letter-spacing: 0.08em;
    pointer-events: none;
}

.controls-panel {
    background: var(--panel-dark);
    border-radius: var(--radius-lg);
    padding: 24px;
    border: 1px solid var(--border);
}

.transport-row {
    display: flex;
    align-items: center;
    gap: 18px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.playlist-controls {
    display: flex;
    gap: 8px;
    margin-left: 0;
    flex: 1 1 100%;
    justify-content: center;
}

.playlist-controls.hidden {
    display: none;
}

.speed-control {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(255, 255, 255, 0.05);
    padding: 10px 14px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    flex: 1 1 220px;
}

.speed-control label {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
}

.speed-control input[type="range"] {
    width: 120px;
}

.speed-control span {
    min-width: 48px;
    text-align: right;
    font-weight: 600;
    letter-spacing: 0.04em;
}

.volume-control label {
    min-width: 60px;
}

.volume-control {
    flex: 1 1 220px;
}

.time-display {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    justify-content: center;
    text-align: left;
    margin-left: auto;
}

.status-panel {
    margin: 32px 0 0;
    padding: 16px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.03);
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
    text-align: center;
}

.app-footer {
    text-align: center;
    margin-top: 24px;
    font-size: 14px;
    color: var(--muted);
}

.app-footer p {
    margin: 0 0 8px;
}

.app-footer a {
    color: var(--muted);
    text-decoration: none;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.app-footer a:hover {
    opacity: 1;
    text-decoration: underline;
}

.round-btn {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.07);
    color: var(--text);
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease;
}



.play-btn {
    justify-content: center;
    background: rgba(255, 255, 255, 0.12);
    color: var(--text);
}

.play-btn.playing {
    background: var(--accent-2);
    color: #03140f;
}

.play-btn.playing:not(:disabled):hover {
    background: #29e090;
}

.round-btn.info-btn,
.round-btn.info-close {
    width: 40px;
    height: 40px;
    font-size: 16px;
    background: rgba(255, 255, 255, 0.12);
    color: var(--text);
}

.round-btn.download-btn {
    font-size: 18px;
}

.round-btn.info-btn:not(:disabled):hover,
.round-btn.info-close:not(:disabled):hover {
    background: rgba(255, 255, 255, 0.25);
}

.round-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.round-btn:not(:disabled):hover {
    background: rgba(255, 255, 255, 0.2);
}

.time-display span {
    font-size: 13px;
    color: var(--muted);
}

.time-display strong {
    display: block;
    font-size: 32px;
    letter-spacing: 0.04em;
    margin-top: -4px;
    min-width: 90px;
    text-align: left;
}

.btn {
    border: none;
    border-radius: var(--radius-md);
    padding: 0 18px;
    height: 52px;
    font-weight: 600;
    cursor: pointer;
    color: var(--text);
    background: rgba(255, 255, 255, 0.1);
    transition:
        background 0.2s ease,
        transform 0.1s ease;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn.primary {
    background: var(--accent);
}

.btn.ghost {
    background: rgba(255, 255, 255, 0.08);
}

.btn.success {
    background: var(--accent-2);
    color: #03140f;
}

.btn.success.inactive {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text);
}

.btn.mini {
    height: 36px;
    padding: 0 14px;
    font-size: 13px;
}

.btn.mini.danger {
    background: var(--accent);
}

.btn.loop-marker {
    background: #f6c343;
    color: #2a1700;
}

.btn.loop-marker:not(:disabled):hover {
    background: #ffd24f;
}

.btn:not(:disabled):active {
    transform: translateY(1px);
}

.progress-block {
    margin-bottom: 26px;
}

#progressSlider {
    --loop-start: 0%;
    --loop-end: 0%;
    background: linear-gradient(to right,
            rgba(255, 255, 255, 0.15) 0%,
            rgba(255, 255, 255, 0.15) var(--loop-start),
            #f6c343 var(--loop-start),
            #f6c343 var(--loop-end),
            rgba(255, 255, 255, 0.15) var(--loop-end),
            rgba(255, 255, 255, 0.15) 100%);
}

input[type="range"] {
    appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.15);
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
}

input[type="range"]:disabled {
    opacity: 0.4;
}

.loop-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 18px;
    margin-bottom: 24px;
}

.loop-card {
    padding: 16px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.03);
}

.loop-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    gap: 12px;
}

.loop-title {
    margin: 0;
    font-size: 14px;
    letter-spacing: 0.04em;
    color: var(--muted);
    text-transform: uppercase;
}

.loop-time {
    margin: 0;
    font-size: 26px;
    font-weight: 600;
}

.mode-hint {
    margin: 0;
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.status-text-group {
    display: flex;
    align-items: center;
    gap: 12px;
}

.status-message {
    margin: 0;
    font-weight: 500;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.status-message.status-error {
    color: #ff4e47;
}

.status-message.clickable {
    cursor: pointer;
    text-decoration: underline;
}

.modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
}

.modal.hidden {
    display: none;
}

.modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
}

.modal-box {
    position: relative;
    background: var(--panel-dark);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    padding: 24px;
    width: min(420px, 90%);
    box-shadow: var(--shadow);
    z-index: 1;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.modal-header h3 {
    margin: 0;
    font-size: 20px;
}

.info-list {
    margin: 0 0 16px;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.info-list dt {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    margin: 0;
}

.info-list dd {
    margin: 2px 0 0;
    font-weight: 600;
    font-size: 15px;
}

.help-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.help-grid h4 {
    margin: 0 0 8px;
    font-size: 16px;
    color: var(--accent-2);
}

.help-grid ul {
    margin: 0;
    padding-left: 18px;
    color: var(--muted);
    font-size: 14px;
}

@media (max-width: 768px) {
    body {
        padding: 16px;
    }

    .app-shell {
        padding: 20px;
    }

    .input-bar {
        grid-template-columns: 1fr;
    }

    .transport-row {
        flex-direction: column;
        align-items: flex-start;
    }

    .time-display strong {
        font-size: 24px;
    }
}