:root {
    --bg-a: #eef3f6;
    --bg-b: #e4edf2;
    --ink: #163a3c;
    --muted: #6d7f84;
    --card: rgba(255, 255, 255, 0.7);
    --line: rgba(22, 58, 60, 0.08);
    --teal: #3cc8cb;
    --teal-deep: #1aa8ac;
    --play: #16324a;
    --live: #e31b3c;
    --ok: #21a35a;
    --danger: #d64545;
    --radius: 28px;
    --shadow: 0 20px 50px rgba(22, 58, 70, 0.1);
    --font: Tajawal, Cairo, "Segoe UI", Tahoma, sans-serif;
}

* { box-sizing: border-box; }

html,
body {
    margin: 0;
    min-height: 100%;
    background: linear-gradient(160deg, var(--bg-a) 0%, #f7fafc 42%, var(--bg-b) 100%);
    color: var(--ink);
    font-family: var(--font);
}

body { overflow-x: hidden; }

.radio-app {
    min-height: 100vh;
    max-width: 980px;
    margin: 0 auto;
    padding: 22px 22px 28px;
    display: flex;
    flex-direction: column;
}

.radio-header {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 16px;
    min-height: 72px;
    margin-bottom: 18px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    justify-self: end;
}

.logo {
    width: 58px;
    height: 58px;
    display: grid;
    place-items: center;
    color: var(--ink);
}

.logo img {
    width: 58px;
    height: 58px;
    object-fit: contain;
}

.brand-text h1 {
    margin: 0;
    font-size: 1.28rem;
    font-weight: 800;
    line-height: 1.2;
    color: var(--ink);
}

.brand-en {
    direction: ltr;
    unicode-bidi: isolate;
}

.brand-sep {
    margin: 0 4px;
    font-weight: 700;
    color: var(--muted);
}

.brand-kicker {
    margin: 2px 0 0;
    color: var(--muted);
    font-size: 13px;
    font-weight: 400;
}

.live-indicator {
    justify-self: center;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 36px;
    padding: 0 16px;
    border-radius: 999px;
    background: #edf1f4;
    color: #8a969a;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.12em;
}

.live-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
}

.live-indicator.is-live {
    background: var(--live);
    color: #fff;
    box-shadow: 0 0 0 6px rgba(227, 27, 60, 0.16), 0 8px 22px rgba(227, 27, 60, 0.28);
}

.live-indicator.is-live .live-dot {
    background: #fff;
    box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.7);
    animation: live-pulse 1.6s infinite;
}

.connection {
    justify-self: start;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-size: 14px;
    font-weight: 700;
}

.connection.is-connected {
    color: var(--ok);
}

.signal-icon { flex: 0 0 auto; }

.player-shell {
    flex: 1;
    display: grid;
    place-items: center;
}

.player-card {
    width: min(100%, 760px);
    padding: 34px 42px 28px;
    border-radius: var(--radius);
    background: var(--card);
    border: 1px solid rgba(255, 255, 255, 0.8);
    box-shadow: var(--shadow);
    backdrop-filter: blur(18px);
    text-align: center;
}

.now-playing {
    margin: 0 0 8px;
    color: var(--muted);
    font-size: 14px;
    font-weight: 500;
}

.track-title {
    margin: 0 0 6px;
    font-size: clamp(1.7rem, 4vw, 2.35rem);
    font-weight: 800;
    line-height: 1.35;
    color: var(--ink);
}

.playlist-name {
    margin: 0 0 18px;
    color: var(--muted);
    font-size: 15px;
    min-height: 1.4em;
}

.visualizer-wrap {
    position: relative;
    height: 78px;
    margin: 6px auto 14px;
    max-width: 520px;
}

.visualizer,
.visual-fallback {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.visualizer {
    filter: drop-shadow(0 8px 16px rgba(60, 200, 203, 0.28));
}

.visual-fallback {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 3px;
}

.visual-fallback span {
    width: 4px;
    border-radius: 99px;
    background: var(--teal);
    opacity: 0.85;
    height: 18%;
}

.visual-fallback span:nth-child(4n) { height: 34%; }
.visual-fallback span:nth-child(4n+1) { height: 58%; }
.visual-fallback span:nth-child(4n+2) { height: 26%; }
.visual-fallback span:nth-child(4n+3) { height: 72%; }
.visual-fallback span:nth-child(odd) { height: 44%; }

.radio-app.is-playing .visual-fallback span {
    animation: wave 1s ease-in-out infinite;
}

.visual-fallback span:nth-child(3n) { animation-delay: .08s; }
.visual-fallback span:nth-child(3n+1) { animation-delay: .16s; }
.visual-fallback span:nth-child(3n+2) { animation-delay: .24s; }

.status-text {
    margin: 0 0 18px;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.8;
}

.progress-block {
    margin: 0 0 22px;
}

.progress {
    position: relative;
    height: 4px;
    border-radius: 999px;
    background: rgba(22, 58, 60, 0.12);
    cursor: pointer;
}

.progress-bar {
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: var(--teal);
}

.progress-thumb {
    position: absolute;
    top: 50%;
    left: 0;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--teal);
    transform: translate(-50%, -50%);
    box-shadow: 0 0 0 4px rgba(60, 200, 203, 0.16);
}

.time-row {
    display: flex;
    justify-content: space-between;
    margin-top: 8px;
    color: var(--muted);
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}

.controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
}

.transport {
    display: flex;
    align-items: center;
    gap: 14px;
    flex: 0 0 auto;
}

.icon-btn,
.play-btn,
.speed-btn,
.join-btn {
    appearance: none;
    border: 0;
    cursor: pointer;
    font-family: inherit;
    background: transparent;
    color: inherit;
}

.icon-btn {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    color: var(--ink);
    opacity: 0.85;
}

.icon-btn:hover { opacity: 1; }

.play-btn {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: var(--play);
    color: #fff;
    display: grid;
    place-items: center;
    box-shadow: 0 10px 24px rgba(22, 50, 74, 0.28);
}

.play-btn .icon-pause { display: none; }
.radio-app.is-playing .play-btn .icon-play { display: none; }
.radio-app.is-playing .play-btn .icon-pause { display: grid; }

.play-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.play-btn:focus-visible,
.icon-btn:focus-visible,
.speed-btn:focus-visible,
.join-btn:focus-visible,
input[type="range"]:focus-visible {
    outline: 3px solid rgba(60, 200, 203, 0.45);
    outline-offset: 3px;
}

.controls-secondary {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 16px;
    flex: 1 1 auto;
    min-width: 0;
}

.volume-field {
    display: flex;
    align-items: center;
    gap: 8px;
    width: min(160px, 100%);
    color: var(--ink);
}

input[type="range"] {
    width: 100%;
    height: 4px;
    accent-color: var(--teal);
}

.speed-options {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.speed-btn {
    min-height: 32px;
    padding: 0 10px;
    border-radius: 999px;
    background: #edf2f4;
    color: var(--ink);
    font-size: 12px;
    font-weight: 700;
}

.speed-btn.is-active {
    background: #5f6f73;
    color: #fff;
}

.error-text {
    margin: 0 0 12px;
    padding: 10px 12px;
    border-radius: 12px;
    background: rgba(214, 69, 69, 0.1);
    color: var(--danger);
    font-size: 13px;
}

.join-overlay {
    position: fixed;
    inset: auto 0 24px;
    z-index: 5;
    display: grid;
    place-items: center;
    pointer-events: none;
}

.join-overlay[hidden] { display: none !important; }

.join-btn {
    pointer-events: auto;
    min-height: 48px;
    padding: 0 22px;
    border-radius: 999px;
    background: var(--play);
    color: #fff;
    font-size: 15px;
    font-weight: 800;
    box-shadow: var(--shadow);
}

.site-footer {
    margin-top: 22px;
    text-align: center;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.7;
}

.site-footer strong {
    display: block;
    color: var(--ink);
    font-weight: 800;
}

.site-footer a {
    display: inline-block;
    margin-top: 4px;
    color: var(--teal-deep);
    text-decoration: none;
    direction: ltr;
    unicode-bidi: isolate;
}

.site-footer a:hover {
    text-decoration: underline;
}

.contact-dock {
    position: fixed;
    inset: 0;
    z-index: 20;
    pointer-events: none;
}

.contact-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(22, 58, 70, 0.18);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
}

.contact-dock.is-open .contact-backdrop {
    opacity: 1;
    pointer-events: auto;
}

.contact-popup[hidden] {
    display: none !important;
}

.contact-popup {
    position: absolute;
    left: max(16px, env(safe-area-inset-left));
    bottom: calc(78px + env(safe-area-inset-bottom, 0px));
    width: min(400px, calc(100vw - 32px));
    max-height: calc(100dvh - 108px);
    overflow: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    pointer-events: none;
    visibility: hidden;
    opacity: 0;
    transform: translateY(14px) scale(0.94);
    transform-origin: 28px calc(100% + 18px);
    transition: opacity 0.22s cubic-bezier(0.22, 1, 0.36, 1),
        transform 0.22s cubic-bezier(0.22, 1, 0.36, 1),
        visibility 0.22s;
}

.contact-dock.is-open .contact-popup {
    pointer-events: auto;
    visibility: visible;
    opacity: 1;
    transform: translateY(0) scale(1);
}

.contact-card {
    padding: 18px 18px 16px;
    border-radius: 22px;
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid rgba(255, 255, 255, 0.88);
    box-shadow: 0 16px 40px rgba(22, 58, 70, 0.16);
    backdrop-filter: blur(18px);
}

.contact-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8px;
}

.contact-header h2 {
    margin: 0;
    font-size: 1.15rem;
    font-weight: 800;
}

.contact-close {
    appearance: none;
    flex: 0 0 auto;
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: 50%;
    background: #edf2f4;
    color: var(--ink);
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    font-family: inherit;
}

.contact-close:hover {
    background: #e2e9ec;
}

.contact-intro {
    margin: 0 0 14px;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.7;
}

.contact-success-panel {
    display: none;
    padding: 18px 8px 12px;
    text-align: center;
}

.contact-dock.is-success .contact-form-wrap {
    display: none;
}

.contact-dock.is-success .contact-success-panel {
    display: block;
}

.contact-success-title {
    margin: 0 0 8px;
    color: var(--ok);
    font-size: 1.05rem;
    font-weight: 800;
}

.contact-success-copy {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.7;
}

.contact-form-error {
    margin: 0 0 12px;
    padding: 10px 12px;
    border-radius: 12px;
    background: rgba(214, 69, 69, 0.1);
    color: var(--danger);
    font-size: 13px;
    line-height: 1.6;
}

.contact-form {
    display: grid;
    gap: 10px;
}

.contact-form label {
    display: grid;
    gap: 6px;
    text-align: right;
    color: var(--ink);
    font-weight: 700;
    font-size: 13px;
}

.contact-form input,
.contact-form textarea {
    width: 100%;
    max-width: 100%;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 11px 12px;
    font-family: inherit;
    font-size: 15px;
    font-weight: 400;
    background: rgba(255, 255, 255, 0.88);
    color: var(--ink);
}

.contact-form input[aria-invalid="true"],
.contact-form textarea[aria-invalid="true"] {
    border-color: rgba(214, 69, 69, 0.55);
}

.contact-form textarea {
    resize: vertical;
    min-height: 96px;
}

.contact-field-error {
    color: var(--danger);
    font-size: 12px;
    font-weight: 500;
}

.contact-submit {
    appearance: none;
    border: 0;
    min-height: 44px;
    margin-top: 4px;
    border-radius: 999px;
    background: var(--play);
    color: #fff;
    font-family: inherit;
    font-size: 15px;
    font-weight: 800;
    cursor: pointer;
}

.contact-submit:hover:not(:disabled) {
    filter: brightness(1.06);
}

.contact-submit:disabled {
    opacity: 0.72;
    cursor: wait;
}

.contact-fab {
    appearance: none;
    pointer-events: auto;
    position: absolute;
    left: max(16px, env(safe-area-inset-left));
    bottom: max(20px, env(safe-area-inset-bottom));
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 46px;
    padding: 0 16px 0 14px;
    border: 0;
    border-radius: 999px;
    background: var(--play);
    color: #fff;
    font-family: inherit;
    font-size: 14px;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 8px 22px rgba(22, 50, 74, 0.22);
}

.contact-fab:hover {
    filter: brightness(1.06);
}

.contact-dock.is-open .contact-fab {
    box-shadow: 0 6px 16px rgba(22, 50, 74, 0.18);
}

.contact-fab svg {
    flex: 0 0 auto;
}

.contact-close:focus-visible,
.contact-fab:focus-visible,
.contact-submit:focus-visible,
.contact-form input:focus-visible,
.contact-form textarea:focus-visible {
    outline: 3px solid rgba(60, 200, 203, 0.45);
    outline-offset: 3px;
}

.radio-app.is-muted #mute-btn {
    opacity: 0.45;
}

@keyframes live-pulse {
    70% { box-shadow: 0 0 0 8px rgba(255, 255, 255, 0); }
}

@keyframes wave {
    50% { transform: scaleY(1.55); }
}

@media (prefers-reduced-motion: reduce) {
    .live-indicator.is-live .live-dot,
    .radio-app.is-playing .visual-fallback span {
        animation: none;
    }

    .contact-backdrop,
    .contact-popup {
        transition: none;
    }
}

@media (max-width: 820px) {
    .radio-header {
        grid-template-columns: 1fr;
        justify-items: center;
        text-align: center;
        gap: 10px;
        margin-bottom: 16px;
    }

    .brand,
    .connection,
    .live-indicator {
        justify-self: center;
    }

    .brand { flex-direction: column; }

    .player-card {
        padding: 26px 18px 22px;
        border-radius: 24px;
    }

    .contact-popup {
        left: 12px;
        right: 12px;
        width: auto;
        bottom: calc(76px + env(safe-area-inset-bottom, 0px));
        max-height: calc(100dvh - 100px);
        transform-origin: 24px calc(100% + 16px);
    }

    .contact-card {
        padding: 16px 14px 14px;
        border-radius: 20px;
    }

    .contact-form textarea {
        min-height: 84px;
    }

    .controls {
        flex-direction: column;
    }

    .transport {
        width: 100%;
        justify-content: space-between;
        padding: 0 8px;
    }

    .controls-secondary {
        width: 100%;
        flex-direction: column;
        align-items: stretch;
    }

    .volume-field {
        width: 100%;
    }

    .speed-options {
        justify-content: space-between;
    }

    .speed-btn {
        flex: 1 1 0;
    }
}

@media (min-width: 821px) {
    .radio-app { padding: 28px 28px 32px; }
}
