/* =========================================================
   가방 현장용어 사전 - 사용자(학습) 화면 전용 스타일
   공통 기준(색·글꼴·헤더·버튼)은 base.css 에 있습니다.
   ========================================================= */

/* sr-only 는 absolute 이므로 가로 스크롤 영역 안에서는 기준 상자가 필요합니다 */
.view-tab,
.legend-item,
.term-card,
.result {
    position: relative;
}

/* 가리기(학습) 모드에서 현장용어 자리를 덮는 블록 */
.mask {
    display: inline-block;
    width: calc(var(--len, 3) * 1em);
    max-width: 100%;
    height: 0.95em;
    vertical-align: -0.1em;
    border-radius: 4px;
    background: var(--mask);
}

/* ---------- 헤더 검색 ---------- */

.search {
    position: relative;
    flex: 1;
    max-width: 520px;
    margin-left: auto;
}

.search input {
    width: 100%;
    height: 44px;
    padding: 0 44px 0 42px;
    border: 1px solid var(--line-strong);
    border-radius: var(--r-ctl);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 15px;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.search input::placeholder {
    color: var(--text-muted);
    opacity: 1;
}

.search input::-webkit-search-cancel-button {
    -webkit-appearance: none;
    appearance: none;
}

.search input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-ring);
}

.search-icon {
    position: absolute;
    left: 13px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

.search-kbd {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    padding: 4px 8px;
    border: 1px solid var(--line-strong);
    border-radius: 6px;
    background: var(--surface-2);
    color: var(--text-muted);
    font: 600 12px/1 var(--font);
    pointer-events: none;
}

.search:focus-within .search-kbd,
.search.has-value .search-kbd {
    display: none;
}

.search-clear {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    padding: 0;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
}

.search-clear:hover {
    background: var(--surface-2);
    color: var(--text);
}

.search-results {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 6px);
    max-height: min(440px, 70dvh);
    overflow-y: auto;
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: var(--r-box);
    background: var(--surface);
    box-shadow: var(--shadow-lg);
}

.result {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--r-ctl);
    cursor: pointer;
}

.result[aria-selected="true"] {
    background: var(--accent-soft);
}

.result-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.result-term {
    font-weight: 600;
}

.result-std {
    font-size: 14px;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.result-where {
    flex: none;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    white-space: nowrap;
}

.result mark {
    background: transparent;
    color: var(--accent-ink);
    font-weight: 700;
}

.result-empty,
.result-more {
    padding: 12px;
    font-size: 14px;
    color: var(--text-muted);
}

.result-more {
    border-top: 1px solid var(--line);
    margin-top: 4px;
    padding-bottom: 8px;
}

.search + .topbar-actions {
    margin-left: 0;
}

/* ---------- 학습 영역 ---------- */

.workspace {
    max-width: 1320px;
    margin: 0 auto;
    padding: 20px 24px 40px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 400px;
    gap: 24px;
    align-items: start;
}

.viewer {
    min-width: 0;
}

.viewer:focus {
    outline: none;
}

.view-tabs {
    display: flex;
    gap: 8px;
    margin: -2px -2px 14px;
    padding: 2px;
    overflow-x: auto;
    scrollbar-width: none;
    scroll-snap-type: x proximity;
}

.view-tabs::-webkit-scrollbar {
    display: none;
}

.view-tab {
    flex: none;
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 50px;
    padding: 6px 12px 6px 6px;
    border: 1px solid var(--line);
    border-radius: var(--r-ctl);
    background: var(--surface);
    cursor: pointer;
    scroll-snap-align: start;
    transition: border-color 0.15s, background-color 0.15s;
}

.view-tab img {
    width: 36px;
    height: 36px;
    border-radius: calc(var(--r-ctl) - 4px);
    object-fit: cover;
    background: var(--surface-2);
}

.view-tab-label {
    font-size: 15px;
    font-weight: 600;
}

.view-tab-count {
    min-width: 24px;
    height: 22px;
    padding: 0 7px;
    display: grid;
    place-items: center;
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.view-tab-count:empty {
    display: none;
}

.view-tab:hover {
    border-color: var(--line-strong);
}

.view-tab[aria-selected="true"] {
    border-color: var(--accent);
    background: var(--accent-soft);
    box-shadow: inset 0 0 0 1px var(--accent);
}

.view-tab[aria-selected="true"] .view-tab-label {
    color: var(--accent-text);
}

.view-tab[aria-selected="true"] .view-tab-count {
    background: var(--accent);
    color: var(--on-accent);
}

/* 사진 무대: 화면 높이에 맞춰 사진 전체가 한눈에 보이도록 제한 */
.stage {
    --stage-h: clamp(340px, calc(100dvh - var(--header-h) - 120px), 780px);
    display: flex;
    justify-content: center;
    border-radius: var(--r-box);
    background: var(--surface-2);
}

/* 핀 좌표(%)는 사진 크기 기준이므로 frame 은 사진과 정확히 같은 크기여야 합니다 */
.frame {
    --ar: 1.0625;
    position: relative;
    width: min(100%, calc(var(--stage-h) * var(--ar)));
    aspect-ratio: var(--ar);
    border-radius: var(--r-box);
}

.frame .main-image {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: inherit;
    transition: opacity 0.2s ease;
}

.frame.is-loading .main-image {
    opacity: 0.35;
}

.frame-error {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: var(--text-muted);
    font-weight: 600;
}

.pins-layer {
    position: absolute;
    inset: 0;
}

.stage-hint {
    display: none;
}

/* 번호 핀: 바깥 버튼은 위치와 터치 영역, 안쪽 점이 크기 변화를 담당 */
.pin {
    position: absolute;
    z-index: 1;
    width: 32px;
    height: 32px;
    margin: -16px 0 0 -16px;
    padding: 0;
    border: 0;
    background: transparent;
    border-radius: 50%;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.pin::before {
    content: "";
    position: absolute;
    inset: -7px;
    border-radius: 50%;
}

.pin-dot {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    border: 2px solid var(--pin-ring);
    border-radius: 50%;
    background: var(--pin);
    color: var(--pin-ring);
    font-size: 13px;
    font-weight: 700;
    line-height: 1;
    font-variant-numeric: tabular-nums;
    box-shadow: 0 2px 6px rgb(10 12 16 / 0.4);
    transition: transform 0.18s var(--ease), opacity 0.18s, box-shadow 0.18s;
}

.pin:hover {
    z-index: 3;
}

.pin:hover .pin-dot {
    transform: scale(1.12);
}

.pin.is-active {
    z-index: 4;
}

.pin.is-active .pin-dot {
    transform: scale(1.22);
    box-shadow: 0 0 0 5px rgb(42 82 201 / 0.4), 0 2px 8px rgb(10 12 16 / 0.45);
}

.pins-layer.has-active .pin:not(.is-active):not(:hover):not(:focus-visible) .pin-dot {
    opacity: 0.72;
}

.pin:focus-visible {
    z-index: 4;
    outline: 3px solid var(--pin-ring);
    outline-offset: 4px;
}

.pin-tip {
    position: absolute;
    left: 50%;
    bottom: calc(100% + 10px);
    transform: translateX(-50%);
    padding: 5px 10px;
    border-radius: 8px;
    background: var(--tip-bg);
    color: var(--tip-text);
    font-size: 13px;
    font-weight: 600;
    line-height: 1.4;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s;
}

.pin:hover .pin-tip,
.pin:focus-visible .pin-tip,
.pin.is-active .pin-tip {
    opacity: 1;
}

.pin.tip-below .pin-tip {
    bottom: auto;
    top: calc(100% + 10px);
}

.pin.tip-start .pin-tip {
    left: -4px;
    transform: none;
}

.pin.tip-end .pin-tip {
    left: auto;
    right: -4px;
    transform: none;
}

/* ---------- 오른쪽 패널 ---------- */

.panel {
    position: sticky;
    top: calc(var(--header-h) + 20px);
    max-height: calc(100dvh - var(--header-h) - 40px);
    overflow-y: auto;
    overscroll-behavior: contain;
    border: 1px solid var(--line);
    border-radius: var(--r-box);
    background: var(--surface);
}

.detail {
    padding: 24px;
    border-bottom: 1px solid var(--line);
}

.detail:focus {
    outline: none;
}

.detail-empty-icon {
    width: 28px;
    height: 28px;
    color: var(--accent-ink);
}

.detail-empty-title {
    margin-top: 12px;
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.detail-empty p {
    margin-top: 6px;
    color: var(--text-muted);
    font-size: 15px;
}

.detail-empty .detail-tip {
    margin-top: 14px;
    font-size: 14px;
}

.detail-tip kbd {
    padding: 2px 7px;
    border: 1px solid var(--line-strong);
    border-radius: 6px;
    background: var(--surface-2);
    font: 600 12px/1.4 var(--font);
    color: var(--text);
}

.detail-head {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 40px;
    margin-bottom: 10px;
}

.detail-where {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
}

.detail-close {
    display: none;
    margin-left: auto;
}

.detail-term {
    font-size: 30px;
    font-weight: 700;
    line-height: 1.25;
    letter-spacing: -0.02em;
}

.detail-term:focus {
    outline: none;
}

.reveal-btn {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    padding: 8px 14px;
    border: 1px dashed var(--line-strong);
    border-radius: var(--r-ctl);
    background: var(--surface-2);
    cursor: pointer;
    font-size: inherit;
}

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

.reveal-label {
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0;
    color: var(--accent-ink);
}

.detail-std {
    margin-top: 10px;
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 2px 10px;
}

.detail-std dt {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
}

.detail-std dd {
    font-size: 17px;
    font-weight: 600;
}

.detail-desc {
    max-width: 62ch;
    margin-top: 16px;
    font-size: 16px;
    line-height: 1.75;
    white-space: pre-line;
}

.detail-desc.is-blank {
    color: var(--text-muted);
}

.detail-note {
    margin-top: 14px;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    color: var(--text-muted);
}

.detail-figure {
    display: block;
    width: 100%;
    margin-top: 18px;
    padding: 0;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--r-ctl);
    background: var(--surface-2);
    text-align: left;
    cursor: zoom-in;
}

.detail-figure img {
    width: 100%;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    transition: transform 0.3s var(--ease);
}

.detail-figure:hover img {
    transform: scale(1.02);
}

.detail-figure-cap {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 9px 12px;
    background: var(--surface);
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
}

.detail-figure-zoom {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.detail-nav {
    margin-top: 20px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.step-btn {
    min-width: 0;
    min-height: 54px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border: 1px solid var(--line);
    border-radius: var(--r-ctl);
    background: var(--surface);
    text-align: left;
    cursor: pointer;
    transition: border-color 0.15s, background-color 0.15s, transform 0.15s var(--ease);
}

.step-btn.is-next {
    justify-content: flex-end;
    text-align: right;
}

.step-btn .icon {
    color: var(--text-muted);
}

.step-text {
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.step-text small {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
}

.step-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 15px;
    font-weight: 600;
}

.step-btn:hover:not(:disabled) {
    border-color: var(--line-strong);
    background: var(--surface-2);
}

.step-btn:active:not(:disabled) {
    transform: translateY(1px);
}

.step-btn:disabled {
    opacity: 0.45;
    cursor: default;
}

/* 목록(범례) */
.legend {
    padding: 16px 12px;
}

.legend-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 0 12px 10px;
}

.legend-title {
    font-size: 16px;
    font-weight: 700;
}

.toggle {
    flex: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 34px;
    padding: 0 12px;
    border: 1px solid var(--line-strong);
    border-radius: var(--r-ctl);
    background: var(--surface);
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}

.toggle:hover {
    background: var(--surface-2);
}

.toggle[aria-pressed="true"] {
    border-color: var(--accent);
    background: var(--accent);
    color: var(--on-accent);
}

.study-hint {
    margin: 0 12px 10px;
    padding: 10px 12px;
    border-radius: var(--r-ctl);
    background: var(--accent-soft);
    color: var(--accent-text);
    font-size: 13px;
    line-height: 1.55;
}

.legend-item {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border: 0;
    border-radius: var(--r-ctl);
    background: transparent;
    text-align: left;
    cursor: pointer;
    transition: background-color 0.12s;
}

.legend-item:hover {
    background: var(--surface-2);
}

.legend-item[aria-current="true"] {
    background: var(--accent-soft);
}

.legend-item[aria-current="true"] .legend-term {
    color: var(--accent-text);
}

.legend-text {
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.legend-term {
    font-size: 16px;
    font-weight: 600;
    line-height: 1.4;
}

.legend-std {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 14px;
    line-height: 1.4;
    color: var(--text-muted);
}

.legend-sub {
    padding: 14px 12px 4px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
}

.legend-empty {
    padding: 4px 12px 8px;
    color: var(--text-muted);
    font-size: 15px;
}

.chips {
    margin-top: 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.chip {
    height: 36px;
    padding: 0 12px;
    border: 1px solid var(--line-strong);
    border-radius: var(--r-ctl);
    background: var(--surface);
    color: var(--text);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}

.chip:hover {
    border-color: var(--accent);
    color: var(--accent-ink);
}

.state-error {
    margin: 4px 12px 8px;
    padding: 16px;
    border-radius: var(--r-ctl);
    background: var(--danger-soft);
    color: var(--danger);
}

.state-error-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
}

.state-error p {
    margin: 4px 0 14px;
    font-size: 14px;
}


/* ---------- 전체 용어 ---------- */

.catalog {
    max-width: 1320px;
    margin: 0 auto;
    padding: 8px 24px 72px;
}

.catalog-head {
    padding-top: 28px;
    border-top: 1px solid var(--line);
}

.catalog-title {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.catalog-sub {
    margin-top: 4px;
    font-size: 15px;
    color: var(--text-muted);
}

.cat-group {
    margin-top: 28px;
}

.cat-group-title {
    margin-bottom: 12px;
    font-size: 16px;
    font-weight: 700;
}

.cat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 12px;
}

.cat-grid > li {
    display: flex;
}

.term-card {
    width: 100%;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: var(--r-box);
    background: var(--surface);
    text-align: left;
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s var(--ease);
}

.term-card:hover {
    border-color: var(--line-strong);
    box-shadow: var(--shadow-sm);
}

.term-card:active {
    transform: translateY(1px);
}

.term-card[aria-current="true"] {
    border-color: var(--accent);
    box-shadow: inset 0 0 0 1px var(--accent);
}

.term-card-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.term-card-term {
    font-size: 17px;
    font-weight: 700;
    line-height: 1.4;
}

.term-card-std {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
}

.term-card-desc {
    margin-top: 6px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    font-size: 14px;
    line-height: 1.55;
    color: var(--text-muted);
}

.term-card-note {
    margin-top: 6px;
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
    color: var(--text-muted);
}

.term-card-thumb {
    width: 56px;
    height: 56px;
    flex: none;
    border-radius: calc(var(--r-box) - 6px);
    object-fit: cover;
    background: var(--surface-2);
}

.sk-card {
    height: 104px;
    border-radius: var(--r-box);
}

.catalog-empty {
    margin-top: 20px;
    padding: 28px 24px;
    border: 1px dashed var(--line-strong);
    border-radius: var(--r-box);
    color: var(--text-muted);
}

.catalog-empty strong {
    display: block;
    margin-bottom: 4px;
    color: var(--text);
    font-size: 17px;
}

/* ---------- 참고 사진 크게 보기 ---------- */

.lightbox {
    max-width: min(92vw, 960px);
    max-height: 94dvh;
    padding: 0;
    border: 0;
    background: transparent;
    overflow: visible;
}

.lightbox::backdrop {
    background: rgb(10 12 16 / 0.8);
}

.lightbox img {
    max-height: calc(94dvh - 56px);
    width: auto;
    margin: 0 auto;
    border-radius: var(--r-box);
}

.lightbox-cap {
    padding-top: 12px;
    color: #e9ebef;
    font-size: 15px;
    font-weight: 600;
    text-align: center;
}

.lightbox-close {
    position: fixed;
    top: 16px;
    right: 16px;
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: rgb(252 252 253 / 0.16);
    color: #fcfcfd;
    cursor: pointer;
}

.lightbox-close:hover {
    background: rgb(252 252 253 / 0.28);
}

/* ---------- 움직임 (설명 가능한 상태 변화만) ---------- */

@media (prefers-reduced-motion: no-preference) {
    .pins-layer.is-entering .pin-dot {
        animation: pin-in 0.34s var(--ease) both;
        animation-delay: calc(var(--i, 0) * 28ms);
    }

    .lightbox[open] {
        animation: fade-in 0.18s ease both;
    }
}

@keyframes pin-in {
    from {
        opacity: 0;
        transform: scale(0.4);
    }
}

@keyframes fade-in {
    from {
        opacity: 0;
    }
}


/* ---------- 반응형 ---------- */

@media (max-width: 1140px) {
    .workspace {
        grid-template-columns: minmax(0, 1fr) 360px;
    }
}

/* 태블릿·모바일: 한 줄 배치, 설명은 아래에서 올라오는 시트 */
@media (max-width: 959.98px) {
    .search {
        order: 3;
        flex-basis: 100%;
        max-width: none;
        margin-left: 0;
    }

    .search + .topbar-actions {
        margin-left: auto;
    }

    .search-kbd,
    .detail-tip {
        display: none;
    }

    .workspace {
        grid-template-columns: minmax(0, 1fr);
        gap: 16px;
        padding: 4px 16px 24px;
    }

    .view-tabs {
        margin: -2px -16px 12px;
        padding: 2px 16px;
        scroll-padding-inline: 16px;
    }

    .stage-hint {
        display: block;
        margin-top: 10px;
        font-size: 14px;
        color: var(--text-muted);
    }

    .panel {
        position: static;
        max-height: none;
        overflow: visible;
    }

    /* 시트 = 머리글 / 본문(스크롤) / 이전·다음(항상 보임) */
    .detail {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 30;
        max-height: min(56dvh, 520px);
        display: flex;
        flex-direction: column;
        overflow: hidden;
        padding: 0;
        border: 1px solid var(--line);
        border-bottom: 0;
        border-radius: var(--r-box) var(--r-box) 0 0;
        background: var(--surface);
        box-shadow: var(--shadow-sheet);
        transform: translateY(105%);
        visibility: hidden;
        transition: transform 0.28s var(--ease), visibility 0s linear 0.28s;
    }

    .detail.is-open {
        transform: none;
        visibility: visible;
        transition: transform 0.28s var(--ease), visibility 0s;
    }

    .detail-head {
        flex: none;
        margin: 0;
        padding: 10px 10px 4px 20px;
    }

    .detail-body {
        flex: 1 1 auto;
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
        padding: 0 20px 16px;
    }

    .detail-nav {
        flex: none;
        margin: 0;
        padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
        border-top: 1px solid var(--line);
    }

    .step-btn {
        min-height: 48px;
    }

    .detail-close {
        display: grid;
    }

    .detail-term {
        font-size: 26px;
    }

    .detail-figure img {
        aspect-ratio: 16 / 9;
    }

    body.sheet-open {
        padding-bottom: var(--sheet-h, 0px);
    }

    .legend {
        padding: 12px 4px;
    }

    .catalog {
        padding: 0 16px 56px;
    }
}

@media (max-width: 560px) {
    .cat-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    .legend-head {
        flex-wrap: wrap;
    }
}
