:root {
    --bg-color: #121212;
    --surface-color: #1e1e1e;
    --text-color: #ffffff;
    --text-secondary: #aaaaaa;
    --accent-color: #007AFF;
    --border-color: #333333;

    --grid-gap: 4px;
    --grid-columns: 3;
    --card-ratio: 1.777;
    /* Default 16:9 vertical-ish */
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: 'Inter', sans-serif;
    height: 100vh;
    overflow: hidden;
    /* Prevent body scroll, handle in containers */
}

/* Typography */
h1,
h2,
h3 {
    font-weight: 500;
}

a {
    color: inherit;
    text-decoration: none;
}

button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    background: none;
    color: inherit;
}

/* Layout */
#app {
    display: flex;
    height: 100%;
    position: relative;
}

.sidebar {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 280px;
    background-color: var(--surface-color);
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    padding: 20px;
    display: flex;
    flex-direction: column;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.5);
}

.sidebar.open {
    transform: translateX(0);
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
}

#main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    width: 100%;
}

.app-header {
    height: 60px;
    display: flex;
    align-items: center;
    padding: 0 16px;
    background-color: rgba(18, 18, 18, 0.95);
    backdrop-filter: blur(10px);
    z-index: 10;
    position: sticky;
    top: 0;
    border-bottom: 1px solid var(--border-color);
}

.icon-btn {
    font-size: 24px;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#page-title {
    font-size: 18px;
    margin-left: 16px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.spacer {
    flex: 1;
}

.view-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 10px;
    scroll-behavior: smooth;
}

/* Controls */
.control-group {
    margin-bottom: 24px;
}

.control-group label {
    display: block;
    margin-bottom: 10px;
    color: var(--text-secondary);
    font-size: 14px;
}

.toggle-switch {
    display: flex;
    background: #000;
    border-radius: 8px;
    padding: 2px;
}

.toggle-switch button {
    flex: 1;
    padding: 8px;
    font-size: 14px;
    border-radius: 6px;
}

.toggle-switch button.active {
    background-color: var(--accent-color);
    color: white;
}

input[type=range] {
    width: 100%;
    accent-color: var(--accent-color);
}

select {
    width: 100%;
    padding: 10px;
    background: #000;
    color: white;
    border: 1px solid var(--border-color);
    border-radius: 6px;
}

/* Lightbox */
.lightbox {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #000;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.lightbox.active {
    opacity: 1;
    pointer-events: auto;
}

.lightbox-controls {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 1001;
}

#lb-close {
    color: white;
    font-size: 32px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 50%;
    width: 44px;
    height: 44px;
}

.lightbox-content {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    touch-action: none;
    /* Critical for custom gestures */
}

#lb-img {
    max-width: 100%;
    max-height: 100%;
    transform-origin: center center;
    /* transition handled in JS for panning, CSS for reset */
}

/* Home View Styles */
.section-title {
    font-size: 20px;
    margin: 20px 0 10px;
    padding-left: 8px;
    color: var(--text-color);
}

.categories-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 16px;
    padding: 8px;
}

.category-card {
    position: relative;
    border-radius: 12px;
    overflow: hidden;
    aspect-ratio: 1;
    cursor: pointer;
    transition: transform 0.2s;
}

.category-card:active {
    transform: scale(0.96);
}

.category-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.category-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    padding: 10px;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.8), transparent);
    color: white;
    font-weight: 500;
}

.trends-container {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 8px;
}

.trend-chip {
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.trend-chip:active {
    background-color: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}

/* Album View Styles */
.album-header {
    display: flex;
    align-items: center;
    margin-bottom: 20px;
    padding: 0 8px;
}

.back-btn {
    font-size: 24px;
    margin-right: 10px;
    padding: 4px 8px;
}

.album-grid {
    display: grid;
    grid-template-columns: repeat(var(--grid-columns), 1fr);
    gap: var(--grid-gap);
    width: 100%;
}

.photo-item {
    position: relative;
    width: 100%;
    /* aspect-ratio set via JS or inline style if needed, or default via CSS variable if uniform */
    aspect-ratio: var(--card-ratio);
    overflow: hidden;
    background-color: #2a2a2a;
    border-radius: 4px;
    cursor: pointer;
}

.photo-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: opacity 0.3s;
    opacity: 0;
    /* Fade in on load */
}

.photo-item img.loaded {
    opacity: 1;
}

/* Scroll Layout Mode Overrides */
.album-grid.scroll-mode {
    display: flex;
    flex-direction: column;
    gap: 20px;
    max-width: 600px;
    margin: 0 auto;
}

.album-grid.scroll-mode .photo-item {
    aspect-ratio: auto;
    /* Let image define height or set max-height */
    border-radius: 0;
}

.album-grid.scroll-mode .photo-item img {
    height: auto;
    max-height: 80vh;
}