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

:root {
    /* Baseline M3 Color System (Neutral/Blue Tonal) */
    --md-sys-color-primary: #3f51b5;
    --md-sys-color-on-primary: #ffffff;
    --md-sys-color-primary-container: #e8eaf6;
    --md-sys-color-on-primary-container: #1a237e;

    --md-sys-color-secondary: #5c5e71;
    --md-sys-color-on-secondary: #ffffff;
    --md-sys-color-secondary-container: #e1e2f6;

    --md-sys-color-surface: #fdfbff;
    --md-sys-color-on-surface: #1b1b1f;
    --md-sys-color-surface-variant: #e2e2ec;
    --md-sys-color-on-surface-variant: #45464f;
    --md-sys-color-outline: #757780;

    --md-sys-color-error: #ba1a1a;
    --md-sys-color-on-error: #ffffff;

    /* M3 Surface Containers (Opaque) */
    --md-sys-color-surface-container-low: #f7f2fa;
    --md-sys-color-surface-container: #f3edf7;
    --md-sys-color-surface-container-high: #ece6f0;
    --md-sys-color-surface-container-highest: #e6e0e9;

    /* Shapes */
    --md-sys-shape-corner-extra-small: 4px;
    --md-sys-shape-corner-small: 8px;
    --md-sys-shape-corner-medium: 12px;
    --md-sys-shape-corner-large: 16px;
    --md-sys-shape-corner-extra-large: 28px;
    --md-sys-shape-corner-full: 9999px;

    /* Elevation */
    --md-sys-elevation-1: 0 1px 2px 0 rgba(0, 0, 0, 0.3), 0 1px 3px 1px rgba(0, 0, 0, 0.15);
    --md-sys-elevation-2: 0 1px 2px 0 rgba(0, 0, 0, 0.3), 0 2px 6px 2px rgba(0, 0, 0, 0.15);
    --md-sys-elevation-3: 0 4px 8px 3px rgba(0, 0, 0, 0.15), 0 1px 3px 0 rgba(0, 0, 0, 0.3);
}

body {
    margin: 0;
    font-family: 'Inter', 'Noto Sans JP', sans-serif;
    background-color: var(--md-sys-color-surface);
    color: var(--md-sys-color-on-surface);
    -webkit-font-smoothing: antialiased;
    line-height: 1.5;
    letter-spacing: 0.01em;
}

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

.premium-header {
    background-color: var(--md-sys-color-surface);
    color: var(--md-sys-color-primary);
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--md-sys-color-outline);
    position: sticky;
    top: 0;
    z-index: 1000;
}

.premium-header .brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.premium-header h1 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: 0.05rem;
}

.premium-header .actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.5rem 1rem;
    width: 100%;
    box-sizing: border-box;
    flex: 1;
}

.nav-item {
    padding: 0.75rem 1rem;
    margin: 0.25rem 0.75rem;
    /* M3 sidebar/drawer item spacing */
    border-radius: var(--md-sys-shape-corner-full);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--md-sys-color-on-surface-variant);
}

.nav-item:hover {
    background: var(--md-sys-color-surface-variant);
}

.nav-item.active {
    background: var(--md-sys-color-secondary-container);
    color: var(--md-sys-color-on-secondary-container);
}

.card {
    background: var(--md-sys-color-surface);
    border-radius: var(--md-sys-shape-corner-large);
    padding: 1.25rem;
    box-shadow: var(--md-sys-elevation-1);
    border: 1px solid var(--md-sys-color-outline);
    transition: box-shadow 0.2s, transform 0.2s;
}

.card:hover {
    box-shadow: var(--md-sys-elevation-2);
}

.card h2 {
    margin-top: 0;
    font-size: 1.1rem;
    font-weight: 500;
    color: var(--md-sys-color-on-surface);
    margin-bottom: 1rem;
    letter-spacing: 0.02rem;
}

/* List Items */
.list-unstyled {
    list-style: none;
    padding: 0;
    margin: 0;
}

/* Inputs & Buttons */
.input-group {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.search-input-container {
    position: relative;
    flex: 1;
    display: flex;
    align-items: center;
}

.modal-content.drawer .input-group {
    flex-direction: column;
    margin-bottom: 2rem;
    padding: 0 1.5rem;
}

input[type="text"] {
    padding: 12px 16px;
    border-radius: 8px;
    border: 1px solid var(--md-sys-color-outline);
    font-size: 1rem;
    background: var(--md-sys-color-surface);
    color: var(--md-sys-color-on-surface);
    transition: all 0.2s;
    font-family: inherit;
    box-sizing: border-box;
}

/* Add padding for right-aligned clear button */
.search-input-container input[type="text"] {
    padding-right: 2.5rem;
}

.modal-content.drawer input[type="text"] {
    width: 100%;
}

input[type="text"]:focus {
    outline: none;
    border-color: var(--md-sys-color-primary);
    box-shadow: 0 0 0 2px var(--md-sys-color-primary-container);
}

.btn {
    padding: 0.75rem 1.5rem;
    border-radius: var(--md-sys-shape-corner-full);
    border: none;
    background: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    font-family: inherit;
    position: relative;
    overflow: hidden;
    box-sizing: border-box;
    white-space: nowrap;
    /* Prevent wrapping which causes circular buttons */
    flex-shrink: 0;
    /* Prevent buttons from being squashed in flex containers */
}

.modal-content.drawer .btn {
    width: 100%;
}

.btn:hover {
    background: var(--md-sys-color-primary);
    box-shadow: var(--md-sys-elevation-1);
}

.btn::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--md-sys-color-on-primary);
    opacity: 0;
    transition: opacity 0.2s;
}

.btn:hover::after {
    opacity: 0.08;
}

.btn:active::after {
    opacity: 0.12;
}

.btn:disabled {
    opacity: 0.38;
    cursor: not-allowed;
    background: var(--md-sys-color-on-surface);
    color: var(--md-sys-color-surface);
}

.btn-secondary {
    background: var(--md-sys-color-secondary-container);
    color: var(--md-sys-color-on-secondary);
}

.btn-danger {
    background: var(--md-sys-color-error);
    color: var(--md-sys-color-on-error);
}

.btn-danger::after {
    background: var(--md-sys-color-on-error);
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--md-sys-color-outline);
    color: var(--md-sys-color-primary);
}

.btn-outline:hover {
    background: var(--md-sys-color-primary-container);
}

.icon-button {
    background: transparent;
    color: var(--md-sys-color-on-surface-variant);
    width: 40px;
    height: 40px;
    border: none;
    cursor: pointer;
    border-radius: var(--md-sys-shape-corner-full);
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.input-clear-btn {
    position: absolute;
    right: 8px;
    background: transparent;
    border: none;
    color: var(--md-sys-color-on-surface-variant);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 4px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    transition: background 0.2s;
}

.input-clear-btn:hover {
    background: var(--md-sys-color-surface-variant);
}

.icon-button:hover {
    background: var(--md-sys-color-surface-variant);
    color: var(--md-sys-color-primary);
}

.icon-button.mobile-only:hover {
    background: rgba(255, 255, 255, 0.2);
}

.fav-active {
    color: #eab308 !important;
}

/* Content Area */
.content-grid {
    display: grid;
    grid-template-columns: 1fr 1.5fr;
    gap: 2rem;
}

.column-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.column-header h3 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
}

/* Thread/Post Items */
.thread-item {
    margin-bottom: 0.5rem;
    cursor: pointer;
    padding: 1rem !important;
    border: 1px solid var(--md-sys-color-outline);
    border-radius: var(--md-sys-shape-corner-medium);
    transition: all 0.2s ease;
    background: var(--md-sys-color-surface);
}

.thread-item:hover {
    background: var(--md-sys-color-surface-variant);
    border-color: var(--md-sys-color-primary);
}

.thread-item.selected {
    background: var(--md-sys-color-primary-container);
    border-color: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary-container);
}

.post-item {
    margin-bottom: 1rem;
    padding: 1rem !important;
    border: 1px solid var(--md-sys-color-outline);
    border-radius: var(--md-sys-shape-corner-large);
    background: var(--md-sys-color-surface);
    transition: all 0.2s;
}

.post-item:hover {
    box-shadow: var(--md-sys-elevation-1);
    transform: translateY(-1px);
}

.post-content {
    font-size: 1rem;
    line-height: 1.6;
    color: var(--text);
    white-space: pre-wrap;
    word-break: break-all;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    /* M3 Scrim */
    backdrop-filter: blur(4px);
    /* Slightly stronger blur for premium feel */
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 4000;
    /* High enough to over everything */
}

.modal-overlay.drawer {
    justify-content: flex-end;
    background: rgba(0, 0, 0, 0.4);
    /* Pure scrim */
    backdrop-filter: blur(4px);
    z-index: 5000;
}

.modal-content {
    width: 90%;
    max-width: 560px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    padding: 0 !important;
    overflow: hidden;
    background: var(--md-sys-color-surface-container);
    /* Explicit opaque background */
    border-radius: var(--md-sys-shape-corner-extra-large);
    box-shadow: var(--md-sys-elevation-3);
    border: none;
    animation: modalFadeIn 0.3s cubic-bezier(0, 0, 0.2, 1);
}

.modal-content.drawer {
    width: 100%;
    max-width: 360px;
    height: 100%;
    border-radius: 28px 0 0 28px;
    /* M3 Standard Drawer shape */
    margin-left: auto;
    animation: drawerSlideIn 0.3s cubic-bezier(0, 0, 0.2, 1);
    background: var(--md-sys-color-surface-container-low);
    box-shadow: var(--md-sys-elevation-3);
    border: none;
    overflow-y: auto;
    /* Required for long menus */
    max-height: 100vh;
}

@keyframes modalFadeIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes drawerSlideIn {
    from {
        transform: translateX(100%);
    }

    to {
        transform: translateX(0);
    }
}

.modal-header {
    padding: 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--md-sys-color-surface-container);
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 0 1.5rem 1.5rem 1.5rem;
}

/* Animations */
/* Anchor Popup Overlay - Invisible but blocks interaction and allows closing by clicking outside */
.anchor-popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 2500;
    background: rgba(0, 0, 0, 0.1);
    /* Subtle scrim for popup */
}

.anchor-popup {
    position: fixed;
    max-width: 480px;
    width: 90%;
    z-index: 2600;
    background: var(--md-sys-color-surface-container-high);
    border-radius: var(--md-sys-shape-corner-extra-large);
    /* M3 Dialogs use extra large radius */
    box-shadow: var(--md-sys-elevation-3);
    border: none;
    padding: 1.5rem !important;
    /* Standard M3 Dialog padding */
    animation: modalFadeIn 0.2s cubic-bezier(0, 0, 0.2, 1);
}

.highlight-post {
    animation: highlight-fade 3s ease-in-out forwards;
    border-left: 8px solid var(--md-sys-color-primary) !important;
}

@keyframes highlight-fade {
    0% {
        background-color: #fef08a;
    }

    100% {
        background-color: var(--md-sys-color-surface);
    }
}

.fade-in {
    animation: fadeIn 0.3s ease-out;
}

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

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Spinner */
.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--md-sys-color-secondary-container);
    border-top: 4px solid var(--md-sys-color-primary);
    border-radius: var(--md-sys-shape-corner-full);
    animation: spin 0.8s cubic-bezier(0.4, 0, 0.2, 1) infinite;
    margin: 2rem auto;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* Board Browser Specifics */
.category-title {
    background: transparent;
    padding: 1rem 0 0.5rem 0;
    border: none;
    margin-bottom: 0.5rem;
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--md-sys-color-primary);
    letter-spacing: 0.1px;
}

.board-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 0.5rem;
}

.board-item-btn {
    padding: 0.75rem 1rem;
    border: 1px solid var(--md-sys-color-outline);
    background: var(--md-sys-color-surface);
    cursor: pointer;
    border-radius: var(--md-sys-shape-corner-small);
    font-size: 0.875rem;
    text-align: center;
    transition: all 0.2s;
    font-family: inherit;
    color: var(--md-sys-color-on-surface);
}

.board-item-btn:hover {
    background: var(--md-sys-color-surface-variant);
    border-color: var(--md-sys-color-primary);
}

.region-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 0.75rem;
}

.region-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 1.25rem 0.75rem;
    background: var(--md-sys-color-surface-container);
    border: none;
    border-radius: var(--md-sys-shape-corner-large);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: inherit;
    box-shadow: var(--md-sys-elevation-1);
}

.region-btn:hover {
    background: var(--md-sys-color-surface-variant);
    box-shadow: var(--md-sys-elevation-2);
}

.region-icon {
    font-size: 1.5rem;
}

.region-name {
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--md-sys-color-on-surface);
}

/* Mobile Responsive */
.mobile-only {
    display: none;
}

@media (max-width: 1024px) {
    .content-grid {
        grid-template-columns: 1fr;
    }
}

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

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

    .container {
        padding: 1rem 0.5rem;
    }

    .card {
        padding: 1rem;
    }
}
/* Pagination Improvements */
.pagination-container {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1.5rem;
    margin-top: 1.5rem;
    padding: 0.5rem;
}

.pagination-btn {
    min-width: 100px;
    padding: 8px 16px;
    border-radius: 20px; /* Fully rounded capsule */
    justify-content: center; /* Center text */
    font-weight: 500;
}

.pagination-info {
    font-size: 0.9rem;
    color: var(--md-sys-color-on-surface-variant);
    font-family: inherit;
    font-weight: 500;
}
