:root {
    --bg: #f5f7fa;
    --panel: #ffffff;
    --panel-2: #f8fafc;
    --panel-hover: #f7f9fc;
    --border: #e5e7eb;
    --text: #1f2937;
    --muted: #6b7280;
    --accent: #4f8fd8;
    --accent-hover: #6aa3e6;
    --accent-soft: rgba(79, 143, 216, 0.10);
    --button: #f3f4f6;
    --button-hover: #e9edf2;
    --danger: #dc4b4b;
}

[data-theme="dark"] {
    --bg: #0d0f13;
    --panel: #171a20;
    --panel-2: #1b1f27;
    --panel-hover: #222731;
    --border: #2a303a;
    --text: #f3f4f6;
    --muted: #8c95a3;
    --accent: #60a5fa;
    --accent-hover: #7db5ff;
    --accent-soft: rgba(96, 165, 250, 0.12);
    --button: #20252e;
    --button-hover: #292f39;
    --danger: #ef4444;
}

* {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    height: 100%;
}

body {
    margin: 0;
    min-width: 320px;
    min-height: 100vh;
    height: 100vh;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font-family:
        Inter,
        system-ui,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;
}

button,
input {
    font: inherit;
}

button {
    -webkit-tap-highlight-color: transparent;
}

/* ========================================
   APP
======================================== */

.player-app {
    width: min(100% - 24px, 1100px);
    margin: 0 auto;
    padding: 24px 0 36px;
}

/* ========================================
   PLAYER
======================================== */

.player {
    position: relative;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 32px 38px 30px;
    box-shadow: 0 8px 28px rgba(31, 41, 55, 0.05);
}

/* ========================================
   TRACK INFO
======================================== */

.track-info {
    min-width: 0;
    text-align: center;
    margin-bottom: 28px;
}

.track-title {
    max-width: 1000px;
    margin: 0 auto;

    font-size: clamp(18px, 1.8vw, 24px);
    font-weight: 600;
    line-height: 1.35;

    overflow: hidden;
    overflow-wrap: anywhere;

    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
}

.track-meta {
    margin-top: 8px;

    color: var(--muted);
    font-size: 14px;
    line-height: 1.2;

    text-transform: uppercase;
    letter-spacing: 0.08em;
}

/* ========================================
   PROGRESS
======================================== */

.progress-area {
    display: grid;
    grid-template-columns: 52px minmax(0, 1fr) 68px;
    align-items: center;
    gap: 12px;
    margin-bottom: 28px;
}

.progress-area span {
    color: var(--muted);
    font-size: 13px;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.progress-area span:last-child {
    text-align: right;
}

input[type="range"] {
    width: 100%;
    height: 20px;
    margin: 0;
    cursor: pointer;
    accent-color: var(--accent);
}

/* ========================================
   VOLUME
======================================== */

.volume-area {
    width: min(100%, 330px);
    margin: 18px auto 28px;

    display: flex;
    align-items: center;
    gap: 8px;
}

.volume-area input {
    flex: 1;
}

.icon-button {
    width: 42px;
    height: 42px;
    flex: 0 0 42px;

    display: inline-flex;
    align-items: center;
    justify-content: center;

    border: 1px solid transparent;
    border-radius: 50%;

    background: transparent;
    color: var(--muted);

    cursor: pointer;

    transition:
        color 0.15s ease,
        background 0.15s ease,
        transform 0.12s ease;
}

.icon-button:hover {
    color: var(--text);
    background: var(--button);
}

.icon-button:active {
    transform: scale(0.94);
}

/* ========================================
   CONTROLS
======================================== */

.controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;

    width: 100%;
    min-width: 0;
}

.control-button {
    position: relative;

    width: 52px;
    height: 52px;
    flex: 0 0 52px;

    display: inline-flex;
    align-items: center;
    justify-content: center;

    border: 1px solid var(--border);
    border-radius: 50%;

    background: var(--button);
    color: #b8c0cc;

    cursor: pointer;

    transition:
        color 0.15s ease,
        background 0.15s ease,
        border-color 0.15s ease,
        transform 0.12s ease;
}

.control-button:hover {
    color: var(--text);
    background: var(--button-hover);
    border-color: #d1d5db;
}

.control-button:active {
    transform: scale(0.93);
}

/* Previous / Next */

.control-button.secondary {
    font-size: 18px;
}

/* -10 / +10 */

.control-button.seek {
    gap: 1px;
    font-size: 15px;
}

.control-button.seek i {
    font-size: 13px;
}

.control-button.seek span {
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
}

/* Play / Pause */

.control-button.primary {
    width: 72px;
    height: 72px;
    flex: 0 0 72px;

    margin: 0 4px;

    border: 0;

    background: var(--accent);
    color: #ffffff;

    font-size: 24px;

    box-shadow: 0 6px 18px rgba(79, 143, 216, 0.22);
}

.control-button.primary:hover {
    background: var(--accent-hover);
    color: #ffffff;
    transform: translateY(-1px);
}

.control-button.primary:active {
    transform: scale(0.94);
}

/* Stop */

.control-button.stop {
    color: #aeb6c2;
}

.control-button.stop:hover {
    color: var(--text);
}

/* Repeat */

.control-button.repeat {
    margin-left: 4px;
}

.control-button.repeat.active {
    color: var(--accent);
    background: var(--accent-soft);
    border-color: rgba(96, 165, 250, 0.35);
}

/* Focus */

.icon-button:focus-visible,
.control-button:focus-visible,
.playlist-item:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
}

/* ========================================
   PLAYLIST
======================================== */

.playlist-section {
    margin-top: 18px;

    background: var(--panel);

    border: 1px solid var(--border);
    border-radius: 20px;

    overflow: hidden;
}

.playlist-header {
    min-height: 62px;
    padding: 0 24px;

    display: flex;
    align-items: center;
    justify-content: space-between;

    gap: 12px;

    border-bottom: 1px solid var(--border);
}

.playlist-header h2 {
    margin: 0;

    font-size: 15px;
    font-weight: 700;

    text-transform: uppercase;
    letter-spacing: 0.1em;
}

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

.playlist {
    max-height: 420px;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.playlist-item {
    width: 100%;
    min-height: 64px;

    padding: 10px 22px;

    display: grid;
    grid-template-columns: 42px minmax(0, 1fr) auto;
    align-items: center;

    gap: 12px;

    border: 0;
    border-bottom: 1px solid #eef0f3;

    background: transparent;
    color: var(--text);

    text-align: left;

    cursor: pointer;

    transition:
        background 0.15s ease,
        color 0.15s ease;
}

.playlist-item:last-child {
    border-bottom: 0;
}

.playlist-item:hover {
    background: var(--panel-hover);
}

.playlist-item.active {
    background: var(--accent-soft);
}

.playlist-number {
    color: var(--muted);

    font-size: 13px;
    text-align: center;

    font-variant-numeric: tabular-nums;
}

.playlist-item.active .playlist-number {
    color: var(--accent);
    font-weight: 600;
}

.playlist-name {
    min-width: 0;

    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;

    font-size: 16px;
    line-height: 1.4;
}

.playlist-duration {
    color: var(--muted);

    font-size: 13px;
    line-height: 1.2;

    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.playlist-loading,
.playlist-error {
    padding: 30px 20px;

    color: var(--muted);

    text-align: center;
    font-size: 14px;
}

.playlist-error {
    color: var(--danger);
}

/* ========================================
   TABLET
======================================== */

@media (max-width: 767px) {
    .player-app {
        width: min(100% - 16px, 1100px);
        padding: 10px 0 22px;
    }

    .player {
        padding: 26px 18px 24px;
        border-radius: 18px;
    }

    .track-title {
        font-size: 20px;
        -webkit-line-clamp: 2;
    }

    .volume-area {
        width: min(240px, 42%);
    }

    .controls {
        gap: 7px;
        margin-top: 20px;
    }

    .control-button {
        width: 48px;
        height: 48px;
        flex-basis: 48px;
    }

    .control-button.primary {
        width: 64px;
        height: 64px;
        flex-basis: 64px;
    }

    .playlist-section {
        margin-top: 14px;
        border-radius: 18px;
    }

    .playlist {
        max-height: calc(100vh - 360px);
    }

    .playlist-item {
        min-height: 60px;
        padding: 9px 15px;

        grid-template-columns: 32px minmax(0, 1fr) auto;
        gap: 9px;
    }

    .playlist-name {
        white-space: normal;

        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;

        font-size: 16px;
    }

    .playlist-number {
        font-size: 13px;
    }

    .playlist-duration {
        font-size: 13px;
    }
}

/* ========================================
   MOBILE
======================================== */

@media (max-width: 600px) {
    .theme-toggle {
        top: 12px;
        right: 12px;
        z-index: 20;
    }

    .track-info {
        padding-top: 34px;
    }

    body {
        background: var(--bg);
    }

    .player-app {
        width: 100%;
        padding: 0 0 16px;
    }

    .player {
        width: 100%;

        padding: 24px 12px 22px;

        border-radius: 0 0 18px 18px;
        border-left: 0;
        border-right: 0;
    }

    .track-info {
        margin-bottom: 22px;
    }

    .track-title {
        padding: 0 4px;

        font-size: 19px;
        line-height: 1.38;

        -webkit-line-clamp: 2;
    }

    .track-meta {
        margin-top: 7px;
        font-size: 12px;
    }

    /* Progress */

    .progress-area {
        grid-template-columns: 44px minmax(0, 1fr) 60px;
        gap: 7px;
    }

    .progress-area span {
        font-size: 12px;
    }

    /* Volume */

    .playlist-header .volume-area {
        width: min(180px, 45%);
    }

    .icon-button {
        width: 40px;
        height: 40px;
        flex-basis: 40px;
    }

    /* Controls */

    .controls {
        gap: 4px;
        margin-top: 18px;
    }

    .control-button {
        width: 44px;
        height: 44px;
        flex-basis: 44px;
    }

    .control-button.secondary {
        font-size: 16px;
    }

    .control-button.seek {
        font-size: 13px;
    }

    .control-button.seek i {
        font-size: 12px;
    }

    .control-button.seek span {
        font-size: 10px;
    }

    .control-button.primary {
        width: 60px;
        height: 60px;
        flex-basis: 60px;

        margin: 0 1px;

        font-size: 21px;
    }

    .control-button.repeat {
        margin-left: 1px;
    }

    /* Playlist */

    .playlist-section {
        width: 100%;
        margin-top: 10px;

        border-radius: 18px 18px 0 0;
        border-left: 0;
        border-right: 0;
    }

    .playlist-header {
        min-height: 54px;
        padding: 0 14px;
        gap: 10px;
    }

    .playlist-header h2 {
        font-size: 15px;
    }

    .playlist-header span {
        font-size: 13px;
    }

    .playlist-header .volume-area {
        width: min(150px, 40%);
        gap: 4px;
    }

    .playlist-header .icon-button {
        width: 34px;
        height: 34px;
        flex-basis: 34px;
    }

    .playlist {
        max-height: calc(100vh - 350px);
    }

    .playlist-item {
        min-height: 58px;

        padding: 9px 12px;

        grid-template-columns: 30px minmax(0, 1fr) auto;
        gap: 8px;
    }

    .playlist-number {
        font-size: 13px;
    }

    .playlist-name {
        font-size: 16px;
        line-height: 1.38;
    }

    .playlist-duration {
        font-size: 13px;
    }
}

/* ========================================
   SMALL MOBILE
======================================== */

@media (max-width: 380px) {
    .player {
        padding-left: 7px;
        padding-right: 7px;
    }

    .track-title {
        padding: 0 2px;
        font-size: 18px;
    }

    .progress-area {
        grid-template-columns: 40px minmax(0, 1fr) 56px;
        gap: 5px;
    }

    .controls {
        gap: 1px;
        margin-top: 16px;
    }

    .control-button {
        width: 40px;
        height: 40px;
        flex-basis: 40px;
    }

    .control-button.primary {
        width: 54px;
        height: 54px;
        flex-basis: 54px;
    }

    .control-button.secondary {
        font-size: 14px;
    }

    .control-button.seek {
        font-size: 11px;
    }

    .control-button.seek i {
        font-size: 10px;
    }

    .control-button.seek span {
        font-size: 9px;
    }

    .playlist-name {
        font-size: 15px;
    }

    .playlist-number {
        font-size: 13px;
    }

    .playlist-duration {
        font-size: 13px;
    }

    .playlist-item {
        padding-left: 10px;
        padding-right: 10px;
    }
}

/* ========================================
   LANDSCAPE MOBILE
======================================== */

@media (orientation: landscape) and (max-height: 600px) {
    .player {
        padding-top: 16px;
        padding-bottom: 18px;
    }

    .track-info {
        margin-bottom: 12px;
    }

    .track-title {
        font-size: 18px;
    }

    .playlist-header .volume-area {
        width: min(180px, 42%);
    }

    .control-button {
        width: 44px;
        height: 44px;
        flex-basis: 44px;
    }

    .control-button.primary {
        width: 58px;
        height: 58px;
        flex-basis: 58px;
    }

    .playlist {
        max-height: calc(100vh - 250px);
    }
}

/* ========================================
   REDUCED MOTION
======================================== */

@media (prefers-reduced-motion: reduce) {
    .icon-button,
    .control-button,
    .playlist-item {
        transition: none;
    }
}

/* ========================================
   THEME TOGGLE
======================================== */

.theme-toggle {
    position: absolute;
    top: 18px;
    right: 20px;

    width: 40px;
    height: 40px;
    flex: 0 0 40px;

    display: inline-flex;
    align-items: center;
    justify-content: center;

    border: 1px solid var(--border);
    border-radius: 50%;

    background: var(--button);
    color: var(--muted);

    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;

    transition:
        color 0.15s ease,
        background 0.15s ease,
        border-color 0.15s ease,
        transform 0.12s ease;
}

.theme-toggle:hover {
    color: var(--text);
    background: var(--button-hover);
    border-color: #d1d5db;
}

.theme-toggle:active {
    transform: scale(0.94);
}

.theme-toggle:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
}

/* ========================================
   INLINE SVG ICONS
   ======================================== */

.icon-button svg,
.control-button svg,
.theme-toggle svg {
    display: block;
    width: 1em;
    height: 1em;
    fill: currentColor;
    flex: 0 0 auto;
}

.control-button.seek svg {
    width: 1em;
    height: 1em;
}