/* 모바일(v4.71, MO-1): 휴대폰·태블릿(터치만 있고 마우스가 없는 기기)에서만 켜진다(client/js/mobile.js가 html에 is-mobile).
   PC에는 이 파일의 어떤 규칙도 걸리지 않는다(모두 html.is-mobile 아래). 세로 화면 고정(가로면 돌려 달라는 안내).
   --app-h·--app-top: 화면 키보드를 뺀 보이는 높이와 위치(visualViewport). 필드는 위, 입력칸은 키보드 바로 위.
   v4.81: 시스템 자판 대신 게임 두벌식 자판(콘솔 맨 아래), 생명력 막대·아이콘 한 줄, 필드 축소(--field-zoom) */

html.is-mobile,
html.is-mobile body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

html.is-mobile body {
  position: fixed;
  inset: 0;
  touch-action: manipulation;
}

/* 길게 눌러도 글자 고르기·그림 저장 메뉴가 뜨지 않게(입력칸은 그대로) */
html.is-mobile #game,
html.is-mobile .login-screen {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

/* 필드는 터치를 스스로 다룬다(스크롤·확대 없이 바로 이동, 터치를 막을 수 있게) */
html.is-mobile #field-canvas {
  touch-action: none;
}

html.is-mobile input,
html.is-mobile textarea {
  -webkit-user-select: text;
  user-select: text;
}

/* ── 게임 화면: 한 열(필드 위, 콘솔 아래), 보이는 높이에 맞춘다 ── */
html.is-mobile .app {
  position: fixed;
  top: var(--app-top, 0px);
  right: 0;
  left: 0;
  grid-template-columns: minmax(0, 1fr);
  gap: 4px;
  height: var(--app-h, 100dvh);
  padding: 4px;
}

html.is-mobile .main-column {
  gap: 4px;
}

/* HUD: 작게, 줄바꿈 허용. 볼륨 막대는 숨기고(기기 볼륨) 이름표 글자는 뺀다 */
html.is-mobile .hud {
  flex-wrap: wrap;
  gap: 3px;
  padding: 4px;
}

html.is-mobile .hud-box {
  padding: 2px 6px;
  font-size: 11px;
}

html.is-mobile .hud-label,
html.is-mobile .sound-volume,
html.is-mobile #boss-gauge-box .hud-label {
  display: none;
}

html.is-mobile .hud-right {
  flex-wrap: wrap;
  gap: 3px;
}

html.is-mobile .boss-bar {
  width: 54px;
  min-width: 40px;
}

html.is-mobile .hud-button {
  padding: 3px 7px;
  font-size: 11px;
}

/* 필드 위의 것들: 작게 */
html.is-mobile .skill-bar {
  bottom: 4px;
  left: 4px;
  transform: scale(0.68);
  transform-origin: left bottom;
}

html.is-mobile .minimap {
  right: 4px;
  bottom: 4px;
  transform: scale(0.55);
  transform-origin: right bottom;
}

html.is-mobile .party-frame {
  bottom: 120px;
  left: 4px;
  transform: scale(0.75);
  transform-origin: left bottom;
}

html.is-mobile .chat-box {
  top: 108px; /* HUD가 세 줄까지 접혀도 겹치지 않게 */
  left: 4px;
  width: 64%;
  font-size: 11px;
}

html.is-mobile .chat-log {
  max-height: 64px;
}

html.is-mobile .boss-stack > .boss-panel {
  width: 100%;
}

/* 레이드 카드(v4.88): 채팅 아래 오른쪽에 작게 */
html.is-mobile .raid-card {
  top: 108px;
  right: 4px;
  transform: scale(0.72);
  transform-origin: top right;
}

/* ── 콘솔(v4.81): 위에 생명력 막대·경험치, 타자 입력칸, 아이콘 한 줄(물약 1~4·캐릭터·능력치·길드·펫), 그 아래 게임 두벌식 자판.
   치명타 구슬·능력치 다섯·로그·도감 단추는 숨긴다(로그는 캐릭터 창의 [로그] 탭에 있다) ── */
html.is-mobile .console {
  --orb-size: 0px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 4px 6px;
  height: auto;
  padding: 5px 5px 4px;
  border-radius: 6px;
}

html.is-mobile .console-center {
  display: contents; /* 경험치·입력·아이콘 줄이 콘솔 격자의 칸이 된다 */
}

html.is-mobile .orb-crit,
html.is-mobile .console-stats,
html.is-mobile #open-log,
html.is-mobile #items-guide-button {
  display: none;
}

/* 생명력: 구슬 대신 막대(--hp-ratio, statusView) */
html.is-mobile .orb-hp {
  position: relative;
  inset: auto;
  grid-column: 1;
  grid-row: 1;
  width: auto;
  height: 18px;
  border-radius: 4px;
  border: 1px solid #5a1d17;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.8);
  background: #120806;
}

html.is-mobile .orb-hp::before,
html.is-mobile .orb-hp::after,
html.is-mobile .orb-hp .orb-shine {
  display: none;
}

html.is-mobile .orb-hp .orb-liquid {
  position: absolute;
  inset: 0 auto 0 0;
  width: calc(var(--hp-ratio, 1) * 100%);
  height: 100% !important; /* PC 구슬은 높이로 그린다 */
  border-radius: 0;
  background: linear-gradient(180deg, #ff6a55, #c4241a 55%, #7a120c);
  transition: width 0.25s;
}

html.is-mobile .orb-hp .orb-text {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 5px;
  line-height: 1;
  white-space: nowrap;
  transform: none;
}

html.is-mobile .orb-hp .orb-text small {
  font-size: 10px;
}

html.is-mobile .orb-hp .orb-text b {
  font-size: 11px;
}

html.is-mobile .console-exp {
  grid-column: 2;
  grid-row: 1;
  gap: 4px;
  font-size: 10px;
}

html.is-mobile .console-exp-bar {
  height: 18px;
}

/* 타자 입력칸(시스템 자판을 띄우지 않는 readonly 칸, 게임 자판이 채운다). 타속·정확도·콤보는 칸 오른쪽에 작게 */
html.is-mobile .console-input {
  position: relative;
  grid-column: 1 / -1;
  grid-row: 2;
  display: block;
}

html.is-mobile .console .typing-input {
  width: 100%;
  height: 38px;
  padding-right: 92px;
  font-size: 18px;
  caret-color: transparent;
}

html.is-mobile .typing-info {
  position: absolute;
  top: 50%;
  right: 6px;
  width: 84px;
  font-size: 9px;
  line-height: 1.2;
  text-align: right;
  transform: translateY(-50%);
  pointer-events: none;
}

html.is-mobile .typing-info .typing-stats {
  white-space: normal;
}

/* 아이콘 한 줄: 물약 4칸 + 캐릭터·능력치·길드·펫 */
html.is-mobile .console-bottom {
  grid-column: 1 / -1;
  grid-row: 3;
  display: flex;
  align-items: stretch;
  gap: 4px;
}

html.is-mobile .console .hotkey-bar,
html.is-mobile .console-menu {
  display: contents;
}

html.is-mobile .hotkey {
  flex: 1 1 0;
  min-width: 0;
}

html.is-mobile .hotkey-bar .slot,
html.is-mobile .hotkey-slot {
  width: 100%;
  height: 40px;
}

html.is-mobile .console-button {
  flex: 1 1 0;
  width: auto;
  min-width: 0;
  height: 40px;
  padding: 1px;
}

html.is-mobile .console-button span {
  font-size: 15px;
  line-height: 1;
}

html.is-mobile .console-button small {
  font-size: 9px;
}

html.is-mobile .console-badge {
  top: -4px;
  right: -2px;
}

/* 게임 두벌식 자판 */
html.is-mobile .game-keyboard {
  position: relative;
  grid-column: 1 / -1;
  grid-row: 4;
  display: grid;
  gap: 5px;
  padding: 5px 0 2px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

html.is-mobile.kb-system .game-keyboard {
  display: none; /* 채팅처럼 시스템 자판을 쓰는 동안 */
}

html.is-mobile .gk-row {
  display: flex;
  justify-content: center;
  gap: 4px;
}

html.is-mobile .gk-row-2 {
  padding: 0 5%;
}

html.is-mobile .gk-key {
  flex: 1 1 0;
  min-width: 0;
  height: 42px;
  padding: 0;
  color: #f4ead6;
  background: linear-gradient(180deg, #3a3026, #241d16);
  border: 1px solid #5c4a30;
  border-radius: 6px;
  box-shadow: 0 2px 0 #0b0806, inset 0 1px 0 rgba(255, 230, 170, 0.12);
  font: 600 19px/1 var(--font-sans);
  touch-action: manipulation;
}

html.is-mobile .gk-key.is-down {
  background: linear-gradient(180deg, #5a4a35, #3a2f22);
  border-color: var(--gold);
  transform: translateY(1px);
  box-shadow: 0 1px 0 #0b0806;
}

html.is-mobile .gk-wide {
  flex: 1.45 1 0;
  color: var(--gold);
  font-size: 17px;
}

html.is-mobile .gk-shift.is-on {
  color: #1b140c;
  background: linear-gradient(180deg, #ffd98a, #c99a3e);
}

/* 화면 바꾸기·기능 키(v4.90): !#1·한/영·가·!@#·123·⌨·.,?!·▶·⌫ */
html.is-mobile .gk-func {
  color: var(--gold);
  font-size: 16px;
}

html.is-mobile .gk-mode {
  flex: 1.15 1 0;
  font-size: 14px;
  letter-spacing: -0.02em;
}
html.is-mobile .gk-space {
  flex: 5 1 0;
  color: var(--text-dim);
  font-size: 13px;
}

html.is-mobile .gk-enter {
  flex: 2.4 1 0;
  color: #1b140c;
  background: linear-gradient(180deg, #ffd98a, #d29b35 60%, #a8741f);
  border-color: #ffdf99;
  font-size: 14px;
  font-weight: 800;
}

/* 누른 키를 위로 크게 */
html.is-mobile .gk-pop {
  position: absolute;
  z-index: 3;
  min-width: 40px;
  padding: 6px 8px;
  color: #fff6e6;
  background: #3d3226;
  border: 1px solid var(--gold);
  border-radius: 8px;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.6);
  font: 700 26px/1 var(--font-sans);
  text-align: center;
  transform: translate(-50%, -105%);
  pointer-events: none;
}

/* ── 필드 축소(v4.81): 필드 묶음(캔버스·단어·말풍선)을 --field-zoom만큼 줄여 더 넓게 본다. 글자는 조금 키워 읽기 쉽게 ── */
html.is-mobile .field-world {
  inset: auto;
  top: 0;
  left: 0;
  width: calc(100% / var(--field-zoom, 1));
  height: calc(100% / var(--field-zoom, 1));
  transform: scale(var(--field-zoom, 1));
  transform-origin: 0 0;
}

html.is-mobile .field-world .unit-word {
  font-size: 23px;
  padding: 2px 9px 3px;
}

html.is-mobile .field-world .unit-bar {
  width: 56px;
  height: 7px;
}

html.is-mobile .field-world .float-text {
  font-size: 24px;
}

html.is-mobile .field-world .chat-bubble {
  font-size: 18px;
}

/* ── 창: 화면을 덮는 시트(보이는 높이 안에서 스크롤) ── */
html.is-mobile .side-column.char-window {
  position: fixed;
  top: var(--app-top, 0px);
  right: 0;
  left: 0;
  z-index: 40;
  width: 100%;
  max-width: none;
  height: var(--app-h, 100dvh);
  max-height: none;
  overflow-y: auto;
  border-radius: 0;
}

html.is-mobile .shop-panel {
  position: fixed;
  top: calc(var(--app-top, 0px) + 6px) !important;
  right: 6px !important;
  bottom: auto !important;
  left: 6px !important;
  z-index: 45;
  width: auto !important;
  max-width: none !important;
  max-height: calc(var(--app-h, 100dvh) - 12px);
  overflow-y: auto;
  transform: none !important;
}

html.is-mobile .confirm-dialog,
html.is-mobile .context-menu {
  z-index: 60;
}

/* ── 가로 화면: 돌려 달라는 안내(세로 고정) ── */
html.is-mobile .rotate-notice {
  display: none;
}

html.is-mobile.is-landscape .rotate-notice {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text);
  background: #0d0b09;
  font: 700 18px var(--font-sans);
  text-align: center;
}

html.is-mobile .rotate-notice span {
  font-size: 54px;
  animation: rotate-hint 1.8s ease-in-out infinite;
}

@keyframes rotate-hint {
  0%, 30% { transform: rotate(90deg); }
  60%, 100% { transform: rotate(0deg); }
}

/* ── 로그인 화면: 키보드가 올라와도 틀이 보이는 높이 안에 ── */
html.is-mobile .login-screen {
  position: fixed;
  top: var(--app-top, 0px);
  height: var(--app-h, 100dvh);
}

/* 휴대폰은 로그인 틀(그림 x 584~1226) 폭에 맞춰 크게 보이고, 틀 가운데(905)·로고~틀(약 y 250~871)을 화면 가운데에 둔다 */
html.is-mobile .login-stage {
  --px: min(100vw / 680, var(--app-h, 100dvh) / 680);
  transform: translate(calc(-50% - var(--px) * 69), calc(-50% - var(--px) * 90));
}

html.is-mobile .login-intro {
  top: 50px;
  right: 8px;
  width: 112px;
}

html.is-mobile .login-intro-play {
  width: 34px;
  height: 34px;
}

html.is-mobile .login-intro-play::after {
  border-top-width: 7px;
  border-bottom-width: 7px;
  border-left-width: 12px;
}

html.is-mobile .login-intro-label {
  font-size: 10px;
}

html.is-mobile .login-music {
  top: 8px;
  right: 8px;
  padding: 4px 9px;
  font-size: 11px;
}

/* ── 모바일 안내(PC 전용 콘텐츠 등) ── */
html.is-mobile .mobile-toast {
  position: fixed;
  top: calc(var(--app-top, 0px) + 60px);
  left: 50%;
  z-index: 70;
  max-width: calc(100% - 32px);
  padding: 10px 14px;
  color: var(--text);
  background: rgba(20, 16, 12, 0.95);
  border: 1px solid var(--gold);
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.6);
  font-size: 14px;
  text-align: center;
  transform: translateX(-50%);
  pointer-events: none;
}

/* ── 무대 자판(v4.82, MO-3): 자리 연습장·콜로세움·월드 보스 무대 아래에 붙는 게임 두벌식 자판(무대 틀 바깥, 화면 아래) ── */
html.is-mobile .stage-keyboard {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 5;
  display: grid;
  gap: 5px;
  padding: 6px 5px calc(6px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(180deg, #221b14, #120e0a);
  border-top: 2px solid #8a7040;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

html.is-mobile .stage-keyboard .gk-key.is-next {
  color: #1b140c;
  background: linear-gradient(180deg, #ffe7a8, #e0a840);
  border-color: #fff0c4;
  box-shadow: 0 0 10px rgba(255, 210, 110, 0.75), 0 2px 0 #0b0806;
}

html.is-mobile .stage-keyboard .gk-key.is-good {
  background: linear-gradient(180deg, #4fbf6a, #2b7a3e);
}

html.is-mobile .stage-keyboard .gk-key.is-bad {
  background: linear-gradient(180deg, #d0504a, #7c2420);
}

/* ── 천지인 자판(v4.83): 4×4 큰 키. ⌨로 두벌식 ↔ 천지인(이 기기에 기억) ── */
html.is-mobile .gk-switch {
  flex: 1 1 0;
  color: var(--gold);
  font-size: 18px;
}

/* 격자 줄(v4.90): 천지인·숫자는 4칸, 기호는 7칸. 키는 칸을 꽉 채워 위아래 줄의 크기·자리가 맞는다 */
html.is-mobile .game-keyboard .gk-grid4,
html.is-mobile .game-keyboard .gk-grid7 {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 5px;
  padding: 0;
}

html.is-mobile .game-keyboard .gk-grid7 {
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
}

html.is-mobile .game-keyboard .gk-span2 {
  grid-column: span 2;
}

/* 한 칸을 둘로(맨 아래 첫 칸 [!#1][한/영], 숫자 화면 [!@#][가]) */
html.is-mobile .game-keyboard .gk-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  min-width: 0;
}

html.is-mobile .game-keyboard .gk-split .gk-key {
  font-size: 12px;
}

html.is-mobile .game-keyboard .gk-grid4 .gk-key,
html.is-mobile .game-keyboard .gk-grid7 .gk-key {
  height: 44px;
}

html.is-mobile .game-keyboard[data-mode='num'] .gk-char {
  font-size: 23px;
}

html.is-mobile .game-keyboard[data-mode='sym'] .gk-char {
  font-size: 19px;
}

html.is-mobile .game-keyboard .gk-cycle {
  font-size: 14px;
  letter-spacing: 0.04em;
}

html.is-mobile .game-keyboard.is-cheonjiin .gk-key {
  height: 44px;
  font-size: 21px;
}

html.is-mobile .game-keyboard.is-cheonjiin .gk-cj-cons {
  letter-spacing: 2px;
}

html.is-mobile .game-keyboard.is-cheonjiin .gk-cj-stroke {
  font-size: 26px;
  font-weight: 800;
}

html.is-mobile .game-keyboard.is-cheonjiin .gk-key.is-pending {
  color: #1b140c;
  background: linear-gradient(180deg, #ffe7a8, #e0a840);
  border-color: #fff0c4;
}

html.is-mobile .game-keyboard.is-cheonjiin .gk-next,
html.is-mobile .game-keyboard.is-cheonjiin .gk-erase {
  color: var(--gold);
  font-size: 19px;
}

html.is-mobile .game-keyboard.is-cheonjiin .gk-split .gk-key {
  font-size: 12px;
}

html.is-mobile .game-keyboard.is-cheonjiin .gk-space {
  font-size: 13px;
}

/* 자음을 친 바로 뒤: 띄어쓰기가 조합만 끝낸다(v5.15) */
html.is-mobile .game-keyboard.is-cheonjiin .gk-space.is-confirm {
  color: #f3d58a;
  box-shadow: inset 0 0 0 1px rgba(243, 213, 138, 0.55);
}

html.is-mobile .game-keyboard.is-cheonjiin .gk-enter {
  font-size: 14px;
}

html.is-mobile .game-keyboard .gk-blank {
  visibility: hidden;
}

/* 캐릭터 선택창(v4.94): 휴대폰 세로는 카드 셋을 한 줄에 작게 */
html.is-mobile .char-select {
  justify-content: flex-start;
  gap: 12px;
  padding: calc(var(--app-top, 0px) + 18px) 8px 18px;
}

html.is-mobile .cs-title {
  font-size: 26px;
}

html.is-mobile .cs-slots {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  width: 100%;
}

html.is-mobile .cs-card {
  height: 268px;
  padding: 8px 4px 10px;
}

html.is-mobile .cs-figure {
  height: 160px;
}

html.is-mobile .cs-figure canvas {
  height: 156px;
}

html.is-mobile .cs-name {
  font-size: 15px;
}

html.is-mobile .cs-meta {
  font-size: 12px;
}

html.is-mobile .cs-empty .cs-plus {
  width: 46px;
  height: 46px;
  font-size: 30px;
}

html.is-mobile .cs-empty strong {
  font-size: 12px;
}

html.is-mobile .cs-button {
  min-width: 0;
  flex: 1 1 30%;
  padding: 10px 6px;
  font-size: 14px;
}

html.is-mobile .cs-zone {
  font-size: 10px;
}

html.is-mobile .cs-button kbd {
  display: none;
}

/* 마을 대장장이(v5.0): 휴대폰에서는 칸을 줄이고 재료 칸을 두 줄로 */
html.is-mobile .smith-forge { flex-wrap: wrap; justify-content: center; gap: 8px; }
html.is-mobile .smith-panel { aspect-ratio: auto; display: flex; }
html.is-mobile .smith-slots { --smith-cell: 50px; gap: 6px; padding: 8px; }
html.is-mobile .smith-result { width: 64px; height: 64px; font-size: 32px; }
html.is-mobile .smith-bag { --smith-cell: 44px; grid-template-columns: repeat(auto-fill, 44px); max-height: 32vh; }

/* v5.0.2 휴대폰 HUD 한 줄: 왼쪽 지역 이름, 오른쪽 위에 소리·목표·랭킹·로그아웃(전원 아이콘)·전체 화면.
   사냥터의 보스 게이지는 지역 이름 아래 둘째 줄 왼쪽. 채팅은 지역 이름 바로 아래(게임 화면을 더 넓게) */
html.is-mobile .hud {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 3px;
  top: 4px;
  left: 4px;
  right: 4px;
  padding: 0;
}
html.is-mobile .hud > .hud-box {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
html.is-mobile .hud-right {
  flex-wrap: nowrap;
  justify-content: flex-end;
  gap: 3px;
}
html.is-mobile .hud-right > .hud-box {
  height: 26px;
}
html.is-mobile .hud-sound {
  gap: 2px;
  padding: 2px 4px;
}
html.is-mobile #boss-gauge-box {
  position: absolute;
  top: 30px;
  left: 0;
}
html.is-mobile .logout-button {
  display: grid;
  place-items: center;
  width: 28px;
  padding: 0;
}
html.is-mobile .logout-button .logout-icon {
  display: block;
}
html.is-mobile .logout-button .logout-text {
  display: none;
}
html.is-mobile .chat-box,
html.is-mobile .raid-card {
  top: 34px; /* 마을: 지역 이름 바로 아래 */
}
html.is-mobile .field:has(#boss-gauge-box:not([hidden])) .chat-box,
html.is-mobile .field:has(#boss-gauge-box:not([hidden])) .raid-card {
  top: 60px; /* 사냥터: 보스 게이지 줄 아래 */
}

/* v5.19 캐릭터 선택창 오른쪽 위 로그아웃: 휴대폰은 전원 아이콘 */
html.is-mobile .char-select .cs-logout {
  top: 6px;
  right: 6px;
  height: 28px;
}
