/* Video Downloader — one stylesheet, light by default, dark when the phone/OS
   is in dark mode. Every colour is a token below; components only use tokens. */

:root {
    color-scheme: light dark;

    --bg: #f4f6fb;
    --surface: #ffffff;
    --surface-2: #f0f3f8;
    --border: #e1e6ef;
    --text: #172033;
    --muted: #5d6779;
    --accent: #2f6fed;
    --accent-hover: #2459c9;
    --accent-soft: rgba(47, 111, 237, 0.12);
    --on-accent: #ffffff;
    --ok: #1d8f53;
    --error: #c93c3c;
    --error-soft: rgba(201, 60, 60, 0.08);
    --note: #9a6400;
    --track: #e4e9f2;
    --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 6px 20px rgba(16, 24, 40, 0.06);
    --focus: 0 0 0 3px rgba(47, 111, 237, 0.35);

    --radius: 16px;
    --radius-sm: 10px;
    --tap: 44px; /* minimum touch target */
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0e131b;
        --surface: #161d29;
        --surface-2: #1d2635;
        --border: #283245;
        --text: #e8edf5;
        --muted: #9aa5b8;
        --accent: #5d8dff;
        --accent-hover: #7aa3ff;
        --accent-soft: rgba(93, 141, 255, 0.16);
        --on-accent: #0b1220;
        --ok: #4cc38a;
        --error: #f07a7a;
        --error-soft: rgba(240, 122, 122, 0.1);
        --note: #e6b450;
        --track: #253044;
        --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
        --focus: 0 0 0 3px rgba(93, 141, 255, 0.4);
    }
}

/* --- Base ---------------------------------------------------------------- */

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

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 16px;
    line-height: 1.45;
    -webkit-text-size-adjust: 100%;
}

p {
    margin: 0;
}

a {
    color: var(--accent);
    font-weight: 600;
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

button, textarea {
    font: inherit;
    color: inherit;
}

button {
    cursor: pointer;
}

:focus-visible {
    outline: none;
    box-shadow: var(--focus);
}

/* --- Layout -------------------------------------------------------------- */

.container,
.container--wide {
    width: 100%;
}

.hero-layout {
    display: grid;
    gap: 16px;
    width: 100%;
    max-width: 560px;
    margin: 0 auto;
    padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
}

/* Side by side on wide screens — form on the left, downloads on the right —
   but only once there are downloads to show; until then the form stays centred. */
@media (min-width: 960px) {
    .hero-layout {
        padding-top: 64px;
    }

    .hero-layout:has(.job, .resume-notice) {
        max-width: 1040px;
        grid-template-columns: 420px 1fr;
        align-items: start;
    }

    .panel--form {
        position: sticky;
        top: 32px;
    }
}

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
}

/* The downloads side is just a list; its cards carry the styling. */
.panel--progress {
    background: none;
    border: none;
    box-shadow: none;
    padding: 0;
    display: grid;
    gap: 12px;
}

.app-title {
    font-size: 1.6rem;
    font-weight: 750;
    letter-spacing: -0.02em;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 12px;
}

.app-logo {
    flex: none;
    width: 40px;
    height: 40px;
    border-radius: 10px; /* matches the tile's rounding, so its shadow fits */
    box-shadow: 0 4px 12px var(--accent-soft);
}

.app-subtitle {
    color: var(--muted);
    margin: 4px 0 20px;
}

/* --- Form ---------------------------------------------------------------- */

.download-form {
    display: grid;
    gap: 10px;
}

.download-form label {
    font-size: 0.85rem;
    font-weight: 650;
    color: var(--muted);
}

.url-row {
    display: flex;
    gap: 8px;
    align-items: stretch;
}

.url-row textarea {
    flex: 1;
    min-width: 0;
    min-height: calc(var(--tap) * 1.6);
    resize: vertical;
    padding: 10px 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 1rem; /* 16px+ stops iPhone Safari zooming in on focus */
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.url-row textarea::placeholder {
    color: var(--muted);
    opacity: 0.8;
}

.url-row textarea:focus-visible {
    border-color: var(--accent);
}

/* Hidden unless static/paste.js finds a browser that can read the clipboard. */
.paste-btn {
    display: none;
    min-width: var(--tap);
    padding: 0 16px;
    background: var(--accent-soft);
    color: var(--accent);
    border: none;
    border-radius: var(--radius-sm);
    font-weight: 650;
}

.can-paste .paste-btn {
    display: block;
}

.paste-btn:hover {
    background: var(--accent);
    color: var(--on-accent);
}

.form-msg {
    font-size: 0.9rem;
    color: var(--note);
}

.form-msg:empty {
    display: none;
}

#submit-btn {
    min-height: var(--tap);
    padding: 0 20px;
    background: var(--accent);
    color: var(--on-accent);
    border: none;
    border-radius: var(--radius-sm);
    font-weight: 700;
    font-size: 1rem;
    transition: background 0.15s ease, opacity 0.15s ease;
}

#submit-btn:hover {
    background: var(--accent-hover);
}

/* Dimmed until there's something in the box (the textarea is `required`). */
.download-form:has(textarea:invalid) #submit-btn {
    opacity: 0.45;
    pointer-events: none;
}

.download-form button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

/* --- Download rows ---------------------------------------------------------- */

#job-list,
.job-group {
    display: grid;
    gap: 12px;
}

#job-list:empty {
    display: none;
}

.job {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 14px 16px;
}

.job-body {
    flex: 1;
    min-width: 0;
    display: grid;
    gap: 6px;
}

.job-title {
    font-weight: 650;
    overflow-wrap: anywhere;
    /* Long titles: two lines, then an ellipsis. */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.job-status,
.progress-label,
.job-hint {
    font-size: 0.875rem;
    color: var(--muted);
}

.job-status--ok {
    color: var(--ok);
    font-weight: 650;
}

.job-status--error {
    color: var(--error);
    font-weight: 650;
}

.job-detail {
    font-size: 0.8rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    color: var(--error);
    background: var(--error-soft);
    border-radius: 8px;
    padding: 6px 8px;
    overflow-wrap: anywhere;
}

.progress-bar-wrap {
    height: 8px;
    background: var(--track);
    border-radius: 999px;
    overflow: hidden;
}

.progress-bar-fill {
    width: var(--pct, 0%);
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--ok));
    border-radius: inherit;
    transition: width 0.3s ease;
}

.progress-label {
    font-variant-numeric: tabular-nums;
}

.job-actions:empty {
    display: none;
}

.cancel-btn {
    min-height: 36px;
    padding: 0 12px;
    background: none;
    color: var(--muted);
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 600;
}

.cancel-btn:hover {
    color: var(--error);
    border-color: var(--error);
}

.job-done {
    display: grid;
    gap: 6px;
}

.done-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-top: 6px;
}

.download-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: var(--tap);
    padding: 0 20px;
    background: var(--accent);
    color: var(--on-accent);
    border-radius: var(--radius-sm);
    font-weight: 700;
}

.download-btn:hover {
    background: var(--accent-hover);
    text-decoration: none;
}

.dismiss-btn {
    width: var(--tap);
    height: var(--tap);
    background: var(--surface-2);
    color: var(--muted);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
}

.dismiss-btn:hover {
    color: var(--text);
}

/* --- "Your other downloads" (fresh page, from the jobs cookie) ----------------- */

.resume-notice {
    display: grid;
    gap: 8px;
    background: var(--accent-soft);
    border-radius: var(--radius);
    padding: 14px 16px;
}

.resume-heading {
    font-weight: 700;
}

.resume-item {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 10px;
    align-items: baseline;
    font-size: 0.9rem;
}

.resume-state {
    color: var(--muted);
    white-space: nowrap;
}

.resume-label {
    flex: 1;
    min-width: 0;
    overflow-wrap: anywhere;
}

/* --- Phones ----------------------------------------------------------------- */

@media (max-width: 480px) {
    .hero-layout {
        padding-top: 16px;
    }

    .panel--form {
        padding: 16px;
    }

    #submit-btn,
    .download-btn {
        flex: 1;
    }
}

@media (prefers-reduced-motion: reduce) {
    * {
        transition: none !important;
    }
}
