/* nko-downloader — Apple-inspired aesthetic.
   Uses Apple system colors (Human Interface Guidelines), system fonts via
   -apple-system, soft rounded corners, and translucent surfaces. Class/id
   names are unchanged from the previous design so all JS keeps working. */

/* ---------- Design tokens ---------- */
:root {
    /* surfaces */
    --bg: #f2f2f7;
    --bg-elevated: #ffffff;
    --container-bg: #ffffff;
    --input-bg: #f2f2f7;
    --icon-bg: rgba(255, 255, 255, 0.7);
    /* text */
    --fg: #1c1c1e;
    --fg-muted: rgba(60, 60, 67, 0.6);
    --fg-faint: rgba(60, 60, 67, 0.4);
    --input-fg: #1c1c1e;
    --icon-fg: #1c1c1e;
    /* lines */
    --border: rgba(60, 60, 67, 0.18);
    --rule: rgba(60, 60, 67, 0.1);
    /* Apple system colors */
    --primary: #007aff;
    --primary-fg: #ffffff;
    --primary-hover: #0062cc;
    --primary-tint: rgba(0, 122, 255, 0.12);
    --green: #34c759;
    --green-hover: #2eb04e;
    --green-tint: rgba(52, 199, 89, 0.14);
    --orange: #ff9500;
    --orange-hover: #db8002;
    --red: #ff3b30;
    --red-hover: #cc2f26;
    --danger-border: rgba(255, 59, 48, 0.4);
    /* status */
    --result-bg: rgba(52, 199, 89, 0.08);
    --result-border: rgba(52, 199, 89, 0.28);
    --error-fg: #c4170c;
    --error-bg: rgba(255, 59, 48, 0.1);
    --error-border: rgba(255, 59, 48, 0.3);
    --success-fg: #1f7a35;
    --success-bg: rgba(52, 199, 89, 0.12);
    --success-border: rgba(52, 199, 89, 0.3);
    /* shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 1px 3px rgba(0, 0, 0, 0.04), 0 8px 28px rgba(0, 0, 0, 0.06);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #000000;
        --bg-elevated: #1c1c1e;
        --container-bg: #1c1c1e;
        --input-bg: #2c2c2e;
        --icon-bg: rgba(44, 44, 46, 0.78);
        --fg: #ffffff;
        --fg-muted: rgba(235, 235, 245, 0.6);
        --fg-faint: rgba(235, 235, 245, 0.38);
        --input-fg: #ffffff;
        --icon-fg: #ffffff;
        --border: rgba(84, 84, 88, 0.65);
        --rule: rgba(84, 84, 88, 0.35);
        --primary: #0a84ff;
        --primary-fg: #ffffff;
        --primary-hover: #339fff;
        --primary-tint: rgba(10, 132, 255, 0.22);
        --green: #30d158;
        --green-hover: #4be07a;
        --green-tint: rgba(48, 209, 88, 0.22);
        --orange: #ff9f0a;
        --orange-hover: #ffb340;
        --red: #ff453a;
        --red-hover: #ff6b62;
        --danger-border: rgba(255, 69, 58, 0.45);
        --result-bg: rgba(48, 209, 88, 0.12);
        --result-border: rgba(48, 209, 88, 0.35);
        --error-fg: #ff6b62;
        --error-bg: rgba(255, 69, 58, 0.16);
        --error-border: rgba(255, 69, 58, 0.4);
        --success-fg: #4be07a;
        --success-bg: rgba(48, 209, 88, 0.16);
        --success-border: rgba(48, 209, 88, 0.35);
        --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.5);
        --shadow-md: 0 1px 3px rgba(0, 0, 0, 0.4), 0 8px 28px rgba(0, 0, 0, 0.6);
    }
}

/* Explicit overrides win against the @media block above. */
[data-theme="light"] {
    --bg: #f2f2f7;
    --bg-elevated: #ffffff;
    --container-bg: #ffffff;
    --input-bg: #f2f2f7;
    --icon-bg: rgba(255, 255, 255, 0.7);
    --fg: #1c1c1e;
    --fg-muted: rgba(60, 60, 67, 0.6);
    --fg-faint: rgba(60, 60, 67, 0.4);
    --input-fg: #1c1c1e;
    --icon-fg: #1c1c1e;
    --border: rgba(60, 60, 67, 0.18);
    --rule: rgba(60, 60, 67, 0.1);
    --primary: #007aff;
    --primary-hover: #0062cc;
    --primary-tint: rgba(0, 122, 255, 0.12);
    --green: #34c759;
    --green-hover: #2eb04e;
    --green-tint: rgba(52, 199, 89, 0.14);
    --orange: #ff9500;
    --orange-hover: #db8002;
    --red: #ff3b30;
    --red-hover: #cc2f26;
    --danger-border: rgba(255, 59, 48, 0.4);
    --result-bg: rgba(52, 199, 89, 0.08);
    --result-border: rgba(52, 199, 89, 0.28);
    --error-fg: #c4170c;
    --error-bg: rgba(255, 59, 48, 0.1);
    --error-border: rgba(255, 59, 48, 0.3);
    --success-fg: #1f7a35;
    --success-bg: rgba(52, 199, 89, 0.12);
    --success-border: rgba(52, 199, 89, 0.3);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 1px 3px rgba(0, 0, 0, 0.04), 0 8px 28px rgba(0, 0, 0, 0.06);
}

[data-theme="dark"] {
    --bg: #000000;
    --bg-elevated: #1c1c1e;
    --container-bg: #1c1c1e;
    --input-bg: #2c2c2e;
    --icon-bg: rgba(44, 44, 46, 0.78);
    --fg: #ffffff;
    --fg-muted: rgba(235, 235, 245, 0.6);
    --fg-faint: rgba(235, 235, 245, 0.38);
    --input-fg: #ffffff;
    --icon-fg: #ffffff;
    --border: rgba(84, 84, 88, 0.65);
    --rule: rgba(84, 84, 88, 0.35);
    --primary: #0a84ff;
    --primary-hover: #339fff;
    --primary-tint: rgba(10, 132, 255, 0.22);
    --green: #30d158;
    --green-hover: #4be07a;
    --green-tint: rgba(48, 209, 88, 0.22);
    --orange: #ff9f0a;
    --orange-hover: #ffb340;
    --red: #ff453a;
    --red-hover: #ff6b62;
    --danger-border: rgba(255, 69, 58, 0.45);
    --result-bg: rgba(48, 209, 88, 0.12);
    --result-border: rgba(48, 209, 88, 0.35);
    --error-fg: #ff6b62;
    --error-bg: rgba(255, 69, 58, 0.16);
    --error-border: rgba(255, 69, 58, 0.4);
    --success-fg: #4be07a;
    --success-bg: rgba(48, 209, 88, 0.16);
    --success-border: rgba(48, 209, 88, 0.35);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.5);
    --shadow-md: 0 1px 3px rgba(0, 0, 0, 0.4), 0 8px 28px rgba(0, 0, 0, 0.6);
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }

html { color-scheme: light dark; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text",
                 "Helvetica Neue", "Segoe UI", Roboto, sans-serif;
    font-size: 17px;
    line-height: 1.5;
    letter-spacing: -0.01em;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    background: var(--bg);
    color: var(--fg);
    margin: 0;
    padding: 2rem 1rem;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

/* ---------- Container card ---------- */
.container {
    background: var(--container-bg);
    border-radius: 18px;
    padding: 2rem;
    box-shadow: var(--shadow-md);
    width: 100%;
    max-width: 600px;
}

/* ---------- Typography ---------- */
h1, h2, h3, h4 {
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display",
                 "Helvetica Neue", sans-serif;
    color: var(--fg);
    margin: 0;
}

h1 {
    font-size: 1.875rem;     /* 30px */
    font-weight: 700;
    letter-spacing: -0.025em;
    line-height: 1.2;
    margin-bottom: 0.4rem;
}

h2 {
    font-size: 1.0625rem;    /* 17px */
    font-weight: 400;
    color: var(--fg-muted);
    letter-spacing: -0.01em;
    line-height: 1.45;
    margin-bottom: 1.5rem;
}

h2:empty { display: none; margin: 0; }

h3 {
    font-size: 1.0625rem;
    font-weight: 600;
    letter-spacing: -0.015em;
    margin-bottom: 0.75rem;
}

h4 {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--fg-muted);
    margin-bottom: 0.5rem;
}

/* ---------- Form controls ---------- */
input[type="url"],
input[type="password"],
input[type="text"] {
    width: 100%;
    padding: 14px 16px;
    background: var(--input-bg);
    border: 1px solid transparent;
    border-radius: 12px;
    color: var(--input-fg);
    font-family: inherit;
    font-size: 17px;                /* 17px prevents iOS zoom-on-focus */
    line-height: 1.3;
    margin-bottom: 1rem;
    transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

input::placeholder { color: var(--fg-faint); }

input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-tint);
}

/* ---------- SVG icons ---------- */
/* Inline SVGs use currentColor so they inherit text color and adapt to theme.
   Default is outline (stroke-based) at SF Symbols-ish weight. Use .filled for
   filled glyphs (play, pause). Sizes scale with the containing text (1em),
   with explicit overrides for icon-only contexts. */
.icon {
    display: inline-block;
    width: 1em;
    height: 1em;
    vertical-align: -0.18em;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex-shrink: 0;
}
.icon.filled { fill: currentColor; stroke: none; }
.icon.icon-lg { width: 1.2em; height: 1.2em; }

/* ---------- Buttons ---------- */
button, .icon-btn {
    -webkit-appearance: none;
    appearance: none;
    background: var(--primary);
    color: var(--primary-fg);
    padding: 13px 22px;
    border: none;
    border-radius: 12px;
    font-family: inherit;
    font-size: 17px;
    font-weight: 600;
    letter-spacing: -0.01em;
    cursor: pointer;
    transition: background 0.15s, transform 0.08s ease-out, opacity 0.15s;
    /* Inline-flex so icon + label align cleanly with a consistent gap. */
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5em;
    line-height: 1;
}

button:hover { background: var(--primary-hover); }
button:active { transform: scale(0.97); }
button:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.button-group { display: flex; gap: 10px; }
/* Result-block action buttons (Open in new tab + optional archive) right-align,
   following Apple's pattern of pairing actions with the right edge of a card. */
.button-group.dual-buttons { gap: 12px; flex-wrap: wrap; justify-content: flex-end; }
.action-button { flex-grow: 1; }

.action-button.primary-button { background: var(--primary); }
.action-button.primary-button:hover { background: var(--primary-hover); }

.action-button.orange-button {
    background: var(--orange);
    width: 100%;
}
.action-button.orange-button:hover { background: var(--orange-hover); }

/* ---------- Result block ---------- */
#result {
    margin-top: 1.5rem;
    padding: 1.25rem 1.25rem 1rem;
    background: var(--result-bg);
    border: 1px solid var(--result-border);
    border-radius: 14px;
}

#result-label {
    margin: 0 0 0.5rem;
    font-size: 0.9375rem;            /* 15px */
    font-weight: 500;
    color: var(--fg-muted);
    letter-spacing: -0.005em;
}

.result-link {
    color: var(--primary);
    word-break: break-all;
    display: block;
    margin-bottom: 1rem;
    font-size: 0.9375rem;
    line-height: 1.45;
    text-decoration: none;
}
.result-link:hover { text-decoration: underline; }

.result-actions { margin-top: 1rem; }

/* ---------- Flashes / errors / success ---------- */
.flashes {
    list-style: none;
    padding: 0;
    margin: 0 0 1rem;
}

.error-message,
.flashes li.error {
    background: var(--error-bg);
    color: var(--error-fg);
    border: 1px solid var(--error-border);
    padding: 12px 16px;
    border-radius: 12px;
    margin-top: 1rem;
    font-size: 0.9375rem;
}

.flashes li.success,
.flash-success {
    background: var(--success-bg);
    color: var(--success-fg);
    border: 1px solid var(--success-border);
    padding: 12px 16px;
    border-radius: 12px;
    margin-top: 1rem;
    font-size: 0.9375rem;
}

/* ---------- Horizontal rule + footer ---------- */
hr {
    border: 0;
    height: 1px;
    background: var(--rule);
    margin: 2rem 0 1.5rem;
}

footer {
    margin-top: 1.5rem;
    text-align: center;
    font-size: 0.8125rem;            /* 13px */
    line-height: 1.55;
    color: var(--fg-muted);
}
footer a { color: var(--primary); text-decoration: none; }
footer a:hover { text-decoration: underline; }

/* ---------- Top-bar icon buttons (theme toggle, logout, back) ---------- */
.top-bar {
    position: fixed;
    /* max() respects iOS safe-area-inset (notch / Dynamic Island) while
       keeping the default offset on devices without one. */
    top: max(1rem, env(safe-area-inset-top, 1rem));
    right: max(1rem, env(safe-area-inset-right, 1rem));
    display: flex;
    gap: 0.5rem;
    z-index: 10;
}

.icon-btn {
    background: var(--icon-bg);
    color: var(--icon-fg);
    border: 1px solid var(--border);
    width: 38px;
    height: 38px;
    border-radius: 50%;
    padding: 0;
    font-size: 17px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    box-shadow: var(--shadow-sm);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    backdrop-filter: blur(20px) saturate(180%);
}
.icon-btn:hover { background: var(--icon-bg); transform: scale(1.04); }
.icon-btn:active { transform: scale(0.95); }
.icon-btn .icon { width: 19px; height: 19px; vertical-align: 0; }

/* Logs page lock-stats form button reuses .icon-btn shape. */
.top-bar form { margin: 0; padding: 0; }

/* ---------- Audio player ---------- */
#audio-block {
    margin: 1rem 0 0.5rem;
    padding: 1.125rem 1rem 1rem;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 14px;
}

.audio-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.875rem;
    flex-wrap: wrap;
}

.audio-btn {
    background: var(--input-bg);
    color: var(--fg);
    border: none;
    padding: 9px 14px;
    border-radius: 10px;
    font-size: 0.875rem;             /* 14px */
    font-weight: 500;
    font-variant-numeric: tabular-nums;
}
.audio-btn:hover { background: var(--primary-tint); }
.audio-btn:active { transform: scale(0.95); }

.audio-btn.audio-play {
    background: var(--primary);
    color: #fff;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    padding: 0;
    font-size: 22px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.audio-btn.audio-play .icon { width: 24px; height: 24px; vertical-align: 0; }
.audio-btn .icon { vertical-align: 0; }
.audio-btn.audio-play:hover { background: var(--primary-hover); }

.audio-speed {
    margin-left: auto;
    background: var(--input-bg);
    color: var(--fg);
    border: none;
    border-radius: 10px;
    padding: 9px 12px;
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
}
.audio-speed:focus { outline: 2px solid var(--primary); outline-offset: 1px; }

.audio-scrub {
    width: 100%;
    accent-color: var(--primary);
    margin: 0;
}

.audio-times {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;              /* 12px */
    color: var(--fg-muted);
    font-variant-numeric: tabular-nums;
    margin-top: 0.25rem;
    letter-spacing: 0.02em;
}

.audio-links {
    display: flex;
    gap: 1.25rem;
    margin-top: 0.875rem;
    font-size: 0.875rem;
    flex-wrap: wrap;
}
.audio-links a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}
.audio-links a:hover { text-decoration: underline; }

/* ---------- Settings (cog) icon ---------- */
.settings-icon {
    position: fixed;
    bottom: 1.25rem;
    right: 1.25rem;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--icon-bg);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    box-shadow: var(--shadow-sm);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    backdrop-filter: blur(20px) saturate(180%);
    transition: transform 0.2s;
}
.settings-icon:hover { transform: scale(1.06); }
.settings-icon a {
    text-decoration: none;
    color: var(--icon-fg);
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.settings-icon .icon { width: 21px; height: 21px; vertical-align: 0; }

/* ---------- Logs page ---------- */
.stats-container { margin-top: 1.5rem; }

.stats-box {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    padding: 1.25rem;
    border-radius: 14px;
    margin-bottom: 1rem;
    box-shadow: var(--shadow-sm);
}
.stats-box h3 { margin-top: 0; }
.setting-row { display: flex; align-items: center; gap: .75rem; margin-bottom: .75rem; }
.setting-row label { flex: 1; font-size: .9375rem; }

.chart-wrap { position: relative; max-width: 100%; }

.table-wrap {
    overflow-x: auto;
    border-radius: 12px;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;             /* 14px */
}
th, td {
    padding: 10px 8px;
    text-align: left;
    border-bottom: 1px solid var(--rule);
    word-break: break-all;
}
th {
    background: transparent;
    font-weight: 600;
    color: var(--fg-muted);
    border-bottom: 1px solid var(--border);
    letter-spacing: -0.005em;
}
td a { color: var(--primary); text-decoration: none; }
td a:hover { text-decoration: underline; }

.delete-section {
    margin-top: 1.5rem;
    padding: 1.25rem;
    border: 1px solid var(--danger-border);
    border-radius: 14px;
    background: var(--error-bg);
}
.delete-section h3 { color: var(--red); margin-top: 0; }
.delete-section p { color: var(--fg-muted); font-size: 0.9375rem; margin: 0.25rem 0 1rem; }

.delete-button { background: var(--red); }
.delete-button:hover { background: var(--red-hover); }

/* ---------- Mobile tightening ---------- */
/* Reserve vertical clearance for the fixed top-bar icons on any screen narrow
   enough that the centred container card runs full width and the icons would
   otherwise overlap its top-right corner. */
@media (max-width: 720px) {
    body {
        padding-top: calc(38px + 1.5rem + env(safe-area-inset-top, 0px));
    }
}

@media (max-width: 480px) {
    body {
        padding: 1rem;
        padding-top: calc(34px + 1.25rem + env(safe-area-inset-top, 0px));
    }
    .container { padding: 1.5rem 1.25rem; border-radius: 16px; }
    .top-bar {
        top: max(0.75rem, env(safe-area-inset-top, 0.75rem));
        right: max(0.75rem, env(safe-area-inset-right, 0.75rem));
        gap: 0.4rem;
    }
    .icon-btn { width: 34px; height: 34px; font-size: 15px; }
    .icon-btn .icon { width: 17px; height: 17px; }
    .settings-icon {
        width: 40px; height: 40px;
        bottom: max(1rem, env(safe-area-inset-bottom, 1rem));
        right: max(1rem, env(safe-area-inset-right, 1rem));
        font-size: 16px;
    }
    h1 { font-size: 1.625rem; }
    h2 { font-size: 0.9375rem; margin-bottom: 1.25rem; }
    .audio-speed { margin-left: 0; }
    .audio-btn.audio-play { width: 48px; height: 48px; font-size: 20px; }
    .audio-btn { padding: 9px 12px; font-size: 13px; }
}
