@import url('https://fonts.googleapis.com/css2?family=DM+Mono:wght@400;500&family=Syne:wght@400;600;700;800&display=swap');

:root {
    --bg: #0e0e10;
    --surface: #17171a;
    --surface2: #1f1f23;
    --border: #2a2a30;
    --border-light: #38383f;
    --accent: #e8ff47;
    --accent-dim: #c4d93a;
    --accent-muted: rgba(232,255,71,0.08);
    --text: #f0f0f2;
    --text-muted: #808090;
    --text-faint: #4a4a5a;
    --red: #ff4f4f;
    --green: #47ffb0;
    --blue: #47a3ff;
    --radius: 10px;
    --shadow: 0 8px 20px rgba(0,0,0,0.3);
    --spinner-bg: rgba(14,14,16,0.4);
    --spinner-fg: #0e0e10;
}

/* Light mode overrides */
body.light-mode {
    --bg: #f5f5f7;
    --surface: #ffffff;
    --surface2: #f0f0f2;
    --border: #d0d0d5;
    --border-light: #b0b0b8;
    --accent: #d4e820;
    --accent-dim: #b8cc1a;
    --accent-muted: rgba(212,232,32,0.1);
    --text: #1a1a1e;
    --text-muted: #5a5a6e;
    --text-faint: #9a9aae;
    --red: #d32f2f;
    --green: #2e7d32;
    --blue: #1976d2;
    --shadow: 0 8px 20px rgba(0,0,0,0.08);
    --spinner-bg: rgba(0,0,0,0.1);
    --spinner-fg: #1a1a1e;
}

/* Theme toggle button */
.theme-toggle {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 20px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-muted);
    transition: all 0.15s;
    margin-left: 8px;
}
.theme-toggle:hover {
    background: var(--surface2);
    color: var(--accent);
    border-color: var(--accent);
}

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

body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Syne', sans-serif;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ---------- Navigation ---------- */
.navbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 48px;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
    gap: 20px;
    background: var(--bg);
}
.nav-brand .logo-link {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    color: inherit;
}
.logo-mark {
    width: 36px; height: 36px;
    background: var(--accent);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.logo-mark svg { width: 18px; height: 18px; }
.brand-text {
    font-weight: 800;
    font-size: 20px;
    letter-spacing: -0.5px;
}
.nav-links {
    display: flex;
    align-items: center;
    gap: 28px;
    font-family: 'DM Mono', monospace;
    font-size: 13px;
}

/* All nav items share vertical rhythm */
.nav-links a,
.dropdown-btn,
.theme-toggle {
    line-height: 1;
    display: flex;
    align-items: center;
}

/* Plain links */
.nav-links a {
    color: var(--text-muted);
    text-decoration: none;
    transition: color 0.15s;
    font-weight: 500;
    padding: 8px 0;
}
.nav-links a:hover {
    color: var(--accent);
}

/* ---------- Dropdowns ---------- */
.dropdown {
    position: relative;
}
.dropdown-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-family: 'DM Mono', monospace;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 0;
    transition: color 0.15s;
}
.dropdown-btn:hover {
    color: var(--accent);
}
.dropdown-btn .arrow {
    font-size: 8px;
    transition: transform 0.2s;
}
.dropdown-content {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    min-width: 180px;
    padding: 8px 0;
    z-index: 100;
    box-shadow: var(--shadow);
}
.dropdown-content a {
    display: block;
    padding: 8px 16px;
    color: var(--text-muted);
    text-decoration: none;
    font-family: 'DM Mono', monospace;
    font-size: 12px;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
}
.dropdown-content a:hover {
    background: var(--accent-muted);
    color: var(--accent);
}

/* JS drives open/close — no CSS :hover on the panel itself */
.dropdown.open .dropdown-content {
    display: block;
}
.dropdown.open .dropdown-btn .arrow {
    transform: rotate(180deg);
}

/* Mobile dropdown open state */
.dropdown.open .dropdown-content {
    display: block;
}
.dropdown.open .dropdown-btn .arrow {
    transform: rotate(180deg);
}

/* Focus states for accessibility */
a:focus-visible,
button:focus-visible,
.dropdown-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 4px;
}

/* ---------- Main Layout ---------- */
main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 40px 24px 80px;
    flex: 1;
    width: 100%;
}

/* ---------- Content Pages ---------- */
.content-page {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 40px;
}
.content-page h1 {
    font-size: 32px;
    font-weight: 800;
    letter-spacing: -1px;
    margin-bottom: 16px;
}
.content-page h2 {
    font-size: 20px;
    font-weight: 700;
    margin: 32px 0 16px;
    color: var(--accent);
}
.content-page h3 {
    font-size: 16px;
    font-weight: 600;
    margin: 24px 0 12px;
}
.content-page p {
    font-family: 'DM Mono', monospace;
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-muted);
    margin-bottom: 16px;
}
.content-page ul, .content-page ol {
    font-family: 'DM Mono', monospace;
    font-size: 14px;
    color: var(--text-muted);
    margin-left: 24px;
    margin-bottom: 20px;
}
.content-page li {
    margin-bottom: 8px;
}
.content-page a {
    color: var(--accent);
    text-decoration: none;
}
.content-page a:hover { text-decoration: underline; }

/* ---------- Tool Cards ---------- */
.tools-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 24px;
    margin: 40px 0;
}
.tool-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px;
    text-decoration: none;
    color: var(--text);
    transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.tool-card:hover {
    transform: translateY(-4px);
    border-color: var(--accent);
    box-shadow: var(--shadow);
}
.tool-icon {
    width: 48px; height: 48px;
    background: var(--surface2);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 20px;
    border: 1px solid var(--border);
}
.tool-card h3 {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 8px;
}
.tool-card p {
    font-family: 'DM Mono', monospace;
    font-size: 13px;
    color: var(--text-muted);
}

/* ---------- Drop Zone & UI Components ---------- */
#drop-zone {
    border: 2px dashed var(--border-light);
    border-radius: var(--radius);
    padding: 52px 40px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
    position: relative;
    overflow: hidden;
}
#drop-zone:hover { border-color: var(--accent); background: var(--accent-muted); }
#drop-zone::before {
    content: '';
    position: absolute; inset: 0;
    background: radial-gradient(ellipse at 50% 0%, rgba(232,255,71,0.04) 0%, transparent 70%);
    pointer-events: none;
}
#drop-zone.drag-over { border-color: var(--accent); background: var(--accent-muted); }
#drop-zone .dz-icon {
    width: 48px; height: 48px;
    margin: 0 auto 16px;
    background: var(--surface2);
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    border: 1px solid var(--border);
}
#drop-zone h2 { font-size: 16px; font-weight: 700; margin-bottom: 6px; letter-spacing: -0.3px; }
#drop-zone p { font-family: 'DM Mono', monospace; font-size: 12px; color: var(--text-muted); }
#file-input { display: none; }

.btn-add, .btn {
    display: inline-flex; align-items: center; gap: 7px;
    margin-top: 20px; padding: 10px 20px;
    background: var(--accent); color: #0e0e10;
    border: none; border-radius: 7px;
    font-family: 'Syne', sans-serif; font-size: 13px; font-weight: 700;
    cursor: pointer; transition: transform 0.1s, background 0.15s; letter-spacing: 0.2px;
}
.btn-add:hover, .btn:hover { background: var(--accent-dim); transform: translateY(-1px); }
.btn-add:active, .btn:active { transform: translateY(0); }

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

.section-header {
    display: flex; align-items: center; justify-content: space-between;
    margin: 36px 0 14px; gap: 12px; flex-wrap: wrap;
}
.section-header-left { display: flex; align-items: center; gap: 10px; }
.section-header h3 { font-size: 13px; font-weight: 700; color: var(--text-muted); letter-spacing: 1.5px; text-transform: uppercase; }
.count-badge {
    font-family: 'DM Mono', monospace; font-size: 11px;
    color: var(--accent); background: var(--accent-muted);
    border: 1px solid rgba(232,255,71,0.2);
    padding: 2px 9px; border-radius: 20px;
}

.sort-controls { display: flex; align-items: center; gap: 6px; }
.sort-label { font-family: 'DM Mono', monospace; font-size: 11px; color: var(--text-faint); }
.sort-btn {
    font-family: 'DM Mono', monospace; font-size: 11px;
    padding: 4px 10px;
    background: var(--surface2); color: var(--text-muted);
    border: 1px solid var(--border); border-radius: 5px;
    cursor: pointer; transition: background 0.12s, color 0.12s, border-color 0.12s;
    white-space: nowrap;
}
.sort-btn:hover { background: var(--border); color: var(--text); border-color: var(--border-light); }

#pdf-list { display: flex; flex-direction: column; gap: 8px; min-height: 20px; }

.pdf-strip {
    display: flex; align-items: center; gap: 12px;
    padding: 14px 16px;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    cursor: default; transition: border-color 0.15s, background 0.15s, transform 0.15s, box-shadow 0.15s;
    user-select: none; position: relative;
}
.pdf-strip:hover { border-color: var(--border-light); background: var(--surface2); }
.pdf-strip.dragging { opacity: 0.4; border-color: var(--accent); }
.pdf-strip.drag-target { border-color: var(--accent); background: var(--accent-muted); transform: scale(1.01); box-shadow: 0 0 0 2px rgba(232,255,71,0.15); }

.strip-index { font-family: 'DM Mono', monospace; font-size: 12px; color: var(--text-faint); width: 20px; text-align: right; flex-shrink: 0; }

.drag-handle {
    cursor: grab; color: var(--text-faint);
    display: flex; align-items: center; padding: 4px; border-radius: 4px;
    transition: color 0.15s, background 0.15s; flex-shrink: 0;
}
.drag-handle:hover { color: var(--text-muted); background: var(--surface2); }
.drag-handle:active { cursor: grabbing; }

.strip-icon {
    width: 36px; height: 44px; background: var(--surface2); border: 1px solid var(--border);
    border-radius: 6px; display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; position: relative; overflow: hidden;
}
.strip-icon::after {
    content: ''; position: absolute; top: 0; right: 0;
    width: 10px; height: 10px; background: var(--bg);
    clip-path: polygon(100% 0, 0 0, 100% 100%);
    border-left: 1px solid var(--border); border-bottom: 1px solid var(--border);
}
.strip-icon span { font-family: 'DM Mono', monospace; font-size: 8px; font-weight: 500; color: var(--red); letter-spacing: 0.5px; }

.strip-info { flex: 1; min-width: 0; }
.strip-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: -0.2px; }
.strip-meta { display: flex; align-items: center; gap: 10px; margin-top: 4px; }
.strip-meta span { font-family: 'DM Mono', monospace; font-size: 11px; color: var(--text-muted); }
.strip-meta .dot { color: var(--text-faint); }

.strip-arrows { display: flex; flex-direction: column; gap: 2px; flex-shrink: 0; }
.arrow-btn {
    width: 26px; height: 22px; background: var(--surface2); border: 1px solid var(--border);
    border-radius: 4px; cursor: pointer; display: flex; align-items: center; justify-content: center;
    color: var(--text-muted); transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.arrow-btn:hover { background: var(--border); color: var(--text); border-color: var(--border-light); }
.arrow-btn:disabled { opacity: 0.25; cursor: not-allowed; }
.arrow-btn svg { width: 10px; height: 10px; }

.remove-btn {
    width: 30px; height: 30px; background: transparent; border: 1px solid transparent;
    border-radius: 6px; cursor: pointer; display: flex; align-items: center; justify-content: center;
    color: var(--text-faint); transition: background 0.12s, color 0.12s, border-color 0.12s; flex-shrink: 0;
}
.remove-btn:hover { background: rgba(255,79,79,0.1); color: var(--red); border-color: rgba(255,79,79,0.3); }
.remove-btn svg { width: 14px; height: 14px; }

.actions-bar { margin-top: 28px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.btn-primary { background: var(--accent); color: #0e0e10; }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border-light); }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { color: var(--red); border-color: rgba(255,79,79,0.4); background: rgba(255,79,79,0.05); }

.actions-spacer { flex: 1; }

#status { margin-top: 16px; font-family: 'DM Mono', monospace; font-size: 12px; min-height: 20px; transition: color 0.2s; }
#status.working { color: var(--accent); }
#status.success { color: var(--green); }
#status.error { color: var(--red); }

#empty-state { text-align: center; padding: 40px 0; color: var(--text-faint); font-family: 'DM Mono', monospace; font-size: 12px; display: none; }

@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
    width: 14px; height: 14px;
    border: 2px solid var(--spinner-bg);
    border-top-color: var(--spinner-fg);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    display: inline-block;
}

.progress-wrap { margin-top: 14px; height: 3px; background: var(--surface2); border-radius: 2px; overflow: hidden; display: none; }
.progress-wrap.visible { display: block; }
.progress-bar { height: 100%; background: var(--accent); border-radius: 2px; transition: width 0.3s; width: 0%; }

@keyframes slideIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }
.pdf-strip { animation: slideIn 0.2s ease; }

/* ---------- Splitter Specific ---------- */
.page-thumbnails {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 12px;
    margin-top: 20px;
}
.page-thumb {
    background: var(--surface2);
    border: 2px solid var(--border);
    border-radius: 8px;
    padding: 8px;
    cursor: pointer;
    transition: border-color 0.15s;
    text-align: center;
}
.page-thumb.selected { border-color: var(--accent); }
.page-thumb canvas {
    width: 100%;
    height: auto;
    border-radius: 4px;
}
.page-label {
    font-family: 'DM Mono', monospace;
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* ---------- Annotator Specific ---------- */
.annotator-container {
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.toolbar {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    padding: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.tool-btn {
    width: 40px; height: 40px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s;
}
.tool-btn.active {
    background: var(--accent);
    color: #0e0e10;
    border-color: var(--accent);
}
.tool-btn:hover { background: var(--border); color: var(--text); }
.color-picker { width: 40px; height: 40px; padding: 4px; background: transparent; border: 1px solid var(--border); border-radius: 6px; cursor: pointer; }
.canvas-wrapper {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    overflow: auto;
    text-align: center;
    max-height: 70vh;
    display: block;
}
#pdf-canvas-container {
    position: relative;
    display: inline-block;
    min-width: 100px;
    min-height: 100px;
}
#pdf-canvas, #drawing-canvas {
    display: block;
    max-width: 100%;
    height: auto;
}
#drawing-canvas {
    position: absolute;
    top: 0;
    left: 0;
}

/* ---------- Footer ---------- */
.site-footer {
    border-top: 1px solid var(--border);
    padding: 32px 48px;
    margin-top: 40px;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    font-family: 'DM Mono', monospace;
    font-size: 12px;
    color: var(--text-faint);
    background: var(--surface);
}
.footer-links {
    display: flex;
    gap: 28px;
    flex-wrap: wrap;
}
.footer-links a {
    color: var(--text-muted);
    text-decoration: none;
    transition: color 0.15s;
}
.footer-links a:hover { color: var(--accent); }

/* ---------- Responsive ---------- */
@media (max-width: 600px) {
    .navbar { padding: 20px; }
    .nav-links { gap: 16px; flex-wrap: wrap; }
    main { padding: 28px 16px 0; }
    .sort-controls { display: none; }
    .site-footer { padding: 24px; flex-direction: column; align-items: flex-start; }
    .content-page { padding: 24px; }
}