/* The native frame is preserved on every screen. Web input/zoom helpers are siblings. */
html:has(body.native-ui),
body.native-ui {
  height: 100%;
  min-height: 0;
  overflow: hidden;
}
body.native-ui {
  height: var(--mobile-height, 100dvh);
  display: flex;
  flex-direction: column;
  margin: 0;
}
body.native-ui .page-header {
  display: none !important;
}
body.native-ui main,
body.native-ui.portal-runtime main {
  display: flex;
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: none;
  padding: 0;
  margin: 0;
}
body.native-ui #game,
body.native-ui:not(.portal-runtime) #game {
  display: flex;
  flex: 1;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  max-width: none;
  width: 100%;
  margin: 0;
}
body.native-ui .game-toolbar {
  display: flex !important;
  flex: 0 0 auto;
  min-height: 44px;
  height: 44px;
  padding: 2px 6px;
  gap: 6px;
  overflow-x: auto;
  white-space: nowrap;
}
body.native-ui .game-toolbar .location {
  min-width: 100px;
  flex: 1;
  font-size: 11px;
}
body.native-ui .game-toolbar button,
body.native-ui .game-toolbar select {
  min-height: 38px;
}
body.native-ui #frame-fit {
  position: relative;
  display: flex;
  flex: 1 1 0;
  min-height: 0;
  min-width: 0;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #080b08;
}
body.native-ui #game .game-shell {
  position: relative;
  flex: 0 0 640px;
  width: 640px;
  height: 480px;
  min-height: 480px;
  display: grid;
  grid-template-columns: 640px;
  grid-template-rows: 363px 117px;
  overflow: visible;
}
body.native-ui #game .stage {
  width: 640px;
  height: 363px;
  min-height: 363px;
}
body.native-ui .hud-shell {
  display: block;
  width: 640px;
  height: 117px;
  min-height: 117px;
  padding: 0;
  gap: 0;
}
body.native-ui .hud-left,
body.native-ui #mobile-chat-toggle {
  display: none !important;
}
body.native-ui .hud-shell .native-menu {
  display: block;
  min-height: 0;
  height: 21px;
}
body.native-ui .native-menu button {
  min-width: 0;
  min-height: 0;
  height: 21px;
}
body.native-ui .hud-shell .chat {
  left: 146px;
  right: auto;
  top: 29px;
  bottom: auto;
  width: 330px;
  height: 78px;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  display: block;
  z-index: 1;
  background: #000;
}
body.native-ui .chat ol {
  height: 56px;
  min-height: 0;
  max-height: none;
  overflow: auto;
  border: 0;
  border-radius: 0;
}
body.native-ui .chat form {
  min-height: 0;
  height: 15px;
  left: 10px;
  top: 63px;
  width: 311px;
}
body.native-ui .chat input {
  min-height: 0;
  height: 15px;
  font-size: 12px !important;
}
body.native-ui .chat form button {
  display: none;
}
body.native-ui .drawer.native-panel {
  left: auto;
  right: 0;
  top: 0;
  bottom: auto;
  max-width: none;
  margin: 0;
  z-index: 9;
  overflow: visible;
  border-radius: 0;
  transform: none;
}
body.native-ui .drawer.native-panel .drawer-header {
  min-height: 0;
  height: 13px;
}
body.native-ui .drawer.native-panel .drawer-header h2 {
  margin: 0;
  line-height: 13px;
}
body.native-ui .drawer.native-panel #close-drawer {
  position: absolute;
  right: 0;
  top: 0;
  width: 10px;
  height: 13px;
  min-width: 0;
  min-height: 0;
  padding: 0;
  font-size: 12px;
  line-height: 13px;
  border: 0;
  border-radius: 0;
}
body.native-ui .drawer.native-panel #drawer-content {
  overflow: hidden;
  left: 11px;
  top: 144px;
  width: 160px;
  height: 202px;
}
body.native-ui .original-item-surface,
body.native-ui .original-magic-surface {
  position: relative;
  width: 160px;
  height: 202px;
  padding: 0;
  border: 0;
  background: #000;
}
body.native-ui .original-item-slot,
body.native-ui .original-magic-slot {
  position: absolute;
  display: block;
  min-width: 0;
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 0 !important;
  border-radius: 0;
  background: #000 !important;
  box-shadow: none !important;
  overflow: hidden;
  outline-offset: -1px;
}
body.native-ui .original-item-slot canvas {
  width: 32px !important;
  height: 32px !important;
  margin: 0;
  display: block;
}
body.native-ui .original-magic-slot canvas {
  width: 40px !important;
  height: 40px !important;
  margin: 0;
  display: block;
}
body.native-ui .original-item-count {
  position: absolute;
  right: 0;
  bottom: 0;
  color: #fff;
  font:
    11px Arial,
    sans-serif;
  line-height: 12px;
  text-shadow: 1px 1px #000;
  pointer-events: none;
}
body.native-ui .original-item-slot:disabled,
body.native-ui .original-magic-slot:disabled {
  opacity: 1;
}
body.native-ui .native-profession-button {
  border: 0 !important;
  background: transparent !important;
  border-radius: 0;
  box-shadow: none;
  min-width: 0;
  min-height: 0;
}
body.native-ui .native-stat-value {
  min-width: 0;
  min-height: 0;
  font:
    12px/12px Arial,
    sans-serif;
  color: #fff;
  border: 0 !important;
  box-shadow: none;
  background: #000 !important;
}
body.native-ui .native-character-name {
  pointer-events: none;
}
body.native-ui .native-portrait {
  pointer-events: auto;
  touch-action: none;
  cursor: grab;
}
body.native-ui .quick-skill {
  min-width: 0 !important;
  min-height: 0 !important;
}
body.native-ui .game-footer {
  display: flex;
  flex: 0 0 auto;
  min-height: 48px;
  height: 48px;
  max-height: none;
  gap: 5px;
  padding: 2px 6px;
  overflow-x: auto;
  flex-wrap: nowrap;
  white-space: nowrap;
  background: #10170f;
  border-top: 1px solid #263124;
}
body.native-ui .game-footer button,
body.native-ui .game-footer a {
  flex: 0 0 auto;
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  height: 44px;
  padding: 4px 8px;
  font-size: 12px;
  white-space: nowrap;
}
body.native-ui #progress {
  display: none;
}
body.native-ui #online-count {
  margin-right: auto;
  font-size: 11px;
}
body.native-ui .provenance {
  display: none;
}
.qol-layer {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}
.qol-layer > * {
  pointer-events: auto;
}
body.native-ui .qol-layer .world-overview,
body.native-ui .qol-layer .target-card {
  display: none !important;
}
body.native-ui .qol-layer .toast {
  position: absolute;
  top: 4px;
  left: 50%;
  max-width: min(90%, 500px);
  transform: translateX(-50%);
  width: max-content;
  font-size: 13px;
}
body.native-ui .qol-layer .joystick {
  position: absolute;
  display: none;
  left: max(10px, env(safe-area-inset-left));
  bottom: 10px;
  width: 88px;
  height: 88px;
  transform: none;
}
body.native-ui .qol-layer .joystick span {
  left: 27px;
  top: 27px;
  width: 34px;
  height: 34px;
}
body.native-ui .qol-layer .touch-actions {
  position: absolute;
  display: none;
  right: max(10px, env(safe-area-inset-right));
  bottom: 10px;
  gap: 6px;
  transform: none;
}
body.native-ui .qol-layer .touch-actions button {
  min-width: 54px;
  min-height: 54px;
  width: 56px;
  height: 56px;
  font-size: 12px;
}
body.native-ui .qol-layer #touch-interact {
  width: 62px;
  min-width: 62px;
}
body.native-ui .qol-layer #touch-attack[aria-pressed="true"] {
  font-size: 11px;
  padding: 2px;
  white-space: nowrap;
}
body.native-ui .native-panel-viewport {
  position: absolute;
  inset: 0;
  z-index: 40;
  background: #060906ed;
  overflow: auto;
  padding: 6px;
  overscroll-behavior: contain;
  touch-action: pan-x pan-y;
}
.native-panel-tools {
  position: sticky;
  top: 0;
  z-index: 42;
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
  min-width: 340px;
  height: 48px;
  background: #0a100a;
}
.native-menu-zoom {
  position: relative;
  width: 232px;
  height: 44px;
  background: var(--native-bottom) -1042px -186px/1280px 234px no-repeat;
  flex: none;
}
.native-menu-scroll {
  width: 232px;
  flex: 0 0 auto;
}
.native-panel-scroll {
  position: relative;
}
.native-panel-step {
  display: none;
}
.native-menu-zoom button {
  position: absolute;
  top: 0;
  width: 46px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent !important;
  font-size: 0;
}
.native-zoom-close {
  min-width: 88px;
  min-height: 44px;
  height: 44px;
  font-size: 12px;
}
.native-panel-zoom {
  position: relative;
  width: 360px;
  height: 726px;
  margin: 8px auto;
}
body.native-ui .native-panel-zoom > .drawer.native-panel {
  position: absolute;
  left: 0;
  right: auto;
  top: 0;
  bottom: auto;
  transform: scale(2);
  transform-origin: 0 0;
}
body.native-panel-zoomed .qol-layer {
  display: none;
}
/* A movable viewport around the original FrmAttrib, never a replacement UI. */
body.native-panel-docked .native-panel-viewport {
  display: flex;
  flex-direction: column;
  inset: auto;
  right: var(--native-panel-right, 0px);
  top: var(--native-panel-top, 0px);
  width: var(--native-panel-width, 247.5px);
  height: var(--native-panel-height, 100%);
  padding: 0;
  overflow: hidden;
  background: transparent;
}
body.native-panel-docked .native-panel-tools {
  position: relative;
  flex: 0 0 var(--native-panel-tools-height, 48px);
  height: var(--native-panel-tools-height, 48px);
  min-width: 0;
  gap: 2px;
  justify-content: flex-start;
}
body.native-panel-docked .native-menu-scroll {
  flex: 1 1 auto;
  min-width: 0;
  height: 48px;
  overflow: auto hidden;
  touch-action: pan-x;
}
body.native-panel-docked .native-panel-tools > .native-zoom-close {
  order: -1;
  flex: 0 0 44px;
  min-width: 44px;
  width: 44px;
  padding: 0;
  font-size: 11px;
}
body.native-panel-docked .native-panel-tools > .native-panel-step {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 44px;
  width: 44px;
  min-width: 44px;
  min-height: 44px;
  height: 44px;
  padding: 0;
  font-size: 16px;
}
body.native-panel-docked .native-panel-scroll {
  flex: 1 1 0;
  min-height: 0;
  overflow: hidden auto;
  scrollbar-width: none;
  overscroll-behavior: contain;
  touch-action: pan-x pan-y;
}
body.native-panel-docked .native-panel-scroll::-webkit-scrollbar {
  display: none;
}
body.native-panel-docked
  .native-panel-viewport[data-horizontal="true"]
  .native-panel-scroll {
  overflow-x: auto;
}
body.native-panel-docked .native-panel-zoom {
  width: var(--native-panel-source-width, 247.5px);
  height: var(--native-panel-source-height, 499.125px);
  margin: 0;
}
body.native-ui.native-panel-docked .native-panel-zoom > .drawer.native-panel {
  transform: scale(var(--native-panel-scale, 1.375));
}
body.native-panel-docked .qol-layer .touch-actions {
  display: none;
}
/* NEW_IMPLEMENTATION: a web magnifier around the unchanged FrmBottom nodes. */
body.native-ui .native-hud-viewport {
  position: fixed;
  z-index: 45;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #060906;
}
.native-hud-tools {
  display: flex;
  flex: 0 0 48px;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 2px 6px;
  font-size: 12px;
}
.native-hud-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  touch-action: pan-x pan-y;
}
.native-hud-surface {
  position: relative;
  width: 1280px;
  height: 234px;
}
.native-hud-source {
  position: absolute;
  left: 0;
  top: 0;
  width: 640px;
  height: 117px;
  transform: scale(2);
  transform-origin: 0 0;
  font-family: Arial, "Malgun Gothic", sans-serif;
}
.native-hud-vitals-anchor {
  position: absolute;
  left: 0;
  top: -363px;
  width: 640px;
  height: 117px;
  pointer-events: none;
}
body.native-hud-zoomed .qol-layer {
  display: none;
}
.web-tools {
  max-width: min(500px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  overflow: auto;
  color: #eee;
  background: #151b15;
  border: 1px solid #68715a;
  padding: 18px;
  box-sizing: border-box;
}
.web-tools::backdrop {
  background: #000a;
}
.web-tools h2 {
  margin: 0 70px 18px 0;
  font-size: 18px;
}
.web-tools > button {
  position: absolute;
  right: 8px;
  top: 8px;
  min-width: 52px;
  min-height: 44px;
}
.web-tools .setting-row {
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.web-tools input {
  min-height: 44px;
  max-width: 100%;
}
.web-tools form {
  display: grid;
  gap: 10px;
}
@media (max-width: 950px), (pointer: coarse) {
  body.native-ui .qol-layer .joystick {
    display: block;
  }
  body.native-ui .qol-layer .touch-actions {
    display: flex;
  }
  body.native-ui #coordinates,
  body.native-ui #connection {
    display: none;
  }
  body.native-ui .game-toolbar .location {
    min-width: 80px;
    font-size: 10px;
  }
  body.native-ui .game-toolbar .compact-label {
    font-size: 10px;
  }
  body.native-ui .game-toolbar select {
    font-size: 12px !important;
    min-height: 38px;
    max-width: 80px;
  }
  body.native-ui .game-footer {
    padding-bottom: max(2px, env(safe-area-inset-bottom));
    height: calc(48px + env(safe-area-inset-bottom));
  }
  body.native-ui #online-count {
    display: none;
  }
}

/* Preserve hidden state and native control typography after mobile web helpers. */
body.native-ui #game [hidden] {
  display: none !important;
}
body.native-ui .game-toolbar {
  height: 48px;
  min-height: 48px;
  overflow-y: hidden;
}
body.native-ui .game-toolbar button,
body.native-ui .game-toolbar select {
  min-height: 44px;
  height: 44px;
}
body.native-ui #online-count {
  flex: 0 0 auto;
}
body.native-ui .native-character-select input {
  font-size: 12px !important;
  min-height: 0;
}
body.native-ui .native-character-select select {
  font-size: 12px !important;
  min-height: 0;
}

@media (max-width: 650px) and (orientation: landscape) {
  body.native-ui .qol-layer .touch-actions {
    flex-direction: column;
    gap: 4px;
  }
  body.native-ui .qol-layer .touch-actions button {
    height: 48px;
    min-height: 44px;
    width: 56px;
  }
}

body.native-ui .original-item-slot[draggable="true"],
body.native-ui .original-magic-slot[draggable="true"] {
  touch-action: none;
}

/* Phone convenience: expand terrain, retain every native form coordinate.
   Never stretch/crop the 640x480 HUD to fit a wide or tall phone. */
#mobile-screen-tools,
#mobile-screen-fit {
  display: none;
}
@media (max-width: 950px), (max-width: 1100px) and (max-height: 600px) {
  body.native-ui #mobile-screen-fit {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    font-size: 12px;
    min-width: 96px;
    order: -1;
  }
}
body.native-ui.mobile-screen-fill #frame-fit {
  box-sizing: border-box;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px)
    env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
}
body.native-ui.mobile-screen-fill #game .game-shell {
  position: absolute;
  left: var(--mobile-shell-center, 50%);
  bottom: var(--mobile-safe-bottom, 0px);
  flex: none;
  transform: translateX(-50%) scale(var(--native-scale, 1));
  transform-origin: center bottom;
}
body.native-ui.mobile-screen-fill #game .stage {
  z-index: auto;
  isolation: auto;
}
body.native-ui.mobile-screen-fill #world {
  position: absolute;
  z-index: 0;
  left: var(--mobile-world-left, 0px);
  top: var(--mobile-world-top, 0px);
  width: var(--mobile-world-width, 640px);
  height: var(--mobile-world-height, 363px);
  max-width: none;
  max-height: none;
}
body.native-ui.mobile-screen-fill .loading {
  inset: auto;
  left: var(--mobile-world-left, 0px);
  top: var(--mobile-world-top, 0px);
  width: var(--mobile-world-width, 640px);
  height: var(--mobile-world-height, 363px);
}
body.native-ui.mobile-screen-fill .hud-shell {
  z-index: 1;
}
body.native-ui.mobile-screen-fill .game-toolbar,
body.native-ui.mobile-screen-fill .game-footer {
  display: none !important;
  position: fixed;
  left: max(4px, env(safe-area-inset-left, 0px));
  right: max(4px, env(safe-area-inset-right, 0px));
  width: auto;
  z-index: 115;
  min-height: 48px;
  height: 48px;
  padding: 2px 4px;
  flex-wrap: nowrap;
  overflow: auto hidden;
  border: 1px solid #887247;
}
body.native-ui.mobile-screen-fill .game-toolbar {
  top: calc(54px + env(safe-area-inset-top, 0px));
}
body.native-ui.mobile-screen-fill .game-footer {
  bottom: max(4px, env(safe-area-inset-bottom, 0px));
}
body.native-ui.mobile-screen-fill.mobile-screen-tools-open .game-toolbar,
body.native-ui.mobile-screen-fill.mobile-screen-tools-open .game-footer {
  display: flex !important;
}
body.native-ui.mobile-screen-fill .game-toolbar .location,
body.native-ui.mobile-screen-fill .game-toolbar #connection,
body.native-ui.mobile-screen-fill .game-toolbar #help-button {
  display: none;
}
body.native-ui.mobile-screen-fill #fullscreen {
  order: -2;
  flex: 0 0 auto;
}
body.native-ui.mobile-screen-fill #mobile-screen-tools {
  display: block;
  position: fixed;
  z-index: 110;
  left: calc(
    (100% + env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)) /
      2
  );
  transform: translateX(-50%);
  top: max(4px, env(safe-area-inset-top, 0px));
  min-height: 44px;
  min-width: 52px;
  padding: 2px 4px;
  font-size: 7.8px;
  touch-action: manipulation;
}
body.native-ui.mobile-screen-fill .qol-layer .joystick,
body.native-ui.mobile-screen-fill .qol-layer .touch-actions {
  bottom: calc(
    var(--mobile-hud-height, 100px) + 10px + env(safe-area-inset-bottom, 0px)
  );
}
body.native-panel-zoomed #mobile-screen-tools,
body.native-panel-docked #mobile-screen-tools,
body.native-hud-zoomed #mobile-screen-tools,
body.mobile-screen-fill:has(.cheonnyeon-guidance:not([hidden]))
  #mobile-screen-tools {
  display: none !important;
}
