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

:root {
    --bg: #f8fafc;
    --bg2: #f1f5f9;
    --ink: #0a0a0a;
    --ink2: #0a0a0a;
    --ink3: #334155;
    --accent: #2563eb;
    --accent2: #0ea5e9;
    --white: #ffffff;
    --text: #0f172a;
    --muted: #64748b;
    --input-bg: #f8fafc;
    --border: #cbd5e1;
    --card-bg: rgba(255, 255, 255, 0.92);
    --shadow: 0 2px 12px rgba(31,41,55,0.08);
    --radius: 12px;
}

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

.post-card, .post-card * { text-decoration: none !important; }
.post-card__main-link::after { content: "" !important; position: absolute !important; inset: 0 !important; z-index: 1 !important; }
.post-card__title a { color: var(--ink) !important; }

body {
    background-color: var(--bg);
    background-image:
        radial-gradient(ellipse at 20% 0%, rgba(14,165,233,0.06) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 100%, rgba(37,99,235,0.05) 0%, transparent 55%);
    color: var(--ink);
    font-family: monospace;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* ── User Menu (nav-right) ── */
.nav-right {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-left: auto;
    justify-content: flex-end;
}

.user-menu-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    background: white;
    border: 1px solid rgba(15, 23, 42, 0.08);
    border-radius: 12px;
    padding: 7px 14px;
    cursor: pointer;
    font-family: 'IBM Plex Sans', sans-serif;
    font-size: 0.88rem;
    color: var(--ink);
    transition: all 0.2s ease;
    white-space: nowrap;
}

.user-menu-btn:hover {
    background: rgba(37, 99, 235, 0.08);
    border-color: var(--accent);
}

.user-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 0.8rem;
    flex-shrink: 0;
    overflow: hidden;
}

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

.user-dropdown { position: relative; display: inline-block; }

.user-dropdown-menu {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 10px);
    background: var(--white);
    border: 1px solid rgba(15, 23, 42, 0.1);
    border-radius: 16px;
    box-shadow: 0 18px 48px rgba(15, 23, 42, 0.16);
    z-index: 1000;
    min-width: 200px;
    overflow: hidden;
}

.user-dropdown-menu.visible { display: block; }

.user-dropdown-menu a,
.user-dropdown-menu button {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 11px 16px;
    border: none;
    background: none;
    text-align: left;
    color: var(--ink);
    text-decoration: none;
    font-size: 0.88rem;
    cursor: pointer;
    transition: background 0.2s;
    border-bottom: 1px solid #eee;
    font-family: 'IBM Plex Sans', sans-serif;
}

.user-dropdown-menu a:last-child,
.user-dropdown-menu button:last-child { border-bottom: none; }
.user-dropdown-menu a:hover,
.user-dropdown-menu button:hover { background: var(--bg2); }
.user-dropdown-menu button { color: #dc2626; }
.user-dropdown-menu button:hover { background: #fee2e2; }

/* ── Page layout ── */
.page-wrapper {
    width: 100%;
    max-width: 1080px;
    padding: 36px 24px 56px;
    margin: 0 auto;
}

.page-header {
    margin-bottom: 28px;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.18);
}

.page-header--compact { margin-bottom: 0; border-bottom: none; }

.page-header h1 {
    font-size: clamp(1.6rem, 2.4vw, 2.8rem);
    line-height: 1.1;
    letter-spacing: -0.04em;
    margin-bottom: 12px;
}

.page-subtitle {
    color: var(--muted);
    font-size: 1rem;
    max-width: 760px;
    line-height: 1.68;
}

.post-count {
    color: var(--ink3);
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.95rem;
}

.panel {
    background: var(--card-bg);
    border: 1px solid rgba(148, 163, 184, 0.18);
    border-radius: var(--radius);
    padding: 28px;
    box-shadow: var(--shadow);
    width: 100%;
}

.panel--narrow { max-width: 680px; margin: 0 auto; }
.panel-title { font-size: 1.25rem; margin-bottom: 18px; }

/* ── Forms ── */
.form-row {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 20px;
}

.form-row label { font-size: 0.92rem; color: var(--muted); font-weight: 500; }

.form-row input,
.form-row textarea,
.form-row select {
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--input-bg);
    color: var(--text);
    font-family: inherit;
    font-size: 1rem;
    padding: 13px 16px;
    transition: border-color 0.2s, box-shadow 0.2s;
    width: 100%;
    box-sizing: border-box;
}

.form-row input:focus,
.form-row textarea:focus,
.form-row select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12);
}

.form-row textarea { min-height: 180px; resize: vertical; line-height: 1.6; }

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

/* ── Buttons ── */
.btn, .btn-full {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 999px;
    padding: 11px 20px;
    background: var(--accent);
    color: white;
    text-decoration: none;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
    white-space: nowrap;
}

.btn-full { width: 100%; }
.btn:hover, .btn-full:hover { transform: translateY(-1px); background: var(--accent2); }
.btn:disabled, .btn-full:disabled { opacity: 0.58; cursor: not-allowed; }
.btn--secondary { background: white; color: var(--ink); border: 1px solid rgba(15, 23, 42, 0.12); }
.btn--secondary:hover { background: rgba(37, 99, 235, 0.08); color: var(--ink); }
.btn--danger { background: #ef4444; color: white; }
.btn--danger:hover { background: #dc2626; }
.btn--small { padding: 7px 14px; font-size: 0.85rem; }

.post-card__actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }

/* ── Posts grid ── */
.posts-grid {
    display: grid;
    gap: 20px;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

/* ── Post cards ── */
.post-card, .admin-post-card {
    position: relative;
    background: var(--card-bg);
    border: 1px solid rgba(148, 163, 184, 0.18);
    border-radius: 20px;
    box-shadow: var(--shadow);
    padding: 24px;
    transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
    display: flex;
    flex-direction: column;
}

.post-card:hover, .admin-post-card:hover {
    transform: translateY(-3px);
    border-color: var(--accent);
    box-shadow: 0 8px 24px rgba(31, 41, 55, 0.12);
}

.post-card__heading, .admin-post-card__heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}

.post-card__title, .admin-post-card__heading h3 {
    font-size: 1.1rem;
    font-weight: 700;
    line-height: 1.3;
    color: var(--ink);
    margin: 0;
}

.post-card__main-link { text-decoration: none !important; color: inherit !important; }
.post-card__main-link::after { content: ""; position: absolute; inset: 0; z-index: 1; }
.post-card:hover .post-card__title { color: var(--accent); }

.post-badges { display: flex; flex-wrap: wrap; gap: 8px; position: relative; z-index: 2; }

.post-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--accent);
    background: rgba(37, 99, 235, 0.08);
}

.post-badge--highlight { color: #92400e; background: #fef3c7; }

.post-preview {
    color: var(--ink3);
    line-height: 1.6;
    margin: 12px 0;
    text-decoration: none !important;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    font-size: 0.9rem;
}

.post-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: auto;
    font-size: 0.88rem;
    color: var(--muted);
    text-decoration: none !important;
}

.post-meta { text-decoration: none !important; font-size: 0.82rem; }

/* ── Modal ── */
.post-modal {
    position: fixed;
    inset: 0;
    background: rgba(10, 10, 10, 0.6);
    display: grid;
    place-items: center;
    padding: 16px;
    z-index: 2000;
}

.post-modal__content {
    width: min(760px, 100%);
    max-height: 90vh;
    overflow: auto;
    background: white;
    border-radius: 20px;
    padding: 28px;
    position: relative;
    box-shadow: 0 24px 80px rgba(15, 23, 42, 0.24);
}

.post-modal__close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: rgba(15, 23, 42, 0.08);
    cursor: pointer;
    font-size: 1.2rem;
    color: var(--ink3);
}

.post-modal__close:hover { background: rgba(15, 23, 42, 0.14); }
.post-content { white-space: pre-wrap; line-height: 1.75; color: var(--ink3); margin-top: 18px; }

/* ── Loading/Empty ── */
.loading-state, .empty-state {
    color: var(--muted);
    font-size: 0.98rem;
    display: flex;
    align-items: center;
    gap: 12px;
    justify-content: center;
    min-height: 140px;
    padding: 24px;
    text-align: center;
}

.empty-state a { color: var(--accent); text-decoration: none; }
.empty-state a:hover { text-decoration: underline; }

.spinner {
    width: 24px; height: 24px;
    border: 3px solid rgba(15, 23, 42, 0.12);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.status { font-size: 0.95rem; line-height: 1.6; margin-top: 14px; }
.status--error { color: #dc2626; }
.status--ok { color: #16a34a; }

/* ── Auth ── */
.auth-box, .login-box {
    width: 100%;
    max-width: 480px;
    margin: 48px auto;
    background: var(--card-bg);
    border: 1px solid rgba(148, 163, 184, 0.18);
    border-radius: var(--radius);
    padding: 32px;
    box-shadow: var(--shadow);
}

.auth-box h1, .login-box h1 { margin-bottom: 6px; }
.auth-box p.sub, .login-box p { color: var(--muted); margin-bottom: 24px; line-height: 1.7; }

.auth-tabs { display: flex; gap: 10px; margin-bottom: 24px; }

.auth-tab {
    flex: 1;
    padding: 11px 14px;
    border: 1px solid rgba(148, 163, 184, 0.28);
    background: transparent;
    color: var(--ink3);
    border-radius: 12px;
    cursor: pointer;
    font-size: 0.95rem;
    transition: all 0.2s ease;
}

.auth-tab.active {
    background: white;
    color: var(--ink);
    border-color: transparent;
    box-shadow: var(--shadow);
}

/* ── Profile ── */
.profile-header {
    display: flex;
    align-items: flex-start;
    gap: 20px;
    padding: 24px 0;
    border-bottom: 1px solid rgba(148, 163, 184, 0.18);
    margin-bottom: 28px;
    flex-wrap: wrap;
}

.avatar-large {
    width: 80px; height: 80px;
    border-radius: 50%;
    background: var(--accent);
    display: grid;
    place-items: center;
    font-size: 1.8rem;
    font-weight: 700;
    color: white;
    overflow: hidden;
    flex-shrink: 0;
}

.profile-info { flex: 1; min-width: 0; }
.profile-info h2 { font-size: 1.6rem; margin-bottom: 6px; word-break: break-word; }
.profile-bio, .profile-joined { color: var(--muted); }
.profile-bio { margin-top: 6px; line-height: 1.7; }
.profile-joined { margin-top: 6px; font-size: 0.9rem; }

.edit-profile-form { display: none; flex-direction: column; gap: 16px; margin-bottom: 28px; }
.edit-profile-form.visible { display: flex; }
.profile-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.profile-info .btn { margin-top: 10px; }
.section-title { margin-bottom: 16px; }

/* ── Community ── */
.community-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 28px;
    gap: 16px;
    flex-wrap: wrap;
}

.user-bar { display: flex; align-items: center; gap: 12px; }

.avatar-small {
    width: 34px; height: 34px;
    border-radius: 50%;
    background: var(--accent);
    display: grid;
    place-items: center;
    font-size: 0.85rem;
    font-weight: 700;
    color: white;
    overflow: hidden;
    flex-shrink: 0;
}

.avatar-small img { width: 100%; height: 100%; object-fit: cover; }
.post-author a { color: var(--accent); }
.post-author a:hover { text-decoration: underline; }

/* ── Admin ── */
.admin-topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 24px;
}

.admin-layout { display: grid; gap: 24px; }
.admin-post-list { display: grid; gap: 16px; }
.admin-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }

/* ── Post Interactions ── */
.post-interactions {
    display: flex;
    gap: 16px;
    margin: 24px 0;
    padding: 18px 0;
    border-top: 1px solid rgba(148, 163, 184, 0.18);
    border-bottom: 1px solid rgba(148, 163, 184, 0.18);
    flex-wrap: wrap;
}

.like-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: rgba(37, 99, 235, 0.08);
    color: var(--accent);
    border: 1px solid rgba(37, 99, 235, 0.24);
    border-radius: 999px;
    padding: 10px 16px;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

.like-btn:hover { background: rgba(37, 99, 235, 0.16); border-color: var(--accent); transform: translateY(-1px); }
.like-btn.liked { background: var(--accent); color: white; border-color: var(--accent); }
.like-btn.liked:hover { background: var(--accent2); border-color: var(--accent2); }
.like-btn svg { width: 18px; height: 18px; display: inline-block; }
.like-btn.liked svg { fill: currentColor; }
.like-count { font-weight: 600; min-width: 20px; text-align: center; }

/* ── Comments ── */
.comments-section { margin-top: 28px; }
.comments-heading { font-size: 1.1rem; margin-bottom: 16px; color: var(--ink); }
.comments-list { display: flex; flex-direction: column; gap: 14px; margin-bottom: 22px; }

.comment {
    background: rgba(15, 23, 42, 0.02);
    border: 1px solid rgba(148, 163, 184, 0.12);
    border-radius: 12px;
    padding: 14px;
    transition: all 0.2s ease;
}

.comment:hover { background: rgba(37, 99, 235, 0.04); border-color: rgba(37, 99, 235, 0.24); }

.comment-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.comment-author {
    font-weight: 600;
    color: var(--ink);
    display: inline-flex;
    align-items: center;
    padding: 3px 8px;
    background: rgba(37, 99, 235, 0.1);
    border-radius: 6px;
    font-size: 0.88rem;
}

.comment-date { color: var(--muted); font-size: 0.82rem; }

.comment-delete-btn {
    margin-left: auto;
    background: transparent;
    border: 1px solid #ef4444;
    color: #ef4444;
    padding: 3px 10px;
    border-radius: 6px;
    font-size: 0.78rem;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
    font-weight: 500;
}

.comment-delete-btn:hover { background: #fee2e2; border-color: #dc2626; color: #dc2626; }

.comment-body {
    color: var(--ink3);
    line-height: 1.65;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: break-word;
    margin: 0;
    font-size: 0.93rem;
}

.comments-empty, .comments-error {
    color: var(--muted);
    text-align: center;
    padding: 20px;
    font-style: italic;
    background: rgba(15, 23, 42, 0.02);
    border-radius: 12px;
    border: 1px dashed rgba(148, 163, 184, 0.18);
}

.comments-error { color: #ef4444; }

.comment-form { display: flex; flex-direction: column; gap: 12px; }

.comment-input {
    border: 1px solid rgba(148, 163, 184, 0.24);
    border-radius: 12px;
    background: var(--input-bg);
    color: var(--text);
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.93rem;
    padding: 12px 14px;
    resize: vertical;
    min-height: 90px;
    line-height: 1.6;
    transition: border-color 0.2s, box-shadow 0.2s;
    width: 100%;
    box-sizing: border-box;
}

.comment-input::placeholder { color: var(--muted); }
.comment-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12); background: white; }

.comment-submit-btn {
    align-self: flex-start;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 999px;
    padding: 10px 20px;
    font-size: 0.93rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

.comment-submit-btn:hover { background: var(--accent2); transform: translateY(-1px); }
.comment-submit-btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* ════════════════════════════════════════
   MOBILE RESPONSIVE
   ════════════════════════════════════════ */

@media (max-width: 768px) {
    /* nav-right (user menu) header ichida */
    #nav-right {
        display: flex;
        align-items: center;
    }

    .user-menu-btn {
        padding: 6px 10px;
        font-size: 0.82rem;
    }

    .page-wrapper {
        padding: 20px 16px 48px;
    }

    .page-header h1 {
        font-size: 1.6rem;
    }

    .posts-grid {
        grid-template-columns: 1fr;
        gap: 14px;
    }

    .post-card, .admin-post-card {
        padding: 18px;
        border-radius: 16px;
    }

    .panel {
        padding: 20px;
        border-radius: 10px;
    }

    .community-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .admin-topbar {
        flex-direction: column;
        align-items: stretch;
    }

    .profile-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .form-actions {
        flex-direction: column;
    }

    .form-actions .btn {
        width: 100%;
    }

    .post-modal__content {
        padding: 20px;
        border-radius: 16px;
        max-height: 92vh;
    }

    .auth-box, .login-box {
        padding: 24px 20px;
        margin: 24px auto;
    }
}

@media (max-width: 480px) {
    .page-wrapper {
        padding: 16px 12px 40px;
    }

    .page-header h1 {
        font-size: 1.4rem;
    }

    .post-card, .admin-post-card {
        padding: 16px;
    }

    .panel {
        padding: 16px;
    }

    .btn, .btn-full {
        width: 100%;
        text-align: center;
    }

    .avatar-large {
        width: 64px; height: 64px;
        font-size: 1.4rem;
    }

    .profile-info h2 {
        font-size: 1.3rem;
    }

    .auth-box, .login-box {
        padding: 20px 16px;
        margin: 16px auto;
    }

    .post-modal__content {
        padding: 16px;
        border-radius: 12px;
    }

    .comment-submit-btn {
        width: 100%;
    }

    .user-dropdown-menu {
        right: -10px;
        min-width: 180px;
    }

    .posts-grid {
        grid-template-columns: 1fr;
    }
}
:root {
    --bg-color: #f8f9fa;
    --text-color: #212529;
    --panel-bg: #ffffff;
    --panel-border: #e0e0e0;
    --accent-color: #007bff;
}

[data-theme="dark"] {
    --bg-color: #121212;
    --text-color: #e0e0e0;
    --panel-bg: #1e1e1e;
    --panel-border: #333333;
    --accent-color: #375a7f;
}

body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    transition: background-color 0.3s ease, color 0.3s ease;
}

.content {
    padding: 40px;
    max-width: 800px;
    margin: 0 auto;
}

.settings-toggle {
    position: fixed;
    top: 20px;
    right: 20px;
    background-color: var(--panel-bg);
    border: 1px solid var(--panel-border);
    color: var(--text-color);
    width: 45px;
    height: 45px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    z-index: 1000;
    transition: transform 0.2s ease, background-color 0.3s;
}

.settings-toggle:hover {
    transform: scale(1.05);
}

.settings-panel {
    position: fixed;
    top: 0;
    right: -320px;
    width: 280px;
    height: 100vh;
    background-color: var(--panel-bg);
    border-left: 1px solid var(--panel-border);
    box-shadow: -4px 0 12px rgba(0,0,0,0.05);
    padding: 30px 20px;
    box-sizing: border-box;
    transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 999;
}

.settings-panel.open {
    right: 0;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    border-bottom: 1px solid var(--panel-border);
    padding-bottom: 15px;
}

.panel-header h3 {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 600;
}

.close-panel {
    background: none;
    border: none;
    color: var(--text-color);
    font-size: 18px;
    cursor: pointer;
    opacity: 0.7;
}

.close-panel:hover {
    opacity: 1;
}

.setting-section {
    margin-bottom: 20px;
}

.setting-label {
    display: block;
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 12px;
    opacity: 0.8;
}

.theme-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.theme-btn {
    background-color: var(--bg-color);
    border: 2px solid var(--panel-border);
    color: var(--text-color);
    padding: 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s ease;
}

.theme-btn:hover {
    border-color: var(--accent-color);
}

.theme-btn.active {
    border-color: var(--accent-color);
    background-color: var(--accent-color);
    color: #ffffff;
}
