/* ============================================================
   iOS Native Glass Style — Magazine Reader
   Targets iOS 16+ visual language with "Liquid Glass" aesthetic
   ============================================================ */

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

/* === Icon Button & SVG Icon Styles === */
.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    padding: 8px;
    margin: 0;
    cursor: pointer;
    border-radius: 50%;
    color: inherit;
    -webkit-tap-highlight-color: transparent;
    transition: opacity 0.14s, transform 0.14s;
}

.icon-btn:active {
    opacity: 0.65;
    transform: scale(0.9);
}

.icon-btn svg {
    width: 24px;
    height: 24px;
}

/* === Design Tokens — Dark (Default) === */
:root {
    /* Backgrounds */
    --sys-bg:           #000000;
    --sys-bg-elevated:  #1c1c1e;
    --sys-bg-card:      #2c2c2e;

    /* Labels */
    --sys-label:        #ffffff;
    --sys-label-2:      rgba(235, 235, 245, 0.60);
    --sys-label-3:      rgba(235, 235, 245, 0.30);

    /* Fills */
    --sys-fill:         rgba(120, 120, 128, 0.36);
    --sys-fill-2:       rgba(120, 120, 128, 0.32);
    --sys-fill-3:       rgba(118, 118, 128, 0.24);
    --sys-fill-4:       rgba(118, 118, 128, 0.18);

    /* Separators */
    --sys-sep:          rgba(84, 84, 88, 0.65);
    --sys-sep-opaque:   #38383a;

    /* System Accent Colors */
    --sys-blue:         #0a84ff;
    --sys-red:          #ff453a;
    --sys-green:        #30d158;
    --sys-orange:       #ff9f0a;
    --sys-teal:         #5ac8fa;
    --sys-indigo:       #5e5ce6;
    --sys-pink:         #ff375f;
    --sys-accent:       #0a84ff;

    /* Glass Material */
    --glass-bg:         rgba(28, 28, 30, 0.78);
    --glass-tint:       rgba(255, 255, 255, 0.05);
    --glass-border:     rgba(255, 255, 255, 0.10);
    --glass-highlight:  rgba(255, 255, 255, 0.06);
    --glass-blur:       blur(28px) saturate(200%);

    /* Chrome backgrounds */
    --tab-bg:           rgba(18, 18, 18, 0.82);
    --tab-border:       rgba(255, 255, 255, 0.10);
    --nav-bg:           rgba(10, 10, 10, 0.85);
    --nav-border:       rgba(255, 255, 255, 0.08);

    /* Shadows */
    --shadow-sm:        0 1px 3px rgba(0, 0, 0, 0.40);
    --shadow-md:        0 4px 20px rgba(0, 0, 0, 0.55);
    --shadow-lg:        0 10px 40px rgba(0, 0, 0, 0.65);

    /* Card overlay gradients */
    --card-grad-mid:    rgba(0, 0, 0, 0.75);
    --card-grad-end:    rgba(0, 0, 0, 0.96);
    --card-txt-glow:    rgba(0, 0, 0, 0.90);
    --card-txt-soft:    rgba(0, 0, 0, 0.75);
}

/* === Light Theme === */
html[data-theme="light"] {
    --sys-bg:           #f2f2f7;
    --sys-bg-elevated:  #ffffff;
    --sys-bg-card:      #f2f2f7;

    --sys-label:        #000000;
    --sys-label-2:      rgba(60, 60, 67, 0.60);
    --sys-label-3:      rgba(60, 60, 67, 0.30);

    --sys-fill:         rgba(120, 120, 128, 0.20);
    --sys-fill-2:       rgba(120, 120, 128, 0.16);
    --sys-fill-3:       rgba(118, 118, 128, 0.12);
    --sys-fill-4:       rgba(118, 118, 128, 0.08);

    --sys-sep:          rgba(60, 60, 67, 0.29);
    --sys-sep-opaque:   #c6c6c8;

    --sys-blue:         #007aff;
    --sys-red:          #ff3b30;
    --sys-green:        #34c759;
    --sys-accent:       #007aff;

    --glass-bg:         rgba(255, 255, 255, 0.80);
    --glass-tint:       rgba(0, 0, 0, 0.025);
    --glass-border:     rgba(60, 60, 67, 0.10);
    --glass-highlight:  rgba(255, 255, 255, 0.90);
    --glass-blur:       blur(28px) saturate(180%);

    --tab-bg:           rgba(245, 245, 248, 0.90);
    --tab-border:       rgba(60, 60, 67, 0.16);
    --nav-bg:           rgba(249, 249, 251, 0.94);
    --nav-border:       rgba(60, 60, 67, 0.16);

    --shadow-sm:        0 1px 3px rgba(0, 0, 0, 0.12);
    --shadow-md:        0 4px 20px rgba(0, 0, 0, 0.16);
    --shadow-lg:        0 10px 40px rgba(0, 0, 0, 0.22);

    --card-grad-mid:    rgba(0, 0, 0, 0.70);
    --card-grad-end:    rgba(0, 0, 0, 0.90);
    --card-txt-glow:    rgba(0, 0, 0, 0.90);
    --card-txt-soft:    rgba(0, 0, 0, 0.75);
}

/* === System Light Media Query === */
@media (prefers-color-scheme: light) {
    html:not([data-theme]) {
        --sys-bg:           #f2f2f7;
        --sys-bg-elevated:  #ffffff;
        --sys-bg-card:      #f2f2f7;

        --sys-label:        #000000;
        --sys-label-2:      rgba(60, 60, 67, 0.60);
        --sys-label-3:      rgba(60, 60, 67, 0.30);

        --sys-fill:         rgba(120, 120, 128, 0.20);
        --sys-fill-2:       rgba(120, 120, 128, 0.16);
        --sys-fill-3:       rgba(118, 118, 128, 0.12);
        --sys-fill-4:       rgba(118, 118, 128, 0.08);

        --sys-sep:          rgba(60, 60, 67, 0.29);
        --sys-sep-opaque:   #c6c6c8;

        --sys-blue:         #007aff;
        --sys-red:          #ff3b30;
        --sys-green:        #34c759;
        --sys-accent:       #007aff;

        --glass-bg:         rgba(255, 255, 255, 0.80);
        --glass-tint:       rgba(0, 0, 0, 0.025);
        --glass-border:     rgba(60, 60, 67, 0.10);
        --glass-highlight:  rgba(255, 255, 255, 0.90);
        --glass-blur:       blur(28px) saturate(180%);

        --tab-bg:           rgba(245, 245, 248, 0.90);
        --tab-border:       rgba(60, 60, 67, 0.16);
        --nav-bg:           rgba(249, 249, 251, 0.94);
        --nav-border:       rgba(60, 60, 67, 0.16);

        --shadow-sm:        0 1px 3px rgba(0, 0, 0, 0.12);
        --shadow-md:        0 4px 20px rgba(0, 0, 0, 0.16);
        --shadow-lg:        0 10px 40px rgba(0, 0, 0, 0.22);

        --card-grad-mid:    rgba(0, 0, 0, 0.70);
        --card-grad-end:    rgba(0, 0, 0, 0.90);
        --card-txt-glow:    rgba(0, 0, 0, 0.90);
        --card-txt-soft:    rgba(0, 0, 0, 0.75);
    }
}

/* ============================================================
   Base
   ============================================================ */

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text',
                 system-ui, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--sys-bg);
    color: var(--sys-label);
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.hidden {
    display: none !important;
}

/* ============================================================
   Layout
   ============================================================ */

.container {
    padding: 0 16px 110px;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
    box-sizing: border-box;
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
    gap: 14px;
    margin-top: 12px;
}

/* ============================================================
   Top Navigation Bar
   ============================================================ */

.top-bar {
    position: sticky;
    top: 0;
    z-index: 100;
    height: 56px;
    background: var(--nav-bg);
    -webkit-backdrop-filter: var(--glass-blur);
    backdrop-filter: var(--glass-blur);
    border-bottom: 0.5px solid var(--nav-border);
    display: flex;
    align-items: center;
    padding: 0 4px 0 2px;
    color: var(--sys-label);
    transition: opacity 0.25s ease;
}

.top-bar.hidden {
    display: none !important;
}

#top-bar-title {
    font-size: 1.0625rem;
    font-weight: 600;
    letter-spacing: -0.022em;
    margin-left: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--sys-label);
}

.top-bar .icon-btn {
    color: var(--sys-accent);
}

/* ============================================================
   Bottom Tab Bar — Floating Glass Pill
   ============================================================ */

.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
    display: flex;
    justify-content: center;
    padding: 12px 24px;
    padding-bottom: max(16px, env(safe-area-inset-bottom, 16px));
    pointer-events: none;
}

.tabs {
    display: flex;
    align-items: stretch;
    background: var(--tab-bg);
    -webkit-backdrop-filter: blur(36px) saturate(220%);
    backdrop-filter: blur(36px) saturate(220%);
    border: 0.5px solid var(--tab-border);
    border-radius: 24px;
    padding: 6px;
    gap: 2px;
    box-shadow:
        var(--shadow-lg),
        inset 0 1px 0 var(--glass-highlight);
    pointer-events: auto;
    width: 100%;
    max-width: 440px;
}

.tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 9px 4px 7px;
    cursor: pointer;
    border-radius: 18px;
    gap: 3px;
    color: var(--sys-label-2);
    transition:
        color 0.18s ease,
        background 0.18s ease,
        transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    min-width: 60px;
}

.tab svg {
    width: 22px;
    height: 22px;
    display: block;
    transition:
        color 0.18s ease,
        transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.tab span {
    font-size: 0.6875rem;
    font-weight: 500;
    letter-spacing: -0.01em;
    transition: color 0.18s ease;
    line-height: 1;
}

.tab.active {
    background: var(--glass-tint);
    color: var(--sys-accent);
}

.tab.active svg {
    transform: scale(1.08);
}

.tab:active {
    transform: scale(0.91);
}

/* ============================================================
   View Sections
   ============================================================ */

.view-section {
    animation: ios-rise 0.28s cubic-bezier(0.25, 0.46, 0.45, 0.94) both;
}

@keyframes ios-rise {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

.view-section > h2 {
    font-size: 1.875rem;
    font-weight: 700;
    letter-spacing: -0.038em;
    padding: 18px 4px 4px;
    margin: 0;
    color: var(--sys-label);
}

/* ============================================================
   Magazine & Issue Cards
   ============================================================ */

.magazine-card,
.issue-card {
    background: var(--sys-bg-elevated);
    border-radius: 18px;
    overflow: hidden;
    cursor: pointer;
    transition:
        transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1),
        box-shadow 0.28s ease;
    display: flex;
    flex-direction: column;
    position: relative;
    aspect-ratio: 1 / 1.4;
    width: 100%;
    height: auto;
    box-shadow: var(--shadow-md);
}

.magazine-card:hover,
.issue-card:hover {
    transform: translateY(-5px) scale(1.015);
    box-shadow: var(--shadow-lg);
}

.magazine-card:active,
.issue-card:active {
    transform: scale(0.96);
    box-shadow: var(--shadow-sm);
    transition-duration: 0.1s;
}

.card-content {
    position: absolute;
    inset: 0;
    padding: 12px;
    background: linear-gradient(
        to bottom,
        transparent 0%,
        transparent 58%,
        var(--card-grad-mid) 80%,
        var(--card-grad-end) 100%
    );
    color: #ffffff;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    pointer-events: none;
    z-index: 2;
}

.card-title {
    font-size: 0.9375rem;
    font-weight: 600;
    line-height: 1.2;
    letter-spacing: -0.016em;
    margin-bottom: 3px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-shadow:
        0 0 8px var(--card-txt-glow),
        0 1px 3px var(--card-txt-glow);
}

.card-subtitle {
    font-size: 0.75rem;
    font-weight: 400;
    color: rgba(255, 255, 255, 0.82);
    letter-spacing: -0.01em;
    text-shadow:
        0 0 6px var(--card-txt-soft),
        0 1px 2px var(--card-txt-glow);
}

/* ============================================================
   Loading Placeholder
   ============================================================ */

@keyframes pulse {
    0%   { opacity: 0.35; }
    50%  { opacity: 0.65; }
    100% { opacity: 0.35; }
}

.loading-placeholder {
    background: var(--sys-fill);
    animation: pulse 1.6s ease-in-out infinite;
}

.image-container {
    position: absolute;
    inset: 0;
    overflow: hidden;
}

.image-placeholder {
    position: absolute;
    inset: 0;
    z-index: 1;
}

.magazine-card img,
.issue-card img {
    display: block;
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    transition: opacity 0.45s ease-in-out;
    z-index: 2;
}

.magazine-card img.loaded,
.issue-card img.loaded {
    opacity: 1;
}

/* ============================================================
   Login Page
   ============================================================ */

.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100dvh;
    padding: 24px;
    background:
        radial-gradient(ellipse 140% 80% at 50% -10%,
            rgba(10, 132, 255, 0.18) 0%,
            transparent 65%),
        var(--sys-bg);
}

.login-card {
    background: var(--glass-bg);
    -webkit-backdrop-filter: var(--glass-blur);
    backdrop-filter: var(--glass-blur);
    border: 0.5px solid var(--glass-border);
    box-shadow: var(--shadow-lg), inset 0 1px 0 var(--glass-highlight);
    padding: 36px 28px 32px;
    border-radius: 26px;
    width: 100%;
    max-width: 360px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.login-card h2 {
    margin: 0;
    text-align: center;
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.035em;
    color: var(--sys-label);
}

.login-field {
    width: 100%;
    position: relative;
    margin-top: 6px;
}

.login-field input {
    width: 100%;
    height: 52px;
    padding: 18px 16px 6px;
    border-radius: 12px;
    border: 1.5px solid var(--sys-sep);
    background: var(--sys-fill-3);
    color: var(--sys-label);
    font-size: 1rem;
    font-family: inherit;
    box-sizing: border-box;
    transition: border-color 0.2s, background 0.2s;
    -webkit-appearance: none;
    appearance: none;
    outline: none;
}

.login-field input::placeholder {
    color: transparent;
}

.login-field input:focus {
    border-color: var(--sys-accent);
    background: var(--sys-fill-4);
}

.login-field label {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 1rem;
    color: var(--sys-label-2);
    pointer-events: none;
    transition:
        top 0.18s ease,
        transform 0.18s ease,
        font-size 0.18s ease,
        color 0.18s ease;
}

.login-field input:focus + label,
.login-field input:not(:placeholder-shown) + label {
    top: 10px;
    transform: translateY(0);
    font-size: 0.72rem;
    color: var(--sys-accent);
}

.login-field input:not(:focus):not(:placeholder-shown) + label {
    color: var(--sys-label-3);
}

.login-btn {
    background: var(--sys-accent);
    color: #ffffff;
    border: none;
    border-radius: 14px;
    height: 52px;
    width: 100%;
    margin-top: 4px;
    font-size: 1.0625rem;
    font-weight: 600;
    font-family: inherit;
    letter-spacing: -0.022em;
    cursor: pointer;
    transition: opacity 0.14s, transform 0.14s;
    -webkit-tap-highlight-color: transparent;
    box-shadow: 0 2px 12px rgba(10, 132, 255, 0.38);
}

.login-btn:active {
    opacity: 0.82;
    transform: scale(0.975);
}

/* ============================================================
   Settings — iOS Grouped List
   ============================================================ */

.settings-section {
    padding: 8px 0 24px;
    display: flex;
    flex-direction: column;
    gap: 28px;
}

.settings-group-wrapper {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.settings-group-label {
    font-size: 0.8125rem;
    font-weight: 400;
    color: var(--sys-label-2);
    text-transform: uppercase;
    letter-spacing: 0.045em;
    padding: 0 20px;
    margin: 0;
}

.settings-group {
    background: var(--glass-bg);
    -webkit-backdrop-filter: var(--glass-blur);
    backdrop-filter: var(--glass-blur);
    border: 0.5px solid var(--glass-border);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: var(--shadow-sm), inset 0 1px 0 var(--glass-highlight);
}

.settings-row {
    display: flex;
    align-items: center;
    padding: 13px 16px;
    gap: 12px;
    color: var(--sys-label);
    position: relative;
    min-height: 48px;
}

.settings-row + .settings-row::before {
    content: '';
    position: absolute;
    top: 0;
    left: 16px;
    right: 0;
    height: 0.5px;
    background: var(--sys-sep);
}

.settings-row-label {
    flex: 1;
    font-size: 1rem;
    font-weight: 400;
    letter-spacing: -0.01em;
}

/* === iOS Segmented Control === */

.segmented-control {
    display: flex;
    background: var(--sys-fill-2);
    border-radius: 9px;
    padding: 2px;
    gap: 2px;
}

.theme-option {
    flex: 1;
    padding: 7px 10px;
    border: none;
    border-radius: 7px;
    font-size: 0.8125rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.18s, box-shadow 0.18s, color 0.18s;
    background: transparent;
    color: var(--sys-label);
    -webkit-tap-highlight-color: transparent;
    letter-spacing: -0.01em;
}

.theme-option.active {
    background: var(--sys-bg-elevated);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25), 0 0 0 0.5px var(--sys-sep);
    color: var(--sys-label);
}

/* === Destructive button === */

.ios-btn-destructive {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    width: 100%;
    height: 44px;
    border: none;
    border-radius: 12px;
    background: transparent;
    color: var(--sys-red);
    font-size: 1rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    letter-spacing: -0.01em;
    transition: opacity 0.14s, transform 0.14s;
    -webkit-tap-highlight-color: transparent;
}

.ios-btn-destructive:active {
    opacity: 0.65;
    transform: scale(0.97);
}

/* ============================================================
   Reader
   ============================================================ */

#pdf-container {
    position: absolute;
    inset: 0;
    background: #000;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

canvas {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    image-rendering: -webkit-optimize-contrast;
    image-rendering: high-quality;
}

img {
    image-rendering: high-quality;
}

.reader-ui {
    position: absolute;
    z-index: 10;
    inset: 0;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.reader-header {
    background: linear-gradient(to bottom,
        rgba(0, 0, 0, 0.70) 0%,
        rgba(0, 0, 0, 0.00) 100%);
    color: #ffffff;
    padding: 10px 12px 28px;
    display: flex;
    align-items: center;
    pointer-events: auto;
    transition: opacity 0.28s ease;
    min-height: 68px;
    box-sizing: border-box;
}

.reader-footer {
    background: linear-gradient(to top,
        rgba(0, 0, 0, 0.85) 0%,
        rgba(0, 0, 0, 0.00) 100%);
    color: #ffffff;
    padding: 32px 16px 16px;
    padding-bottom: max(20px, env(safe-area-inset-bottom, 20px));
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    pointer-events: auto;
    transition: opacity 0.28s ease;
}

.reader-ui.ui-hidden .reader-header,
.reader-ui.ui-hidden .reader-footer {
    opacity: 0;
    pointer-events: none;
}

.page-info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin-bottom: 10px;
}

.page-info-row span {
    font-size: 0.875rem;
    font-weight: 500;
    letter-spacing: -0.01em;
    opacity: 0.85;
}

.reader-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 4px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.28);
    outline: none;
    cursor: pointer;
}

.reader-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #ffffff;
    cursor: pointer;
    box-shadow: 0 1px 6px rgba(0, 0, 0, 0.50);
    transition: transform 0.12s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.reader-slider:active::-webkit-slider-thumb {
    transform: scale(1.3);
}

.reader-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #ffffff;
    cursor: pointer;
    border: none;
    box-shadow: 0 1px 6px rgba(0, 0, 0, 0.50);
}
