:root {
    /* =====================================================
       사이트 디자인 토큰 v2 — 2026-04 통합 체계
       모든 페이지는 이 토큰을 우선 사용. 페이지별 프리픽스
       (xp-, ps-, sc-) 변수는 여기 토큰으로 폴백되도록 한다.
       ===================================================== */

    /* Surface (배경 / 패널) */
    --wq-bg:          #13151b;
    --wq-surface:     #1a1d24;
    --wq-surface-2:   #23262f;
    --wq-surface-3:   #2b2f3a;

    /* Typography */
    --wq-text:        #e8eaf0;
    --wq-text-soft:   #c9d1d9;
    --wq-text-muted:  #9aa0ad;
    --wq-text-dim:    #6b7280;

    /* Borders */
    --wq-border:        #2b2f3a;
    --wq-border-strong: #424857;

    /* Brand / Accent — muted sky with a dark foreground on filled controls. */
    --wq-accent:        #78bdd2;
    --wq-accent-hover:  #94cede;
    --wq-accent-soft:   rgba(120, 189, 210, 0.14);
    --wq-accent-2:      #a0d3e1;
    --wq-on-accent:     #102f3b;

    /* Semantic */
    --wq-success:       #22c55e;
    --wq-success-soft:  rgba(34, 197, 94, 0.12);
    --wq-warning:       #fbbf24;
    --wq-warning-soft:  rgba(251, 191, 36, 0.14);
    --wq-danger:        #ef4444;
    --wq-danger-soft:   rgba(239, 68, 68, 0.12);
    --wq-info:          #a78bfa;
    --wq-info-soft:     rgba(167, 139, 250, 0.12);

    /* Radius scale */
    --wq-radius-xs: 6px;
    --wq-radius-sm: 10px;
    --wq-radius-md: 14px;
    --wq-radius-lg: 20px;
    --wq-radius-xl: 28px;
    --wq-radius-pill: 999px;

    /* Spacing scale (8px base) */
    --wq-space-1: 4px;
    --wq-space-2: 8px;
    --wq-space-3: 12px;
    --wq-space-4: 16px;
    --wq-space-5: 20px;
    --wq-space-6: 24px;
    --wq-space-7: 32px;
    --wq-space-8: 40px;
    --wq-space-9: 56px;

    /* Shadow scale */
    --wq-shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.20);
    --wq-shadow-md: 0 6px 16px rgba(0, 0, 0, 0.26);
    --wq-shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.36);
    --wq-shadow-xl: 0 24px 60px rgba(0, 0, 0, 0.45);

    /* Transition */
    --wq-transition-fast: 0.12s ease;
    --wq-transition-base: 0.2s ease;

    /* Font sizes (rem 기반) */
    --wq-fs-xs:  0.72rem;
    --wq-fs-sm:  0.82rem;
    --wq-fs-base: 0.92rem;
    --wq-fs-md:  1.0rem;
    --wq-fs-lg:  1.15rem;
    --wq-fs-xl:  1.4rem;
    --wq-fs-2xl: 1.75rem;
    --wq-fs-3xl: 2.25rem;

    /* 이전 토큰은 호환을 위해 유지 (같은 값으로 매핑) */
    --primary-color: var(--wq-accent);
    --primary-hover: var(--wq-accent-hover);
    --background-color: var(--wq-bg);
    --card-background: var(--wq-surface);
    --card-background-2: var(--wq-surface-2);
    --text-color: var(--wq-text);
    --text-muted: var(--wq-text-muted);
    --border-color: var(--wq-border);
    --border-color-strong: var(--wq-border-strong);
    --accent-danger: var(--wq-danger);
    --sidebar-width: 250px;
    --bottom-nav-height: calc(60px + env(safe-area-inset-bottom));
    --mobile-header-height: calc(56px + env(safe-area-inset-top));

    /* =====================================================
       Page shell widths — 2026-04 통합
       모든 "콘텐츠 뷰" 페이지는 이 세 가지 폭 중 하나를 선택해서
       `.wq-page` / `.wq-page--narrow` / `.wq-page--wide` 를 쓴다.
       페이지마다 따로 1080/1024/900/880/... 을 박아 넣던 것을 통일.
       ===================================================== */
    --wq-page-max:        1080px;  /* 기본: 학습지 목록, 오답노트, 히스토리, 포인트 상점, 탐색 등 */
    --wq-page-max-narrow:  880px;  /* 읽기 중심: 리뷰(결과·히스토리 상세), 컬렉션 상세, 약관 등 */
    --wq-page-max-wide:   1280px;  /* 캘린더 · 관리자 · 뱃지 상세 등 실질적으로 넓어야 하는 화면 */

    /* 페이지 공용 h1/통계 수치 타이포 — wrong_answers / rv-* 를 기준으로 맞춘다 */
    --wq-page-title-size: 1.35rem;
    --wq-page-stat-size:  1.1rem;

    /* =====================================================
       페이지 상단 여백(gutter) — 사이드바/네비바 바로 아래에서
       콘텐츠 첫 블록까지의 수직 간격. 모든 페이지가 동일한
       offset 에서 시작하도록 한 군데에서 관리.
       ===================================================== */
    --wq-page-top-gutter: 1.25rem;

    /* =====================================================
       버튼 계층 토큰 — 같은 계층 버튼은 같은 크기로.
         lg : 페이지 대표 CTA (이어서 공부하기, 오답 모아 풀기 등)
         md : 섹션/카드 내 기본 액션
         sm : 보조/아이콘 버튼, 테이블 행 액션
         xs : 태그/칩
       모든 버튼에서 높이·폰트·패딩을 동일 토큰으로 맞춘다.
       ===================================================== */
    --wq-btn-lg-height: 40px;
    --wq-btn-lg-padding: 0 18px;
    --wq-btn-lg-font:    0.92rem;
    --wq-btn-lg-radius:  10px;

    --wq-btn-md-height: 34px;
    --wq-btn-md-padding: 0 14px;
    --wq-btn-md-font:    0.85rem;
    --wq-btn-md-radius:  8px;

    --wq-btn-sm-height: 28px;
    --wq-btn-sm-padding: 0 10px;
    --wq-btn-sm-font:    0.78rem;
    --wq-btn-sm-radius:  6px;

    --wq-btn-xs-height: 22px;
    --wq-btn-xs-padding: 0 8px;
    --wq-btn-xs-font:    0.72rem;
    --wq-btn-xs-radius:  999px;
}

/* =====================================================
   Page shell — 페이지 본문 최상위 래퍼. 페이지마다 다르던
   max-width/margin/word-break 를 한 자리에서 관리한다.
   `.main-wrapper > .container` 가 바깥 프레임(1400px)을 잡고,
   `.wq-page` 가 안쪽 읽기 폭을 결정한다.
   ===================================================== */
.wq-page {
    max-width: var(--wq-page-max);
    margin: 0 auto;
    width: 100%;
    word-break: keep-all;
}
.wq-page--narrow { max-width: var(--wq-page-max-narrow); }
.wq-page--wide   { max-width: var(--wq-page-max-wide); }

.wq-page-title {
    margin: 0;
    color: var(--wq-text);
    font-size: var(--wq-page-title-size);
    font-weight: 700;
    line-height: 1.25;
    letter-spacing: -0.01em;
}

/* 통계 숫자 — summary-pill / mq-stat / ach-tile 등에서 재사용 */
.wq-page-stat {
    color: var(--wq-text);
    font-size: var(--wq-page-stat-size);
    font-weight: 800;
    line-height: 1.2;
    letter-spacing: -0.01em;
    font-variant-numeric: tabular-nums;
}

/* =====================================================
   공통 유틸 컴포넌트 — 모든 페이지에서 재사용
   ===================================================== */

/* 카드 */
.wq-card {
    background: var(--wq-surface);
    border: 1px solid var(--wq-border);
    border-radius: var(--wq-radius-lg);
    padding: var(--wq-space-6);
    transition: border-color var(--wq-transition-base), transform var(--wq-transition-base);
}
.wq-card:hover {
    border-color: var(--wq-border-strong);
}
.wq-card--compact { padding: var(--wq-space-4); border-radius: var(--wq-radius-md); }

/* 버튼 시스템 — 크기 토큰(.wq-btn-lg/md/sm/xs)으로 통일.
   같은 계층급 버튼은 HTML 에서 동일한 토큰 클래스를 쓴다.
   기본(.wq-btn) 은 md 크기. */
.wq-btn {
    display: inline-flex; align-items: center; justify-content: center;
    gap: 6px;
    height: var(--wq-btn-md-height);
    padding: var(--wq-btn-md-padding);
    border-radius: var(--wq-btn-md-radius);
    font-size: var(--wq-btn-md-font);
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    text-decoration: none;
    border: 1px solid transparent;
    transition: all var(--wq-transition-base);
    white-space: nowrap;
    box-sizing: border-box;
}
.wq-btn--primary {
    background: var(--wq-accent); color: var(--wq-on-accent, #102f3b); border-color: var(--wq-accent);
}
.wq-btn--primary:hover {
    background: var(--wq-accent-hover); border-color: var(--wq-accent-hover);
    transform: translateY(-1px);
    box-shadow: var(--wq-shadow-md);
}
.wq-btn--outline {
    background: transparent; color: var(--wq-text);
    border-color: var(--wq-border-strong);
}
.wq-btn--outline:hover {
    border-color: var(--wq-accent); color: var(--wq-accent);
    background: var(--wq-accent-soft);
}
.wq-btn--ghost {
    background: var(--wq-surface-2); color: var(--wq-text);
    border-color: var(--wq-border);
}
.wq-btn--ghost:hover {
    background: var(--wq-surface-3); border-color: var(--wq-border-strong);
}
.wq-btn--danger {
    background: var(--wq-danger-soft); color: var(--wq-danger);
    border-color: rgba(239, 68, 68, 0.3);
}
.wq-btn--xs { height: var(--wq-btn-xs-height); padding: var(--wq-btn-xs-padding); font-size: var(--wq-btn-xs-font); border-radius: var(--wq-btn-xs-radius); }
.wq-btn--sm { height: var(--wq-btn-sm-height); padding: var(--wq-btn-sm-padding); font-size: var(--wq-btn-sm-font); border-radius: var(--wq-btn-sm-radius); }
.wq-btn--md { height: var(--wq-btn-md-height); padding: var(--wq-btn-md-padding); font-size: var(--wq-btn-md-font); border-radius: var(--wq-btn-md-radius); }
.wq-btn--lg { height: var(--wq-btn-lg-height); padding: var(--wq-btn-lg-padding); font-size: var(--wq-btn-lg-font); border-radius: var(--wq-btn-lg-radius); }

/* =====================================================
   페이지 계층별 버튼 매핑 — 기존 페이지 로컬 버튼 클래스를
   공용 사이즈 토큰으로 끌어당겨 통일감을 준다.
   "같은 계층급이면 같은 크기" 원칙.
   ===================================================== */

/* [LG] 페이지 대표 CTA — 헤더 우측의 이어서 공부하기/오답 모아 풀기/회원가입 등 */
.top-study-btn,
.header-btn.primary,
.hero-btn.primary,
.ps-hero-cta,
.xp-hero-cta,
.hero-cta,
.btn-auth-primary,
.btn-save,
.btn-redeem,
.btn-danger {
    min-height: var(--wq-btn-lg-height);
    padding: var(--wq-btn-lg-padding) !important;
    font-size: var(--wq-btn-lg-font) !important;
    border-radius: var(--wq-btn-lg-radius) !important;
    font-weight: 700;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    box-sizing: border-box;
}

/* [MD] 섹션/카드 내 기본 액션 — 풀이 기록, 내 학습지, 캘린더 관리, 포인트 상점, 공부하기 등 */
.header-btn.secondary,
.hero-btn.secondary,
.hero-btn,
.panel-link,
.btn-follow,
.btn-security,
.mq-action,
.mq-hub__action,
.ps-action,
.xp-action,
.xp-btn,
.rv-btn,
.section-action,
.btn-action,
.btn-create-new,
.btn-back,
.access-btn,
.atc-btn,
.btn-custom,
.btn-social,
.sg-btn,
.about-btn {
    min-height: var(--wq-btn-md-height);
    padding: var(--wq-btn-md-padding) !important;
    font-size: var(--wq-btn-md-font) !important;
    border-radius: var(--wq-btn-md-radius) !important;
    font-weight: 700;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    box-sizing: border-box;
}

/* [SM] 보조/아이콘 버튼 — 페이지네이션, 테이블 행 인라인 액션 */
.page-link,
.page-num,
.row-action,
.wa-row-action,
.prob-action,
.action-btn,
.btn-edit-item,
.btn-remove-item,
.btn-save-edit,
.btn-cancel-edit,
.btn-add-item,
.btn-search-item,
.btn-toggle-doc-editor,
.btn-preview-doc,
.btn-save-doc,
.btn-cancel-doc,
.btn-create-small,
.btn-start-small,
.close-btn,
.cancel-btn,
.submit-btn {
    min-height: var(--wq-btn-sm-height);
    font-size: var(--wq-btn-sm-font) !important;
    border-radius: var(--wq-btn-sm-radius);
    font-weight: 600;
    line-height: 1;
}

/* [XS] 칩 형태의 초소형 태그/필터 버튼 */
.topic-btn,
.pop-btn {
    min-height: var(--wq-btn-xs-height);
    font-size: var(--wq-btn-xs-font) !important;
    border-radius: var(--wq-btn-xs-radius);
    font-weight: 600;
    line-height: 1;
}

/* 뱃지/칩 */
.wq-chip {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 4px 10px;
    border-radius: var(--wq-radius-pill);
    font-size: var(--wq-fs-xs);
    font-weight: 600;
    background: var(--wq-surface-2);
    color: var(--wq-text-soft);
    border: 1px solid var(--wq-border);
    white-space: nowrap;
}
.wq-chip--accent { background: var(--wq-accent-soft); color: var(--wq-accent-2); border-color: rgba(120, 189, 210,0.3); }
.wq-chip--success { background: var(--wq-success-soft); color: var(--wq-success); border-color: rgba(34,197,94,0.3); }
.wq-chip--warning { background: var(--wq-warning-soft); color: var(--wq-warning); border-color: rgba(251,191,36,0.3); }
.wq-chip--danger  { background: var(--wq-danger-soft); color: var(--wq-danger); border-color: rgba(239,68,68,0.3); }
.wq-chip--info    { background: var(--wq-info-soft); color: var(--wq-info); border-color: rgba(167,139,250,0.3); }

/* 입력 — 탐색 페이지 기준의 모던한 검색창 디자인 */
.wq-input {
    width: 100%;
    padding: 12px 16px;
    background: var(--wq-surface-2);
    border: 1px solid var(--wq-border);
    border-radius: var(--wq-radius-sm);
    color: var(--wq-text);
    font-size: var(--wq-fs-base);
    font-family: inherit;
    transition: all var(--wq-transition-base);
}
.wq-input::placeholder { color: var(--wq-text-muted); }
.wq-input:focus {
    outline: none;
    border-color: var(--wq-accent);
    background: var(--wq-surface);
    box-shadow: 0 0 0 3px var(--wq-accent-soft);
}

/* 통합 검색창 (아이콘 + 입력 + 제출 버튼) */
.wq-searchbar {
    display: flex;
    align-items: center;
    gap: var(--wq-space-2);
    padding: 6px 6px 6px 18px;
    background: var(--wq-surface);
    border: 1px solid var(--wq-border);
    border-radius: var(--wq-radius-pill);
    transition: border-color var(--wq-transition-base), box-shadow var(--wq-transition-base);
}
.wq-searchbar:focus-within {
    border-color: var(--wq-accent);
    box-shadow: 0 0 0 3px var(--wq-accent-soft);
}
.wq-searchbar__icon {
    flex-shrink: 0;
    width: 18px; height: 18px;
    color: var(--wq-text-muted);
    display: flex; align-items: center; justify-content: center;
}
.wq-searchbar__input {
    flex: 1;
    min-width: 0;
    padding: 10px 4px;
    background: transparent;
    border: 0;
    outline: none;
    color: var(--wq-text);
    font-size: var(--wq-fs-base);
    font-family: inherit;
}
.wq-searchbar__input::placeholder { color: var(--wq-text-muted); }
.wq-searchbar__clear {
    width: 28px; height: 28px;
    display: inline-flex; align-items: center; justify-content: center;
    border: 0; background: transparent; cursor: pointer;
    color: var(--wq-text-muted);
    border-radius: 50%;
    text-decoration: none;
    transition: all var(--wq-transition-fast);
}
.wq-searchbar__clear:hover { background: var(--wq-surface-2); color: var(--wq-text); }
.wq-searchbar__submit {
    padding: 9px 20px;
    border-radius: var(--wq-radius-pill);
    background: var(--wq-accent); color: var(--wq-on-accent, #102f3b);
    border: 0; cursor: pointer;
    font-size: var(--wq-fs-sm); font-weight: 700;
    transition: background var(--wq-transition-base);
}
.wq-searchbar__submit:hover { background: var(--wq-accent-hover); }

/* 컴팩트 검색바 — 상세 페이지 인라인 검색 */
.wq-searchbar--sm {
    padding: 2px 4px 2px 12px;
    gap: 6px;
}
.wq-searchbar--sm .wq-searchbar__icon { width: 14px; height: 14px; }
.wq-searchbar--sm .wq-searchbar__input { padding: 7px 2px; font-size: var(--wq-fs-sm); }
.wq-searchbar--sm .wq-searchbar__clear { width: 24px; height: 24px; }
.wq-searchbar--sm .wq-searchbar__submit { padding: 6px 14px; font-size: var(--wq-fs-xs); }

/* 섹션 헤더 */
.wq-section-header {
    display: flex; align-items: center;
    justify-content: space-between;
    gap: var(--wq-space-4);
    margin-bottom: var(--wq-space-5);
    flex-wrap: wrap;
}
.wq-section-title {
    display: flex; align-items: center; gap: var(--wq-space-3);
    margin: 0;
    font-size: var(--wq-fs-xl);
    font-weight: 700;
    color: var(--wq-text);
}
.wq-section-kicker {
    font-size: var(--wq-fs-xs);
    font-weight: 800;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--wq-accent);
    margin-bottom: 6px;
}

/* 섹션 구분 악센트 바 */
.wq-accent-bar {
    width: 4px;
    height: 22px;
    border-radius: 2px;
    background: linear-gradient(180deg, var(--wq-accent-2), var(--wq-accent));
}

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

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    font-family: 'Noto Sans KR', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--background-color);
    color: var(--text-color);
    line-height: 1.6;
    padding-bottom: var(--bottom-nav-height);
    /* For mobile */
    -webkit-tap-highlight-color: transparent;
    /* Remove default tap highlight */
}

/* --- Mobile Interactions --- */
.btn:active,
.card:active,
.nav-item:active,
.bottom-nav-item:active {
    transform: scale(0.98);
    transition: transform 0.1s;
}

/* --- Form Optimization for Mobile --- */
input[type="text"],
input[type="password"],
input[type="email"],
input[type="search"],
input[type="number"],
input[type="tel"],
input[type="url"],
select,
textarea {
    font-size: 16px;
    /* Prevent iOS zoom */
    min-height: 48px;
    /* Touch target size */
}

@media (max-width: 1023px) and (orientation: portrait), (max-width: 768px) {
    html,
    body {
        overscroll-behavior-x: none;
    }

    body {
        min-height: 100dvh;
    }

    .top-header,
    .bottom-nav {
        transform: translateZ(0);
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
    }

    a,
    button,
    [role="button"] {
        touch-action: manipulation;
    }

    h1 {
        font-size: 1.5rem;
    }

    h2 {
        font-size: 1.25rem;
    }

    h3 {
        font-size: 1.1rem;
    }

    .question-text {
        font-size: 1.05rem;
        line-height: 1.6;
    }

    /* 공통 — 모바일에서 숨길 데스크탑 전용 요소. 학습/시청 페이지 헤더 액션 등에서 사용. */
    .mobile-hidden { display: none !important; }
}

/* --- Layout Structure --- */
:root {
    --top-header-height: 64px;
}

/* Top Header - Unified for Desktop & Mobile */
.top-header {
    position: sticky;
    top: 0;
    left: 0;
    right: 0;
    height: var(--top-header-height);
    background-color: #010409;
    box-shadow: 0 1px 0 #2b2f3a;
    z-index: 50;
    transition: transform 0.3s ease;
}

.top-header.hide {
    transform: translateY(-100%);
}

.top-header-container {
    max-width: 1400px;
    margin: 0 auto;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    gap: 1rem;
    position: relative;
    /* Context for absolute logo */
}

/* Desktop Navigation */
.top-nav {
    display: none;
    align-items: center;
    gap: 0.25rem;
    flex: 1;
    margin-left: 2rem;
}

.top-nav-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    color: var(--text-color);
    text-decoration: none;
    font-size: 0.95rem;
    font-weight: 500;
    border-radius: 0.5rem;
    transition: all 0.2s;
    white-space: nowrap;
}

.top-nav-item:hover {
    background-color: #23262f;
    color: var(--primary-color);
}

.top-nav-item.active {
    background-color: rgba(120, 189, 210, 0.1);
    color: var(--primary-color);
}

.top-nav-item svg {
    flex-shrink: 0;
}

/* Top Header Right Section */
.top-header-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/* Right Navigation Items (학습 현황, 이어서 공부하기) */
.top-nav-right {
    display: none;
    align-items: center;
    gap: 0.2rem;
}

.top-nav-right .top-nav-item {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
}

.top-nav-right .top-nav-cta {
    margin-left: 0.9rem;
}

/* CTA Button - Apple SF Style */
.top-nav-cta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1.25rem;
    background: #78bdd2;
    color: var(--wq-on-accent, #102f3b);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 600;
    border-radius: 2rem;
    transition: all 0.2s;
    white-space: nowrap;
    box-shadow: none;
}

.top-nav-cta:hover {
    background: #0066D6;
    transform: none;
    box-shadow: none;
}

.top-nav-cta svg {
    flex-shrink: 0;
}

/* Desktop Auth Buttons */
.top-auth-buttons {
    display: none;
    align-items: center;
    gap: 0.75rem;
}

.btn-top-login {
    padding: 0.5rem 1.25rem;
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 600;
    border-radius: 0.5rem;
    transition: all 0.2s;
}

.btn-top-login:hover {
    background-color: rgba(120, 189, 210, 0.1);
}

.btn-top-signup {
    padding: 0.5rem 1.25rem;
    background: white;
    color: var(--primary-color);
    border: 1px solid #bfdbfe;
    text-decoration: none;
    font-weight: 600;
    border-radius: 0.5rem;
    transition: all 0.2s;
}

.btn-top-signup:hover {
    background-color: #f0f8fa;
    border-color: #b8e0ea;
}


/* User Dropdown */
.user-dropdown {
    display: none;
    position: relative;
}

.user-dropdown-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.375rem 0.75rem 0.375rem 0.375rem;
    background: #23262f;
    border: 1px solid #424857;
    border-radius: 2rem;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.user-dropdown-btn:hover {
    background: #262c36;
    border-color: var(--primary-color);
}

.user-avatar {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, #78bdd2, #94cede);
    color: var(--wq-on-accent, #102f3b);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
    font-weight: 600;
}

.user-name {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-color);
}

.user-dropdown-menu {
    position: absolute;
    top: calc(100% + 0.65rem);
    right: 0;
    min-width: 200px;
    padding: 6px;
    background: var(--wq-surface, #1a1d24);
    border: 1px solid var(--wq-border, #424857);
    border-radius: 14px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.2);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-6px);
    transition: opacity 0.16s, transform 0.16s, visibility 0.16s;
    z-index: 100;
}

.user-dropdown-menu.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.user-dropdown-menu .dropdown-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    color: var(--wq-text, var(--text-color));
    text-decoration: none;
    font-size: 0.875rem;
    transition: background-color 0.16s;
    width: 100%;
    border: none;
    border-radius: 9px;
    background: none;
    cursor: pointer;
    font-family: inherit;
    text-align: left;
}

.user-dropdown-menu .dropdown-item svg { flex-shrink: 0; color: var(--wq-text-muted); }
.user-dropdown-menu form { margin: 4px 0 0; padding-top: 4px; border-top: 1px solid var(--wq-border); }
.user-dropdown-menu .dropdown-item:hover, .user-dropdown-menu .dropdown-item:focus-visible { background: var(--wq-surface-3, #23262f); color: var(--wq-text); }
.user-dropdown-menu .dropdown-item:focus-visible { outline: 2px solid var(--primary-color); outline-offset: -2px; }
.user-dropdown-menu .dropdown-item.logout-item { color: var(--wq-text-muted, #9ca3af); }

/* Mobile User Greeting (visible only on mobile) */
.mobile-user-greeting {
    font-size: 0.85rem;
    font-weight: 500;
    /* 로고는 헤더 중앙(absolute, left:50%) 에 ~92px 폭으로 떠있어 우측 끝이
       calc(50% + 46px) 위치. 닉네임은 우측 정렬되어 right:16px(padding)
       기준이라, 로고와 안전 거리 ~10px 을 두고 사용 가능한 폭은
       (100% - 16px) - (50% + 56px) = (50vw - 72px). 작은 폰일수록 폭이
       자연스럽게 좁아지고, 큰 폰에선 140px 에서 잘려 헤더가 닉네임으로
       도배되는 것을 막는다. ellipsis 로 길어도 안전하게 잘림. */
    max-width: min(calc(50vw - 72px), 140px);
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: right;
    padding-right: 4px;
}

/* Main Wrapper */
.main-wrapper {
    /* margin-top 을 페이지 공용 gutter 로 통일 —
       페이지별 자체 top padding 은 제거(0)하고 여기서만 관리한다. */
    margin-top: var(--wq-page-top-gutter, 1rem);
    padding: 0 16px;
    min-height: calc(100vh - var(--top-header-height) - var(--bottom-nav-height));
}

/* --- Desktop Styles (Media Query) --- */
@media (min-width: 1024px), (min-width: 768px) and (orientation: landscape) and (min-height: 600px) {
    body {
        padding-bottom: 0;
    }

    .mobile-hamburger-btn,
    .mobile-user-greeting,
    .bottom-nav {
        display: none !important;
    }

    .top-nav {
        display: flex;
    }

    .top-auth-buttons {
        display: flex;
    }

    .top-nav-right {
        display: flex;
    }

    .user-dropdown {
        display: block;
    }

    .main-wrapper {
        /* 데스크톱에서도 공용 gutter 를 사용. 페이지별 로컬 값 없음. */
        margin-top: var(--wq-page-top-gutter, 1.25rem);
        padding: 0 2rem;
        max-width: 1400px;
        margin-left: auto;
        margin-right: auto;
        min-height: calc(100vh - var(--top-header-height));
    }
}

/* --- Sidebar Components --- */
.sidebar-header {
    height: 64px;
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    border-bottom: 1px solid var(--border-color);
    position: relative;
}

.sidebar-header .logo {
    position: static;
    transform: none;
    left: auto;
}


/* Base Logo Style (Mobile Centered) */
.logo {
    display: flex;
    align-items: center;
    text-decoration: none;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}

/* Desktop Logo Reset */
@media (min-width: 1024px), (min-width: 768px) and (orientation: landscape) and (min-height: 600px) {
    .logo {
        position: static;
        transform: none;
        left: auto;
    }
}

.logo img {
    height: 22px;
    width: auto;
}

.sidebar-nav {
    flex: 1;
    padding: 1.5rem 0;
    overflow-y: auto;
}

.nav-section {
    margin-bottom: 2rem;
}

.nav-label {
    padding: 0 1.5rem;
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.nav-item {
    display: flex;
    align-items: center;
    padding: 0.75rem 1.5rem;
    color: var(--text-color);
    text-decoration: none;
    transition: background-color 0.2s;
}

.nav-item:hover {
    background-color: #23262f;
    color: var(--primary-color);
}

.nav-item.active {
    background-color: rgba(120, 189, 210, 0.1);
    color: var(--primary-color);
    border-right: 3px solid var(--primary-color);
}

.nav-item .icon {
    margin-right: 0.75rem;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    line-height: 0;
    /* Remove text height influence */
}

.nav-item .icon svg {
    width: 20px;
    height: 20px;
    transition: transform 0.2s ease;
    margin: auto;
    /* Ensure centering in flex container */
}

.nav-item:hover .icon svg {
    transform: scale(1.1);
}

.sidebar-footer {
    padding: 1.5rem;
    border-top: 1px solid var(--border-color);
    background-color: #010409;
}

.sidebar-footer .copyright {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 1rem;
}

/* --- Bottom Nav (Mobile) --- */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--bottom-nav-height);
    background-color: #010409;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: 40;
    padding-bottom: env(safe-area-inset-bottom);
}

.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    color: var(--text-muted);
    font-size: 0.72rem;
    font-weight: 500;
    flex: 1;
    height: 100%;
    gap: 3px;
    transition: color 0.18s ease, transform 0.18s ease;
    background: none;
    border: none;
    cursor: pointer;
    font-family: inherit;
    padding: 4px 0 6px;
    position: relative;
    -webkit-tap-highlight-color: transparent;
}

.bottom-nav-item:active {
    transform: scale(0.94);
}

.bottom-nav-item.active {
    color: var(--primary-color);
    font-weight: 600;
}

.bottom-nav-item.active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 28px;
    height: 3px;
    background: var(--primary-color);
    border-radius: 0 0 3px 3px;
}

.bottom-nav-item .nav-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    transition: transform 0.18s ease;
}

.bottom-nav-item.active .nav-icon {
    transform: translateY(-1px) scale(1.05);
}

.bottom-nav-item .nav-icon svg {
    width: 22px;
    height: 22px;
    stroke-width: 1.75;
    transition: all 0.18s ease;
}

.bottom-nav-item.active .nav-icon svg {
    stroke: var(--primary-color);
    stroke-width: 2.25;
}

.bottom-nav-item .icon {
    font-size: 1.25rem;
    margin-bottom: 2px;
}

/* Mobile Hamburger Button */
.mobile-hamburger-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    margin-right: 8px;
    border-radius: 8px;
    transition: background-color 0.2s ease;
    color: var(--text-color);
}

.mobile-hamburger-btn:hover,
.mobile-hamburger-btn:active {
    background-color: rgba(0, 0, 0, 0.05);
}

.mobile-hamburger-btn svg {
    width: 20px;
    height: 20px;
}

/* --- Mobile Menu Overlay --- */
.mobile-menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 100;
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease, visibility 0s linear 0.3s;
    backdrop-filter: blur(4px);
}

.mobile-menu-overlay.active {
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
    transition: opacity 0.3s ease, visibility 0s linear 0s;
}

.mobile-menu-content {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(320px, 86vw);
    max-width: 360px;
    background-color: #13151b;
    box-shadow: 4px 0 16px rgba(0, 0, 0, 0.5);
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    padding-bottom: env(safe-area-inset-bottom);
}

.mobile-menu-overlay.active .mobile-menu-content {
    transform: translateX(0);
}

.mobile-menu-header {
    height: var(--mobile-header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: env(safe-area-inset-top) 1.5rem 0 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.mobile-menu-header h2 {
    font-size: 1.1rem;
    margin: 0;
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
    color: var(--text-muted);
}

.mobile-menu-body {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
}

.user-profile-summary {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 0.75rem;
}

.avatar-circle {
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, #78bdd2, #94cede);
    color: var(--wq-on-accent, #102f3b);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    font-weight: bold;
}

.user-details {
    display: flex;
    flex-direction: column;
}

.user-details .username {
    font-weight: 600;
    font-size: 1rem;
}

.user-details .email {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.menu-section {
    margin-bottom: 2rem;
}

.menu-section h3 {
    font-size: 0.8rem;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
    font-weight: 600;
}

.menu-item {
    display: flex;
    align-items: center;
    padding: 0.75rem 0;
    color: var(--text-color);
    text-decoration: none;
    font-size: 1rem;
    border-radius: 0.5rem;
    transition: background-color 0.2s;
}

.mobile-dark-mode-toggle {
    width: 100%;
    border: none;
    background: none;
    cursor: pointer;
    font-family: inherit;
    text-align: left;
    margin: 0 0 1.25rem;
}

.mobile-dark-mode-toggle .dark-mode-switch {
    margin-left: auto;
}

.menu-item .icon {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 12px;
    flex-shrink: 0;
    line-height: 0;
    /* Remove text height influence */
}

.menu-item .icon svg {
    width: 20px;
    height: 20px;
    margin: auto;
    /* Ensure centering in flex container */
}

.menu-item:active {
    background-color: #F3F4F6;
}

.menu-footer {
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.menu-footer a {
    color: var(--text-muted);
    font-size: 0.8rem;
    text-decoration: none;
}

.logout-btn {
    width: 100%;
    background: none;
    border: none;
    cursor: pointer;
    font-family: inherit;
    text-align: left;
    color: #EF4444;
}

.logout-btn .icon {
    color: #EF4444;
}

/* --- Common UI Components --- */
/* 기본 container — 페이지 최상위 블록 래퍼.
   과거 1024px 였지만, 통합 후 .wq-page 가 실제 읽기 폭을 결정하므로
   여기선 넓게 1400px 프레임만 제공한다 (.main-wrapper 와 동일).
   wq-page 클래스를 사용하는 페이지는 내부에서 1080/880/1280 중 하나로 압축. */
.container {
    max-width: var(--wq-page-max);
    margin: 0 auto;
}

h1,
h2,
h3 {
    margin-bottom: 1rem;
}

.page-header {
    margin-bottom: 1.25rem;
}

.page-header h1,
.page-header h2 {
    margin: 0;
    font-size: var(--wq-page-title-size, 1.35rem);
    font-weight: 700;
    line-height: 1.3;
    color: var(--wq-text, #f3f4f6);
}

.breadcrumb {
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-bottom: 0.45rem;
}

.breadcrumb a {
    color: var(--text-muted);
    text-decoration: none;
}

.breadcrumb a:hover {
    text-decoration: underline;
}

.card {
    background-color: var(--card-background);
    border-radius: 0.5rem;
    box-shadow: none;
    padding: 1.5rem;
    transition: transform 0.2s, box-shadow 0.2s;
    text-decoration: none;
    color: inherit;
    display: block;
    border: 1px solid var(--border-color);
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: none;
    border-color: #424857;
}

.btn {
    display: inline-block;
    background: linear-gradient(135deg, #86c8db, #78bdd2);
    color: var(--wq-on-accent, #102f3b);
    padding: 0.75rem 1.5rem;
    border-radius: 0.375rem;
    text-decoration: none;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(134, 200, 219, 0.4);
}

.btn-secondary {
    background-color: white;
    color: var(--text-color);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background-color: #F9FAFB;
}

.grid {
    display: grid;
    /* Improved grid for responsiveness */
    grid-template-columns: repeat(1, 1fr);
    /* Default mobile 1 column */
    gap: 1.5rem;
}

@media (min-width: 640px) {

    /* Tablet Portrait */
    .grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 1024px) {

    /* Desktop */
    .grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* --- Hero Section --- */
.hero {
    background-color: var(--card-background);
    border-radius: 1rem;
    padding: 3rem 2rem;
    text-align: center;
    margin-bottom: 3rem;
    box-shadow: none;
    border: 1px solid var(--border-color);
}

.hero h1 {
    font-size: 2rem;
    color: var(--text-color);
    margin-bottom: 1rem;
    line-height: 1.3;
}

.hero p {
    color: var(--text-muted);
    margin-bottom: 2rem;
    font-size: 1.1rem;
    word-break: keep-all;
    /* Improve Korean text wrapping */
}

/* --- Forms --- */
input[type="text"],
input[type="password"],
input[type="email"] {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    margin-bottom: 1rem;
    font-size: 1rem;
}

input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(148, 206, 222, 0.1);
}

/* --- Tables --- */
table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

th {
    background-color: #F9FAFB;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.875rem;
}

/* --- Practice Mode & Question Layouts --- */
.question-block {
    background-color: white;
    border-radius: 0.5rem;
    padding: 1.5rem;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    margin-bottom: 1.5rem;
}

.question-text {
    font-size: 1.1rem;
    font-weight: 500;
    margin-bottom: 1.5rem;
    line-height: 1.6;
}

.question-text,
.batch-problem-title,
.option-text,
.flashcard-side-text,
.flashcard-content {
    overflow-wrap: anywhere;
    word-break: break-word;
}

.flashcard-side-text,
.flashcard-content {
    max-width: 100%;
}

.choices {
    list-style: none;
}

.choice-item {
    margin-bottom: 0.75rem;
}

.choice-label {
    display: flex;
    align-items: center;
    padding: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
}

.choice-label:hover {
    background-color: #F9FAFB;
    border-color: var(--primary-color);
}

.choice-label input[type="radio"] {
    margin-right: 0.75rem;
}

/* Feedback Styles */
.result-feedback {
    padding: 1rem;
    border-radius: 0.5rem;
    margin-top: 1rem;
    background-color: #F9FAFB;
    border: 1px solid var(--border-color);
}

.result-feedback.correct {
    background-color: #ECFDF5;
    /* Green-50 */
    border-color: #10B981;
}

.result-feedback.incorrect {
    background-color: #FEF2F2;
    /* Red-50 */
    border-color: #EF4444;
}

.explanation {
    margin-top: 0.5rem;
    color: var(--text-color);
}

/* Score Card */
.score-card {
    text-align: center;
    padding: 3rem 1rem;
    background: white;
    border-radius: 1rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.score-display {
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--primary-color);
    margin: 1.5rem 0;
}

/* Mobile User Greeting */
.mobile-user-greeting {
    font-size: 0.9rem;
    font-weight: 500;
}

/* Auth Buttons Sidebar */
.auth-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.btn-login {
    background: rgba(120, 189, 210, 0.08);
    background-image: none;
    color: var(--primary-color);
    border: 1px solid rgba(120, 189, 210, 0.3);
    text-align: center;
    font-weight: 600;
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    transition: all 0.2s;
}

.btn-login:hover {
    background: rgba(120, 189, 210, 0.15);
    border-color: var(--primary-color);
    transform: none;
    box-shadow: none;
}

.btn-signup {
    background: white;
    background-image: none;
    color: var(--primary-color);
    border: 1px solid rgba(120, 189, 210, 0.3);
    text-align: center;
    font-weight: 600;
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    transition: all 0.2s;
}

.btn-signup:hover {
    background: rgba(120, 189, 210, 0.05);
    border-color: var(--primary-color);
    transform: none;
    box-shadow: none;
}

.btn-logout {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    text-decoration: underline;
    font-size: 0.875rem;
}

/* Body */
html.dark body {
    background-color: var(--background-color);
    color: var(--text-color);
}

/* --- Top Header --- */
html.dark .top-header {
    background-color: #010409;
    box-shadow: 0 1px 0 #2b2f3a;
}

html.dark .top-nav-item {
    color: #c9d1d9;
}

html.dark .top-nav-item:hover {
    background-color: #23262f;
    color: var(--primary-color);
}

html.dark .top-nav-item.active {
    background-color: rgba(120, 189, 210, 0.1);
    color: var(--primary-color);
}

html.dark .top-nav-cta {
    background: #78bdd2;
}

html.dark .top-nav-cta:hover {
    background: #94cede;
}

/* --- User Dropdown --- */
html.dark .user-dropdown-btn {
    background: #23262f;
    border-color: #424857;
}

html.dark .user-dropdown-btn:hover {
    background: #262c36;
    border-color: var(--primary-color);
}

html.dark .user-name {
    color: #e6edf3;
}

/* --- Auth Buttons ---
   로그인(ghost) + 회원가입(filled brand blue) 으로 위계 명확화.
   이전엔 둘 다 회색 ghost 라 회원가입 CTA 임팩트가 약했다. */
html.dark .btn-top-login {
    color: #e2e8f0;
}

html.dark .btn-top-login:hover {
    background-color: rgba(255, 255, 255, 0.08);
}

html.dark .btn-top-signup {
    background: var(--wq-accent, #78bdd2);
    color: var(--wq-on-accent, #102f3b);
    border: 1px solid transparent;
}

html.dark .btn-top-signup:hover {
    background: #94cede;
    border-color: transparent;
}


/* --- Logo --- */
html.dark .logo img {
    filter: brightness(1.2);
}

/* --- Bottom Nav (Mobile) --- */
html.dark .bottom-nav {
    background-color: #010409;
    border-top-color: #2b2f3a;
}

html.dark .bottom-nav-item {
    color: #484f58;
}

html.dark .bottom-nav-item.active {
    color: var(--primary-color);
}

/* --- Mobile Menu --- */
html.dark .mobile-menu-overlay {
    background-color: rgba(0, 0, 0, 0.7);
}

html.dark .mobile-menu-content {
    background-color: #13151b;
    box-shadow: 4px 0 16px rgba(0, 0, 0, 0.5);
}

html.dark .mobile-menu-header {
    border-bottom-color: #2b2f3a;
}

html.dark .mobile-menu-header h2 {
    color: #e6edf3;
}

html.dark .close-btn {
    color: #9aa0ad;
}

html.dark .avatar-circle {
    background: linear-gradient(135deg, #78bdd2, #94cede);
}

html.dark .user-profile-summary {
    border-bottom-color: #2b2f3a;
}

html.dark .user-details .username {
    color: #e6edf3;
}

html.dark .user-details .email {
    color: #9aa0ad;
}

html.dark .menu-section h3 {
    color: #9aa0ad;
}

html.dark .menu-item {
    color: #c9d1d9;
}

html.dark .menu-item:active {
    background-color: #23262f;
}

html.dark .logout-btn {
    color: #f87171;
}

html.dark .logout-btn .icon {
    color: #f87171;
}

html.dark .menu-footer {
    border-top-color: #2b2f3a;
}

html.dark .menu-footer a {
    color: #9aa0ad;
}

/* --- Mobile Hamburger --- */
html.dark .mobile-hamburger-btn {
    color: #c9d1d9;
}

html.dark .mobile-hamburger-btn:hover,
html.dark .mobile-hamburger-btn:active {
    background-color: rgba(255, 255, 255, 0.06);
}

/* --- Mobile User Greeting --- */
html.dark .mobile-user-greeting {
    color: #c9d1d9;
}

html.dark .mobile-user-greeting a {
    color: #c9d1d9 !important;
}

/* --- Cards --- */
html.dark .card {
    background-color: var(--card-background);
    border-color: var(--border-color);
    box-shadow: none;
}

/* --- Forms --- */
html.dark input[type="text"],
html.dark input[type="password"],
html.dark input[type="email"],
html.dark select,
html.dark textarea {
    background-color: #13151b;
    border-color: #424857;
    color: #e6edf3;
}

html.dark input[type="text"]:focus,
html.dark input[type="password"]:focus,
html.dark input[type="email"]:focus,
html.dark select:focus,
html.dark textarea:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(120, 189, 210, 0.15);
}

html.dark input::placeholder,
html.dark textarea::placeholder {
    color: #484f58;
}

/* --- Headings --- */
html.dark h1,
html.dark h2,
html.dark h3 {
    color: #e6edf3;
}

/* --- Links --- */
html.dark a {
    color: var(--primary-color);
}

html.dark .breadcrumb,
html.dark .breadcrumb a {
    color: #9aa0ad;
}

/* --- Sidebar --- */
html.dark .sidebar-footer {
    border-top-color: #2b2f3a;
    background-color: #010409;
}

html.dark .sidebar-footer .copyright {
    color: #9aa0ad;
}

html.dark .nav-item:hover {
    background-color: #23262f;
}

html.dark .nav-item.active {
    background-color: rgba(120, 189, 210, 0.1);
    border-right-color: var(--primary-color);
}

/* --- Toast --- */
html.dark .simple-toast {
    background-color: #23262f;
    color: #e6edf3;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

/* --- Common UI sections --- */
html.dark .page-header {
    color: #e6edf3;
}

/* --- Section titles often used across pages --- */
html.dark .section-title {
    color: #e6edf3;
}

/* --- Empty states --- */
html.dark .empty-state-page {
    background: #1a1d24;
    border-color: #2b2f3a;
    color: #9aa0ad;
}

/* --- Auth pages --- */
html.dark .btn-login {
    background: var(--primary-color);
}

html.dark .btn-signup {
    color: var(--primary-color);
    border-color: #424857;
}

html.dark .btn-signup:hover {
    border-color: var(--primary-color);
}

/* --- Desktop Footer --- */
.desktop-footer {
    display: none;
    background-color: #F9FAFB;
    border-top: 1px solid var(--border-color);
    padding: 2rem 0;
    margin-top: 3rem;
}

@media (min-width: 1024px), (min-width: 768px) and (orientation: landscape) and (min-height: 600px) {
    .desktop-footer {
        display: block;
    }
}

.desktop-footer-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--text-muted);
    font-size: 0.875rem;
}

.footer-links {
    display: flex;
    gap: 1.5rem;
}

.footer-links a {
    color: var(--text-muted);
    text-decoration: none;
    transition: color 0.2s;
}

.footer-links a:hover {
    color: var(--primary-color);
}

/* Dark Mode Footer */
html.dark .desktop-footer {
    background-color: #010409;
    border-top-color: #2b2f3a;
}

html.dark .desktop-footer-container {
    color: #9aa0ad;
}

html.dark .footer-links a {
    color: #9aa0ad;
}

html.dark .footer-links a:hover {
    color: var(--primary-color);
}

/* --- Policy Pages (Terms & Privacy) --- */
.policy-content {
    line-height: 1.8;
    color: var(--text-color);
}

.policy-content h1 {
    margin-bottom: 2rem;
    font-size: 1.75rem;
    font-weight: 700;
}

.policy-content h2 {
    margin-top: 2.5rem;
    margin-bottom: 1rem;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-color);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
}

.policy-content p {
    margin-bottom: 1rem;
    color: var(--text-color);
}

.policy-content ul {
    margin-bottom: 1.5rem;
    padding-left: 1.5rem;
    list-style-type: disc;
}

.policy-content li {
    margin-bottom: 0.5rem;
    color: var(--text-color);
}

.policy-content .last-updated {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 2rem;
    text-align: right;
}

/* Dark Mode Overrides for Policy Pages */
html.dark .policy-content h2 {
    border-bottom-color: #2b2f3a;
    color: #e6edf3;
}

html.dark .policy-content p,
html.dark .policy-content li {
    color: #c9d1d9;
}

html.dark .policy-content .last-updated {
    color: #9aa0ad;
}

/* Ensure question-block has dark mode background */
html.dark .question-block {
    background-color: #1a1d24;
    border: 1px solid #2b2f3a;
    color: #e6edf3;
}

/* Unified workbook action buttons (exam + study) */
.wkb-dual-actions {
    display: flex;
    gap: 8px;
    width: auto;
    justify-content: flex-end;
    flex-shrink: 0;
    position: relative;
    z-index: 3;
}

.wkb-action-btn {
    position: relative;
    z-index: 3;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    border-radius: 11px;
    padding: 6px 8px;
    min-height: 34px;
    font-size: 0.8rem;
    font-weight: 700;
    line-height: 1.2;
    border: 1px solid transparent;
    transition: all 0.2s ease;
    white-space: nowrap;
    min-width: 70px;
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
}

.wkb-action-btn.exam {
    background: #23262f;
    color: #c7cbd5;
    border-color: #424857;
}

.wkb-action-btn.exam:hover {
    background: #2b2f3a;
    color: #e8eaf0;
    border-color: #4a5160;
}

.wkb-action-btn.study {
    background: #78bdd2;
    color: var(--wq-on-accent, #102f3b) !important;
    border-color: #94cede;
    box-shadow: 0 4px 12px rgba(120, 189, 210, 0.25);
}

.wkb-action-btn.study:hover {
    background: #94cede;
    transform: translateY(-1px);
}

/* 시험지(파생 학습지) 전용 '시험 시작' 버튼 — 학습지의 파란색과 구분되도록 보라색 톤. */
.wkb-action-btn.exam-start {
    background: #8b5cf6;
    color: #ffffff !important;
    border-color: #7c3aed;
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.28);
}

.wkb-action-btn.exam-start:hover {
    background: #7c3aed;
    transform: translateY(-1px);
}

/* 낱말카드 자동학습 — 시청형 학습. 파랑/보라와 구분되도록 초록 톤. */
.wkb-action-btn.auto-learn {
    background: #10b981;
    color: #ffffff !important;
    border-color: #059669;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.25);
}

.wkb-action-btn.auto-learn:hover {
    background: #059669;
    border-color: #047857;
    transform: translateY(-1px);
}

.wkb-action-btn.disabled {
    background: #1a1d24 !important;
    color: #8a92a3 !important;
    border-color: #2b2f3a !important;
    box-shadow: none !important;
    pointer-events: none;
    cursor: not-allowed;
    opacity: 0.85;
}

@media (hover: none) {
    .wkb-action-btn.exam:hover {
        background: #23262f;
        color: #c7cbd5;
        border-color: #424857;
        transform: none;
    }

    .wkb-action-btn.study:hover {
        background: #78bdd2;
        border-color: #94cede;
        transform: none;
    }

    .wkb-action-btn.exam-start:hover {
        background: #8b5cf6;
        border-color: #7c3aed;
        transform: none;
    }

    .wkb-action-btn.auto-learn:hover {
        background: #10b981;
        border-color: #059669;
        transform: none;
    }

    .wkb-action-btn.disabled:hover {
        background: #1a1d24 !important;
        color: #8a92a3 !important;
        border-color: #2b2f3a !important;
        box-shadow: none !important;
        transform: none !important;
    }
}

/* Keep workbook topic tag single-line in action rows */
/* Keep workbook topic tag single-line in action rows */
.topic-tag {
    white-space: nowrap;
    font-size: 0.7rem;
    padding: 3px 8px;
}

@media (max-width: 880px) {
    .wkb-dual-actions {
        display: grid;
        width: 100%;
        grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
        justify-content: stretch;
    }

    .wkb-action-btn {
        min-height: 44px;
        padding: 10px 12px;
        font-size: 0.82rem;
    }
}

@media (max-width: 480px) {
    .wkb-action-btn {
        min-height: 46px;
        font-size: 0.85rem;
        border-radius: 12px;
    }
}

/* =====================================================
   모바일 공통 컴포넌트 통합 — 2026-04
   - 모든 페이지 공용 카드/버튼/입력/콘텐츠를 모바일에 맞춤
   - 터치 타겟 44px+ (Apple HIG 기준)
   - 카드 패딩 압축, 이미지 안전, 가로 overflow 방지
   - 데스크톱 기본값 유지하면서 모바일에서만 오버라이드
   ===================================================== */

/* ── 전역 안전: 가로 overflow 방지 + iOS 자동 줌 방지 ── */
@media (max-width: 768px) {
    html, body {
        overflow-x: hidden;
        -webkit-text-size-adjust: 100%;
    }

    /* 본문 좌우 여백 — main-wrapper 보호 */
    .main-wrapper { padding-left: max(14px, env(safe-area-inset-left));
                    padding-right: max(14px, env(safe-area-inset-right)); }

    /* 콘텐츠 영역 이미지 안전 */
    .container img,
    .wq-page img,
    .question-card img,
    .wrong-card img {
        max-width: 100%;
        height: auto;
    }

    /* 표 가로 스크롤 패턴 — 데스크톱에서 큰 표를 모바일에서도 안전하게 */
    .table-responsive,
    table {
        max-width: 100%;
    }
    table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* iOS 자동 확대 우회 — 모든 입력은 16px 이상 */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="search"],
    input[type="number"],
    input[type="tel"],
    input[type="url"],
    select,
    textarea {
        font-size: 16px !important;
    }

    /* 카드 — 모바일 패딩 압축 */
    .wq-card { padding: var(--wq-space-4); border-radius: var(--wq-radius-md); }
    .wq-card--compact { padding: var(--wq-space-3); }

    /* 버튼 — 모바일 터치 타겟 강화 */
    .wq-btn { min-height: 44px; padding: 0 16px; font-size: 0.9rem; }
    .wq-btn--lg { min-height: 48px; padding: 0 20px; font-size: 0.95rem; }
    .wq-btn--md { min-height: 44px; padding: 0 14px; font-size: 0.88rem; }
    .wq-btn--sm { min-height: 40px; padding: 0 12px; font-size: 0.84rem; }
    .wq-btn--xs { min-height: 32px; padding: 0 10px; font-size: 0.76rem; }

    /* 페이지 매핑된 sm 클래스들도 모바일에서 자동 확대 */
    .page-link,
    .page-num,
    .row-action,
    .wa-row-action,
    .prob-action,
    .action-btn,
    .btn-edit-item,
    .btn-remove-item,
    .btn-save-edit,
    .btn-cancel-edit,
    .btn-add-item,
    .btn-search-item,
    .btn-create-small,
    .btn-start-small,
    .close-btn,
    .cancel-btn {
        min-height: 40px !important;
        padding: 0 14px !important;
        font-size: 0.84rem !important;
    }

    /* 페이지 헤더 타이포 압축 */
    .wq-page-title { font-size: 1.2rem; }
    .wq-page-stat { font-size: 1rem; }

    /* 입력 — 모바일 패딩 확대 */
    .wq-input { padding: 14px 16px; }
    .wq-searchbar { padding: 8px 8px 8px 16px; }

    /* 칩/뱃지 — 모바일에서 가독성 */
    .wq-chip { padding: 5px 10px; font-size: 0.74rem; }

    /* 탭 가능 요소 공통 — 더블탭 줌/하이라이트 제거 */
    a, button, [role="button"], input, select, textarea, label {
        -webkit-tap-highlight-color: transparent;
    }

    /* 활성 상태 시각 피드백 (햅틱 대신) */
    .wq-btn:active,
    .practice-btn:active,
    .wn-btn:active,
    .db-btn:active,
    .wkb-action-btn:active {
        transform: scale(0.97);
        transition: transform 0.08s ease;
    }
}

@media (max-width: 480px) {
    /* 작은 폰 — 한 단계 더 압축 */
    .main-wrapper { padding-left: max(12px, env(safe-area-inset-left));
                    padding-right: max(12px, env(safe-area-inset-right)); }
    .wq-card { padding: var(--wq-space-3); }
    .wq-page-title { font-size: 1.1rem; }
}

/* ── 가로 모드 (landscape) — 작은 폰에서 ── */
@media (max-height: 500px) and (orientation: landscape) {
    .top-header { height: 50px; }
    .bottom-nav { height: 50px; }
    .main-wrapper { padding-top: 8px; padding-bottom: 56px; }
    .bottom-nav-item { font-size: 0.65rem; }
    .bottom-nav-item .nav-icon svg { width: 18px; height: 18px; }
}

/* ── 페이지 전환 부드럽게 — 클릭 → 새 페이지 시 약한 페이드 ── */
@media (prefers-reduced-motion: no-preference) {
    .main-wrapper > .container {
        animation: wq-page-enter 0.18s ease-out;
    }
    @keyframes wq-page-enter {
        from { opacity: 0; transform: translateY(4px); }
        to   { opacity: 1; transform: translateY(0); }
    }
}
