/* UX layer over the world: compact HUD, context card (left), proximity
   hints beside NPCs / players, the remote player card and Kiki's hello.
   Light, rounded surfaces with small shadows; the world stays the main
   thing on screen. */

/* ---- HUD: title + buttons; coordinates / FPS only with ?debug=1 ---------- */

body:not(.is-debug) .hud {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    padding: 6px 6px 6px 12px;
    color: #1c2333;
    background: rgba(255, 255, 255, 0.92);
    border-radius: 14px;
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.14);
    backdrop-filter: none;
}

body:not(.is-debug) .hud-title {
    margin: 0 4px 0 0;
    white-space: nowrap;
}

body:not(.is-debug) .hud-stats,
body:not(.is-debug) .hud-help {
    display: none;
}

body:not(.is-debug) .hud .avatar-button {
    margin-top: 0;
    min-height: 32px;
}

body:not(.is-debug) .hud .language-button {
    margin-left: 0;
}

/* ---- Context card ----------------------------------------------------------- */

.context-panel {
    position: fixed;
    left: calc(12px + env(safe-area-inset-left, 0px));
    top: calc(64px + env(safe-area-inset-top, 0px));
    z-index: 11;
    width: 252px;
    max-width: calc(100vw - 24px);
    box-sizing: border-box;
    padding: 10px 10px 10px 12px;
    color: #1c2333;
    font-size: 13px;
    background: rgba(255, 255, 255, 0.94);
    border: 1px solid rgba(28, 35, 51, 0.06);
    border-radius: 16px;
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.16);
    pointer-events: auto;
    touch-action: manipulation;
}

body.is-debug .context-panel {
    top: calc(268px + env(safe-area-inset-top, 0px));
}

.context-head {
    display: flex;
    align-items: center;
    gap: 8px;
}

.context-pin {
    flex: none;
    font-size: 15px;
}

.context-heading {
    flex: 1;
    min-width: 0;
}

.context-eyebrow {
    margin: 0;
    font-size: 11px;
    font-weight: 700;
    color: #6b7385;
}

.context-title {
    margin: 0;
    overflow: hidden;
    font-size: 15px;
    font-weight: 800;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.context-toggle {
    flex: none;
    width: 30px;
    height: 30px;
    padding: 0;
    font: inherit;
    font-size: 17px;
    font-weight: 700;
    line-height: 1;
    color: #475569;
    background: #f1f4fa;
    border: 0;
    border-radius: 9px;
    cursor: pointer;
}

.context-toggle:hover { background: #e7ecf5; }

.context-body {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid #eef1f6;
}

.context-section {
    margin: 0 0 4px;
    font-size: 12px;
    font-weight: 800;
    color: #2563eb;
}

.context-section::before {
    content: "⭐ ";
}

.context-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.context-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 44px;
    padding: 6px 8px 6px 4px;
    font: inherit;
    color: inherit;
    text-align: left;
    background: transparent;
    border: 0;
    border-radius: 10px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.context-item:hover:not(:disabled) { background: #f3f6fc; }
.has-place-explorer .context-item:hover:not(:disabled) { background:#eaf2ff;box-shadow:inset 3px 0 #2563eb; }

.context-item.is-active {
    background: #eaf2ff;
    box-shadow: inset 0 0 0 1px #c5d9ff;
}

.context-item:disabled {
    cursor: default;
    opacity: 0.55;
}

.context-item:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 1px;
}

.context-icon {
    flex: none;
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    font-size: 16px;
    background: #f1f4fa;
    border-radius: 9px;
}

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

.context-icon.context-icon-code { font:700 14px/1 ui-monospace,SFMono-Regular,Menlo,monospace;color:#475569; }

.context-label {
    overflow: hidden;
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.context-meta {
    overflow: hidden;
    font-size: 11px;
    color: #6b7385;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.context-item.is-active .context-meta { color: #2563eb; font-weight: 700; }

.context-hint {
    margin: 6px 0 0 4px;
    font-size: 11px;
    color: #7b8496;
}

.context-panel.is-collapsed {
    width: auto;
    max-width: min(240px, calc(100vw - 24px));
    padding: 6px 6px 6px 10px;
}

.context-panel.is-collapsed .context-body,
.context-panel.is-collapsed .context-eyebrow {
    display: none;
}

.context-panel.is-collapsed .context-title { font-size: 13px; }

/* Folded for a lobby (not by the user): pin + "+" only, clear of the stations. */
.context-panel.is-compact .context-heading { display: none; }

/* Existing location pill owns a dropdown; search stays above the scrolling list. */
.context-panel.has-place-explorer { z-index:23; }
.context-panel.has-place-explorer .context-eyebrow { display:none; }
.context-panel.has-place-explorer .context-heading { display:none; }
.context-panel.has-place-explorer .context-toggle { display:flex;align-items:center;gap:6px;width:100%;min-height:44px;height:auto;padding:0 6px;background:transparent;white-space:nowrap;font-size:13px; }
.context-panel.has-place-explorer .context-toggle:hover { background:#eaf2ff; }
.context-panel.has-place-explorer .context-head { gap:0; }
.place-find-label { flex:1;text-align:left; }.place-find-arrow { flex:none;font-size:18px;line-height:1; }
.place-current-location { margin:0;color:#475569;font-size:12px;line-height:1.5;overflow-wrap:anywhere; }
.context-panel.has-place-explorer:not(.is-collapsed) .context-body {
    position:absolute;left:0;top:calc(100% + 6px);box-sizing:border-box;width:min(340px,calc(100vw - 24px));
    max-height:calc(100dvh - 94px - env(safe-area-inset-top,0px));margin:0;padding:12px;
    display:flex;flex-direction:column;gap:8px;background:#fffffff5;border:1px solid #dbe5ef;border-radius:16px;
    box-shadow:0 8px 24px #0f172a26;overflow:auto;overscroll-behavior:contain;
}
.place-search { display:grid;grid-template-columns:1fr 44px;gap:6px;position:sticky;top:0;background:#fff;z-index:1; }
.place-input,.place-filter { min-width:0;width:100%;box-sizing:border-box;min-height:44px;padding:8px 10px;border:1px solid #cbd5e1;border-radius:9px;background:#fff;color:#263a50;font:inherit; }
.place-filter { grid-column:1/-1; }
.place-reset { min-height:44px;border:1px solid #cbd5e1;border-radius:9px;background:#eff6ff;color:#1d4ed8;cursor:pointer;font:inherit;padding:8px 10px; }
.place-results-title { font-size:13px;margin:0; }
.context-panel .place-results { min-height:96px;max-height:30dvh;overflow:auto;flex-shrink:0;overscroll-behavior:contain; }
.context-panel.has-place-explorer .context-section { margin:0;font-size:11px; }
.context-panel.has-place-explorer [data-context=list] .context-item { min-height:44px;padding:4px;font-size:11px; }
.context-panel.has-place-explorer [data-context=list] .context-meta { display:none; }
.place-detail { border-top:1px solid #e2e8f0;padding-top:8px; }
.place-detail[hidden] { display:none; }
.place-detail-name { display:block; }.place-detail-text,.place-status { font-size:12px;margin:6px 0;line-height:1.5; }
.place-empty { padding:12px;color:#64748b; }
.place-input:focus-visible,.place-filter:focus-visible,.place-reset:focus-visible { outline:2px solid #2563eb;outline-offset:1px; }

/* ---- Proximity hint (beside an NPC / another player) ----------------------- */

.interaction-prompt {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 11;
    display: flex;
    gap: 6px;
    pointer-events: auto;
    touch-action: manipulation;
    will-change: transform;
    animation: ccw-fade-in 0.16s ease-out;
}

.prompt-action {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 32px;
    padding: 0 12px 0 6px;
    font: inherit;
    font-size: 13px;
    font-weight: 700;
    color: #1c2333;
    white-space: nowrap;
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid rgba(28, 35, 51, 0.1);
    border-radius: 999px;
    box-shadow: 0 3px 10px rgba(15, 23, 42, 0.18);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.prompt-action:hover { background: #fff; transform: translateY(-1px); }

.prompt-action .key-hint {
    min-width: 20px;
    padding: 0 5px;
    font-size: 11px;
    line-height: 20px;
    color: #fff;
    text-align: center;
    background: #1c2333;
    border: 0;
    border-radius: 6px;
}

.prompt-icon { font-size: 14px; }

.interaction-prompt[data-kind="remote"] .prompt-action { padding-left: 10px; }
/* Another player close by: a small "선택" hint; the 대화 / 프로필 menu opens
   only when that avatar is picked (ProximityController). */
.interaction-prompt[data-kind="remote-hint"] .prompt-action { min-height: 28px; padding: 0 10px 0 6px; font-size: 12px; opacity: 0.92; }
@media (pointer: coarse) {
    .interaction-prompt[data-kind="remote"] .prompt-action,
    .interaction-prompt[data-kind="remote-hint"] .prompt-action { min-height: 44px; }
}

/* Interior station / exit: name (+ status) above the action, centred. */
.interaction-prompt[data-kind="spot"] {
    flex-flow: row wrap;
    justify-content: center;
    align-items: center;
    gap: 4px;
    max-width: 320px;
}

.prompt-title {
    flex-basis: 100%;
    max-width: max-content;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    max-width: 220px;
    padding: 4px 10px;
    font-size: 12px;
    line-height: 1.3;
    color: #1c2333;
    text-align: center;
    background: rgba(255, 255, 255, 0.92);
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.14);
}

.prompt-title strong { font-size: 13px; }
.prompt-note { color: #5b6476; font-size: 11px; }

/* With a key hint, the icon replaces it on touch screens. */
.prompt-icon.is-touch { display: none; }

@media (hover: none), (pointer: coarse) {
    .prompt-icon.is-touch { display: inline; }
    .prompt-action { min-height: 40px; padding: 0 14px; }
}

.prompt-profile {
    width: 210px;
    padding: 10px 12px;
    font-size: 12px;
    color: #1c2333;
    background: rgba(255, 255, 255, 0.97);
    border: 1px solid rgba(28, 35, 51, 0.08);
    border-radius: 14px;
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.2);
}

.prompt-profile-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 4px;
}

.prompt-profile-head strong {
    overflow: hidden;
    font-size: 14px;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.prompt-profile p { margin: 2px 0; }

.prompt-profile-note {
    margin-top: 6px !important;
    color: #7b8496;
    font-size: 11px;
}

.prompt-profile-close {
    flex: none;
    width: 26px;
    height: 26px;
    font-size: 16px;
    line-height: 1;
    color: #475569;
    background: #f1f4fa;
    border: 0;
    border-radius: 8px;
    cursor: pointer;
}

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

/* ---- Kiki hello bubble (beside the dock) ----------------------------------- */

.kiki-bubble {
    display: flex;
    align-items: flex-start;
    gap: 2px;
    max-width: 236px;
    margin-right: 6px;
    padding: 10px 6px 10px 14px;
    color: #1c2333;
    background: #fff;
    border-radius: 16px 16px 4px 16px;
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.2);
    opacity: 0;
    transform: translateY(6px);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.kiki-bubble.is-visible {
    opacity: 1;
    transform: none;
}

.kiki-bubble-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 0;
    font: inherit;
    color: inherit;
    text-align: left;
    background: none;
    border: 0;
    cursor: pointer;
}

.kiki-bubble-text strong { font-size: 14px; }

.kiki-bubble-text span {
    font-size: 13px;
    line-height: 1.4;
}

.kiki-bubble-text .kiki-bubble-cta {
    margin-top: 4px;
    font-size: 12px;
    font-weight: 800;
    color: #2563eb;
}

.kiki-bubble-close {
    flex: none;
    width: 24px;
    height: 24px;
    padding: 0;
    font-size: 15px;
    line-height: 1;
    color: #64748b;
    background: transparent;
    border: 0;
    border-radius: 50%;
    cursor: pointer;
}

.kiki-bubble-close:hover { background: #f1f5f9; }

.kiki-world.is-open .kiki-bubble { display: none; }

@media (prefers-reduced-motion: reduce) {
    .kiki-bubble,
    .interaction-prompt,
    .portal-panel { transition: none; animation: none; }
}

/* ---- Small screens ----------------------------------------------------------- */

@media (max-width: 640px) {
    body:not(.is-debug) .hud { padding: 4px 4px 4px 10px; }
    body:not(.is-debug) .hud-title { display: none; }

    .context-panel { top: calc(56px + env(safe-area-inset-top, 0px)); width: min(252px, calc(100vw - 24px)); }
    body.npc-dialogue-open .context-panel { display: none; }

    .kiki-bubble { max-width: min(220px, calc(100vw - 100px)); }
}

/* Shared scene policy: place search belongs to the world map, while lobbies
   expose one stable route back regardless of their renderer or theme. */
body.is-building-lobby #context-panel { display: none !important; }
body.is-building-lobby .interaction-prompt[data-spot-id="exit"] { display: none !important; }
.lobby-return-button {
    position: fixed;
    top: calc(12px + env(safe-area-inset-top, 0px));
    left: calc(12px + env(safe-area-inset-left, 0px));
    z-index: 24;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-width: 44px;
    min-height: 44px;
    padding: 0 15px;
    border: 1px solid rgba(18, 43, 64, .14);
    border-radius: 12px;
    background: rgba(255, 255, 255, .96);
    color: #193a55;
    box-shadow: 0 3px 12px rgba(15, 23, 42, .16);
    font-family: inherit;
    font-size: 14px;
    font-weight: 700;
    line-height: 1.2;
    cursor: pointer;
    pointer-events: auto;
    touch-action: manipulation;
}
.lobby-return-button[hidden] { display: none !important; }
.lobby-return-button span:first-child { font-size: 19px; line-height: 1; }
.lobby-return-button:hover { background: #f4f8fb; }
.lobby-return-button:focus-visible { outline: 3px solid #47799d; outline-offset: 2px; }
.room-instance-control{position:fixed;z-index:24;top:calc(64px + env(safe-area-inset-top,0px));left:calc(12px + env(safe-area-inset-left,0px));display:grid;gap:5px;max-width:min(220px,calc(100vw - 24px));font:600 12px/1.25 system-ui,-apple-system,"Segoe UI","Noto Sans KR",sans-serif;pointer-events:auto}.room-instance-control[hidden],.room-instance-options[hidden]{display:none!important}.room-instance-current,.room-instance-options button{min-height:38px;padding:7px 11px;border:1px solid rgba(18,43,64,.15);border-radius:10px;background:rgba(255,255,255,.96);color:#193a55;box-shadow:0 3px 12px rgba(15,23,42,.14);font:inherit;text-align:left;touch-action:manipulation}.room-instance-current{cursor:pointer}.room-instance-current:disabled{cursor:default;opacity:.88}.room-instance-options{display:grid;gap:4px;padding:5px;border:1px solid rgba(18,43,64,.12);border-radius:12px;background:rgba(255,255,255,.96);box-shadow:0 4px 16px rgba(15,23,42,.16)}.room-instance-options button{width:100%;box-shadow:none;cursor:pointer}.room-instance-options button:focus-visible,.room-instance-current:focus-visible{outline:3px solid #47799d;outline-offset:2px}.room-instance-options button:hover{background:#eef5f8}

@media (max-width: 640px) {
    .lobby-return-button { min-height: 48px; padding-inline: 14px; }
    .room-instance-control{top:calc(70px + env(safe-area-inset-top,0px));font-size:11px}.room-instance-current,.room-instance-options button{min-height:42px;padding-inline:10px}
}

/* Video classroom: the canvas-drawn course detail display (VideoDiscoveryRoom). */
.video-detail-guard { position: fixed; pointer-events: none; opacity: 0; }
@media (max-width: 649px) {
    body.video-detail-open .ccw-chat { display: none; }
}
@media (max-width: 649px) {
    /* Phone video classroom: search and categories fit the screen width
       (the board they sit on is wider than the phone view). */
    .course-space-ui [data-discovery=search] { left: 12px !important; width: calc(100vw - 24px) !important; transform: none !important; }
    .course-space-ui [data-discovery=category-chips] { left: 12px !important; width: calc(100vw - 24px) !important; transform: none !important; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
    .course-space-ui [data-discovery=category-chips] > button { flex: 0 0 auto; }
    /* Detail view: the course detail has the screen. */
    body.video-detail-open .course-space-ui [data-discovery=search],
    body.video-detail-open .course-space-ui [data-discovery=category-chips],
    body.video-detail-open .course-space-ui [data-discovery=previous],
    body.video-detail-open .course-space-ui [data-discovery=next] { display: none !important; }
}
