/* ==========================================================================
   roles.css (2026-10-11) — 맨 마지막에 읽는다.
   1) 해설 자막: 이름 없는 목소리 (이름표·📖·그림 없음, 기울임 · 중립색)
   2) 꼬미 = 강아지 친구 (첫 인사 그림·이름)
   3) 여러 입장에서 말해 보기: 역할 고르기 · 장면의 "나" 표시 · 결과 화면 "이번엔 ○○가 되어 볼까?" · 카드의 해 본 표시
   4) 화면별 맞춤: 폰 가로(손가락, 낮은 높이) / PC(마우스, 넓은 화면) — UA 가 아니라 미디어 쿼리로 나눈다
   ========================================================================== */

:root {
  --narr-ink: #5d5348;            /* 해설 글자 (중립 갈색 회색) */
  --narr-ink-dark: #efe6da;       /* 어두운 자막 띠 위 해설 글자 */
  --me-ring: #5aa9e6;             /* 아이가 맡은 친구 표시 */
  --me-ink: #1f5f8f;
  --tap-min: 44px;                /* 손가락 최소 크기 */
}

/* ------------------------------------------------------------------ 1. 해설 */
.narr-tag { display: none !important; }   /* 예전 '꼬미' 이름표는 어디에도 보이지 않는다 */
#stage-floor > .stage-caption.is-guide { font-style: italic; color: var(--narr-ink-dark); gap: 8px; padding-left: 16px; }
#stage-floor > .stage-caption.is-guide .narr-text { font-style: italic; font-weight: 600; letter-spacing: .01em; }
#stage-floor > .stage-caption:not(.is-guide) { font-style: italic; }
.bubble-caption.is-narration {
  align-self: center; max-width: 92%;
  font-style: italic; font-weight: 600; color: var(--narr-ink);
  background: rgba(255, 252, 245, .72); border: 1.5px dashed rgba(138, 122, 104, .45);
  border-radius: 14px; padding: 7px 14px; text-align: center; word-break: keep-all;
}
.bubble-caption.is-narration.has-replay { display: inline-flex; align-items: center; gap: 8px; }
.bubble-caption.is-narration .bubble-replay { flex: none; font-style: normal; }
.log-line.is-narrator .log-who:empty { display: none; }
.log-line.is-narrator .log-text { font-style: italic; color: var(--narr-ink); }
.practice-bubble.is-narration { font-style: italic; }
.practice-bubble.is-narration .pb-text { color: var(--narr-ink); }
#stage-prompt-text, #home-hint-text { font-style: normal; }
.reflection-box #ending-reflection-text { font-style: italic; color: var(--narr-ink); }

/* ------------------------------------------------------------------ 2. 꼬미 (강아지 친구) 첫 인사 */
.pip-greet-kkomi { max-width: 150px; }
.pip-greet-name {
  display: block; width: max-content; margin: 0 auto 4px; padding: 1px 10px; border-radius: 999px;
  background: #ffe9c7; color: #8a4b12; font-size: .82rem; font-weight: 800; font-style: normal;
}
/* 토리 오른쪽 길 위 (왼쪽 '놀이터' 표지판과 겹치지 않게) */
.meadow-chick.meadow-kkomi { left: 55%; bottom: 9%; width: 21cqh; z-index: 2; }   /* 꼬미 16cm ≥ 토리 15cm */
.meadow-kkomi img { animation-delay: .4s; }

/* ------------------------------------------------------------------ 3-a. 역할 고르기 */
.role-pick {
  position: fixed; inset: 0; z-index: 950;
  display: flex; align-items: center; justify-content: center;
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: rgba(26, 18, 10, .62); animation: overlay-in .3s ease both;
}
.role-pick-card {
  width: min(760px, 100%); max-height: 100%; overflow: auto;
  background: var(--paper, #fffaf0); border: 3px solid var(--line-strong, #e3c98f); border-radius: 26px;
  padding: 18px 22px 16px; text-align: center; box-shadow: 0 18px 40px rgba(0, 0, 0, .35);
}
.role-pick-ep { margin: 0; font-size: .86rem; color: #8a7a68; font-weight: 700; }
.role-pick-title { margin: 2px 0 2px; font-family: var(--font-display, inherit); font-size: 1.7rem; color: var(--ink, #3b2f24); }
.role-pick-sub { margin: 0 0 12px; font-size: .92rem; color: #6b5d4f; word-break: keep-all; }
.role-pick-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.role-card {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px;
  min-height: var(--tap-min); padding: 12px 12px 14px; cursor: pointer;
  background: #fff; border: 3px solid #eadcc2; border-radius: 22px; color: var(--ink, #3b2f24);
  font: inherit; transition: transform .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.role-card .role-art { width: auto; height: 132px; max-width: 100%; object-fit: contain; filter: drop-shadow(0 6px 8px rgba(60, 40, 20, .2)); }
.role-card .role-art-avatar { display: inline-flex; width: 132px; height: 132px; align-items: center; justify-content: center; }
.role-card .role-art-avatar img { width: 100%; height: 100%; object-fit: contain; }
.role-name { font-family: var(--font-display, inherit); font-size: 1.25rem; }
.role-feel { font-size: .88rem; color: #6b5d4f; word-break: keep-all; line-height: 1.35; }
.role-card.is-default { border-color: var(--me-ring); box-shadow: 0 0 0 4px rgba(90, 169, 230, .22); }
.role-card:active { transform: scale(.97); }
.role-card:focus-visible { outline: 3px solid #2563eb; outline-offset: 3px; }
.role-done, .role-rec {
  position: absolute; top: 8px; right: 10px; padding: 2px 9px; border-radius: 999px; font-size: .78rem; font-weight: 800;
}
.role-done { background: #dcf3dc; color: #2f7a31; }
.role-rec { background: #e3f1fc; color: var(--me-ink); }
.role-key {
  position: absolute; top: 8px; left: 10px; width: 24px; height: 24px; border-radius: 7px;
  display: none; align-items: center; justify-content: center;
  background: #f4ead8; color: #8a6a3a; font-size: .8rem; font-weight: 800; font-style: normal;
}
.role-pick-back {
  margin-top: 12px; min-height: var(--tap-min); padding: 0 18px; border-radius: 999px; cursor: pointer;
  background: transparent; border: 2px solid #e3d3b6; color: #6b5d4f; font: inherit; font-weight: 700;
}

/* ------------------------------------------------------------------ 3-b. 장면: 내가 맡은 친구 */
.char-chip.is-me .char-chip-name { background: var(--me-ring); color: #fff; box-shadow: 0 0 0 2px #fff; }
.char-chip.is-me .char-chip-avatar::before { background: rgba(90, 169, 230, .45); width: 82%; height: 18px; filter: blur(2px); }
.char-chip-me {
  position: absolute; left: 50%; top: -4px; translate: -50% 0; z-index: 3;
  min-width: 30px; padding: 1px 8px; border-radius: 999px; pointer-events: none;
  background: var(--me-ring); color: #fff; font-size: .78rem; font-weight: 900; text-align: center;
  box-shadow: 0 0 0 2px #fff, 0 3px 8px rgba(0, 0, 0, .25);
}
.speech-float.is-me .speech-body { border-color: var(--me-ring); background: #eef7ff; }
.speech-float.is-me strong { color: var(--me-ink); }
#stage-subtitle.is-me .sub-who { color: #9fd3ff; }
.log-line.is-me .log-who, .log-line.is-child .log-who { color: var(--me-ink); }
.bubble-row.is-me .bubble { border-color: var(--me-ring); background: #eef7ff; }
.stage-role-chip {
  flex: none; display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px 0 4px;
  border-radius: 999px; background: #eef7ff; border: 2px solid var(--me-ring); color: var(--me-ink);
  font-size: .86rem; font-weight: 700; white-space: nowrap;
}
.stage-role-chip .src-art { width: 26px; height: 26px; object-fit: contain; }
.stage-role-chip .role-art-avatar { display: inline-flex; width: 26px; height: 26px; }
.stage-role-chip .role-art-avatar img { width: 100%; height: 100%; object-fit: contain; }

/* ------------------------------------------------------------------ 3-c. 결과 화면: 이번엔 ○○가 되어 볼까? */
.ending-roles {
  width: 100%; margin: 6px 0 10px; padding: 8px 10px; text-align: center;
  background: #f3f9ff; border: 2px solid #cfe5f7; border-radius: 18px;
}
.er-top { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 4px 10px; }
.er-head { margin: 0; font-family: var(--font-display, inherit); font-size: 1.12rem; color: var(--me-ink); }
.er-progress { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.er-feel { margin: 8px 0 4px; padding: 8px 10px; border-radius: 16px; background: rgba(243, 249, 255, .85); border: 1.5px solid #dbe9f5; }
.er-step { padding: 2px 10px; border-radius: 999px; background: #fff; border: 1.5px solid #dfe9f2; color: #7a8796; font-size: .82rem; font-weight: 700; }
.er-step.is-done { background: #e3f5e1; border-color: #b6dfb1; color: #2f7a31; }
.er-q { margin: 2px 0 4px; font-size: .9rem; font-weight: 700; color: #4a5866; }
.er-feel-row { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.er-chip {
  min-height: 36px; padding: 0 12px; border-radius: 999px; cursor: pointer;
  background: #fff; border: 1.5px solid #cfdcea; color: #3d4b59; font: inherit; font-size: .85rem; font-weight: 700;
}
.er-chip.is-on { background: var(--me-ring); border-color: var(--me-ring); color: #fff; }
.er-feel-reply { margin: 6px 0 0; font-size: .85rem; font-style: italic; color: var(--narr-ink); }
.er-again { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 6px; }
.er-role-btn {
  position: relative; display: flex; align-items: center; gap: 10px; min-height: 56px; padding: 6px 14px 6px 8px;
  border-radius: 18px; cursor: pointer; text-align: left;
  background: #fff; border: 3px solid var(--me-ring); color: var(--ink, #3b2f24); font: inherit;
  box-shadow: 0 4px 0 #b8d8f0;
}
.er-role-btn .er-art { height: 52px; width: auto; object-fit: contain; }
.er-role-btn .role-art-avatar { display: inline-flex; width: 52px; height: 52px; }
.er-role-btn .role-art-avatar img { width: 100%; height: 100%; object-fit: contain; }
.er-role-text { display: flex; flex-direction: column; line-height: 1.25; }
.er-role-text b { font-size: 1.02rem; }
.er-role-text small { font-size: .78rem; color: #6b5d4f; }
.er-role-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 #b8d8f0; }
.er-role-btn .role-key { top: -8px; left: -8px; }

/* ------------------------------------------------------------------ 3-d. 새 메시지 카드: 친구별로 해 봤는지 */
.ep-roles { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.ep-role { padding: 1px 8px; border-radius: 999px; background: #f2f6fa; color: #6f7c89; font-size: .74rem; font-weight: 700; }
.ep-role.is-done { background: #e3f5e1; color: #2f7a31; }

/* ==========================================================================
   4-a. 폰 가로 (손가락 · 낮은 높이: 844×390, 915×412, 740×360)
   - 위 띠를 얇게, 장면이 높이 대부분을 쓴다, 페이지가 스크롤되지 않는다
   - 고르는 말(연습 말풍선·아까 연습한 말·추천 문장)은 가로로 밀어 보는 한 줄
   - 누르는 것은 모두 44px 이상, 마이크는 크게
   ========================================================================== */
@media (pointer: coarse) and (orientation: landscape) and (max-height: 500px) {
  html, body { overscroll-behavior: none; }
  #screen-stage { overflow: hidden; }
  #screen-stage .stage-topbar { min-height: 0; padding-top: 2px; padding-bottom: 2px; gap: 6px; }
  #screen-stage .stage-topbar .stage-brand { display: none; }
  #screen-stage .stage-topbar .icon-btn, #screen-stage .back-btn { min-width: var(--tap-min); min-height: var(--tap-min); }
  .stage-role-chip { height: 30px; font-size: .8rem; padding-right: 10px; }

  /* 가로로 밀어 보는 고르기 줄 */
  .practice-choices, #stage-examples-row, .mic-rest-suggest {
    display: flex !important; flex-direction: row !important; flex-wrap: nowrap !important; overflow-x: auto; overflow-y: hidden;
    grid-template-columns: none !important; max-height: none !important;
    gap: 8px; scroll-snap-type: x proximity; -webkit-overflow-scrolling: touch; scrollbar-width: none;
    padding-bottom: 2px;
  }
  .practice-choices::-webkit-scrollbar, #stage-examples-row::-webkit-scrollbar, .mic-rest-suggest::-webkit-scrollbar { display: none; }
  .practice-choices > *, #stage-examples-row > *, .mic-rest-suggest > * {
    flex: 0 0 auto; max-width: 72vw; scroll-snap-align: start; min-height: var(--tap-min);
  }
  .practice-choice { width: auto !important; }
  .practice-choice .practice-bubble { white-space: nowrap; width: auto; }
  #btn-practice-fold, #btn-practice-skip, #btn-practice-next { min-height: var(--tap-min); }
  .mic-rest-chip { min-height: var(--tap-min); white-space: nowrap; }

  /* 손가락 크기 */
  .char-chip { min-width: var(--tap-min); min-height: var(--tap-min); }
  .bubble-replay, .sub-replay, #btn-prompt-replay, #btn-subtitle-replay { min-width: var(--tap-min); min-height: var(--tap-min); }
  #btn-text-send, .mic-confirm .btn { min-height: var(--tap-min); }
  #btn-mic.mic-btn { min-width: 64px; min-height: 64px; }

  /* 장면이 높이 대부분: 아래 이야기 판을 한 줄로 (질문 ← → 큰 마이크). 일반 안내 줄은 질문이 보이면 숨긴다 */
  #screen-stage .stage-tools .stage-pill, #screen-stage .stage-tools .back-btn.stage-pill, #screen-stage .stage-tools .icon-btn.stage-pill {
    height: var(--tap-min); min-height: var(--tap-min); padding: 0 12px;
  }
  #screen-stage { --top-h: 46px; }
  .screen-stage:not(.is-practicing) .stage-side {
    flex-direction: row; flex-wrap: wrap; align-items: center; justify-content: center; column-gap: 12px; row-gap: 4px;
    min-height: 0;
  }
  .screen-stage:not(.is-practicing) .stage-side > * { width: auto; }
  .screen-stage:not(.is-practicing) .stage-side > .stage-examples,
  .screen-stage:not(.is-practicing) .stage-side > .demo-banner,
  .screen-stage:not(.is-practicing) .stage-side > .transfer-bar,
  .screen-stage:not(.is-practicing) .stage-side > .safety-panel { flex: 1 1 100%; }
  .stage-side:has(> .stage-prompt:not([hidden])) > .stage-hint { display: none; }
  .screen-stage:not(.is-practicing) .stage-side > .stage-prompt { flex: 0 1 auto; min-width: 0; text-align: left; justify-content: flex-start; }
  .screen-stage:not(.is-practicing) .stage-side > .stage-footer { flex: none; }
  html.mic-resting .screen-stage:not(.is-practicing) .stage-side > .stage-footer { flex: 1 1 100%; }
  .stage-side > .stage-prompt .icon-btn.small { width: var(--tap-min); height: var(--tap-min); min-width: var(--tap-min); min-height: var(--tap-min); }
  .mic-btn, .screen-stage.is-practicing .mic-btn { width: 64px; height: 64px; }
  .mic-hint { display: none; }
  .stage-hint .icon-btn, #btn-stage-hint-close { width: var(--tap-min); height: var(--tap-min); min-width: var(--tap-min); min-height: var(--tap-min); }
  .stage-main > .stage-skills .stage-chip, .stage-main > .stage-objects .object-chip { min-height: var(--tap-min); }

  /* 결과 화면 · 홈: 손가락 크기 */
  .back-btn, .icon-btn, .gear-btn { min-width: var(--tap-min); min-height: var(--tap-min); }
  #btn-replay-reflection { width: var(--tap-min); height: var(--tap-min); }
  .er-chip { min-height: var(--tap-min); }

  /* 역할 고르기: 낮은 화면에서는 그림을 작게, 두 카드를 한 줄로 */
  .role-pick-card { padding: 10px 16px 10px; border-radius: 20px; }
  .role-pick-title { font-size: 1.3rem; }
  .role-pick-sub { margin-bottom: 8px; font-size: .82rem; }
  .role-pick-list { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .role-card { flex-direction: row; text-align: left; padding: 8px 12px; gap: 10px; }
  .role-card .role-art, .role-card .role-art-avatar { height: 84px; width: auto; flex: none; }
  .role-card .role-name { font-size: 1.05rem; }
  .role-card .role-feel { font-size: .8rem; }
  .role-pick-back { margin-top: 8px; }
  .role-card > .role-name, .role-card > .role-feel { display: block; }
  .role-card { display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 10px; align-items: center; }
  .role-card .role-art, .role-card .role-art-avatar { grid-row: 1 / span 2; }
  .role-card .role-name { align-self: end; }
  .role-card .role-feel { align-self: start; }

  /* 결과 화면의 다시 하기 */
  .ending-roles { padding: 6px 8px; margin: 2px 0 6px; }
  .er-head { font-size: 1rem; margin-bottom: 4px; }
  .er-role-btn { min-height: 48px; }
  .er-role-btn .er-art { height: 42px; }
}

/* ==========================================================================
   4-b. PC (마우스 · 넓은 화면: 1280×720 ~ 1920×1080)
   - 가운데 무대 폭을 정하고 글자를 키운다, 마우스를 올리면 반응, 단축키 표시(1~4 · Enter · Space)
   ========================================================================== */
@media (pointer: fine) and (min-width: 1200px) and (min-height: 650px) {
  :root { --side-w: clamp(340px, 30%, 520px); }
  #app { max-width: 1760px; max-height: 990px; }
  html { font-size: clamp(16px, calc(var(--frame-h) / 42), 22px); }

  /* 마우스를 올리면 */
  .role-card:hover { transform: translateY(-3px); border-color: var(--me-ring); box-shadow: 0 10px 24px rgba(31, 95, 143, .18); }
  .er-role-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 0 #b8d8f0; }
  .er-chip:hover, .mic-rest-chip:hover, .practice-choice:hover .practice-bubble { border-color: var(--me-ring); background: #f3f9ff; }
  .char-chip:not(.is-me):hover .char-chip-name { background: #fff3c4; }
  .char-chip:not(.is-me):hover .char-chip-img { filter: drop-shadow(0 0 6px rgba(255, 205, 70, .8)) drop-shadow(0 4px 6px rgba(60, 40, 20, .28)); }
  .episode-card:hover { transform: translateY(-2px); box-shadow: 0 10px 22px rgba(92, 64, 30, .16); }
  .btn:hover { filter: brightness(1.04); }
  .char-chip, .role-card, .er-role-btn, .episode-card, .mic-btn { cursor: pointer; }

  /* 단축키 표시 */
  .role-key { display: inline-flex; }
  .practice-choices, #stage-examples-row, .mic-rest-suggest { counter-reset: kb; }
  .practice-choice, #stage-examples-row > *, .mic-rest-chip { position: relative; counter-increment: kb; }
  .practice-choice:nth-child(-n+4)::before, #stage-examples-row > :nth-child(-n+4)::before, .mic-rest-chip:nth-child(-n+4)::before {
    content: counter(kb); position: absolute; top: -8px; left: -6px; z-index: 2;
    width: 20px; height: 20px; border-radius: 6px; display: flex; align-items: center; justify-content: center;
    background: #f4ead8; color: #8a6a3a; font-size: .72rem; font-weight: 800; font-style: normal;
    box-shadow: 0 1px 0 #d9c6a3;
  }
  /* 마이크 아래 '눌러서 말하기' 글자 뒤에 단축키 (글자를 겹쳐 놓지 않는다) */
  .mic-hint::after {
    content: "Space"; display: inline-block; margin-left: 6px; padding: 0 6px; border-radius: 5px;
    background: #f4ead8; color: #8a6a3a; font-size: .72em; font-weight: 800; letter-spacing: .03em; vertical-align: 1px;
    box-shadow: 0 1px 0 #d9c6a3;
  }
  .role-pick-title { font-size: 2rem; }
  .role-card .role-art { height: 170px; }
}
