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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #1a1a1a;
    color: #ffffff;
    overflow: hidden;
    overscroll-behavior: none;
}

.auth-overlay {
    position: fixed;
    inset: 0;
    background: rgba(10, 10, 10, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.auth-overlay.hidden {
    display: none;
}

.auth-card {
    background: #2d2d2d;
    border: 1px solid #404040;
    border-radius: 12px;
    padding: 2rem 2.5rem;
    max-width: 420px;
    width: 90%;
    text-align: center;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
}

.auth-card h2 {
    color: #00d4ff;
    margin-bottom: 0.75rem;
}

.auth-card p {
    color: #d0d0d0;
    margin-bottom: 1.5rem;
}

.auth-card #google-signin-button {
    display: flex;
    justify-content: center;
}

.google-signin-btn {
    background: #ffffff;
    color: #1f1f1f;
    border: 1px solid #dadce0;
    border-radius: 999px;
    padding: 12px 20px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.google-signin-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 10px 18px rgba(0, 0, 0, 0.2);
}

.auth-card .disabled {
    opacity: 0.6;
    pointer-events: none;
}

.auth-error {
    color: #ff6b6b;
    margin-top: 1rem;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Header */
.header {
    background: #2d2d2d;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid #404040;
    max-height: 120px;
    transition: max-height 1s ease, padding 1s ease, border-width 1s ease, opacity 1s ease;
}

.header h1 {
    font-size: 1.5rem;
    color: #00d4ff;
}

.controller-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.user-menu {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.user-menu[hidden] {
    display: none !important;
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #444;
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.9rem;
    overflow: hidden;
    border: none;
    cursor: pointer;
    padding: 0;
    position: relative;
    z-index: 2;
}

.user-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.user-menu-panel {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%) scaleX(0.95);
    transform-origin: right center;
    background: #2a2a2a;
    border: 1px solid #3a3a3a;
    border-radius: 999px;
    padding: 0.35rem 2.8rem 0.35rem 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 1;
}

.user-menu.open .user-menu-panel,
.user-menu:hover .user-menu-panel,
.user-menu:focus-within .user-menu-panel {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(-50%) scaleX(1);
}

.user-name {
    font-size: 0.9rem;
    color: #d0d0d0;
}

.user-actions {
    background: transparent;
    border: 1px solid #555;
    color: #d0d0d0;
    padding: 0.35rem 0.75rem;
    border-radius: 4px;
    cursor: pointer;
}

.user-actions:hover {
    background: #3a3a3a;
}

.status-indicator {
    font-size: 1.5rem;
}

.status-indicator.online {
    color: #00ff00;
}

.status-indicator.offline {
    color: #ff0000;
}

/* Main viewer */
.viewer-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000000;
    overflow: hidden;
    position: relative;
    touch-action: manipulation;
}

.comic-display {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow-y: auto;
    overflow-x: hidden;
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
}

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

.comic-display.fit-height img {
    height: 100%;
    width: auto;
    max-width: none;
}

.comic-display.fit-width img {
    width: 100%;
    height: auto;
    max-height: none;
}

.comic-display.fit-width {
    align-items: flex-start;
}

.welcome-screen {
    text-align: center;
    padding: 2rem;
    max-width: 600px;
}

.welcome-screen h2 {
    color: #00d4ff;
    margin-bottom: 1rem;
}

.instructions {
    margin-top: 2rem;
    background: #2d2d2d;
    padding: 1.5rem;
    border-radius: 8px;
    text-align: left;
}

.instructions h3 {
    color: #00d4ff;
    margin-bottom: 1rem;
}

.instructions ul {
    list-style-position: inside;
}

.instructions li {
    margin-bottom: 0.5rem;
}

/* Controls */
.controls {
    background: #2d2d2d;
    padding: 1rem 2rem;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 2rem;
    flex-wrap: wrap;
    border-top: 2px solid #404040;
    max-height: 120px;
    transition: max-height 1s ease, padding 1s ease, border-width 1s ease, opacity 1s ease;
}

#app.ui-hidden .header,
#app.ui-hidden .controls {
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    border-width: 0;
    opacity: 0;
    pointer-events: none;
}

.nav-btn {
    background: #00d4ff;
    color: #000;
    border: none;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.3s;
    min-height: 44px;
    min-width: 120px;
}

.nav-btn:hover {
    background: #00a8cc;
}

.nav-btn-secondary {
    background: #2b2b2b;
    color: #d7f6ff;
    border: 1px solid #3f3f3f;
}

.nav-btn-secondary:hover {
    background: #3a3a3a;
}

.nav-btn:disabled {
    background: #555;
    cursor: not-allowed;
}

#page-counter {
    font-size: 1.1rem;
    min-width: 120px;
    text-align: center;
    user-select: none;
}

.fullscreen-hint {
    font-size: 0.85rem;
    color: #b6b6b6;
}

/* Debug panel */
.debug-panel {
    position: fixed;
    bottom: 0;
    right: 0;
    width: 300px;
    max-height: 200px;
    background: rgba(0, 0, 0, 0.9);
    border: 1px solid #00d4ff;
    padding: 1rem;
    font-family: monospace;
    font-size: 0.8rem;
    overflow-y: auto;
    display: none;
}

.debug-panel.visible {
    display: block;
}

.deploy-indicator {
    position: fixed;
    right: 16px;
    bottom: 16px;
    padding: 0.5rem 0.85rem;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.75);
    border: 1px solid rgba(0, 212, 255, 0.5);
    color: #cfefff;
    font-size: 0.8rem;
    letter-spacing: 0.02em;
    backdrop-filter: blur(6px);
    z-index: 1500;
}

.deploy-indicator.hidden {
    display: none;
}

@media (max-width: 900px) {
    .header {
        padding: 0.75rem 1rem;
    }

    .header h1 {
        font-size: 1.2rem;
    }

    .controller-status {
        font-size: 0.85rem;
    }

    .controls {
        padding: 0.75rem 1rem;
        gap: 1rem;
    }
}

@media (max-width: 600px) {
    .header {
        flex-direction: column;
        gap: 0.5rem;
        text-align: center;
    }

    .controls {
        flex-direction: column;
        gap: 0.75rem;
    }

    .nav-btn {
        width: 100%;
        max-width: 280px;
    }
}
#debug-output {
    white-space: pre-wrap;
    color: #00ff00;
}

/* Loading state */
.loading {
    text-align: center;
    padding: 2rem;
}

.loading::after {
    content: '...';
    animation: dots 1.5s steps(4, end) infinite;
}

@keyframes dots {
    0%, 20% { content: '.'; }
    40% { content: '..'; }
    60%, 100% { content: '...'; }
}

/* Page Error State */
.page-error {
    text-align: center;
    padding: 2rem;
    color: #fff;
}

.page-error .error-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
}

.page-error h3 {
    color: #ff6b6b;
    margin-bottom: 0.5rem;
}

.page-error p {
    color: #aaa;
    margin-bottom: 1.5rem;
}

.page-error .retry-btn {
    background: #00d4ff;
    color: #000;
    border: none;
    padding: 0.75rem 2rem;
    font-size: 1rem;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.3s;
    font-weight: bold;
}

.page-error .retry-btn:hover {
    background: #00a8cc;
}

/* Settings panel */
.settings-panel {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.settings-panel.visible {
    display: flex;
}

.settings-header {
    margin-bottom: 1.5rem;
    text-align: center;
}

.settings-header h2 {
    color: #00d4ff;
    margin-bottom: 0.5rem;
}

.settings-header p {
    color: #ccc;
    font-size: 0.9rem;
}

.settings-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.settings-item {
    background: #2d2d2d;
    border: 1px solid #404040;
    padding: 0.75rem 1rem;
    border-radius: 6px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-width: 320px;
    transition: border 0.2s, box-shadow 0.2s;
}

.settings-item.selected {
    border-color: #00d4ff;
    box-shadow: 0 0 0 2px rgba(0, 212, 255, 0.25);
}

.settings-label {
    font-weight: 600;
}

.settings-value {
    color: #00d4ff;
    font-variant-numeric: tabular-nums;
}

.settings-footer {
    text-align: center;
}

.settings-close {
    background: #00d4ff;
    color: #000;
    border: none;
    padding: 0.6rem 1.5rem;
    font-size: 1rem;
    border-radius: 4px;
    cursor: pointer;
}

.settings-close:hover {
    background: #00a8cc;
}

.settings-card {
    background: #1f1f1f;
    border: 1px solid #404040;
    border-radius: 10px;
    padding: 1.5rem 2rem;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}
