:root {
    --bg-main: #0f172a;
    --bg-card: #1e293b;
    --bg-card-hover: #27354a;
    --accent: #38bdf8;
    --accent-hover: #0ea5e9;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border: #334155;
    --success: #22c55e;
    --warning: #f59e0b;
    --font: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

.account-bar { display:flex; flex-wrap:wrap; justify-content:flex-end; align-items:center; gap:1rem; }
.account-bar a { color:var(--accent); }
.account-bar form { margin:0; }
.auth-container { max-width:450px; margin:8vh auto; width:calc(100% - 2rem); }
.auth-container h1 { font-size:1.4rem; margin-bottom:1rem; }
.auth-container h2 { margin-bottom:1rem; }
.auth-form { display:grid; gap:1rem; max-width:450px; margin-top:1rem; }
.auth-form label { display:grid; gap:.4rem; }
.auth-form input { width:100%; padding:.7rem; background:var(--bg-main); color:var(--text-main); border:1px solid var(--border); border-radius:.4rem; font:inherit; }
.auth-error { color: #fca5a5; margin:1rem 0; }
.login-session { display:flex; justify-content:space-between; align-items:center; flex-wrap:wrap; gap:1rem; padding:1rem 0; border-bottom:1px solid var(--border); margin-bottom:1rem; }
.login-session > div { flex:1; min-width:200px; overflow-wrap:anywhere; }
.login-session small { color:var(--text-muted); }

.comic-meta a, .comic-card-footer a:not(.btn), .issue-index-link {
    color: var(--accent);
    text-underline-offset: .15em;
    overflow-wrap: anywhere;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-main);
    color: var(--text-main);
    font-family: var(--font);
    line-height: 1.5;
    min-height: 100vh;
}

.navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    background: rgba(30, 41, 59, 0.85);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-area .icon {
    font-size: 1.8rem;
}

.logo-area h1 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.model-badge {
    background: rgba(56, 189, 248, 0.15);
    border: 1px solid rgba(56, 189, 248, 0.3);
    color: var(--accent);
    padding: 0.35rem 0.85rem;
    border-radius: 9999px;
    font-size: 0.85rem;
}

.container {
    max-width: 1200px;
    margin: 2rem auto;
    padding: 0 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.grid-2col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

@media (max-width: 850px) {
    .grid-2col {
        grid-template-columns: 1fr;
    }
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 1rem;
    padding: 1.5rem;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.3);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.card-header h2 {
    font-size: 1.2rem;
    font-weight: 600;
}

.desc {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 1.25rem;
}

.badge {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-muted);
    padding: 0.25rem 0.6rem;
    border-radius: 0.5rem;
    font-size: 0.8rem;
}

.qr-container {
    display: flex;
    justify-content: center;
    padding: 1rem;
    background: #ffffff;
    border-radius: 0.75rem;
    width: fit-content;
    margin: 0 auto 1.25rem auto;
}

.qr-container img {
    width: 220px;
    height: 220px;
    display: block;
}

.mobile-url-box {
    text-align: center;
    font-size: 0.85rem;
}

.mobile-url-box label {
    display: block;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}

.mobile-url-box a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
    word-break: break-all;
}

.mobile-url-box a:hover {
    text-decoration: underline;
}

.session-box {
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 1rem;
    margin-bottom: 1.5rem;
}

.features-list h3 {
    font-size: 0.95rem;
    margin-bottom: 0.75rem;
    color: var(--text-muted);
}

.features-list ul {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    font-size: 0.9rem;
}

/* Progress bar */
.progress-area {
    margin-top: 1rem;
}

.progress-bar-bg {
    background: rgba(255, 255, 255, 0.1);
    height: 10px;
    border-radius: 5px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.progress-bar-fill {
    background: linear-gradient(90deg, var(--accent), var(--success));
    height: 100%;
    transition: width 0.3s ease;
}

.progress-text {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.hidden {
    display: none !important;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.6rem 1.2rem;
    border-radius: 0.5rem;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
    text-decoration: none;
}

.btn-primary {
    background: var(--accent);
    color: #0f172a;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-secondary {
    background: var(--border);
    color: var(--text-main);
}

.btn-secondary:hover {
    background: #475569;
}

.btn-success {
    background: var(--success);
    color: #0f172a;
}

.btn-success:hover {
    filter: brightness(1.1);
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-main);
}

.btn-outline:hover {
    background: rgba(255, 255, 255, 0.05);
}

.btn-large {
    padding: 0.85rem 1.5rem;
    font-size: 1rem;
}

.btn-block {
    width: 100%;
}

/* Results Grid */
.results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr));
    gap: 1.5rem;
    margin-top: 1rem;
}

.gallery-toolbar, .gallery-pagination, .comic-summary, .detail-toolbar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: .75rem;
}

.gallery-toolbar {
    justify-content: space-between;
    margin-top: 1rem;
    scroll-margin-top: 1rem;
}

.gallery-toolbar label { color: var(--text-muted); font-size: .9rem; }
.gallery-pagination { justify-content: center; }
.gallery-pagination-bottom { margin-top: 1.5rem; }
.page-status { color: var(--text-muted); font-size: .85rem; }
.btn:disabled { opacity: .4; cursor: default; }

.gallery-toolbar select, .filter-box select {
    padding: .5rem;
    color: var(--text-main);
    background: var(--bg-main);
    border: 1px solid var(--border);
    border-radius: .5rem;
    font: inherit;
}

.comic-open {
    display: block;
    width: 100%;
    border: 0;
    color: var(--text-main);
    background: transparent;
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.comic-open:focus-visible { outline: 3px solid var(--accent); outline-offset: -3px; }
.comic-open .comic-thumb-wrapper img { width: 100%; height: 100%; }
.comic-summary { justify-content: space-between; padding: .85rem 1rem; font-size: .9rem; }
.comic-date { color: var(--accent); }

body.details-open { overflow: hidden; }
.comic-details {
    margin: auto;
    width: min(1100px, calc(100% - 2rem));
    max-height: calc(100dvh - 2rem);
    padding: 0;
    color: var(--text-main);
    background: var(--bg-main);
    border: 1px solid var(--border);
    border-radius: .75rem;
    overflow-y: auto;
}
.comic-details::backdrop { background: rgba(0, 0, 0, .8); }
.detail-toolbar {
    position: sticky;
    top: 0;
    z-index: 1;
    padding: 1rem;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
}
#detailClose { margin-left: auto; }
#detailPosition { color: var(--text-muted); font-size: .85rem; }
.detail-heading { padding: 1rem; }
.detail-title-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.detail-title-row h2 { min-width: 0; overflow-wrap: anywhere; }
.detail-edit { flex-shrink: 0; }
.detail-heading p { margin-top: .4rem; color: var(--text-muted); }
.detail-image { display: block; background: #000; }
.detail-image img { display: block; width: 100%; height: auto; }
.detail-notice { color: var(--warning); }
.recognized-text summary { cursor: pointer; font-weight: 600; padding: .5rem 0; }
.recognized-text summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.recognized-text[open] .dialogue-box { margin-top: .5rem; }
.detail-description, .comic-details .dialogue-box, .comic-details .caption-box { white-space: pre-wrap; }
.comic-details .dialogue-box, .comic-details .caption-box { max-height: none; }
.comic-details .comic-card-footer { flex-wrap: wrap; justify-content: flex-start; gap: 1rem; }
.comic-details small { overflow-wrap: anywhere; color: var(--text-muted); }

@media (max-width: 600px) {
    .results-card > .card-header { align-items: stretch; flex-direction: column; gap: .75rem; }
    .filter-box { display: flex; flex-wrap: wrap; gap: .5rem; }
    .filter-box input { min-width: 0; width: 100%; }
    .gallery-toolbar { justify-content: center; }
    .gallery-pagination { gap: .5rem; }
    .page-status { flex-basis: 100%; text-align: center; order: 1; }
    .comic-details { width: calc(100% - 1rem); max-height: calc(100dvh - 1rem); }
    .detail-toolbar { gap: .5rem; padding: .75rem; }
    .detail-toolbar .btn { padding: .5rem; font-size: .85rem; }
    #detailPosition { flex-basis: 100%; text-align: center; order: 1; }
}

.comic-card {
    background: rgba(15, 23, 42, 0.7);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: transform 0.2s, box-shadow 0.2s;
}

.comic-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 24px -5px rgba(0, 0, 0, 0.4);
    border-color: var(--accent);
}

.comic-thumb-wrapper {
    position: relative;
    background: #000;
    aspect-ratio: 16 / 9;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.comic-thumb-wrapper img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.date-badge {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: rgba(15, 23, 42, 0.85);
    border: 1px solid var(--border);
    padding: 0.2rem 0.5rem;
    border-radius: 0.4rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--accent);
}

.strip-num-badge {
    position: absolute;
    bottom: 0.5rem;
    left: 0.5rem;
    background: rgba(15, 23, 42, 0.85);
    color: #94a3b8;
    padding: 0.2rem 0.5rem;
    border-radius: 0.3rem;
    font-size: 0.75rem;
    font-weight: 600;
    border: 1px solid var(--border);
}

.comic-body {
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex-grow: 1;
}

.comic-title {
    font-size: 1.1rem;
    font-weight: 700;
}

.comic-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.dialogue-box {
    background: rgba(30, 41, 59, 0.5);
    border-left: 3px solid var(--accent);
    padding: 0.5rem 0.75rem;
    border-radius: 0.3rem;
    font-size: 0.85rem;
    font-style: italic;
    color: #e2e8f0;
    max-height: 120px;
    overflow-y: auto;
}

.caption-box {
    background: rgba(245, 158, 11, 0.12);
    border-left: 3px solid #f59e0b;
    padding: 0.5rem 0.75rem;
    border-radius: 0.3rem;
    font-size: 0.85rem;
    color: #fef3c7;
    margin-top: 0.4rem;
    max-height: 140px;
    overflow-y: auto;
}

.caption-label {
    display: block;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #f59e0b;
    margin-bottom: 0.2rem;
}

.comic-card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border);
    margin-top: auto;
}

.filter-box input {
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    font-size: 0.9rem;
    min-width: 250px;
}

.filter-box input:focus {
    outline: none;
    border-color: var(--accent);
}

.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}

/* Mobile specific styling */
.mobile-body {
    background: #090d16;
}

.mobile-header {
    padding: 1rem;
    background: var(--bg-card);
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    border-bottom: 1px solid var(--border);
    gap: 0.25rem;
}

.session-badge {
    font-size: 0.75rem;
    color: var(--accent);
    background: rgba(56, 189, 248, 0.1);
    padding: 0.2rem 0.5rem;
    border-radius: 0.3rem;
}

.mobile-container {
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    max-width: 500px;
    margin: 0 auto;
}

.button-group {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.file-counter {
    text-align: center;
    font-size: 0.9rem;
    margin-bottom: 1rem;
    color: var(--text-muted);
}

.preview-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
    margin-bottom: 1.25rem;
}

.preview-item {
    position: relative;
    aspect-ratio: 1;
    border-radius: 0.5rem;
    overflow: hidden;
    background: #000;
    border: 1px solid var(--border);
}

.preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.preview-item .remove-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    background: rgba(239, 68, 68, 0.85);
    color: white;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.preview-item .order-badge {
    position: absolute;
    bottom: 4px;
    left: 4px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    font-size: 11px;
    padding: 1px 4px;
    border-radius: 3px;
}

.footer {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--text-muted);
    font-size: 0.85rem;
    border-top: 1px solid var(--border);
}
