:root {
  --bg: #15171b;
  --card: #1f2227;
  --line: #2c3037;
  --text: #e8e9ec;
  --dim: #8b9099;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", system-ui, sans-serif;
  display: flex; justify-content: center; align-items: center;
  padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
}
.card {
  position: relative; width: min(100%, 720px); height: min(100dvh - 24px, 860px);
  background: radial-gradient(120% 80% at 35% 35%, #2a2e35 0%, var(--card) 60%);
  border-radius: 20px; overflow: hidden;
  display: grid; grid-template-rows: 1fr auto auto; grid-template-columns: minmax(0, 1fr);
}
.card > * { min-width: 0; }
.chars { position: absolute; top: 18px; left: 18px; display: flex; gap: 6px; z-index: 2; }
.chars button {
  font: inherit; font-size: 13px; color: var(--dim); background: #ffffff0d;
  border: 1px solid var(--line); border-radius: 99px; padding: 5px 11px; cursor: pointer;
}
.chars button[aria-pressed="true"] { color: #111; background: #f3f3f3; border-color: #f3f3f3; font-weight: 700; }

.stage { position: relative; min-height: 0; display: flex; align-items: center; justify-content: flex-start; padding: 56px 0 0 2%; }
.fig { width: min(64%, 440px); aspect-ratio: 1; position: relative; }
.fig-body { position: absolute; inset: 0; transform-origin: 50% 92%; will-change: transform; }
.fig-body img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; opacity: 0; transition: opacity .12s linear; user-select: none; }
.fig-body img.on { opacity: 1; }

.panel {
  position: absolute; top: 20px; right: 20px; width: 236px;
  font: 11.5px/1.75 var(--mono); color: var(--dim); pointer-events: none;
}
.panel h3 { font: inherit; font-size: 11px; font-weight: 700; color: #b5bac2; margin: 12px 0 4px; }
.panel dl { display: grid; grid-template-columns: 52px 1fr; }
.panel dd { color: var(--text); display: flex; align-items: center; gap: 6px; }
.panel dd b { font-weight: 700; }
.panel dd span#emoKo { color: var(--dim); }
.panel i, .panel li::before { width: 7px; height: 7px; border-radius: 50%; display: inline-block; flex: none; }
.panel ul { list-style: none; }
.panel li { display: grid; grid-template-columns: 78px 1fr 44px; align-items: center; gap: 6px; }
.panel li span:first-child { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.panel li.top span:first-child { color: var(--text); font-weight: 700; }
.bar { height: 5px; background: #ffffff12; border-radius: 3px; overflow: hidden; display: block; flex: 1; }
.bar s { display: block; height: 100%; width: 0; border-radius: 3px; background: #f2c94c; transition: width .18s ease-out; }
.panel .cues { grid-column: 1 / -1; margin: 2px 0 4px; min-width: 0; }
.cues .lab { color: var(--dim); flex: none; white-space: nowrap; }
.cues .track { display: flex; gap: 4px; min-width: 0; overflow-x: auto; white-space: nowrap; scrollbar-width: none; pointer-events: auto; }
.cues .track::-webkit-scrollbar { display: none; }
.cues .none { color: #5d626b; }
.chip { flex: none; display: inline-flex; align-items: center; gap: 4px; padding: 0 7px; border-radius: 99px; line-height: 1.7;
  border: 1px solid color-mix(in srgb, var(--c) 55%, transparent); background: color-mix(in srgb, var(--c) 14%, transparent); color: var(--dim); }
.chip b { color: var(--text); font-weight: 700; }
.chip.flip { border-style: dashed; }
.chip s { color: #6b7079; }
.panel em { font-style: normal; color: var(--text); text-align: right; min-width: 40px; }
.panel li em { min-width: 0; }

.input {
  position: relative; margin: 0 18px; border: 2px solid #e9e9e9; border-radius: 18px;
  background: #15171b; padding: 14px 18px 38px;
}
.input textarea {
  width: 100%; resize: none; border: 0; outline: 0; background: transparent; color: var(--text);
  font: inherit; font-size: 17px; line-height: 1.55;
}
.input textarea::placeholder { color: #5d626b; }
.status { position: absolute; right: 18px; bottom: 10px; font-size: 13px; color: var(--dim); display: flex; align-items: center; gap: 7px; }
.status i { width: 9px; height: 9px; border-radius: 50%; background: #4a4f57; }
.status.busy i { background: #f2c94c; }
.status.ok i { background: #6fcf97; }
.foot { font-size: 11px; color: #4f545c; text-align: center; padding: 8px 0 10px; }

@media (max-width: 560px) {
  html, body { overflow: hidden; overscroll-behavior: none; }
  body { padding: 0; align-items: stretch; }
  .card {
    width: 100%; height: var(--app-h, 100dvh); border-radius: 0;
    grid-template-rows: minmax(0, 1fr) auto auto auto;
    padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
  }
  .chars { top: calc(14px + env(safe-area-inset-top)); left: 14px; }
  .stage { padding: 50px 0 2px; justify-content: center; align-items: center; }
  .fig { height: 100%; width: auto; max-width: 84%; }
  .panel { position: static; width: auto; margin: 0 16px 8px; font-size: 10.5px; line-height: 1.6; }
  .panel h3 { margin-top: 6px; }
  .panel h3:nth-of-type(2), .panel #params, .panel h3:nth-of-type(3), .panel .meta { display: none; }
  #probs { columns: 2; column-gap: 14px; }
  .panel li { grid-template-columns: 50px 1fr 34px; break-inside: avoid; }
  .input { margin: 0 12px; padding: 12px 14px 34px; border-radius: 16px; }
  .input textarea { font-size: 16px; } /* 16px 미만이면 iOS 가 입력할 때 화면을 확대한다 */
  .foot { padding: 6px 0 8px; }
}
/* 작은 폰(SE 등): 확률표는 접고 표정·강도·어순만 */
@media (max-width: 560px) and (max-height: 720px) {
  .panel h3, #probs { display: none; }
  .panel .head dt:nth-of-type(3), #level { display: none; }
  .input textarea { height: 3.2em; }
}
@media (max-width: 360px) { .chars button { font-size: 12px; padding: 4px 9px; } }
/* 키보드가 올라오면 캐릭터·읽은 단어 한 줄·입력창만 */
.kb .foot { display: none; }
.kb .panel { display: block; margin: 0 12px 6px; }
.kb .panel > :not(.head), .kb .panel .head > :not(#cuesRow) { display: none; }
.kb .stage { padding-top: 46px; }
.kb .input textarea { height: 3.2em; }
/* 가로 모드 폰: 캐릭터 왼쪽, 판정·입력 오른쪽 */
@media (max-height: 500px) and (orientation: landscape) {
  body { padding: 0; }
  .card { width: 100%; height: var(--app-h, 100dvh); border-radius: 0; grid-template-columns: 45% minmax(0, 1fr); grid-template-rows: 1fr auto auto; }
  .stage { grid-row: 1 / 4; padding: 44px 0 8px; justify-content: center; }
  .fig { height: 100%; width: auto; }
  .panel { position: static; grid-column: 2; width: auto; margin: 14px 16px 6px 0; overflow: auto; }
  .panel h3:nth-of-type(2), .panel #params, .panel h3:nth-of-type(3), .panel .meta { display: none; }
  #probs { columns: 2; column-gap: 12px; }
  .input { grid-column: 2; margin: 0 16px 0 0; }
  .input textarea { font-size: 16px; height: 3.2em; }
  .foot { grid-column: 2; }
}
