/* CSS Variables */
:root {
    --bg-primary: #1a1a1a;
    --bg-secondary: #2a2a2a;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0a0;
    --accent: #ff6600;
    --border: #3a3a3a;
    --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-size: 16px;
}

/* Theme: Light */
[data-theme="light"] {
    --bg-primary: #ffffff;
    --bg-secondary: #f6f6f6;
    --text-primary: #1a1a1a;
    --text-secondary: #666666;
    --border: #e0e0e0;
}

/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: var(--font-size);
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    overflow-x: hidden;
}

/* Header */
header {
    position: sticky;
    top: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    z-index: 100;
    min-height: 56px;
    contain: layout style;
}

header h1 {
    font-size: 18px;
    font-weight: 600;
    flex: 1;
    text-align: center;
}

header h1[style*="cursor: pointer"] {
    transition: opacity 0.2s;
}

header h1[style*="cursor: pointer"]:hover {
    opacity: 0.7;
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background-color 0.2s;
    min-width: 44px;
    min-height: 44px;
}

.icon-btn:hover {
    background-color: var(--bg-primary);
}

.icon-btn:active {
    opacity: 0.7;
    transform: scale(0.95);
}

/* Sidebar */
.sidebar {
    position: fixed;
    top: 0;
    left: -280px;
    width: 280px;
    height: 100%;
    background-color: var(--bg-secondary);
    border-right: 1px solid var(--border);
    z-index: 200;
    transition: left 0.3s ease;
    overflow-y: auto;
}

.sidebar.open {
    left: 0;
}

.sidebar-content {
    padding: 24px 16px;
}

.sidebar h2 {
    font-size: 20px;
    margin-bottom: 24px;
    color: var(--accent);
}

.nav-list {
    list-style: none;
}

.nav-list li {
    margin-bottom: 4px;
}

.nav-list a {
    display: block;
    padding: 12px 16px;
    color: var(--text-primary);
    text-decoration: none;
    border-radius: 4px;
    transition: background-color 0.2s;
    min-height: 44px;
    display: flex;
    align-items: center;
}

.nav-list a:hover,
.nav-list a.active {
    background-color: var(--bg-primary);
}

.nav-list a:active {
    opacity: 0.7;
}

.nav-list a.active {
    color: var(--accent);
    font-weight: 600;
}

.nav-divider {
    height: 1px;
    background-color: var(--border);
    margin: 12px 0;
}

.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 150;
    display: none;
}

.sidebar-overlay.show {
    display: block;
}

/* Main Content */
main {
    min-height: calc(100vh - 56px);
    padding: 16px;
}

body[data-animation="true"] main {
    animation: fadeIn 0.3s ease-in;
}

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

/* Loading */
.loading {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 48px 16px;
    gap: 16px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.loading-text {
    color: var(--text-secondary);
    font-size: 14px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Story List */
.story-list {
    list-style: none;
}

.story-item {
    padding: 16px 0;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    contain: layout style paint;
}

.story-item:active {
    opacity: 0.7;
    background-color: var(--bg-secondary);
}

.story-header {
    display: flex;
    gap: 12px;
    margin-bottom: 8px;
}

.story-score {
    color: var(--accent);
    font-size: 14px;
    font-weight: 600;
    flex-shrink: 0;
}

.story-title {
    font-size: 16px;
    font-weight: 500;
    line-height: 1.4;
    color: var(--text-primary);
}

.story-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    font-size: 14px;
    color: var(--text-secondary);
    margin-top: 8px;
}

.story-author {
    color: var(--accent);
}

.story-domain {
    color: var(--text-secondary);
}

/* Show More Button */
.show-more-btn {
    width: 100%;
    padding: 16px 0;
    margin-top: 12px;
    background: none;
    border: none;
    border-top: 1px solid var(--border);
    color: var(--accent);
    cursor: pointer;
    font-size: 15px;
    font-weight: 500;
    min-height: 44px;
}

.show-more-btn:hover {
    text-decoration: underline;
}

.show-more-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Comment View */
.comment-view {
    max-width: 800px;
}

.story-detail {
    padding: 16px 0;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 24px;
}

.story-detail .story-title {
    font-size: 18px;
    margin-bottom: 12px;
    line-height: 1.4;
}

.story-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 16px;
}

.story-link {
    color: var(--accent);
    text-decoration: none;
    font-size: 15px;
    padding: 8px 0;
    display: block;
    min-height: 44px;
    display: flex;
    align-items: center;
}

.story-link:hover {
    text-decoration: underline;
}

.story-link:active {
    opacity: 0.7;
}

/* Comments */
.comments-section {
    margin-top: 24px;
}

.comments-section h2 {
    font-size: 18px;
    margin-bottom: 16px;
}

.comment {
    margin-bottom: 16px;
    border-left: 2px solid var(--border);
    padding-left: 12px;
    contain: layout style paint;
}

.comment.collapsed > .comment-body,
.comment.collapsed > .comment-replies {
    display: none;
}

.comment-header {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
    cursor: pointer;
    align-items: center;
    min-height: 44px;
}

.comment-author {
    color: var(--accent);
    font-weight: 500;
    font-size: 14px;
}

.comment-time {
    color: var(--text-secondary);
    font-size: 14px;
}

.comment-collapse {
    color: var(--text-secondary);
    font-size: 12px;
    margin-left: auto;
}

.comment-body {
    font-size: 15px;
    line-height: 1.6;
    margin-bottom: 12px;
    word-wrap: break-word;
}

.comment-body p {
    margin-bottom: 8px;
}

.comment-body a {
    color: var(--accent);
    text-decoration: none;
}

.comment-body a:hover {
    text-decoration: underline;
}

.comment-body pre {
    border-left: 2px solid var(--border);
    padding: 8px 12px;
    overflow-x: auto;
    font-size: 14px;
}

.comment-body code {
    color: var(--accent);
    font-size: 14px;
}

.comment-replies {
    margin-left: 16px;
}

.comment-deleted {
    color: var(--text-secondary);
    font-style: italic;
}

.load-replies-btn {
    background: none;
    border: none;
    color: var(--accent);
    cursor: pointer;
    font-size: 14px;
    padding: 8px 0;
    margin: 8px 0;
    text-align: left;
    min-height: 44px;
}

.load-replies-btn:hover {
    text-decoration: underline;
}

.load-replies-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 48px 16px;
    color: var(--text-secondary);
}

.empty-state p {
    margin-bottom: 16px;
}

.retry-btn {
    padding: 12px 24px;
    background-color: var(--accent);
    border: none;
    color: white;
    border-radius: 6px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 500;
    min-height: 44px;
    transition: opacity 0.2s;
}

.retry-btn:hover {
    opacity: 0.9;
}

.retry-btn:active {
    opacity: 0.7;
}

/* Settings View */
.settings-view {
    max-width: 600px;
    padding-bottom: 24px;
}

.settings-view h2 {
    font-size: 24px;
    margin-bottom: 24px;
}

.settings-section {
    margin-bottom: 32px;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--border);
}

.settings-section:last-child {
    border-bottom: none;
}

.settings-section h3 {
    font-size: 16px;
    margin-bottom: 12px;
    color: var(--text-secondary);
    font-weight: 500;
}

.setting-options {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.font-size-options {
    gap: 6px;
}

.setting-option-btn {
    padding: 10px 16px;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    border-radius: 6px;
    cursor: pointer;
    font-size: 15px;
    min-height: 44px;
    transition: all 0.2s;
}

.setting-option-btn:hover {
    background-color: var(--border);
}

.setting-option-btn.active {
    background-color: var(--accent);
    border-color: var(--accent);
    color: white;
}

.font-size-options .setting-option-btn {
    padding: 10px 12px;
    min-width: 50px;
}

.color-picker {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
    gap: 8px;
    max-width: 400px;
}

.color-option {
    width: 40px;
    height: 40px;
    border: 2px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
}

.color-option:hover {
    transform: scale(1.1);
}

.color-option.active {
    border-color: var(--text-primary);
    border-width: 3px;
}

.color-option.active::after {
    content: '✓';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 18px;
    font-weight: bold;
    text-shadow: 0 0 2px rgba(0, 0, 0, 0.5);
}

/* Layout */
main[data-layout="fixed"] {
    max-width: 800px;
}

/* Animations */
body[data-animation="false"] * {
    transition: none !important;
    animation: none !important;
}

body[data-animation="true"] .story-item,
body[data-animation="true"] .show-more-btn,
body[data-animation="true"] .setting-option-btn,
body[data-animation="true"] .color-option {
    transition: all 0.2s;
}

/* User Profile View */
.user-profile {
    max-width: 600px;
    padding-bottom: 24px;
}

.user-profile h2 {
    font-size: 24px;
    margin-bottom: 16px;
    color: var(--accent);
}

.user-info {
    padding: 16px 0;
    margin-bottom: 24px;
    border-bottom: 1px solid var(--border);
}

.user-stat {
    margin-bottom: 8px;
    font-size: 15px;
}

.user-stat-label {
    color: var(--text-secondary);
}

.user-stat-value {
    color: var(--text-primary);
    font-weight: 500;
}

.user-about {
    margin-bottom: 24px;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--border);
}

.user-about h3 {
    font-size: 16px;
    margin-bottom: 12px;
    color: var(--text-secondary);
    font-weight: 500;
}

.user-about-content {
    font-size: 15px;
    line-height: 1.6;
    color: var(--text-primary);
}

.user-about-content p {
    margin-bottom: 8px;
}

.user-about-content a {
    color: var(--accent);
    text-decoration: none;
}

.user-about-content a:hover {
    text-decoration: underline;
}

.user-link {
    margin-top: 16px;
}

/* Responsive */
@media (min-width: 768px) {
    main[data-layout="flexible"] {
        max-width: 1200px;
        margin: 0 auto;
    }

    main[data-layout="fixed"] {
        max-width: 800px;
        margin: 0 auto;
    }
}
