:root {
    --bg: #0b0f14;
    --bg-soft: #10161d;
    --surface: #111820;
    --surface-2: #151f29;
    --surface-3: #1b2733;
    --text: #e6edf3;
    --muted: #9aa7b4;
    --accent: #6db7ff;
    --accent-2: #2e5f8e;
    --danger: #ff6b6b;
    --success: #4cd4b0;
    --border: #26303a;
    --shadow: 0 6px 18px rgba(0, 0, 0, 0.24);
    --radius: 12px;
    --radius-sm: 8px;
    --font-sans: "IBM Plex Sans", "Segoe UI", sans-serif;
    --font-serif: "IBM Plex Serif", "Georgia", serif;
}

[data-theme="light"] {
    --bg: #f5f7fa;
    --bg-soft: #eef2f6;
    --surface: #ffffff;
    --surface-2: #f6f8fb;
    --surface-3: #edf2f7;
    --text: #1b2330;
    --muted: #5f6b78;
    --accent: #2f6ea7;
    --accent-2: #1d4e7a;
    --danger: #d94848;
    --success: #1f8f6a;
    --border: #d6dee6;
    --shadow: 0 12px 25px rgba(16, 25, 35, 0.18);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: var(--font-sans);
    color: var(--text);
    background: var(--bg);
    min-height: 100vh;
}

a {
    color: inherit;
}

.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    max-width: 980px;
    margin: 0 auto;
    padding: 18px 16px 24px;
    gap: 14px;
}

.top-bar,
.bottom-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    box-shadow: none;
}

.top-bar {
    justify-content: space-between;
}

.control-button,
.action-btn {
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    border-radius: var(--radius-sm);
    padding: 8px 10px;
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.control-button:hover,
.action-btn:hover {
    border-color: var(--accent);
    background: var(--surface-3);
}

.control-select {
    flex: 1 1 auto;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 10px;
}

.control-select option {
    background: var(--surface);
    color: var(--text);
}

.main-content {
    flex: 1 1 auto;
    display: flex;
    align-items: stretch;
    position: relative;
    min-height: 0;
}

.story-card {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: none;
    display: grid;
    grid-template-columns: 240px 1fr;
    grid-template-rows: auto auto 1fr;
    gap: 16px;
    padding: 16px;
    animation: cardIn 0.35s ease;
    height: 100%;
    min-height: 0;
}

.story-thumbnail {
    grid-row: 1 / span 3;
}

.story-header {
    grid-column: 2;
    grid-row: 1;
}

.sentiment-strip {
    grid-column: 2;
    grid-row: 2;
}

.loading-indicator {
    position: absolute;
    right: 12px;
    top: 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 0.75rem;
    color: var(--muted);
    letter-spacing: 0.02em;
    z-index: 5;
}

.loading-indicator.hidden {
    display: none;
}

.story-thumbnail img {
    width: 100%;
    height: auto;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface-2);
}

.story-header {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.story-title {
    margin: 0;
    font-family: var(--font-serif);
    font-size: 1.2rem;
    line-height: 1.4;
}

.story-title a {
    text-decoration: none;
}

.timestamp {
    color: var(--muted);
    font-size: 0.85rem;
}

.ward-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--accent);
}

.sentiment-strip {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 6px;
    margin: 8px 0 10px;
}

.sentiment-item {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    text-align: center;
    padding: 8px 6px;
}

.sentiment-label {
    color: var(--muted);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.sentiment-value {
    font-size: 1rem;
    font-weight: 600;
}

.story-body {
    color: var(--text);
    line-height: 1.6;
    font-size: 0.92rem;
    max-height: none;
    overflow-y: auto;
    padding-right: 8px;
    grid-column: 2;
    grid-row: 3;
    min-height: 0;
}

.bottom-bar {
    justify-content: space-between;
}

.score-display {
    font-weight: 600;
    color: var(--muted);
}

.action-btn.primary {
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    color: #07131f;
    border: none;
}

.action-btn.primary:hover {
    filter: brightness(1.02);
}

.profile-overlay,
.help-overlay {
    position: fixed;
    inset: 0;
    background: rgba(3, 6, 10, 0.65);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 1000;
}

.profile-overlay.active,
.help-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.profile-content,
.help-content {
    width: min(480px, 92vw);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: none;
    animation: overlayIn 0.25s ease;
    padding: 16px;
}

.profile-header,
.help-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
    padding-bottom: 10px;
    margin-bottom: 12px;
}

.profile-actions .action-btn {
    width: 100%;
    text-align: center;
    background: var(--surface-2);
}

.comments-panel {
    position: fixed;
    right: 16px;
    bottom: 80px;
    width: min(380px, 92vw);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: none;
    transform: translateY(20px);
    opacity: 0;
    pointer-events: none;
    transition: all 0.2s ease;
    z-index: 900;
}

.comments-panel.active {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
}

.comments-header {
    display: flex;
    justify-content: space-between;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
}

.comment-form {
    display: flex;
    gap: 8px;
    padding: 12px 14px;
    border-top: 1px solid var(--border);
}

.comment-input {
    flex: 1;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
}

@keyframes cardIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes overlayIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 900px) {
    .story-card {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto 1fr;
    }

    .story-thumbnail {
        grid-row: 1;
    }

    .story-header {
        grid-column: 1;
        grid-row: 2;
    }

    .sentiment-strip {
        grid-column: 1;
        grid-row: 3;
    }

    .story-body {
        grid-column: 1;
        grid-row: 4;
    }

    .top-bar,
    .bottom-bar {
        flex-wrap: wrap;
    }
}

@media (max-width: 640px) {
    .app-container {
        height: 100dvh;
        padding: 12px 10px 14px;
    }

    .top-bar,
    .bottom-bar {
        gap: 8px;
    }
}
