/* ====== CSS 변수 ====== */
:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #dbeafe;
    --text-main: #0f172a;
    --text-sub: #475569;
    --text-light: #94a3b8;
    --bg-main: #f8fafc;
    --bg-white: #ffffff;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --radius: 12px;
    --radius-lg: 16px;
}

/* ====== 리셋 및 기본 ====== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-main);
    color: var(--text-main);
    line-height: 1.6;
    padding: 0;
    margin: 0;
    min-height: 100vh;
}

/* ====== 컨테이너 ====== */
.container {
    max-width: 100%;
    padding: 0;
    margin: 0 auto;
    background: var(--bg-white);
    min-height: 100vh;
}

/* ====== 헤더 (히어로 섹션) ====== */
.hero-section {
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    padding: 24px 16px 32px;
    text-align: center;
    position: relative;
    overflow: hidden;
}

.hero-section::before {
    content: '';
    position: absolute;
    top: -50%;
    right: -30%;
    width: 80%;
    height: 200%;
    background: radial-gradient(circle, rgba(37, 99, 235, 0.08) 0%, transparent 70%);
    pointer-events: none;
}

.brand-logo {
    color: rgba(255, 255, 255, 0.5);
    font-size: 0.7rem;
    font-weight: 400;
    letter-spacing: 2px;
    text-transform: uppercase;
    margin-bottom: 12px;
    position: relative;
    z-index: 1;
}

.hero-title {
    color: #ffffff;
    font-size: 1.3rem;
    font-weight: 700;
    line-height: 1.5;
    margin-bottom: 20px;
    position: relative;
    z-index: 1;
    word-break: keep-all;
}

.hero-title span {
    color: #60a5fa;
    position: relative;
}

.hero-title span::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 100%;
    height: 3px;
    background: #60a5fa;
    border-radius: 2px;
}

/* ====== 검색 폼 (SSR 통일) ====== */
.search-wrapper {
    display: flex;
    align-items: center;
    max-width: 500px;
    margin: 0 auto;
    background: var(--bg-white);
    border-radius: 50px;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    position: relative;
    z-index: 1;
    transition: box-shadow 0.3s;
}

.search-wrapper:focus-within {
    box-shadow: 0 4px 30px rgba(37, 99, 235, 0.3);
}

.search-input {
    flex: 1;
    padding: 14px 20px;
    border: none;
    outline: none;
    font-size: 16px;
    font-family: inherit;
    color: var(--text-main);
    background: transparent;
    min-height: 52px;
    -webkit-appearance: none;
}

.search-input::placeholder {
    color: var(--text-light);
    font-size: 0.85rem;
}

.search-btn-icon {
    padding: 14px 22px;
    background: var(--primary);
    color: white;
    border: none;
    cursor: pointer;
    font-size: 1.1rem;
    transition: background 0.2s;
    min-height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.search-btn-icon:active {
    background: var(--primary-dark);
    transform: scale(0.95);
}

/* ====== 인기 검색어 (랜덤 5개) ====== */
.popular-tags {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 6px;
    margin-top: 14px;
    position: relative;
    z-index: 1;
}

.popular-tags .tag-label {
    color: rgba(255, 255, 255, 0.5);
    font-size: 0.75rem;
    font-weight: 400;
    margin-right: 2px;
}

.popular-tags a {
    color: rgba(255, 255, 255, 0.85);
    font-size: 0.75rem;
    text-decoration: none;
    padding: 4px 14px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 20px;
    transition: all 0.3s ease;
    border: 1px solid rgba(255, 255, 255, 0.06);
    white-space: nowrap;
    animation: fadeInTag 0.4s ease forwards;
}

.popular-tags a:active {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(0.95);
}

/* 태그 페이드인 애니메이션 */
@keyframes fadeInTag {
    from {
        opacity: 0;
        transform: translateY(-8px) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* 새로고침 버튼 (선택사항) */
.refresh-tags-btn {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.6);
    border-radius: 50%;
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.7rem;
    transition: all 0.3s;
    padding: 0;
}

.refresh-tags-btn:active {
    transform: rotate(180deg) scale(0.9);
    background: rgba(255, 255, 255, 0.2);
}

/* ====== 벤토 그리드 ====== */
.bento-container {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    padding: 16px;
    max-width: 1200px;
    margin: 0 auto;
}

.bento-card {
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    padding: 20px 16px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.card-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 8px;
}

.card-title i {
    color: var(--primary);
    font-size: 1.1rem;
}

/* ====== 인구 카드 ====== */
.population-card p {
    font-size: 0.85rem;
    color: var(--text-sub);
    margin-bottom: 16px;
    line-height: 1.6;
}

.pop-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.pop-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 14px;
    background: var(--bg-main);
    border-radius: var(--radius);
    text-decoration: none;
    transition: all 0.2s;
    border: 1px solid transparent;
}

.pop-item:active {
    transform: scale(0.98);
    background: var(--primary-light);
    border-color: var(--primary);
}

.pop-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--primary-light);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
    font-size: 1rem;
    flex-shrink: 0;
}

.pop-text strong {
    display: block;
    font-size: 0.9rem;
    color: var(--text-main);
    font-weight: 600;
}

.pop-text span {
    font-size: 0.7rem;
    color: var(--text-light);
}

/* ====== 부동산 카드 ====== */
.region-tabs {
    display: flex;
    gap: 6px;
    margin-bottom: 16px;
    background: var(--bg-main);
    padding: 4px;
    border-radius: 10px;
}

.tab-btn {
    flex: 1;
    padding: 8px 12px;
    border: none;
    background: transparent;
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-sub);
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.tab-btn.active {
    background: var(--bg-white);
    color: var(--primary);
    box-shadow: var(--shadow-sm);
}

.tab-btn:active {
    transform: scale(0.96);
}

.estate-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.estate-box {
    background: var(--bg-main);
    border-radius: var(--radius);
    padding: 12px 14px;
    border: 1px solid var(--border-color);
}

.box-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.box-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-main);
}

.box-icon {
    color: var(--primary);
    font-size: 0.9rem;
    opacity: 0.7;
}

.trade-links {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.trade-btn {
    flex: 1;
    min-width: 40px;
    padding: 4px 6px;
    border-radius: 6px;
    font-size: 0.6rem;
    font-weight: 600;
    text-align: center;
    text-decoration: none;
    transition: all 0.2s;
    border: 1px solid transparent;
}

.trade-btn:active {
    transform: scale(0.95);
}

.trade-btn.sale {
    background: #fef2f2;
    color: #dc2626;
    border-color: #fecaca;
}

.trade-btn.jeonse {
    background: #eff6ff;
    color: #2563eb;
    border-color: #bfdbfe;
}

.trade-btn.wolse {
    background: #f0fdf4;
    color: #16a34a;
    border-color: #bbf7d0;
}

/* ====== 뉴스 섹션 ====== */
.news-section {
    padding: 16px;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

.news-header {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 14px;
    padding: 0 4px;
}

.news-header i {
    color: var(--primary);
    font-size: 1.1rem;
}

.news-list-container {
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    padding: 4px 0;
    box-shadow: var(--shadow-sm);
}

#news-loader {
    text-align: center;
    padding: 30px 16px;
    color: var(--text-light);
    font-size: 0.85rem;
}

#news-loader i {
    margin-right: 8px;
}

.news-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.news-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    gap: 10px;
}

.news-item:last-child {
    border-bottom: none;
}

.news-item a {
    flex: 1;
    color: var(--text-main);
    text-decoration: none;
    font-size: 0.82rem;
    font-weight: 500;
    line-height: 1.4;
    transition: color 0.2s;
    word-break: break-word;
}

.news-item a:active {
    color: var(--primary);
}

.news-date {
    font-size: 0.65rem;
    color: var(--text-light);
    white-space: nowrap;
    flex-shrink: 0;
}

/* ====== 푸터 ====== */
footer {
    padding: 24px 16px 20px;
    text-align: center;
    border-top: 1px solid var(--border-color);
    background: var(--bg-white);
    margin-top: 8px;
}

footer p {
    font-size: 0.75rem;
    color: var(--text-light);
    margin-bottom: 4px;
}

footer a {
    color: var(--text-sub);
    text-decoration: none;
    transition: color 0.2s;
}

footer a:active {
    color: var(--primary);
}

footer p:last-child {
    font-size: 0.65rem;
    opacity: 0.7;
    margin-top: 8px;
}

/* ====== 광고 ====== */
.ad-container-block {
    margin: 12px 16px;
    text-align: center;
    position: relative;
    z-index: 1;
    clear: both;
    overflow: hidden;
    min-height: auto;
    background: transparent;
}

.ad-container-block ins.adsbygoogle {
    display: block !important;
    position: relative !important;
    z-index: 1 !important;
    min-height: 60px;
}

/* ====== 태블릿 (481px ~ 768px) ====== */
@media (min-width: 481px) {
    .hero-section {
        padding: 40px 32px 48px;
    }

    .hero-title {
        font-size: 1.8rem;
    }

    .search-wrapper {
        max-width: 600px;
    }

    .search-input {
        padding: 16px 24px;
        font-size: 1rem;
        min-height: 56px;
    }

    .search-btn-icon {
        padding: 16px 28px;
        min-height: 56px;
        font-size: 1.2rem;
    }

    .bento-container {
        grid-template-columns: 1fr 2fr;
        padding: 20px 24px;
        gap: 20px;
    }

    .estate-grid {
        grid-template-columns: 1fr 1fr;
    }

    .news-section {
        padding: 0 24px 20px;
    }

    .popular-tags a {
        font-size: 0.8rem;
        padding: 5px 16px;
    }

    .container {
        padding: 0;
    }
}

/* ====== 데스크톱 (769px 이상) ====== */
@media (min-width: 769px) {
    .hero-section {
        padding: 56px 40px 64px;
    }

    .hero-title {
        font-size: 2.2rem;
    }

    .search-wrapper {
        max-width: 700px;
    }

    .bento-container {
        grid-template-columns: 1fr 2.5fr;
        padding: 24px 32px;
        gap: 24px;
    }

    .estate-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    .news-section {
        padding: 0 32px 24px;
    }

    .news-item a:hover {
        color: var(--primary);
    }

    .pop-item:hover {
        background: var(--primary-light);
        border-color: var(--primary);
    }

    .trade-btn:hover {
        opacity: 0.8;
    }

    .popular-tags a:hover {
        background: rgba(255, 255, 255, 0.2);
    }
}

/* ====== 데스크톱 (1025px 이상) ====== */
@media (min-width: 1025px) {
    .bento-container {
        padding: 32px 48px;
        gap: 28px;
    }

    .news-section {
        padding: 0 48px 32px;
    }

    .hero-section {
        padding: 64px 48px 72px;
    }

    .hero-title {
        font-size: 2.5rem;
    }
}

/* ====== 애니메이션 ====== */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(16px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.bento-card {
    animation: fadeInUp 0.4s ease forwards;
}

.bento-card:nth-child(2) {
    animation-delay: 0.1s;
}

@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}